[FilterScript] [AFK]Auto-AFK System
#1

[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>
DEFINES

pawn Code:
#define AFK_TIMER 1
 //Timer for detecting whether player in AFK
ENUMS

pawn Code:
enum Info_Afk{Timer, bool: Inactive};
NEWS
pawn Code:
new Player[MAX_PLAYERS][Info_Afk];
new afkname[29],string[128]; //Default name size is 24 but this needs 5 more
FORWARDS
pawn Code:
forward Detect_Afk(playerid);
ON PLAYER CONNECT
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;
}
ON PLAYER SPAWN
pawn Code:
public OnPlayerSpawn(playerid)
{
        Player[playerid][Timer]=SetTimerEx("Detect_Afk", AFK_TIMER, false, "d", playerid);
        return 1;
}
PUBLICS
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;
}
PLAYER KEY STATE CHANGE
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
        Afk_Return(playerid);
        return 1;
}
ON PLAYER TEXT
pawn Code:
public OnPlayerText(playerid,text[])
{
        Afk_Return(playerid);
        return 1;
}
STOCKS
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);
                }
        }
}
ON OLAYER DISCONNECT
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
Reply


Messages In This Thread
[AFK]Auto-AFK System - by Xtreme Brotherz - 28.09.2012, 12:59
Re: [AFK]Auto-AFK System - by -Rafinha_FusioN- - 28.09.2012, 14:57
Re: [AFK]Auto-AFK System - by jpeg - 28.09.2012, 15:06
Re: [AFK]Auto-AFK System - by RaZzZzoR - 28.09.2012, 15:28
Re: [AFK]Auto-AFK System - by Xtreme Brotherz - 28.09.2012, 18:33
Re: [AFK]Auto-AFK System - by KingHual - 28.09.2012, 18:36
Re: [AFK]Auto-AFK System - by Xtreme Brotherz - 28.09.2012, 18:54
Re: [AFK]Auto-AFK System - by KINGINA - 28.09.2012, 19:02
Re: [AFK]Auto-AFK System - by NoahF - 28.09.2012, 22:35
Re: [AFK]Auto-AFK System - by KingHual - 29.09.2012, 00:04

Forum Jump:


Users browsing this thread: 5 Guest(s)