Kimossab

Fixed Anti AFK system

Jan 19th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //*Declared New*/
  2. new AFK_Timer[MAX_PLAYERS];
  3. new acstring[128];
  4.  
  5. new AFKTime[MAX_PLAYERS] = 0;
  6. new AFKCheck[MAX_PLAYERS];
  7.  
  8. /*Dialogs*/
  9. #define DIALOG_AFK 11
  10.  
  11. /*Forwards*/
  12. forward AFK_Kick(playerid);
  13. forward AFK_Bye(playerid);
  14.  
  15. forward Pos_Check(playerid, Float:x, Float:y, Float:z);
  16.  
  17. /*Publics*/
  18. public OnPlayerSpawn(playerid)
  19. {
  20.     new Float:x, Float:y, Float:z;
  21.     GetPlayerPos(playerid, x, y, z);
  22.     AFKCheck[playerid] = SetTimerEx("Pos_Check", 1000, true, "ifff", playerid, x, y, z);
  23. }
  24.  
  25. public Pos_Check(playerid, Float:x, Float:y, Float:z)
  26. {
  27.     if(AFKTime[playerid] < 1000)
  28.     {
  29.         new Float:nx, Float:ny, Float:nz;
  30.         if(nx = x && ny == y && nz = z)
  31.             AFKTime[playerid]++;
  32.         else
  33.             AFKTime[playerid] = 0;
  34.     }
  35.     else
  36.     {
  37.         AFK_Kick(playerid);
  38.         KillTimer(AFKCheck[playerid]);
  39.     }
  40. }
  41.  
  42. stock AFK_Kick(playerid)
  43. {
  44.     ShowPlayerDialog(playerid, DIALOG_AFK, DIALOG_STYLE_MSGBOX, "Are you here ?", "This system is checking if you are AFK.\nYou will see this message if you are in-active for 1 minute.\nYou have 20 seconds to press the continue button.", "Continue", "");
  45.     AFK_Timer[playerid] = SetTimerEx("AFK_Bye", 20000, false, "i", playerid);
  46.     return 1;
  47. }
  48.  
  49. public AFK_Bye(playerid)
  50. {
  51.     format(acstring, sizeof(acstring), "{FF4500}[ANTI CHEAT]{EE0000} %s (%i){FF4500} has been kicked from server. Reason: AFK (Away From Keyboard)", GetName(playerid), playerid);
  52.     SendClientMessageToAll(COLOR_ORANGE, acstring);
  53.     SetTimer("AntiCheat", 100, false);
  54.     return 1;
  55. }
  56.  
  57. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  58. {
  59.     if(dialogid == DIALOG_AFK)
  60.     {
  61.         if(response)
  62.         {
  63.             KillTimer(AFK_Timer[playerid]);
  64.  
  65.             AFKCheck[playerid] = SetTimerEx("Pos_Check", 1000, true, "ifff", playerid, x, y, z);
  66.         }
  67.     }
  68.     return 1;
  69. }
  70.  
  71. public OnPlayerDisconnect(playerid)
  72. {
  73.     KillTimer(AFKCheck[playerid]);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment