SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 16/01/2013, 10:25 AM   #1
101
Big Clucker
 
Join Date: Feb 2011
Location: Sarajevo
Posts: 185
Reputation: 2
Default Is it possible to auto kick paused players without using onplayerupdate?

Is it possible to auto kick paused players without using onplayerupdate? As onplayerupdate gets executed way too much times in a second.
__________________
101 is offline   Reply With Quote
Old 16/01/2013, 10:30 AM   #2
RajatPawar
High-roller
 
RajatPawar's Avatar
 
Join Date: Aug 2011
Location: ヽ༼ຈل͜ຈ༽ノ
Posts: 2,177
Reputation: 320
Default Re: Is it possible to auto kick paused players without using onplayerupdate?

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.
RajatPawar is offline   Reply With Quote
Old 16/01/2013, 11:02 AM   #3
101
Big Clucker
 
Join Date: Feb 2011
Location: Sarajevo
Posts: 185
Reputation: 2
Default Re: Is it possible to auto kick paused players without using onplayerupdate?

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?
__________________
101 is offline   Reply With Quote
Old 16/01/2013, 11:11 AM   #4
RajatPawar
High-roller
 
RajatPawar's Avatar
 
Join Date: Aug 2011
Location: ヽ༼ຈل͜ຈ༽ノ
Posts: 2,177
Reputation: 320
Default Re: Is it possible to auto kick paused players without using onplayerupdate?

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.
RajatPawar is offline   Reply With Quote
Old 16/01/2013, 11:15 AM   #5
101
Big Clucker
 
Join Date: Feb 2011
Location: Sarajevo
Posts: 185
Reputation: 2
Default Re: Is it possible to auto kick paused players without using onplayerupdate?

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.
__________________
101 is offline   Reply With Quote
Old 16/01/2013, 12:53 PM   #6
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,125
Reputation: 529
Default Re: Is it possible to auto kick paused players without using onplayerupdate?

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.
__________________


Kar's Cops and Robbers 2020
Threshold is offline   Reply With Quote
Old 16/01/2013, 12:56 PM   #7
101
Big Clucker
 
Join Date: Feb 2011
Location: Sarajevo
Posts: 185
Reputation: 2
Default Re: Is it possible to auto kick paused players without using onplayerupdate?

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.
__________________
101 is offline   Reply With Quote
Old 16/01/2013, 01:00 PM   #8
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,125
Reputation: 529
Default Re: Is it possible to auto kick paused players without using onplayerupdate?

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


Kar's Cops and Robbers 2020
Threshold is offline   Reply With Quote
Old 16/01/2013, 02:56 PM   #9
CodyCummings
Big Clucker
 
Join Date: Jan 2013
Posts: 61
Reputation: 28
Default Re: Is it possible to auto kick paused players without using onplayerupdate?

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.
__________________


Byt3
San Andreas Roleplay.
Lead Developer & Senior Administrator.
CodyCummings is offline   Reply With Quote
Old 16/01/2013, 03:15 PM   #10
RajatPawar
High-roller
 
RajatPawar's Avatar
 
Join Date: Aug 2011
Location: ヽ༼ຈل͜ຈ༽ノ
Posts: 2,177
Reputation: 320
Default Re: Is it possible to auto kick paused players without using onplayerupdate?

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting paused players? Twisted_Insane Scripting Help 6 14/04/2012 05:24 PM
Kicking Paused Players Michael[NBK] Scripting Help 3 11/11/2011 08:53 PM
Hey auto kick GTA-Roleplay Scripting Help 4 02/09/2011 07:34 AM
Auto-Kick help Sascha Help Archive 2 25/08/2010 04:06 PM
Auto-AFK kick and Ping Kick Garc1a Help Archive 3 28/07/2010 07:26 PM


All times are GMT. The time now is 01:06 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.