17.09.2011, 19:17
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)
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.
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;
}
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.