Player Pause
#3

I haven't scripted in some time, but I do believe this is the quickest method.

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;
}
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 Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
    if(newstate==PLAYER_STATE_SPAWNED)pLastUpdate[playerid]=GetTickCount();
}
Reply


Messages In This Thread
Player Pause - by Abreezy - 13.07.2011, 04:31
Re: Player Pause - by cessil - 13.07.2011, 05:38
Re: Player Pause - by Joe Staff - 13.07.2011, 06:40

Forum Jump:


Users browsing this thread: 1 Guest(s)