03.10.2012, 13:41
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