AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem with AFK Detection (https://forums.alliedmods.net/showthread.php?t=324668)

Shadows Adi 05-23-2020 06:33

Problem with AFK Detection
 
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).

DJEarthQuake 05-23-2020 10:21

Re: Problem with AFK Detection
 
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

Bugsy 05-23-2020 12:37

Re: Problem with AFK Detection
 
Maybe you can tweak this one for what you need?

https://forums.alliedmods.net/showpo...7&postcount=38

Shadows Adi 05-23-2020 13:55

Re: Problem with AFK Detection
 
Quote:

Originally Posted by Bugsy (Post 2701814)
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.

Bugsy 05-23-2020 14:18

Re: Problem with AFK Detection
 
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.

Shadows Adi 05-25-2020 08:43

Re: Problem with AFK Detection
 
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)

Bugsy 05-25-2020 12:49

Re: Problem with AFK Detection
 
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

Shadows Adi 05-25-2020 15:02

Re: Problem with AFK Detection
 
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 }

Bugsy 05-25-2020 21:38

Re: Problem with AFK Detection
 
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



Shadows Adi 05-26-2020 14:12

Re: Problem with AFK Detection
 
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!


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

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