28.09.2012, 12:59
[AFK]AUTO-AFK SYSTEM
Hai Guys!.. I may not be familiar as this is my first filterscript. This FilterScript auto-detects player's AFK status to switch between the states.Inserts these lines in your gamemode or filterscript at respective places.
INCLUDES
pawn Code:
#include <a_samp>
pawn Code:
#define AFK_TIMER 1
//Timer for detecting whether player in AFK
pawn Code:
enum Info_Afk{Timer, bool: Inactive};
pawn Code:
new Player[MAX_PLAYERS][Info_Afk];
new afkname[29],string[128]; //Default name size is 24 but this needs 5 more
pawn Code:
forward Detect_Afk(playerid);
pawn Code:
public OnPlayerConnect(playerid)
{
GetPlayerName(playerid,afkname,sizeof(afkname));
if(strfind(afkname,"[AFK]", true)!=-1)
{
SendClientMessage(playerid,-1,"[ERROR:] Invalid nickname. You have been kicked.");
Kick(playerid);
}
return 1;
}
pawn Code:
public OnPlayerSpawn(playerid)
{
Player[playerid][Timer]=SetTimerEx("Detect_Afk", AFK_TIMER, false, "d", playerid);
return 1;
}
pawn Code:
public Detect_Afk(playerid)
{
GetPlayerName(playerid, afkname, sizeof(afkname));
format(string,sizeof(string),"[AFK]%s",afkname);
SetPlayerName(playerid, string);
Player[playerid][Inactive] = true;
format(string,sizeof(string),"%s {FFFFFF} is AFK",afkname);
SendClientMessageToAll(-1,string);
TogglePlayerControllable(playerid,0);
return 1;
}
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
Afk_Return(playerid);
return 1;
}
pawn Code:
public OnPlayerText(playerid,text[])
{
Afk_Return(playerid);
return 1;
}
pawn Code:
stock Afk_Return(playerid)
{
KillTimer(Player[playerid][Timer]);
Player[playerid][Timer]=SetTimerEx("Detect_Afk", AFK_TIMER, false, "d", playerid);
if(Player[playerid][Inactive])
{
format(string,sizeof(string),"%s {FFFFFF}is back from AFK state",afkname);
SendClientMessageToAll(-1,string);
Player[playerid][Inactive]=false;
TogglePlayerControllable(playerid,1);
GetPlayerName(playerid,afkname,sizeof(afkname));
if(strfind(afkname,"[AFK]", true)!=-1)
{
strdel(afkname,0,5);
SetPlayerName(playerid,afkname);
}
}
}
pawn Code:
public OnPlayerDisconnect(playerid)
{
KillTimer(Player[playerid][Timer]);
Player[playerid][Inactive]=false;
GetPlayerName(playerid,afkname,sizeof(afkname));
if(strfind(afkname,"[AFK]", true)!=-1)
{
strdel(afkname,0,5);
SetPlayerName(playerid,afkname);
}
return 1;
}
Thank you!
+Rep me if u found it useful
[NOTE] : You may use it without credits by giving a +rep