Advertisement
Xenzia

Simple and Automatic AFK system by Xenzia

Jan 25th, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. /* Simple AFK System by Xenzia
  2.  
  3. DISCLAIMER: This is my first script, never judge me if this is simple or what! >.<
  4. I'll update this immediately!
  5.  
  6. FEATURES:
  7.  
  8. * Auto AFK - When you're idling after a minute/s, you'll be automatically AFK
  9. * Auto Back - While in AFK mode, press up button of your keyboard to be back automatically without typing /back!*/
  10.  
  11.  
  12. #define FILTERSCRIPT
  13.  
  14. #include <a_samp>
  15.  
  16. #define COLOR_LIMEGREEN 0x32CD32AA
  17. #define COLOR_RED 0xFF0000FF
  18. #define ms 60000
  19. #define afktime 1 // AFK time in minutes
  20. #define AutoAFKTimer 1 // Enable Auto AFK? 1 = On 0 = Off
  21. #define AutoBackOnButtonPress 1 // Enable Auto Back on "Move Forward" key press? 1 = On 0 = Off
  22.  
  23. forward public PlayerMoveTimer(playerid);
  24. new gPlayers[MAX_PLAYERS][MAX_PLAYER_NAME+1];
  25. new hp = 9999999;
  26. new Float:phealth;
  27. new Float:parmour;
  28. new IsPlayerAfk[MAX_PLAYERS];
  29. new timer[MAX_PLAYERS];
  30. new autoafk=ms*afktime;
  31. new AFKtime=AutoAFKTimer;
  32. new AutoBack=AutoBackOnButtonPress;
  33. new afktag[MAX_PLAYERS];
  34. new pname[16];
  35.  
  36. public OnFilterScriptInit()
  37. {
  38. print("\n--------------------------------------");
  39. print(" Xenzia's Simple AFK System -- Loaded");
  40. print("--------------------------------------\n");
  41. return 1;
  42. }
  43.  
  44. public OnPlayerConnect(playerid)
  45. {
  46. if (AFKtime == 1)
  47. {
  48. SetTimerEx("PlayerMoveTimer", autoafk/2, true, "i", playerid);
  49. }
  50. GetPlayerName(playerid,pname,16);
  51. IsPlayerAfk[playerid] = 0;
  52. return 1;
  53. }
  54.  
  55. public OnPlayerDisconnect(playerid, reason)
  56. {
  57. IsPlayerAfk[playerid] = 0;
  58. return 1;
  59. }
  60.  
  61. public OnPlayerText(playerid, text[])
  62. {
  63. if(IsPlayerAfk[playerid] == 1)
  64. {
  65. SendClientMessage(playerid, COLOR_RED, "You can't talk in chat while you're AFK, /back or press up button of your keyboard to be back from AFK.");
  66. return 0;
  67. }
  68. return 1;
  69. }
  70.  
  71. public OnPlayerCommandText(playerid, cmdtext[])
  72. {
  73. if (strcmp("/afk", cmdtext, true, 10) == 0)
  74. {
  75. new string[33];
  76. new name[16];
  77. new setname[16];
  78. GetPlayerName(playerid,name,128);
  79. if (IsPlayerAfk[playerid] == 0) {
  80. GetPlayerName(playerid,gPlayers[playerid],MAX_PLAYER_NAME);
  81. GetPlayerHealth(playerid,phealth);
  82. SetPlayerHealth(playerid,hp);
  83. GetPlayerArmour(playerid,parmour);
  84. TogglePlayerControllable(playerid, 0);
  85. format(string,sizeof(string),"%s is now Away From Keyboard (AFK)",gPlayers[playerid]);
  86. SendClientMessageToAll(COLOR_RED,string);
  87. format(setname, sizeof(setname), "[AFK]%s",name);
  88. if(!strlen(name[11]))
  89. {
  90. afktag[playerid] = 1;
  91. SetPlayerName(playerid,setname);
  92. }
  93. IsPlayerAfk[playerid] = 1;
  94. return true;
  95. }
  96. if (IsPlayerAfk[playerid] == 1) {
  97. SendClientMessage(playerid, COLOR_RED, "You're already AFK! /back or press up button of your keyboard to be back!");
  98. }
  99. return true;
  100. }
  101. if (strcmp("/back", cmdtext, true, 10) == 0)
  102. {
  103. new string[39];
  104. if (IsPlayerAfk[playerid] == 1) {
  105. TogglePlayerControllable(playerid, 1);
  106. SetPlayerHealth(playerid,phealth);
  107. SetPlayerArmour(playerid,parmour);
  108. format(string,sizeof(string),"%s is not AFK anymore",gPlayers[playerid]);
  109. SendClientMessageToAll(COLOR_LIMEGREEN,string);
  110. if(afktag[playerid] == 1)
  111. {
  112. afktag[playerid] = 0;
  113. SetPlayerName(playerid,pname);
  114. }
  115. IsPlayerAfk[playerid] = 0;
  116. return true;
  117. }
  118. if (IsPlayerAfk[playerid] == 0) {
  119. SendClientMessage(playerid, COLOR_RED, "/afk to be AFK");
  120. }
  121. return true;
  122. }
  123. return 1;
  124. }
  125. public PlayerMoveTimer(playerid)
  126. {
  127. new string[33];
  128. new name[16];
  129. new setname[16];
  130. GetPlayerName(playerid,name,128);
  131. if (IsPlayerAfk[playerid] == 0) {
  132. timer[playerid]++;
  133. }
  134. if ((IsPlayerAfk[playerid] == 0) && (timer[playerid] == 2)) {
  135. GetPlayerName(playerid,gPlayers[playerid],MAX_PLAYER_NAME);
  136. GetPlayerHealth(playerid,phealth);
  137. SetPlayerHealth(playerid,hp);
  138. GetPlayerArmour(playerid,parmour);
  139. TogglePlayerControllable(playerid, 0);
  140. format(string,sizeof(string),"%s is now Away From Keyboard (AFK)",gPlayers[playerid]);
  141. SendClientMessageToAll(COLOR_RED,string);
  142. format(setname, sizeof(setname), "[AFK]%s",name);
  143. if(!strlen(name[11]))
  144. {
  145. afktag[playerid] = 1;
  146. SetPlayerName(playerid,setname);
  147. }
  148. IsPlayerAfk[playerid] = 1;
  149. return true;
  150. }
  151. return 1;
  152. }
  153. public OnPlayerUpdate(playerid)
  154. {
  155. if (IsPlayerAfk[playerid] == 0) {
  156. timer[playerid]=0;
  157. }
  158. new Keys,ud,lr;
  159. new string[39];
  160. GetPlayerKeys(playerid,Keys,ud,lr);
  161.  
  162. if((ud == KEY_UP ) || (ud == KEY_DOWN) || (Keys == KEY_FIRE) || (lr == KEY_LEFT) || (lr == KEY_RIGHT) || (Keys == KEY_ACTION) || (Keys == KEY_JUMP) || (Keys == KEY_SPRINT) && (AutoBack == 1))
  163. {
  164. if (IsPlayerAfk[playerid] == 1) {
  165. TogglePlayerControllable(playerid, 1);
  166. SetPlayerHealth(playerid,phealth);
  167. SetPlayerArmour(playerid,parmour);
  168. format(string,sizeof(string),"%s is not AFK anymore",gPlayers[playerid]);
  169. SendClientMessageToAll(COLOR_LIMEGREEN,string);
  170. if(afktag[playerid] == 1)
  171. {
  172. afktag[playerid] = 0;
  173. SetPlayerName(playerid,pname);
  174. }
  175. IsPlayerAfk[playerid] = 0;
  176. return true;
  177. }
  178. }
  179. return 1;
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement