AFK HELP -
necrobg3 - 03.10.2012
Hey guys. I was wondering if anyone don't move 2 minutes how to make it to become afk?
if is possible to be with this define. ( i already got an AFK system, but only works for /afk and /back )
+REP for the dude who try to help me.
Re: AFK HELP -
gtakillerIV - 03.10.2012
Here,
https://sampforum.blast.hk/showthread.php?tid=381125
AW: AFK HELP -
RanSEE - 03.10.2012
pawn Код:
#define FILTERSCRIPT
#include <a_samp>
forward Timer(playerid);
#if defined FILTERSCRIPT
enum Info
{
OldX,
OldY,
OldZ,
AFK,
}
new Player[MAX_PLAYERS][Info];
public OnFilterScriptInit()
{
print("Loading AFK System");
print("LOADED");
SetTimer("Timer", 1000, true);
return 1;
}
public Timer(playerid)
{
new Virtualworld;
new Float:x, Float:y, Float:z;
Virtualworld = GetPlayerVirtualWorld(playerid);
if(Virtualworld = 0 || (Virtualworld = 1))
{
if(Player[playerid][AFK] = 0) //Only players not considered AFK yet will be checked for their location
{
GetPlayerPos(playerid,x,y,z);
// Saving the current locations
Player[playerid][OldX] = x;
Player[playerid][OldY] = y;
Player[playerid][OldZ] = z;
Player[playerid][AFK] = 1; //Sets on AFK = 1, will only activate a timer and not do any changes to the player
}
if(Player[playerid][AFK] >=1)
{
GetPlayerPos(playerid,x,y,z);
if(x = Player[playerid][OldX]) //The old positions are from above
{
if(y = Player[playerid][OldY])
{
if(z = Player[playerid][OldZ])
{
Player[playerid][AFK] + 1; //Player is marked a posible AFK'er right now. It keeps adding this each second upon no move
if(Player[playerid][AFK] == 900 && (Virtualworld = 0)) //Player is detected to be AFK for 15 minutes (900 seconds) Already AFK players won't be placed AFK again
{
SetPlayerVirtualWorld(playerid, 1); //Player is made invisible!
SendClientMessage(playerid, 0xFFD7004A, "You were made invisible as you're AFK for more than 15 minutes!");
}
}
}
}
else
{
if(Player[playerid][AFK] >= 900) //Player is invisible + AFK
{
Player[playerid][AFK] = 0; //Timer reset
SetPlayerVirtualWorld(playerid, 0);
SendClientMessage(playerid, 0xFFD7004A, "Welcome back ingame! You're visible again!");
}
else
{
Player[playerid][AFK] = 0; //Timer reset
}
}
}
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new Virtualworld;
Virtualworld = GetPlayerVirtualWorld(playerid);
if(Player[playerid][AFK] >= 900 && (Virtualworld = 1))
{
Player[playerid][AFK] = 0; //Timer reset
SetPlayerVirtualWorld(playerid, 0);
//Quicky makes the player visible before disconnecting to prevent bugs on servers with stored positions, like most RP servers
}
return 1;
}
public OnPlayerText(playerid, text[])
{
Player[playerid][AFK] = 0; //Player says something so he is not away from keyboard so his AFK timer resets
return 1;
}
#endif
i had this piece of code for auto afk
Re: AFK HELP -
jessejanssen - 03.10.2012
I quickly made this, haven't tested it but it should work properly;
pawn Код:
forward AFKTimer();
enum afk
{
Float:afkX = 0.0,
Float:afkY = 0.0,
Float:afkZ = 0.0,
IsAFK = 0
}
new AFK[MAX_PLAYERS][afk];
public AFKTimer()
{
new string[110], Float:X, Float:Y, Float:Z, PlayerName[MAX_PLAYER_NAME];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
GetPlayerPos(i, X, Y, Z);
if(X == AFK[i][afkX] && Y == AFK[i][afkY] && Z == AFK[i][afkZ])
{
if(AFK[i][IsAFK] == 0)
{
AFK[i][IsAFK] = 1;
GetPlayerName(i, PlayerName, sizeof(PlayerName));
format(string, sizeof(string), "> AFK System: %s is AFK.", PlayerName);
SendClientMessageToAll(0xFFFFFFFF, string);
}
}
}
}
return 1;
}
public OnGameModeInit()
{
SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
SetTimer("AFKTimer", 120000, true);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
AFK[playerid][afkX] = 0.0;
AFK[playerid][afkY] = 0.0;
AFK[playerid][afkZ] = 0.0;
if(AFK[playerid][IsAFK] == 1)
{
AFK[playerid][IsAFK] = 0;
}
return 1;
}
public OnPlayerUpdate(playerid)
{
new Float:X, Float:Y, Float:Z;
if(AFK[playerid][IsAFK] == 1)
{
new PlayerName[MAX_PLAYER_NAME], string[110];
GetPlayerPos(playerid, X, Y, Z);
if(X != AFK[playerid][afkX] && Y != AFK[playerid][afkY] && Z != AFK[playerid][afkZ])
{
AFK[playerid][IsAFK] = 0;
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
format(string, sizeof(string), "> AFK System: %s is no longer AFK.", PlayerName);
SendClientMessageToAll(0xFFFFFFFF, string);
}
}
if(AFK[playerid][afkX] == 0.0 && AFK[playerid][afkY] == 0.0 && AFK[playerid][afkZ] == 0.0)
{
GetPlayerPos(playerid, X, Y, Z);
AFK[playerid][afkX] = X;
AFK[playerid][afkY] = Y;
AFK[playerid][afkZ] = Z;
}
return 1;
}
Used no plugins as foreach whatsoever because I don't know if you have and/or use them.
Best regards,
Jesse
EDIT:
Uploaded the sourcefile ( .pwn ) and the file itself ( .amx ). Click
here to download it!