How to detect if player is in menu/tabbed ? -
Phil_Cutcliffe - 03.02.2014
I have one problem with my gang capture zones. When a player is in the menu or tabbed out of the game they can remain in the checkpoint and capture the zone. How can I detect if they are in the menu or tabbed out - How can I prevent this? Any examples would be great! I've been scripting my GM for nearly 2 years and I can't remember whether I put in an AFK system but I'm pretty sure I didn't and this is the standard thing with SA-MP.
Would it be PLAYER_STATE_NONE?
Re: How to detect if player is in menu/tabbed ? -
Lordzy - 03.02.2014
It's simple - OnPlayerUpdate callback don't get called when the player is paused. So you could calculate whether player is AFK or not by running a timer and checking if OnPlayerUpdate was called or not at that interval and declare whether the player was AFK or not.
Re: How to detect if player is in menu/tabbed ? -
Phil_Cutcliffe - 03.02.2014
Ahhh I see. Any chance of an example?
EDIT: Not to worry my brain is alive again I know what to do... I've been having too many brain farts lately but thankyou very much for your help.
Re: How to detect if player is in menu/tabbed ? -
Lordzy - 03.02.2014
Quote:
Originally Posted by Phil_Cutcliffe
Ahhh I see. Any chance of an example?
|
Here's my AutoAFK detector which has been created as an include for my personal use a long time ago. However, I've just added it on GitHub now and you can use it in case if you want.
https://github.com/Lordzy/AutoAFK
You can use either the callbacks -
OnPlayerPause and
OnPlayerResume or
IsPlayerPaused function which would return true if paused and false if not paused.
There might be better AFK detectors, I used this for my personal use before. It works well though.
Re: How to detect if player is in menu/tabbed ? -
Phil_Cutcliffe - 03.02.2014
Quote:
Originally Posted by Lordz™
Here's my AutoAFK detector which has been created as an include for my personal use a long time ago. However, I've just added it on GitHub now and you can use it in case if you want.
https://github.com/Lordzy/AutoAFK
You can use either the callbacks - OnPlayerPause and OnPlayerResume or IsPlayerPaused function which would return true if paused and false if not paused.
There might be better AFK detectors, I used this for my personal use before. It works well though.
|
Thanks all I've done is just simple added a timer to detect if that players onupdateplayer function was called or not. Should work just fine. If it's not called I'll just set a variable for PlayerPaused[playerid]
EDIT: Thanks again for the help I did +rep you
EDIT2:
pawn Код:
forward PauseCheck();
public PauseCheck()
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(OnPlayerUpdate(i) == 0)
{
PlayerPaused[i] = 1;
}
if(OnPlayerUpdate(i) == 1)
{
PlayerPaused[i] = 0;
}
}
}
}
Re: How to detect if player is in menu/tabbed ? -
Phil_Cutcliffe - 03.02.2014
EDIT: Thank you very much for sharing your include it works perfectly!
Re: How to detect if player is in menu/tabbed ? -
Phil_Cutcliffe - 03.02.2014
Ok I still have one problem.. Everything works fine BUT when a player tabs he is still in god mode. And when I use your OnPlayerPause to kill them if they're in a capture zone it doesn't work until they tab back into game. I need it to work straight away.
EDIT: All sorted now I figured a perfect way to do it