Jethro Posted March 15, 2017 Posted March 15, 2017 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! Quote
0 n0tttt Posted March 15, 2017 Posted March 15, 2017 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; } Quote
0 Jethro Posted March 19, 2017 Author Posted March 19, 2017 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 Quote
Question
Jethro
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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.