[CSTRIKE FIX] mp_autokick/cs_get_user_lastactivity FIX
Posted: Mon Sep 28, 2026 12:54 pm
Last Activity GameTime is stored in a private player offset that is updated each PreThink to the current gametime,
if players button have changed since last frame (button are stored each PostThink in another pdata).
Problem with this is that sometimes the game reset player button, so last activity is updated even if players are AFK.
The first plugin attempts to remove that bug, it makes so pdata is not updated in most situations like descripted above.
2nd plugin updates pdatas when players send a command, because if a player sends a command it means he is not AFK.
3rd plugin check players angles and updates pdatas if angles have changed,
so the pdata only takes in account AFK and not camping.
Related stuff :
To kick a player for idle, you can try this stock (not tested) :
Other version :
Note : Max Idle Time allowed to a player is equal to mp_roundtime * 2 and is stored at each new round.
if players button have changed since last frame (button are stored each PostThink in another pdata).
Problem with this is that sometimes the game reset player button, so last activity is updated even if players are AFK.
The first plugin attempts to remove that bug, it makes so pdata is not updated in most situations like descripted above.
2nd plugin updates pdatas when players send a command, because if a player sends a command it means he is not AFK.
3rd plugin check players angles and updates pdatas if angles have changed,
so the pdata only takes in account AFK and not camping.
Related stuff :
To kick a player for idle, you can try this stock (not tested) :
Code: Select all
KickPlayerForIdle(id)
{
#if !defined m_flLastActivityTime
#define m_flLastActivityTime 124
#endif
#if !defined m_flNextIdleCheckTime
#define m_flNextIdleCheckTime 190
#endif
#if !defined m_afButtonLast
#define m_afButtonLast 245
#endif
#if !defined mp_autokick
static mp_autokick
#endif
if( !mp_autokick )
{
mp_autokick = get_cvar_pointer("mp_autokick")
}
new iAutoKick = get_pcvar_num(mp_autokick)
if( !iAutoKick )
{
set_pcvar_num(mp_autokick, 1)
}
set_pdata_float(id, m_flLastActivityTime, -9999.9)
set_pdata_float(id, m_flNextIdleCheckTime, 0.0)
set_pev(id, pev_button, get_pdata_int(id, m_afButtonLast)
dllfunc(id, DLLFunc_PlayerPreThink)
if( !iAutoKick )
{
set_pcvar_num(mp_autokick, 0)
}
} Code: Select all
KickPlayerForIdle(id)
{
static __msgTextMsg = 0
if( !__msgTextMsg )
{
__msgTextMsg = get_user_msgid("TextMsg")
}
new name[32] ; get_user_name(id, name, charsmax(name))
emessage_begin(MSG_ALL, __msgTextMsg)
ewrite_byte( print_console )
ewrite_string( "#Game_idle_kick" )
ewrite_string( name )
emessage_end()
server_cmd("kick ^"%s^"", name)
}