Is this a good idea?
#1

So I want OnPlayerUpdate to get called only ONCE per second and NOT when the player is AFK.
I know it gets called very often, but who cares? It will only continue the rest if g_switch is true, right?

This is what i did: (lol)

pawn Код:
#include <a_samp>

new bool:g_switch[MAX_PLAYERS];

public OnFilterScriptInit()
{
    SetTimer("SwitchVar", 1000, true);
    return true;
}

forward SwitchVar();
public SwitchVar()
{
    for(new i=0; i<MAX_PLAYERS; i++) //I don't wanna use foreach for this. :)
    if(IsPlayerConnected(i) && !IsPlayerNPC(i)) g_switch[i] = true;
    return true;
}

public OnPlayerUpdate(playerid)
{
    if(g_switch[playerid])
    {
        SendClientMessage(playerid, -1, "Update/sec..");
    }
   
    g_switch[playerid] = false;
    return true;
}
Seems to work JUST FINE. The way I want it to. And my functions work without any bug.

The question is: Is there a better way to do it?

Reply ONLY if you understand or else ignore it.

PS: Don't tell me to rename OnPlayerUpdate and use a timer+loop.
Reply


Messages In This Thread
Is this a good idea? - by iPLEOMAX - 17.09.2011, 19:17
Re: Is this a good idea? - by TheArcher - 17.09.2011, 19:18
Re: Is this a good idea? - by wouter0100 - 17.09.2011, 19:21
Re: Is this a good idea? - by iPLEOMAX - 17.09.2011, 19:22
Re: Is this a good idea? - by TheArcher - 17.09.2011, 19:24
Re: Is this a good idea? - by iPLEOMAX - 17.09.2011, 19:27
Re: Is this a good idea? - by wouter0100 - 17.09.2011, 19:28
Re: Is this a good idea? - by iPLEOMAX - 17.09.2011, 19:30
Re: Is this a good idea? - by wouter0100 - 17.09.2011, 19:31
Re: Is this a good idea? - by TheArcher - 17.09.2011, 19:32

Forum Jump:


Users browsing this thread: 5 Guest(s)