Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Simple AFK System by DeWilX */
- #define FILTERSCRIPT
- #include <a_samp>
- #define COLOR_YELLOW 0xFFFF00AA
- #define COLOR_RED 0xFF0000FF
- #define ms 60000
- #define afktime 1 // AFK time in minutes
- forward public PlayerMoveTimer(playerid);
- new gPlayers[MAX_PLAYERS][MAX_PLAYER_NAME+1];
- new hp = 9999999;
- new Float:phealth;
- new IsPlayerAfk[MAX_PLAYERS];
- new i=0;
- new autoafk = ms*afktime;
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print(" DeWilX's Simple AFK System -- Loaded");
- print("--------------------------------------\n");
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- SetTimerEx("PlayerMoveTimer", autoafk/2, true, "i", playerid);
- IsPlayerAfk[playerid] = 0;
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- IsPlayerAfk[playerid] = 0;
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- if(IsPlayerAfk[playerid] == 1)
- {
- SendClientMessage(playerid, COLOR_RED, "ERROR : You can not use chat when you're AFK. Use /back to be back!");
- return 0;
- }
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if (strcmp("/afk", cmdtext, true, 10) == 0)
- {
- new string[33];
- if (IsPlayerAfk[playerid] == 0) {
- GetPlayerName(playerid,gPlayers[playerid],MAX_PLAYER_NAME);
- GetPlayerHealth(playerid,phealth);
- SetPlayerHealth(playerid,hp);
- TogglePlayerControllable(playerid, 0);
- format(string,sizeof(string),"***Player [ %s ] is afk!",gPlayers[playerid]);
- SendClientMessageToAll(COLOR_RED,string);
- IsPlayerAfk[playerid] = 1;
- return true;
- }
- if (IsPlayerAfk[playerid] == 1) {
- SendClientMessage(playerid, COLOR_RED, "ERROR : You are alredy AFK! Use /back to be back!");
- }
- return true;
- }
- if (strcmp("/back", cmdtext, true, 10) == 0)
- {
- new string[33];
- if (IsPlayerAfk[playerid] == 1) {
- TogglePlayerControllable(playerid, 1);
- SetPlayerHealth(playerid,phealth);
- format(string,sizeof(string),"<<< [ %s ] is back! >>>",gPlayers[playerid]);
- SendClientMessageToAll(COLOR_YELLOW,string);
- IsPlayerAfk[playerid] = 0;
- return true;
- }
- if (IsPlayerAfk[playerid] == 0) {
- SendClientMessage(playerid, COLOR_RED, "ERROR : You arent AFK! Use /afk to be AFK!");
- }
- return true;
- }
- return 1;
- }
- public PlayerMoveTimer(playerid)
- {
- new string[33];
- if (IsPlayerAfk[playerid] == 0) {
- i++;
- }
- if ((IsPlayerAfk[playerid] == 0) && (i == 2)) {
- GetPlayerName(playerid,gPlayers[playerid],MAX_PLAYER_NAME);
- GetPlayerHealth(playerid,phealth);
- SetPlayerHealth(playerid,hp);
- TogglePlayerControllable(playerid, 0);
- format(string,sizeof(string),"Player [ %s ] is afk!",gPlayers[playerid]);
- SendClientMessageToAll(COLOR_RED,string);
- IsPlayerAfk[playerid] = 1;
- return true;
- }
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- if (IsPlayerAfk[playerid] == 0) {
- i=0;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement