Advertisement
DeWilX

Simple AFK System [0.5]

Apr 20th, 2013
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.90 KB | None | 0 0
  1. /* Simple AFK System by DeWilX */
  2.  
  3. #define FILTERSCRIPT
  4.  
  5. #include <a_samp>
  6.  
  7. #define COLOR_YELLOW 0xFFFF00AA
  8. #define COLOR_RED 0xFF0000FF
  9. #define ms 60000
  10. #define afktime 1 // AFK time in minutes
  11.  
  12. forward public PlayerMoveTimer(playerid);
  13. new gPlayers[MAX_PLAYERS][MAX_PLAYER_NAME+1];
  14. new hp = 9999999;
  15. new Float:phealth;
  16. new IsPlayerAfk[MAX_PLAYERS];
  17. new i=0;
  18. new autoafk = ms*afktime;
  19.  
  20. public OnFilterScriptInit()
  21. {
  22.     print("\n--------------------------------------");
  23.     print(" DeWilX's Simple AFK System -- Loaded");
  24.     print("--------------------------------------\n");
  25.     return 1;
  26. }
  27.  
  28. public OnPlayerConnect(playerid)
  29. {
  30.     SetTimerEx("PlayerMoveTimer", autoafk/2, true, "i", playerid);
  31.     IsPlayerAfk[playerid] = 0;
  32.     return 1;
  33. }
  34.  
  35. public OnPlayerDisconnect(playerid, reason)
  36. {
  37.     IsPlayerAfk[playerid] = 0;
  38.     return 1;
  39. }
  40.  
  41. public OnPlayerText(playerid, text[])
  42. {
  43.     if(IsPlayerAfk[playerid] == 1)
  44.         {
  45.         SendClientMessage(playerid, COLOR_RED, "ERROR : You can not use chat when you're AFK. Use /back to be back!");
  46.         return 0;
  47.         }
  48.     return 1;
  49. }
  50.  
  51. public OnPlayerCommandText(playerid, cmdtext[])
  52. {
  53. if (strcmp("/afk", cmdtext, true, 10) == 0)
  54. {
  55.     new string[33];
  56.     if (IsPlayerAfk[playerid] == 0) {
  57.     GetPlayerName(playerid,gPlayers[playerid],MAX_PLAYER_NAME);
  58.     GetPlayerHealth(playerid,phealth);
  59.     SetPlayerHealth(playerid,hp);
  60.     TogglePlayerControllable(playerid, 0);
  61.     format(string,sizeof(string),"***Player [ %s ] is afk!",gPlayers[playerid]);
  62.     SendClientMessageToAll(COLOR_RED,string);
  63.     IsPlayerAfk[playerid] = 1;
  64.     return true;
  65.     }
  66.     if (IsPlayerAfk[playerid] == 1) {
  67.     SendClientMessage(playerid, COLOR_RED, "ERROR : You are alredy AFK! Use /back to be back!");
  68.     }
  69.     return true;
  70. }
  71. if (strcmp("/back", cmdtext, true, 10) == 0)
  72. {
  73.     new string[33];
  74.     if (IsPlayerAfk[playerid] == 1) {
  75.     TogglePlayerControllable(playerid, 1);
  76.     SetPlayerHealth(playerid,phealth);
  77.     format(string,sizeof(string),"<<< [ %s ] is back! >>>",gPlayers[playerid]);
  78.     SendClientMessageToAll(COLOR_YELLOW,string);
  79.     IsPlayerAfk[playerid] = 0;
  80.     return true;
  81.     }
  82.     if (IsPlayerAfk[playerid] == 0) {
  83.     SendClientMessage(playerid, COLOR_RED, "ERROR : You arent AFK! Use /afk to be AFK!");
  84.     }
  85.     return true;
  86. }
  87. return 1;
  88. }
  89. public PlayerMoveTimer(playerid)
  90. {
  91.     new string[33];
  92.     if (IsPlayerAfk[playerid] == 0) {
  93.     i++;
  94.     }
  95.     if ((IsPlayerAfk[playerid] == 0) && (i == 2)) {
  96.         GetPlayerName(playerid,gPlayers[playerid],MAX_PLAYER_NAME);
  97.         GetPlayerHealth(playerid,phealth);
  98.         SetPlayerHealth(playerid,hp);
  99.         TogglePlayerControllable(playerid, 0);
  100.         format(string,sizeof(string),"Player [ %s ] is afk!",gPlayers[playerid]);
  101.         SendClientMessageToAll(COLOR_RED,string);
  102.         IsPlayerAfk[playerid] = 1;
  103.         return true;
  104.     }
  105.     return 1;
  106. }
  107. public OnPlayerUpdate(playerid)
  108. {
  109.     if (IsPlayerAfk[playerid] == 0) {
  110.     i=0;
  111.     }
  112.     return 1;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement