[HELP] AFK system
#1

When a player is in motion and he clicks the ESC button the afk system does not work. But if a player is standing and he clicks ESC it works.

The same problem is with player who is in the water but then does not need the esc button it's still doesn't work...

My code, what would you recommend to add?

pawn Код:
if( IsPlayerInAnyVehicle( playerid123 ) )
            {
                if( !IsVehicleMoving( GetPlayerVehicleID(playerid123) ) )
                {
                    if( AFKMODE[ playerid123 ] == false )
                    {
                        AFKKINT[ playerid123 ] ++;
                    }
                }
                else
                {
                    if( AFKMODE[ playerid123 ] == false )
                    {
                        if( AFKKINT[ playerid123 ] > 0 )
                        {
                            AFKKINT[ playerid123 ] = 0;
                        }
                    }
                }
            }
            else
            {
                if( !IsPlayerMoving( playerid123 ) )
                {
                    if( AFKMODE[ playerid123 ] == false )
                    {
                        AFKKINT[ playerid123 ] ++;
                    }
                }
                else
                {
                    if( AFKMODE[ playerid123 ] == false )
                    {
                        if( AFKKINT[ playerid123 ] > 0 )
                        {
                            AFKKINT[ playerid123 ] = 0;
                        }
                    }
                }

          stock IsPlayerMoving(playerid)
{
    GetPlayerVelocity(playerid, Velocity[ playerid ][0], Velocity[ playerid ][1],Velocity[ playerid ][2]);
    if(Velocity[ playerid ][0] == 0 && Velocity[ playerid ][1] == 0 && Velocity[ playerid ][2] == 0) return 0;
    return 1;
}
stock IsVehicleMoving(vehicleid)
{
    GetVehicleVelocity(vehicleid, Velocity[ vehicleid ][0], Velocity[ vehicleid ][1], Velocity[ vehicleid ][2]);
    if(Velocity[ vehicleid ][0] == 0 && Velocity[ vehicleid ][1] == 0 && Velocity[ vehicleid ][2] == 0) return 0;
    return 1;
}
            }
Reply
#2

pawn Код:
#define IsPlayerAFK(%0) AFK[(%0)]
new bool:AFK[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    SetTimerEx("UpdateAFK", 1000, true, "i", playerid);
    return 1;
}

public OnPlayerUpdate(playerid)
{
    AFK[playerid] = false;
    return 1;
}

forward UpdateAFK(playerid);
public UpdateAFK(playerid) return AFK[playerid] = true;
Then you can just do:
pawn Код:
if(IsPlayerAFK(targetid)) //Target is AFK
OnPlayerUpdate is not called when a player pauses their game. So you will be able to tell if a player is AFK depending on whether the 'AFK' variable is true or not.
Reply
#3

Why you're making it so difficult for yourself ?!
It dosn't work because when player in motion and press ESC, player continue moving and other player can see player is moving…
If you want to make a auto afk system just use GetTickCount() in OnPlayerUpdate callback and store it into a PVar or a normal variable
Set a repeating timer and make a loop between players

Just this >>>

pawn Код:
if(GetTickCount() - TickCountVar[i] > 1000) //player pressed ESC and he is afk !

EDIT: ah damn it again i was slow! Sorry all, i'm on my phone and i can't type fast…
Reply
#4

No no, I have all the script that's a part of this.. I need verification these things where I said.
Reply
#5

That's essentially the same thing, but replaces the timer with GetTickCount which could be reasonably easier in terms of lines.

pawn Код:
#define IsPlayerAFK(%0) (GetTickCount() - AFK[(%0)]) >= 1000
new AFK[MAX_PLAYERS];

public OnPlayerUpdate(playerid)
{
    AFK[playerid] = GetTickCount();
    return 1;
}
Hmm, that does look neat, doesn't it?

--

EDIT: There is no need for all that IsVehicleMoving crap. If you just want to detect if they are AFK, this is the way to do it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)