SA-MP Forums Archive
[FilterScript] [AFK]Auto-AFK System - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+--- Thread: [FilterScript] [AFK]Auto-AFK System (/showthread.php?tid=381125)



[AFK]Auto-AFK System - Xtreme Brotherz - 28.09.2012

[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


Re: [AFK]Auto-AFK System - -Rafinha_FusioN- - 28.09.2012

Fico Dahora Lek


Re: [AFK]Auto-AFK System - jpeg - 28.09.2012

not bad..


Re: [AFK]Auto-AFK System - RaZzZzoR - 28.09.2012

That's more a tutorial
Good job.


Re: [AFK]Auto-AFK System - Xtreme Brotherz - 28.09.2012

Thnnx and +rep if its good


Re: [AFK]Auto-AFK System - KingHual - 28.09.2012

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


Re: [AFK]Auto-AFK System - Xtreme Brotherz - 28.09.2012

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

gud joke anyway


Re: [AFK]Auto-AFK System - KINGINA - 28.09.2012

Nice!


Re: [AFK]Auto-AFK System - NoahF - 28.09.2012

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


Re: [AFK]Auto-AFK System - KingHual - 29.09.2012

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.