Raised This Month: $ Target: $400
 0% 

Simple AFK kicker


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dustinandband
Senior Member
Join Date: May 2015
Old 10-03-2017 , 03:18   Simple AFK kicker
Reply With Quote #1

Hi,

I've seen other afk kickers and managers but they seem to only work with one game mode. I'm wanting a plugin that works with L4D2 and is super simple.

Description:

When a player joins a timer is placed on them for 2 hrs to make sure they press a key. Every time they press a key the timer is reset for 2 hrs. If no key is pressed in 2 hrs that person is kicked from the server. Doesn't matter what team they're on or if they're alive or dead.
dustinandband is offline
dustinandband
Senior Member
Join Date: May 2015
Old 10-03-2017 , 13:00   Re: Simple AFK kicker
Reply With Quote #2

Forgot to mention - when someone disconnects their timer is killed.
dustinandband is offline
BraveFox
AlliedModders Donor
Join Date: May 2015
Location: Israel
Old 10-03-2017 , 13:59   Re: Simple AFK kicker
Reply With Quote #3

Check out my afk kicker plugin
__________________
Contact Me:
Steam: NoyB
Discord: Noy#9999
Taking Private Requests
BraveFox is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-03-2017 , 15:56   Re: Simple AFK kicker
Reply With Quote #4

Here simple.
This store timestamp everytime when player toggle button keys.
One repeated timer check every minute all players timestamp when they have last time toggle keys.
After 7200 seconds, it kick player out from server.

PHP Code:
int g_timestamps[MAXPLAYERS+1];

public 
void OnPluginStart()
{
    
HookEventEx("player_connect"player_connect);
    
CreateTimer(60.0tiktak_TIMER_REPEAT);
}

public 
void player_connect(Event event, const char[] namebool dontBroadcast)
{
    
CreateTimer(0.0delayevent.GetInt("userid"));
}

public 
Action delay(Handle timerany data)
{
    
// Doesn't matter if userid return as index 0
    
g_timestamps[GetClientOfUserId(data)] = GetTime();
}

public 
Action tiktak(Handle timer)
{
    for(
int client 1client <= MaxClientsclient++)
    {
        if(!
IsClientInGame(client) || IsFakeClient(client)) continue;

        if((
GetTime() - g_timestamps[client]) >= 7200// 2 hours
        
{
            
KickClient(client"You have idle 2 hours");
        }
    }
}

public 
Action OnPlayerRunCmd(int clientint &buttonsint &impulsefloat vel[3], float angles[3], int &weaponint &subtypeint &cmdnumint &tickcountint &seedint mouse[2])
{
    if(
IsFakeClient(client)) return Plugin_Continue;

    static 
players_buttons[MAXPLAYERS+1];

    if(
players_buttons[client] != buttons)
    {
        
players_buttons[client] = buttons;
        
g_timestamps[client] = GetTime();
    }

    return 
Plugin_Continue;

__________________
Do not Private Message @me
Bacardi is offline
dustinandband
Senior Member
Join Date: May 2015
Old 10-03-2017 , 16:48   Re: Simple AFK kicker
Reply With Quote #5

@ Bacardi
Thanks ! Was after something simple with no (or very little) configuration files since it's a lot simpler to save and refer back to. Compiled with no errors.

Question though: Does it affect anything if a client disconnects? Also whenever a client presses a key, their afk timer is reset to 2 hrs?
dustinandband is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-03-2017 , 18:17   Re: Simple AFK kicker
Reply With Quote #6

Quote:
Originally Posted by dustinandband View Post
@ Bacardi
Thanks ! Was after something simple with no (or very little) configuration files since it's a lot simpler to save and refer back to. Compiled with no errors.

Question though: Does it affect anything if a client disconnects? Also whenever a client presses a key, their afk timer is reset to 2 hrs?
Client disconnect have no affects in this plugin.
Only when player_connect event, I use this because it usually called once when player enter in server.
On this event, player store/save/log/update timestamp (unix time) and everytime when toggle buttons (press button and release button).

Plugin use timestamp, to see when last time player did one of those actions.
When plugin compare (every minute) between current time and timestamp, it kick player if time exceed 2 hours.
__________________
Do not Private Message @me
Bacardi is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 14:19.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode