OnPlayerUpdate Can I use this code?
#1

so, I never used OnPlayerUpdate, but will this code lag it or is it small enough?

pawn Код:
public OnPlayerUpdate(playerid)
{
    if(iscracked[playerid] == 0)
    {
        new Float:h;
        GetPlayerHealth(playerid, h);
        if(h < 11)
        {
            new Float:u, Float:u2, Float:u3;
            GetPlayerPos(playerid, u, u2, u3);
            iscracked[playerid] = 1;
            TogglePlayerControllable(id, 0);
            ApplyAnimation(playerid, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 0, 0); // Dieing of Crack
            SetTimerEx("uncrack", 240000, false, "i", playerid);
            CrackLabel[playerid] = Create3DTextLabel("Injured", COLOR_BLUE, u, u2, u3 + 2, 10, 0);
        }
    }
    return 1;
}
Reply
#2

Yeah, the only thing you really want to avoid is large calculations, or time consuming functions.
Reply
#3

the code wont lag even if it's 1000 lines long, if it's well written, so there's no reason to ask will this code lag because of this amount of code.
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
Have you TESTED it? If you run your server on a 386 then it will probably lag. If you run your server on Jaguar then it probably won't lag. Why should we know? We aren't your server!
It's more that I mean, I heared a lot about OnPlayerUpdate lagging servers with complicated code etc.
And I have a decent server.

But I don't think this is a big/complicated code, just wasn't sure.
Reply
#5

calling the timer at each frame will cause lag/high CPU usage. move the cracked code to OnPlayerStateChange or OnPlayerKeyStateChange - pay attention to the SetTimer, it seems it will get called too often.
the actual miniscript in OnPlayerUpdate() wont cause lag, its really small.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)