Jump to content
  • 0

Optimization of OnPCLoadMapEvent


Question

Posted
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!

2 answers to this question

Recommended Posts

  • 0
Posted

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;
}

 

  • 0
Posted
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

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...