Jump to content
  • 0

Optimization of OnPCLoadMapEvent


Jethro

Question


  • Group:  Members
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  31
  • Reputation:   0
  • Joined:  05/09/12
  • Last Seen:  

setarray .maptrigger$,
		"guild_vs1",
		"guild_vs2",
		"guild_vs3",
		"guild_vs4",
		"guild_vs5";

OnPCLoadMapEvent:
	getmapxy .@map$, .@x, .@y, 0;
	for ( set .@i, 0; .@i < .maptriggersize; set .@i, .@i +1 ) {
		if ( .@map$ == .maptrigger$[.@i] ) break;
	}
	if ( .@i == .maptriggersize ) end;
	end;
}

OR WITHOUT LOOP

setarray .maptrigger$,
		"guild_vs1",
		"guild_vs2",
		"guild_vs3",
		"guild_vs4",
		"guild_vs5";

OnPCLoadMapEvent:
		getmapxy @map$,@x,@y,0;
		if (countstr(@map$, "guild_vs", 0)) {
			// .....
		}
	end;

1) how do i test which is optimized? in microseconds?

2) is there really much that difference between the two approach?

3) do we have in_array function like in PHP? http://php.net/manual/en/function.in-array.php

 

Thanks!

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  303
  • Reputation:   117
  • Joined:  12/10/16
  • Last Seen:  

To test the fastest you have to do this.

 

	.@start=gettimetick(0);
	<here your code>
	.@time=gettimetick(0)-.@start;
    announce "It took "+.@time+" miliseconds.",bc_self;

The best approach is the second one, since it doesn't need to loop through a list and just checks the mapname. You don't need OnInit in that case because you have only 1 check (is it a guild_vsx map?). You could optimize it even more with strcharinfo(3) instead of using getmapxy.

If you want different maps and not a list which shares a common word in the name, you might use this:
 

OnInit:
	setarray .@maps$[0],"prontera","aldebaran","prt_fild05","geffen","custommap";
	for(.@size=getarraysize(.@maps$);.@i.<.@size;.@i++)
		if(getmapusers(.@maps$[.@i])!=-1)
			setd ".map"+.@maps$[.@i],1;
	end;

OnPCLoadMapEvent:
	if(getd(".map"+strcharinfo(3))){
		...
	}
	end;
}

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  31
  • Reputation:   0
  • Joined:  05/09/12
  • Last Seen:  

Quote

OnInit will execute every time the scripts loading is complete

OnPCLoadMapEvent will never trigger if the map has no players in it before the script was loaded
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...