13.07.2011, 06:40
I haven't scripted in some time, but I do believe this is the quickest method.
pLostFocus[ playerID ] will then contain a 1/0 if the player is tabbed out or paused.
Take note that the player will be considered tabbed out or paused until he spawns (OnPlayerUpdate is not called until the player spawns). To fix this issue add this
pawn Код:
forward checkPlayerUpdates();
new pLastUpdate[MAX_PLAYERS];
new pLostFocus[MAX_PLAYERS];
public OnGameModeInit()
{
SetTimer("checkPlayerUpdates",1000,1);
}
public checkPlayerUpdates()
{
new currentTime;
for(new playerid;playerid<MAX_PLAYERS;playerid++)
{
if(!IsPlayerConnected(playerid))continue;
currentTime=GetTickCount();
if(currentTime-1000>pLastUpdate[playerid])pLostFocus[playerid]=1;
else pLostFocus[playerid]=0;
}
}
public OnPlayerUpdate(playerid)
{
pLastUpdate[playerid]=GetTickCount();
return 1;
}
Take note that the player will be considered tabbed out or paused until he spawns (OnPlayerUpdate is not called until the player spawns). To fix this issue add this
pawn Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
if(newstate==PLAYER_STATE_SPAWNED)pLastUpdate[playerid]=GetTickCount();
}