[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
#2

Fico Dahora Lek
Reply
#3

not bad..
Reply
#4

That's more a tutorial
Good job.
Reply
#5

Thnnx and +rep if its good
Reply
#6

Quote:
Originally Posted by Xtreme Brotherz
View Post
Thnnx and +rep if its good
No. Just no.
Reply
#7

Quote:
Originally Posted by king_hual
View Post
No. Just no.
cant stop laughing

gud joke anyway
Reply
#8

Nice!
Reply
#9

Very cool idea! It can be pretty useful for just about any server, another nice release. Keep em' comin'!
Reply
#10

Quote:
Originally Posted by Xtreme Brotherz
View Post
I may not be familiar as this is my first filterscript.
Quote:
Originally Posted by NoahF
View Post
another nice release. Keep em' comin'!
What.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)