[HELP] AFK system - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP] AFK system (
/showthread.php?tid=557644)
[HELP] AFK system -
V4at - 14.01.2015
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;
}
}
Re: [HELP] AFK system -
Threshold - 14.01.2015
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.
Re: [HELP] AFK system -
M4D - 14.01.2015
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…
Re: [HELP] AFK system -
V4at - 14.01.2015
No no, I have all the script that's a part of this.. I need verification these things where I said.
Re: [HELP] AFK system -
Threshold - 14.01.2015
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.