Little problem with detecting if a player is paused
#1

I saw a post saying if a player is paused, the function Onplayerupdate isnt called. So based on that i made this..

Quote:

forward PauseCheck();
public PauseCheck()
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(OnPlayerUpdate(i) == 0)
{
new Float:X, Float:Y, Float:Z;
GetPlayerPos(i, X, Y, Z );
playertextid = CreatePlayer3DTextLabel(i,"PAUSED",0xE60000FF,X,Y, Z,999);
print("/n Someone is Paused");
}
if(OnPlayerUpdate(i) == 1)
{
DeletePlayer3DTextLabel(i, playertextid);
}
}
return 1;
}

I added the
Quote:

print("/n Someone is Paused");

line so i could see if it worked or not while i tested it. Yet the line "Someone is paused" did not come up on the server screen like every other "Print" does.

It compiles no problem, just doesnt seem to actually work.
Is anyone able to help me out with this problem? Any help would be highly appreciated.
Reply
#2

That's not how it works. OnPlayerUpdate just isn't called at all, when a player is alt-tabbed. The only way you can detect if a player is alt-tabbed is to see if OnPlayerUpdate is NOT being called (for example, you could use a timer to get the tick count of the server, and an older version, if the older version isn't somewhat equal to what the check is, then they're alt-tabbed).
Reply
#3

I was just searching for detect pause thing.

I just thought about this:

pawn Код:
public OnPlayerConnect(playerid)
{

  SetPVarInt(playerid, "pause", 0);
  SetTimerEx("Paused", 1000, 1, "i", playerid);
  //ofc could be given an ID to be killed on exit or on gamemode exit, but i'm just making an example
  return 1;
}

public OnPlayerUpdate(playerid)
{
  SetPVarInt(playerid, "pause", 0);
  return 1;
}

forward Paused(playerid);
public Paused(playerid)
{
  if( GetPVarInt(playerid, "pause") != 0 ) printf("%i is paused", playerid);
  SetPVarInt(playerid, "pause", 1);
  return 1;
}
A pretty basic example, what do you guys think ? I think it works just fine .
Reply
#4

I posted this about a week ago, it's probably the simplest way of detecting if a player is paused.

pawn Код:
new lastupdate[MAX_PLAYERS];
public OnPlayerUpdate(playerid) {
  lastupdate[playerid] = GetTickCount();
  return 1;
}
Then to check if they're paused, use:
pawn Код:
if(GetTickCount() > (lastupdate[playerid]+2000))
You can also define it like this, to have a simple function to use:
pawn Код:
#define IsPlayerPaused(%1) GetTickCount() > (lastupdate[%1]+2000)
You could also change the 2000 to something lower or higher.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)