SA-MP Forums Archive
Best way to optimize (i < MAX_PLAYERS ) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Best way to optimize (i < MAX_PLAYERS ) (/showthread.php?tid=598206)



Best way to optimize (i < MAX_PLAYERS ) - iulicxd - 09.01.2016

Hello all,
I know that existing more ways to optimize server for playerids
but which is best?
1)Foreach
2):
Код:
#define MAX_PLAYERS 100
for(new i = 0; i < MAX_PLAYERS; i++)
3)
Код:
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
4)
Код:
for(new i = 0; i < GetMaxPlayers(); i++)
Please help me


Re: Best way to optimize (i < MAX_PLAYERS ) - lucamsx - 09.01.2016

i've seen some people doing something like that - but im almost sure this isnt the best way to do this:
Код:
#define SLOTS 50
#undef MAX_PLAYERS
#define MAX_PLAYERS SLOTS



Re: Best way to optimize (i < MAX_PLAYERS ) - Akbaig - 09.01.2016

I use both:

1. Foreach

2. for(new i = 0; i < MAX_PLAYERS; i++) (FOR loop)

So actually, its your choice. (I guess both works almost same)


Re: Best way to optimize (i < MAX_PLAYERS ) - ikey07 - 09.01.2016

Use foreach where possible, all other methods you showed would loop abit longer than foreach.


lets say you have 2 players on your server with id 1 and id 9,
MAX_PLAYERS would go to 0-100
GetPlayerPoolSize would go to 0-9
GetMaxPlayers would also go from 0-100

while foreach would go 0-1


Re: Best way to optimize (i < MAX_PLAYERS ) - Vince - 09.01.2016

Redefining MAX_PLAYERS is a good way to start. I reckon that a plain player loop would be faster than foreach if the server is full or nearly full all the time because there is no additional processing overhead from foreach in that case. But if your server isn't always full then foreach is probably the way to go. The poolsize loop is a viable alternative if you do not want to use foreach.


Re: Best way to optimize (i < MAX_PLAYERS ) - AbyssMorgan - 10.01.2016

Use
PHP код:
 for(new 0GetPlayerPoolSize(); <= ji++) 



Re: Best way to optimize (i < MAX_PLAYERS ) - Mencent - 10.01.2016

Hello!

GetPlayerPoolSize ist a good method, but redefining MAX_PLAYERS is also a good way.
PHP код:
#undef MAX_PLAYERS
#define MAX_PLAYERS 100 
If you use redefining MAX_PLAYERS, you should do it like this way (look to the code). With this code MAX_PLAYERS will be 100.