11.08.2009, 11:11
I've had far too many people who are wondering why their server lags or gets killed for excessive resources, even blaming our servers for it.
The callback OnPlayerUpdate gets called about 20 to 30 times per player per second, this means about 3000 times a second for 100 players.
Some people do a lot of things in this script, such as save stats, update objects or check for cheats.
Someone even looped into the OnPlayerUpdate past all his 125 players, something like:
This came down to 468750 writes to a file per second.
There are exceptions
You can use the callback for things like anti cheat or to detect idlers, but only if you're an experienced scripter.
Please sanitize and review all code, especially in OnPlayerUpdate, and tune them a lot for performance.
But for all other uses
Revert to alternatives, such as timers and other callbacks.
The callback OnPlayerUpdate gets called about 20 to 30 times per player per second, this means about 3000 times a second for 100 players.
Some people do a lot of things in this script, such as save stats, update objects or check for cheats.
Someone even looped into the OnPlayerUpdate past all his 125 players, something like:
Код:
OnPlayerUpdate(playerid){ for(new i = 0; i < MAX_PLAYERS; i++){ if(IsPlayerConnected(i)){ new File:pos=fopen("players.txt", io_append); format(string, 256, "Admin=%d", level); format(string, 256, "Position=%d", position); format(string, 256, "Money=%d", money); fwrite(pos, string); fclose(pos); } } }
There are exceptions
You can use the callback for things like anti cheat or to detect idlers, but only if you're an experienced scripter.
Please sanitize and review all code, especially in OnPlayerUpdate, and tune them a lot for performance.
But for all other uses
Revert to alternatives, such as timers and other callbacks.