Is it possible to auto kick paused players without using onplayerupdate?
#1

Is it possible to auto kick paused players without using onplayerupdate? As onplayerupdate gets executed way too much times in a second.
Reply
#2

SetTimerEx for a playerid, for about 5-6 seconds, check if he is at the same position for more than 5 timer executions, if yes, kick him. But that would be a bit inaccurate. Best is the onplayerupdate thingy.
Reply
#3

Quote:
Originally Posted by ******
View Post
You mean detect them? And firstly, did you try using OnPlayerUpdate and find that it caused a problem or did you just skip that step and assume it wouldn't be any good?
It will work, and I did test it already. Problem is, onplayerupdate executes a dozen times in a second as far as I'm aware. Isn't that bad?
Reply
#4

OnPlayerUpdate doesn't update a dozen times a second! I once by mistake, added a sendclientmessage under my OnPlayerUpdate, and on connecting, (my timestamp was active), I could see about 2 messages per second. Not bad. However, the frequency increased as I started running/driving.
Reply
#5

Quote:
Originally Posted by ******
View Post
I don't know - is it? When you tested it on your server, what happened?
Well nothing happened, I'm worried of the long term effect on lag on the server. I already have quite a few timers and will using onplayerupdate contribute to any lag? I don't think there is any other way to do this AFK thing without onplayerupdate.
Reply
#6

pawn Code:
public OnPlayerSpawn(playerid)
{
    SetTimerEx("AFKCheck", 300000, false, "i", playerid);
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    KillTimer(AFKCheck(playerid));
    SetTimerEx("AFKCheck", 300000, false, "i", playerid);
    return 1;
}

public OnPlayerText(playerid, text[])
{
    KillTimer(AFKCheck(playerid));
    SetTimerEx("AFKCheck", 300000, false, "i", playerid);
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    KillTimer(AFKCheck(playerid));
    SetTimerEx("AFKCheck", 300000, false, "i", playerid);
    return 1;
}

forward AFKCheck(playerid);
public AFKCheck(playerid)
{
    new string[80];
    format(string, sizeof(string), "Player %s has been kicked | Reason: Away From Keyboard", playername);
    SendClientMessageToAll(0xFF0000FF, string);
    Kick(playerid);
    return 1;
}
Basically, the code above, sets a timer for 5 minutes, and whenever the player does something like move, type a command or speak, the timer will reset.
Reply
#7

Quote:
Originally Posted by BenzoAMG
View Post
pawn Code:
public OnPlayerSpawn(playerid)
{
    SetTimerEx("AFKCheck", 300000, false, "i", playerid);
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    KillTimer(AFKCheck(playerid));
    SetTimerEx("AFKCheck", 300000, false, "i", playerid);
    return 1;
}

public OnPlayerText(playerid, text[])
{
    KillTimer(AFKCheck(playerid));
    SetTimerEx("AFKCheck", 300000, false, "i", playerid);
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    KillTimer(AFKCheck(playerid));
    SetTimerEx("AFKCheck", 300000, false, "i", playerid);
    return 1;
}

forward AFKCheck(playerid);
public AFKCheck(playerid)
{
    new string[80];
    format(string, sizeof(string), "Player %s has been kicked | Reason: Away From Keyboard", playername);
    SendClientMessageToAll(0xFF0000FF, string);
    Kick(playerid);
    return 1;
}
Basically, the code above, sets a timer for 5 minutes, and whenever the player does something like move, type a command or speak, the timer will reset.
I think this is worse than onplayerupdate lol.
Reply
#8

Well you wanted something that wasn't called 3052 or whatever times a second, so there... be happy with it.
Reply
#9

Quote:
Originally Posted by BenzoAMG
View Post
Well you wanted something that wasn't called 3052 or whatever times a second, so there... be happy with it.
This is completely inaccurate, if you're going to try to help at least post something useful.

OnPlayerUpdate is called every time a client updates with the server, so depending on if the player is doing something (moving etc) it will be called more or less, it's not something to avoid almost like it's the plague but you shouldn't pack it full of stuff.

One way to make a detection to see if a player is paused is like this.

Define these global variables...

pawn Code:
new PlayerPaused[MAX_PLAYERS], pausetick[MAX_PLAYERS];
In OnPlayerUpdate, add this...

pawn Code:
pausetick[playerid] = GetTickCount();
Now, in OnGameModeInit start a repeating timer for 1 second, or if you already have a 1 second repeating timer, skip to the next step.

pawn Code:
SetTimer("PauseCheck", 1000, 1);
Now add this public function.

pawn Code:
forward PauseCheck();
public PauseCheck()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(playerid)) continue;
        if(GetTickCount() - pausetick[i] > 1000) // If they haven't updated in 1+ seconds, increase if needed.
        {
            PlayerPaused[i] = 1;
        }
        else
        {
            PlayerPaused[i] = 0;
        }
    }
    return 1;
}
Now, when someone pauses it should set PlayerPaused to 1 after 1 second, if they unpause it gets set to 0 after 1 second.

I'm pretty sure you can take it from here to make an AFK kicker now that you have this pause detector.
Reply
#10

You shouldn't underestimate the capacity of pawn and samp though, huge servers use onplayerupdate without lag.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)