Advertisement
DeWilX

Simple AFK System [0.6]

Apr 20th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.57 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. #define AutoAFKTimer 1 // Enable Auto AFK? 1 = On 0 = Off
  12. #define AutoBackOnButtonPress 1 // Enable Auto Back on "Move Forward" key press? 1 = On 0 = Off
  13.  
  14. forward public PlayerMoveTimer(playerid);
  15. new gPlayers[MAX_PLAYERS][MAX_PLAYER_NAME+1];
  16. new hp = 9999999;
  17. new Float:phealth;
  18. new IsPlayerAfk[MAX_PLAYERS];
  19. new i=0;
  20. new autoafk=ms*afktime;
  21. new AFKtime=AutoAFKTimer;
  22. new AutoBack=AutoBackOnButtonPress;
  23.  
  24. public OnFilterScriptInit()
  25. {
  26.     print("\n--------------------------------------");
  27.     print(" DeWilX's Simple AFK System -- Loaded");
  28.     print("--------------------------------------\n");
  29.     return 1;
  30. }
  31.  
  32. public OnPlayerConnect(playerid)
  33. {
  34.     if (AFKtime == 1)
  35.     {
  36.     SetTimerEx("PlayerMoveTimer", autoafk/2, true, "i", playerid);
  37.     }
  38.     IsPlayerAfk[playerid] = 0;
  39.     return 1;
  40. }
  41.  
  42. public OnPlayerDisconnect(playerid, reason)
  43. {
  44.     IsPlayerAfk[playerid] = 0;
  45.     return 1;
  46. }
  47.  
  48. public OnPlayerText(playerid, text[])
  49. {
  50.     if(IsPlayerAfk[playerid] == 1)
  51.         {
  52.         SendClientMessage(playerid, COLOR_RED, "ERROR : You can not use chat when you're AFK. Use /back to be back!");
  53.         return 0;
  54.         }
  55.     return 1;
  56. }
  57.  
  58. public OnPlayerCommandText(playerid, cmdtext[])
  59. {
  60. if (strcmp("/afk", cmdtext, true, 10) == 0)
  61. {
  62.     new string[33];
  63.     if (IsPlayerAfk[playerid] == 0) {
  64.     GetPlayerName(playerid,gPlayers[playerid],MAX_PLAYER_NAME);
  65.     GetPlayerHealth(playerid,phealth);
  66.     SetPlayerHealth(playerid,hp);
  67.     TogglePlayerControllable(playerid, 0);
  68.     format(string,sizeof(string),"***Player [ %s ] is afk!",gPlayers[playerid]);
  69.     SendClientMessageToAll(COLOR_RED,string);
  70.     IsPlayerAfk[playerid] = 1;
  71.     return true;
  72.     }
  73.     if (IsPlayerAfk[playerid] == 1) {
  74.     SendClientMessage(playerid, COLOR_RED, "ERROR : You are alredy AFK! Use /back to be back!");
  75.     }
  76.     return true;
  77. }
  78. if (strcmp("/back", cmdtext, true, 10) == 0)
  79. {
  80.     new string[33];
  81.     if (IsPlayerAfk[playerid] == 1) {
  82.     TogglePlayerControllable(playerid, 1);
  83.     SetPlayerHealth(playerid,phealth);
  84.     format(string,sizeof(string),"<<< [ %s ] is back! >>>",gPlayers[playerid]);
  85.     SendClientMessageToAll(COLOR_YELLOW,string);
  86.     IsPlayerAfk[playerid] = 0;
  87.     return true;
  88.     }
  89.     if (IsPlayerAfk[playerid] == 0) {
  90.     SendClientMessage(playerid, COLOR_RED, "ERROR : You arent AFK! Use /afk to be AFK!");
  91.     }
  92.     return true;
  93. }
  94. return 1;
  95. }
  96. public PlayerMoveTimer(playerid)
  97. {
  98.     new string[33];
  99.     if (IsPlayerAfk[playerid] == 0) {
  100.     i++;
  101.     }
  102.     if ((IsPlayerAfk[playerid] == 0) && (i == 2)) {
  103.         GetPlayerName(playerid,gPlayers[playerid],MAX_PLAYER_NAME);
  104.         GetPlayerHealth(playerid,phealth);
  105.         SetPlayerHealth(playerid,hp);
  106.         TogglePlayerControllable(playerid, 0);
  107.         format(string,sizeof(string),"Player [ %s ] is afk!",gPlayers[playerid]);
  108.         SendClientMessageToAll(COLOR_RED,string);
  109.         IsPlayerAfk[playerid] = 1;
  110.         return true;
  111.     }
  112.     return 1;
  113. }
  114. public OnPlayerUpdate(playerid)
  115. {
  116.     if (IsPlayerAfk[playerid] == 0) {
  117.     i=0;
  118.     }
  119.     new Keys,ud,lr;
  120.     new string[33];
  121.     GetPlayerKeys(playerid,Keys,ud,lr);
  122.  
  123.     if((ud == KEY_UP) && (AutoBack == 1))
  124.     {
  125.     if (IsPlayerAfk[playerid] == 1) {
  126.     TogglePlayerControllable(playerid, 1);
  127.     SetPlayerHealth(playerid,phealth);
  128.     format(string,sizeof(string),"<<< [ %s ] is back! >>>",gPlayers[playerid]);
  129.     SendClientMessageToAll(COLOR_YELLOW,string);
  130.     IsPlayerAfk[playerid] = 0;
  131.     return true;
  132.     }
  133.     }
  134.     return 1;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement