SA-MP Forums Archive
Player Pause - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Player Pause (/showthread.php?tid=268602)



Player Pause - Abreezy - 13.07.2011

I decided to return to scripting, and work on my script from scratch, The problem is I was planning to use the OnPlayerPause include, but the topic was removed for some reason, may someone give me a direct link for it, thank you very much in advance.



Re: Player Pause - cessil - 13.07.2011

you could just make your own, set a variable under onplayerupdate and run a one second timer to decrease that variable.
since onplayerupdate isn't called when a player is paused the variable would only go down if they were paused


Re: Player Pause - Joe Staff - 13.07.2011

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();
}