#include <a_samp>
//UPDATE_TIME is the time interval to check if player is paused or not.
#define UPDATE_TIME 2000
//PauseTimerr is timer for each player.
new PauseTimer[MAX_PLAYERS];
//To check if player was paused earlier .
new bool:Paused[MAX_PLAYERS];
//This is your 3D Text Label
new Text3D:PauseText[MAX_PLAYERS];
public OnPlayerSpawn(playerid)
{
PauseTimer[playerid] = SetTimerEx("Pause_Check",UPDATE_TIME,true,"i",playerid);
//When a player spawn we start a timer which repeats itself after UPDATE_TIME (2000 ms)
return 1;
}
forward Pause_Check(playerid);
public Pause_Check(playerid)
{
new Float:x,Float:y,Float:z,Float:a;//Get Player Location and facing Angle.
GetPlayerPos(playerid,x,y,z);
GetPlayerFacingAngle(playerid,a);
//If player's location is same as it was before UPDATE_TIME (2000 ms)
if(x == GetPVarFloat(playerid,"x") && y == GetPVarFloat(playerid,"y") && z == GetPVarFloat(playerid,"z") && a == GetPVarFloat(playerid,"a"))
{
if (Paused[playerid] == false)//If he was not paused before 2 sec
{
//Create a 3D Text label .
PauseText[playerid] = Create3DTextLabel("Paused", -1, x, y,z+1.5,100, GetPlayerVirtualWorld(playerid), 0);
}
//We now know he have paused.
//This will take sure that we do not create multiple 3D text labels.
Paused[playerid] = true;
}
//If he have moved/updated
else
{
if (Paused[playerid] == true)//If he was paused before 2 sec.
{
Delete3DTextLabel(PauseText[playerid]);//We will delete the Label we created when he paused.
}
//And make him un pause.
Paused[playerid] = false;
}
//Setting Player varibles.
SetPVarFloat(playerid,"x",x);
SetPVarFloat(playerid,"y",y);
SetPVarFloat(playerid,"z",z);
SetPVarFloat(playerid,"a",a);
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
KillTimer(PauseTimer[playerid]);
return 1;
}
I will show you a VERY BASIC pause system.
BUG : If you do not move for UPDATE_TIME , it will treat you as a paused player. |