How do I detect when a player is paused?
#1

I know it's possible and I've seen it discussed, but I've never seen a straight answer. It has something to do with OnPlayerUpdate, but I'm not sure. Can someone help me?
Reply
#2

Check if they are in the same position.
Reply
#3

What if someone is just standing there?
Reply
#4

Quote:
Originally Posted by 2KY
View Post
What if someone is just standing there?
Check if they are in the same position. If they are not moving for 3-10 minutes, they might be pausing or afk.
Reply
#5

Quote:
Originally Posted by newbienoob
View Post
Check if they are in the same position. If they are not moving for 3-10 minutes, they might be pausing or afk.
Fair enough.

Quote:
Originally Posted by ******
View Post
Why not just ask them? Dialog with "Are you paused? [NO]", if they don't reply, they're paused, and then only do it if they stand still a while.
I actually like that idea. Thank you.
Reply
#6

Lol .. thats cool ******

https://sampforum.blast.hk/showthread.php?tid=365013 - This is something cool and useful for you
Reply
#7

Quote:
Originally Posted by 2KY
View Post
What if someone is just standing there?
Look at them if they're not moving for like 2-3minutes then he's Pausing or AFK
Reply
#8

Or you could created a new variable for each player, adding a timer each second which increases the variable, and set the variable back to 0 OnPlayerUpdate - Since OnPlayerUpdate is not called when a players paused.
pawn Code:
new iPlayerPaused[MAX_PLAYERS];

OnPlayerConnect(playerid) {
    iPlayerPaused[playerid] = 0;
}

OnPlayerUpdate(playerid) {
    iPlayerPaused[playerid] = 0;
}

forward PausedCheck(); public PausedCheck() { // Set timer each second
    for(new i = 0; i < MAX_PLAYERS; i++) {
        iPlayerPaused[i] += 1;
        if(iPlayerPaused[i] > 2) {
            // Players most likely Paused.
        }
    }
}
I literally coded that in the reply message... Improve it as you wish.
Reply
#9

Quote:
Originally Posted by ******
View Post
OnPlayerUpdate isn't called for spectators either.
Interesting, that's one thing I didn't know!

EDIT: what would the best method be? A loop through all of the players, gathering their positions every few minutes and if they are the same after the next loop, then assume they're AFK, or using SetTimerEx and checking every few minutes and doing the same as above?
Reply
#10

This is how I did mine, meant especially for players who are not paused (just standing there getting killed or maybe raksamp bot lol). It works for paused or tabbed players too btw.

PHP Code:
#include <a_samp>
#include <YSI\y_timers>
new ppaused[MAX_PLAYERS];
ptask setafk[145000](playerid)
{
    
ppaused[playerid] = 1;
    
defer afktest(playerid);
}
timer afktest[20000](playerid)
{
    if(
ppaused[playerid] == 1)
    {
        
SendClientMessage(playerid0xFFFF00D4"WARNING: You have not pressed any key for 20 seconds!");
        
SendClientMessage(playerid0xFFFF00D4"You have 2 minutes to press any key or you will be kicked for AFK!");
        
defer afktest2(playerid);
    }
}
timer afktest2[120000](playerid)
{
    new 
string[196], pname[MAX_PLAYER_NAME];
    if (
ppaused[playerid] == 1)
    {
        
GetPlayerName(playeridpnamesizeof(pname));
        
SendClientMessage(playerid0xFF0037BE"You have been kicked for being paused for too long!");
        
SendClientMessage(playerid0xFF0037BE"Come back when you want to play!");
        
format (stringsizeof(string), "{FF0000}%s {FF7D7D}Has Been Automatically Kicked, {FF0000}Reason: {FF7D7D}AFK."pname);
        
SendClientMessageToAll(0xFF0037BE,string);
        
ppaused[playerid] = 0;
        
Kick(playerid);
    }
}
public 
OnPlayerConnect(playerid)
{
    
ppaused[playerid] = 0;
    return 
1;
}
public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    
ppaused[playerid] = 0;
    return 
1;

Reply
#11

Quote:
Originally Posted by Y_Less
View Post
I have to say, I've only just come up with that and as you say - accurate detection can be hard, the simplest solution is often the best.

Edit: Just be careful with players already viewing a dialog.
I've tested it on live servers and the best way is with OnPlayerUpdate + a timer to check.
Just remember when it doesn't get called naturally, I believe most the times are in class selection, while the player is dead and while they are spectating which can all be easily checked.
Reply


Forum Jump:


Users browsing this thread: 8 Guest(s)