Regarding OnPlayerUpdate
#1

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:

Код:
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);
		}
	}
}
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.
Reply
#2

They are just noobs who can't script, you should suspend there servers duing using too mutch CPU/Ram or lagging other server who have good scripts.

They could also read http://forum.sa-mp.com/index.php?topic=79810.0 which i don't think they understand duing leak of script experience.
Reply
#3

Yeah, but to be honest it's easy to create a "minor" onplayerupdate, basically under every other callback call tghe callback"OnPlayerMinorUpdate" (Custom callback) that way it's more efficient than having a timer it's just there are ways of avoiding the callback.
Reply
#4

Quote:
Originally Posted by [NL
WackoX ]
They are just noobs who can't script, you should suspend there servers duing using too mutch CPU/Ram or lagging other server who have good scripts.

They could also read http://forum.sa-mp.com/index.php?topic=79810.0 which i don't think they understand duing leak of script experience.
Why would you think they're noobs? Some people just don't know how to use it as it's a new function.
Reply
#5

Basically it's a tick function. That's how I see it anyway.
Reply
#6

Quote:
Originally Posted by [NL
WackoX ]
They are just noobs who can't script, you should suspend there servers duing using too mutch CPU/Ram or lagging other server who have good scripts.

They could also read http://forum.sa-mp.com/index.php?topic=79810.0 which i don't think they understand duing leak of script experience.
In time when new scripter get used and noing how it work's then they wont make this mistake so theres no need to call peopl noobs as they may not no as when 0.3 there will be new function's and you wont no them all so people could you a noob?
Reply
#7

Hmm, well I know right now I use a lot of timers, some as low as milliseconds, so your telling me keep the buggy timers (sorry but Timer sync is terrible). Instead of having a variable count up to a certain number in OnPlayerUpdate then execute whatever callback was normally called by that timer?

I have played with OnPlayerUpdate and heavy maths or file writes before it returns does cause major desync, but what about using the method I described?

I think instead of telling people what not to do, it would be better to have a more in depth tutorial on HOW TO USE it, because so far with my tests I have been able to get rid of at least 4 or 5 SetTimers and loops. I have yet been able to test on a massive scale only a few people so which method is better?
Reply
#8

Quote:
Originally Posted by /^We(stie|z+[e|a
r)$/ ]
Basically it's a tick function. That's how I see it anyway.
Quote:
Originally Posted by cyber_punk
in depth tutorial on HOW TO USE it,
Westie's right and it should be used as a tick function. Do your script updates after "x" amount of updates, so for example:

pawn Код:
new g_PlayerTick[ MAX_PLAYERS ] = { 999, 999, ... }; // Create an array of ticks for each player and set them ALL to 999.

public OnPlayerUpdate( playerid )
{
  g_PlayerTick[ playerid ] --; // Decrease player ticks for the updating player by one on every update.

  if ( !g_PlayerTick[ playerid ] ) // If the players ticks for the updating player are equal to 0 then we can execute what function we wish to...
  {
    BanEx( playerid, "Using my bandwidthz" ); // Banning the updating player for using your bandwidth

    g_PlayerTick[ playerid ] = 999; // Reset the tick counter for the updating player to the original number once the ticks have run out. This allows us to start counting down again
  }
}
This code* will ban a player after 999 updates and then reset the tick counter so it will start again.

Use multiple tick counters for best effect, it will help balance the CPU load. So what I mean is don't try to run lots of code under one tick updater, try to use multiple tick updaters so you don't get a huge load at one time.

*code not tested, but should work. It serves as a logical explanation, not necessarily a working one..

Hope this helps.
Reply
#9

Nice Job, And Good Explaining ;0!
Reply
#10

Yup that's what I started doing Simon, using a variable to count every call to OnPlayerUpdate then run said function at a certain number while also clearing the variable. While doing so I realized it makes it a lot easier to balance what will execute where at least imo.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)