Yeah I am aware how in general wiki systems work however this can become very quickly messy so I wondered whether there is some sort of higher instance.
Let me take the OnPlayerUpdate entry (
https://sampwiki.blast.hk/wiki/OnPlayerUpdate) as an example:
OnPlayerUpdate, as the warning already forshadows, gets called very frequently
per second per player. Now OnPlayerUpdate is at the same time great for small anti cheat systems - such as detecting whether someone suddenly has a blacklisted gun - however as you can read as well on the forums, it shall be only used if you know what you are doing.
Let's take a look at the first example being made:
Quote:
Example: Make your own callback - OnPlayerChangeWeapon(playerid, oldweapon, newweapon)
|
Already starts of badly in the first line:
Quote:
public OnPlayerUpdate(playerid)
{
new iCurWeap = GetPlayerWeapon(playerid); // Return the player's current weapon
|
Using this example in your code, each time OnPlayerUpdate gets called a new variable eating up 32bit of memory gets declared. Each of those 32bit are being used until your server is closed/restarted as PAWN uses static memory allocation, no dynamic during runtime - they never the freed until then.
It goes further two lines below when the example function OnPlayerChangeWeapon gets called. 3 parameters are being passed, another 3*32bit. However this is not the real problem.
The worst few lines in this example are in OnPlayerChangeWeapon when two Strings of 24 cells each (2*24*32bit) and one string of 128 cells get declared.
You can imagine that players on your server will scroll through their weapons pretty often. Each time they do, in total
5760 bit / 720 byte memory is being used.
This can be easily avoided by either using globals in a clever way or not using OnPlayerUpdate for complex systems - it's not supposed to be used for that anyways.
On the long run and if you have a greater, far-developed script with lots of players you'll definitely have problems.