Advertisement
Guest User

Untitled

a guest
Jul 7th, 2012
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.17 KB | None | 0 0
  1. /*
  2.     AFK System
  3.     By Mado
  4.     V1.0
  5.    
  6.     This filterscript is publicly distributed on the SAMP forums and may be used for server operations,
  7.     editing and learning.
  8.     Please keep all lines of credits in the filterscript.
  9.  
  10.  
  11.     In the script I commented parts in which I explain how it works for those who don't know this.
  12.  
  13.  
  14. */
  15. #define FILTERSCRIPT
  16.  
  17. #include <a_samp>
  18.  
  19. forward Timer(playerid);
  20.  
  21. #if defined FILTERSCRIPT
  22.  
  23. enum Info
  24. {
  25.     OldX,
  26.     OldY,
  27.     OldZ,
  28.     AFK,
  29.  
  30. }
  31.  
  32. new Player[MAX_PLAYERS][Info];
  33.  
  34.  
  35. public OnFilterScriptInit()
  36. {
  37.     print("Loading AFK System");
  38.     print("LOADED");
  39.     SetTimer("Timer", 1000, true);
  40.     return 1;
  41. }
  42.  
  43. public Timer(playerid)
  44. {
  45.     new Virtualworld;
  46.     new Float:x, Float:y, Float:z;
  47.     Virtualworld = GetPlayerVirtualWorld(playerid);
  48.    
  49.     if(Virtualworld = 0 || (Virtualworld = 1))
  50.     {
  51.         if(Player[playerid][AFK] = 0) //Only players not considered AFK yet will be checked for their location
  52.         {
  53.             GetPlayerPos(playerid,x,y,z);
  54.             // Saving the current locations
  55.             Player[playerid][OldX] = x;
  56.             Player[playerid][OldY] = y;
  57.             Player[playerid][OldZ] = z;
  58.             Player[playerid][AFK] = 1; //Sets on AFK = 1, will only activate a timer and not do any changes to the player
  59.        
  60.         }
  61.         if(Player[playerid][AFK] >=1)
  62.         {
  63.             GetPlayerPos(playerid,x,y,z);
  64.             if(x = Player[playerid][OldX]) //The old positions are from above
  65.             {
  66.                 if(y = Player[playerid][OldY])
  67.                 {
  68.                     if(z = Player[playerid][OldZ])
  69.                     {
  70.                         Player[playerid][AFK] + 1; //Player is marked a posible AFK'er right now. It keeps adding this each second upon no move
  71.                        
  72.                         if(Player[playerid][AFK] == 900 && (Virtualworld = 0)) //Player is detected to be AFK for 15 minutes (900 seconds) Already AFK players won't be placed AFK again
  73.                         {
  74.                             SetPlayerVirtualWorld(playerid, 1); //Player is made invisible!
  75.                             SendClientMessage(playerid, 0xFFD7004A, "You were made invisible as you're AFK for more than 15 minutes!");
  76.                         }
  77.                    
  78.                     }
  79.                 }
  80.            
  81.             }
  82.             else
  83.             {
  84.                 if(Player[playerid][AFK] >= 900) //Player is invisible + AFK
  85.                 {
  86.                     Player[playerid][AFK] = 0; //Timer reset
  87.                     SetPlayerVirtualWorld(playerid, 0);
  88.                     SendClientMessage(playerid, 0xFFD7004A, "Welcome back ingame! You're visible again!");
  89.                
  90.                 }
  91.                 else
  92.                 {
  93.                     Player[playerid][AFK] = 0; //Timer reset
  94.                 }
  95.             }
  96.        
  97.         }
  98.    
  99.     }
  100.     return 1;
  101. }
  102.  
  103. public OnPlayerDisconnect(playerid, reason)
  104. {
  105.     new Virtualworld;
  106.     Virtualworld = GetPlayerVirtualWorld(playerid);
  107.     if(Player[playerid][AFK] >= 900 && (Virtualworld = 1))
  108.     {
  109.         Player[playerid][AFK] = 0; //Timer reset
  110.         SetPlayerVirtualWorld(playerid, 0);
  111.         //Quicky makes the player visible before disconnecting to prevent bugs on servers with stored positions, like most RP servers
  112.     }
  113.     return 1;
  114. }
  115.  
  116. public OnPlayerText(playerid, text[])
  117. {
  118.     Player[playerid][AFK] = 0; //Player says something so he is not away from keyboard so his AFK timer resets
  119.     return 1;
  120. }
  121. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement