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!