Raised This Month: $300 Target: $400
 75% 

Problem with AFK Detection


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 05-23-2020 , 06:33   Problem with AFK Detection
Reply With Quote #1

Hello,
I have a problem with AFK Detection, it detect me as afk, but at next spawn, when I move, it count me as AFK.
Code:
Code:
public DeathMsg() {        new iKiller = read_data( 1 );     new iVictim = read_data( 2 );     if(g_bMapBanned || !is_user_connected(iVictim) || !is_user_connected(iKiller))         return PLUGIN_HANDLED         if(afkCheck[iVictim] && afkCheck[iVictim] < 3)     {         new Float:origin[3], Float:angles[3], afk;         pev(iVictim,pev_origin,origin);         pev(iVictim,pev_v_angle,angles);
        if(get_pcvar_num(spawn_afk_protection) == 2) //here is the problem. Explained at (1)
        {             afk = (origin[0] == player_origin[iVictim][0]) && (origin[1] == player_origin[iVictim][1]) && (angles[0] == spawnAngles[iVictim][0]) && (angles[1] == spawnAngles[iVictim][1]) && (angles[2] == spawnAngles[iVictim][2]);         }         else         {             origin[2] = player_origin[iVictim][2]; // ignore Z-component, they fall             afk = (vector_distance(origin,player_origin[iVictim]) < 28.0) && (angles[0] == spawnAngles[iVictim][0]) && (angles[2] == spawnAngles[iVictim][2]);         }                 if(afk)         {             new name[32];             get_user_name(iVictim,name,31);            
            ChatColor(iKiller, "!g* !yPlayer !g%s !yis AFK", name) // (2)
            afkCheck[iVictim] = 0;                         return PLUGIN_HANDLED;         }            else         {
            k++ // the counter
            return PLUGIN_HANDLED         }         return PLUGIN_CONTINUE     }     afkCheck[iVictim] = 0;         return PLUGIN_HANDLED }
Registered events:
Code:
register_event( "DeathMsg" , "DeathMsg" , "a" , "4=knife" , "1>0" ); RegisterHam(Ham_Spawn,"player","fwSpawn",1)

fwSpawn() function:
Code:
public fwSpawn(id) {     if(!is_user_alive(id)         return HAM_IGNORED     spawned(id);     return HAM_IGNORED }

(1): When cvar value is 1, it increase my k with an unit and print the message from (2) point, even I am AFK or not. When it is 2, it doesn't increase k if I am AFK or now, but it show me the message from (2).
__________________

Last edited by Shadows Adi; 05-23-2020 at 06:34.
Shadows Adi is offline
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: All over the place.
Old 05-23-2020 , 10:21   Re: Problem with AFK Detection
Reply With Quote #2

Make something to reset on new round.
For example, on this AFK plugin timer does not start until any 'buttons' are NOT being used.
IN_ATTACK, IN_JUMP, IN_DUCK, IN_FORWARD, IN_BACK, IN_USE, IN_CANCEL, IN_LEFT, IN_RIGHT, IN_MOVELEFT, IN_MOVERIGHT, IN_ATTACK2, IN_RUN, IN_RELOAD, IN_ALT1, IN_SCORE
__________________
"It's not the actual programming that's interesting. But it's what you can accomplish with the end results that are important." -Dennis Ritchie
"Mathematics, rightly viewed, possesses not only truth, but supreme beauty a beauty cold and austere, like that of sculpture..." -Bertrand Russell

Last edited by DJEarthQuake; 05-23-2020 at 10:23. Reason: #define IS_THERE (~(1<<IN_SCORE))
DJEarthQuake is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-23-2020 , 12:37   Re: Problem with AFK Detection
Reply With Quote #3

Maybe you can tweak this one for what you need?

https://forums.alliedmods.net/showpo...7&postcount=38
__________________
Bugsy is online now
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 05-23-2020 , 13:55   Re: Problem with AFK Detection
Reply With Quote #4

Quote:
Originally Posted by Bugsy View Post
Maybe you can tweak this one for what you need?

https://forums.alliedmods.net/showpo...7&postcount=38
I will try this, I need it to don't count the AFK Players Kills.
__________________
Shadows Adi is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-23-2020 , 14:18   Re: Problem with AFK Detection
Reply With Quote #5

Ok, then instead of slaying and moving to spec, set a bool to true for the AFK player then adjust kills for killer each time he kills the AFK player.
__________________
Bugsy is online now
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old Yesterday , 08:43   Re: Problem with AFK Detection
Reply With Quote #6

I've tried your way, but it don't work. This should check if is player AFK after 15 second from spawn.
The code:
Code:
new bool:g_IsAFK[33] public fwSpawn(id) {     if(!is_user_alive(id))         return HAM_IGNORED         if(is_user_alive(id))     {         pev(id, pev_origin, g_arrayOrigin[id]);                 remove_task(id+54784);         set_task(15.0, "Task_CheckAFK", id+54784);     }         return HAM_IGNORED } public Task_CheckAFK(id) {     id -= 54784;     if(is_user_alive(id))     {         new Float:flOrigin[3];         pev(id, pev_origin, flOrigin);                 if(g_arrayOrigin[id][0] == flOrigin[0] && g_arrayOrigin[id][1] == flOrigin[1] && g_arrayOrigin[id][2] == flOrigin[2])         {             g_IsAFK[id] = true         }         else         {             g_IsAFK[id] = false         }     } }

Registered events:
Code:
RegisterHam(Ham_Spawn,"player","fwSpawn",1)
__________________

Last edited by Shadows Adi; Yesterday at 08:45.
Shadows Adi is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old Yesterday , 12:49   Re: Problem with AFK Detection
Reply With Quote #7

Do this at spawn:
PHP Code:
g_IsAFK[id] = false 
And remove this at spawn, since you are already checking alive on the next line of code:
PHP Code:
if(!is_user_alive(id)) 
     return 
HAM_IGNORED 
Did a minor code cleanup with the above included
Spoiler
__________________

Last edited by Bugsy; Yesterday at 13:13.
Bugsy is online now
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old Yesterday , 15:02   Re: Problem with AFK Detection
Reply With Quote #8

Still don't work in this situation:
Code:
public DeathMsg() {        new iKiller = read_data( 1 );     new iVictim = read_data( 2 );     if(g_bMapBanned || !is_user_connected(iVictim) || !is_user_connected(iKiller))         return PLUGIN_HANDLED     if(!g_pdAFKData[ iVictim ][ IsAFK ])     {
        pdData[iKiller][Kills]++;
    }     else     {         ChatColor(iKiller, "!g* !yPlayer !g%s is!teamAFK !ykill doesn't count!")         return PLUGIN_HANDLED     }         return PLUGIN_HANDLED }
__________________
Shadows Adi is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old Yesterday , 21:38   Re: Problem with AFK Detection
Reply With Quote #9

Do some debugging. This involves adding logs/server_prints() in places in your code to help determine why conditions/values are not what you expect.
PHP Code:
public DeathMsg()
{   
    new 
iKiller read_data);
    new 
iVictim read_data);
    if(
g_bMapBanned || !is_user_connected(iVictim) || !is_user_connected(iKiller))
        return 
PLUGIN_HANDLED

    log_amx
"Checking if player %d is AFK= %d" iVictim g_pdAFKDataiVictim ][ IsAFK ] ? "true" "false" );
    if(!
g_pdAFKDataiVictim ][ IsAFK ])
    {
        
pdData[iKiller][Kills]++;
    }
    else
    {
        
ChatColor(iKiller"!g* !yPlayer !g%s is!teamAFK !ykill doesn't count!")
        return 
PLUGIN_HANDLED
    
}
    
    return 
PLUGIN_HANDLED

__________________
Bugsy is online now
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old Today , 14:12   Re: Problem with AFK Detection
Reply With Quote #10

I've solved this bug. I indexed 'origin[ ]' and this seems work
Code:
public e_Spawn(id) {     if(is_user_alive(id))     {         set_task(0.8, "get_spawn", id);     }     return HAM_IGNORED; } public get_spawn(id) {     pev(id, pev_origin, g_pdAFKData[ id ][ SpawnOrigin ]);     set_task(15.0, "check_afk", id); }   public check_afk(id) {     if(is_user_alive(id) && same_origin(id) )     {         g_pdAFKData[ id ][ IsAFK ] = true     }     else     {         g_pdAFKData[ id ][ IsAFK ] = false     } }   public same_origin(id) {     new Float:origin[3];     pev(id, pev_origin, origin);
    for(new i = 0; i < 3; i++)
        if(origin[i] != g_pdAFKData[ id ][ SpawnOrigin ][i])
        return 0;     return 1; }
Thank you!
__________________
Shadows Adi is offline
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

Forum Jump


All times are GMT -4. The time now is 16:48.


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