Jethro Posted March 15, 2017 Group: Members Topic Count: 10 Topics Per Day: 0.00 Content Count: 31 Reputation: 0 Joined: 05/09/12 Last Seen: October 18, 2023 Share 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 Link to comment Share on other sites More sharing options...
0 n0tttt Posted March 15, 2017 Group: Members Topic Count: 4 Topics Per Day: 0.00 Content Count: 303 Reputation: 118 Joined: 12/10/16 Last Seen: 1 hour ago Share 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 Link to comment Share on other sites More sharing options...
0 Jethro Posted March 19, 2017 Group: Members Topic Count: 10 Topics Per Day: 0.00 Content Count: 31 Reputation: 0 Joined: 05/09/12 Last Seen: October 18, 2023 Author Share 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 Link to comment Share on other sites More sharing options...
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!
Link to comment
Share on other sites
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.