Autokick paused players
#1

Fixed!
Reply
#2

I suggest only checking if the player has tabbed not if hes not moving. To do so, you can set a variable to 0 under OnPlayerUpdate (that function only gets called if the player is not tabbed). And use a timer to increase that variable by 1 each second. Once that var hits 60 seconds, then OnPlayerUpdate has never been called that time, then the player is pausing, hence should get kicked.
Reply
#3

Fixed!
Reply
#4

On top:
PHP код:
new AFKTimer[MAX_PLAYERS] = -1
OnPlayerUpdate:
PHP код:
public OnPlayerUpdate(playerid)
{
    
KillTimer(AFKTimer[playerid]);
    
AFKTimer[playerid]=SetTimerEx("KickPlayer"60000false"i"playerid);
    return 
1;

Timer:
PHP код:
forward KickPlayer(playerid);
public 
KickPlayer(playerid)
{
    
Kick(playerid);

Add this in OnPlayerDisconnect otherwise this will kill other timers:
PHP код:
AFKTimer[playerid]=-1
Reply
#5

Fixed!
Reply
#6

https://sampforum.blast.hk/showthread.php?tid=490436

PHP код:
public OnPlayerPause(playerid)
{
     
AFKTimer[playerid]=SetTimerEx("KickPlayer"60000false"i"playerid);
     return 
1;
}

public 
OnPlayerResume(playerid)
{
     
KillTimer(AFKTimer[playerid]);
     return 
1;
}

forward AFKTimer(playerid);
public 
AFKTimer(playerid)
{
     
Kick(playerid);
     return 
1;

Reply
#7

Fixed!
Reply
#8

Instead of using a whole include as suggested, simply supplement something such as:

pawn Код:
#include <a_samp>

new g_iAFK[MAX_PLAYERS];
new g_Timer[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    g_Timer[playerid] = SetTimerEx("UpdatePlayerAFK", 1000, true, "i", playerid);
    g_iAFK[playerid] = 0;
    return 1;
}

public OnPlayerUpdate(playerid) {
    g_iAFK[playerid] = 1;
    return 1;
}

forward UpdatePlayerAFK(playerid);
public UpdatePlayerAFK(playerid) {
    g_iAFK[playerid]++;
   
    if(g_iAFK[playerid] >= 60)
    {
        g_isAFK[playerid] = 1;
        CallLocalFunction("OnPlayerPause", "d", playerid);
    }
   
    if(g_AFK[playerid] < 60 && g_isAFK[playerid])
    {
        g_isAFK[playerid] = 0;
        CallLocalFunction("OnPlayerResume", "d", playerid);
    }
    return 1;
}

forward OnPlayerPause(playerid);
forward OnPlayerResume(playerid);
Most easily as an include. This code is untested as I just wrote it in 1 minute.
Reply
#9

Why not a global timer with a loop?
Reply
#10

Quote:
Originally Posted by Ralfie
Посмотреть сообщение
Why not a global timer with a loop?
Not sure why; I just figure having it per player is better(oh and I forgot to destroy the timer on OnPlayerDisconnect) so you don't have to use any looping.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)