Timer vs OnPlayerUpdate
#1

Hey ppl,
There is this question that is kinda stuck in my head and I can't really decide/findout which one is better
in general, for checks with a repetition of around ~1 sec, which one is more efficient ? checkin with OnPlayerUpdate and maybe using a timestamp variable to stop the madness of 30 updates a sec or timers ?

Examples of usage in question:
1- Speedometer
2- Usual hack checks (money/health/armour etc.)
3-Not totally related but: the SetPlayerCameraPos on OnPlayerConnect solution ?
4-Looking for a car crash
etc.

At this very moment I'm looking at a couple speedometers released on forums and some use timers, some use onplayerupdate, not sure which way I should go, all those experienced enough would love to hear your answers or even better, new suggestions on a 3rd option.
Reply
#2

You should only use OnPlayerUpdate to create custom callbacks as demonstrated on the wiki page (OnPlayerHealthChange, OnPlayerArmourChange, OnPlayerWeaponChange, ...).

The function is not intended to fulfill the role of a general purpose timer. Things like speedometers should not be placed in OnPlayerUpdate; I would reckon that the minimum update interval for speedometers is around 300 milliseconds, (about the time it takes to blink). OnPlayerUpdate is called on average every 30 milliseconds, which is way faster than strictly necessary.
Reply
#3

I see, although there is always another question xD Do these custom callbacks we make for lets say for an anti-cheat worth it resource-wise ? how much pressure a normal HealthChange callback puts on CPU (doubt there is any ram pressure since we don't use much variables)
Reply
#4

OnPlayerUpdate is called almost 90 times per second, it should be used only for anti cheat purposes. It may kill the server if it's used incorrectly. A timer will be more efficient to make things like speedometers or more.

I'll give you some examples of what you could use OnPlayerUpdate.
pawn Код:
public OnPlayerUpdate(playerid)
{
      SendClientMessage(playerid, 0x33CC33FF, "SPAM");//This will spam the chat box. Don't do it.
      GameTextForPlayer(playerid, "SPAM", 3000, 4);//This will make a gametext stay forever. Don't do it
      ...//You can have more ideas, BUT, it can be used for anti cheating purposes.. example:
    if(GetPlayerWeapon(playerid) == 38 && !IsPlayerAdmin(playerid))//Anti minigun
    {
        new msg[128], pname[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pname, sizeof(pname));
        format(msg, sizeof(msg), "%s (%i) was banned for using cheats.", pname, playerid);
        BanEx(playerid, msg);
    }

      return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)