Advertisement
souzaea

Untitled

Feb 22nd, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.13 KB | None | 0 0
  1. new Float:LastPosHash[MAX_PLAYERS];
  2. new InactiveSeconds[MAX_PLAYERS];
  3.  
  4. public OnGameModeInit()
  5. {
  6.     SetTimer("UpdateTimer", 1000, 1);
  7.     return 1;
  8. }
  9.  
  10. stock GetPositionHash(playerid)
  11. {
  12.     new Float:ppx, Float:ppy, Float:ppz;
  13.     GetPlayerPos(playerid, ppx, ppy, ppz);
  14.     return floatround(ppx * ppy * ppz / 3);
  15. }
  16.  
  17. forward UpdateTimer();
  18. public UpdateTimer()
  19. {
  20.     for(new i = 0; i < MAX_PLAYERS; i++)
  21.     {
  22.         if(IsPlayerConnected(i) && !IsPlayerNPC(i))
  23.         {
  24.             if(LastPosHash[i] == GetPositionHash(i))
  25.             {
  26.                InactiveSeconds[i]++;
  27.             }
  28.             else
  29.             {
  30.                 InactiveSeconds[i] = 0;
  31.                 LastPosHash[i] = GetPositionHash(i);
  32.             }
  33.         }
  34.     }
  35. }
  36.  
  37. stock IsPlayerInactive(playerid)
  38. {
  39.     if(InactiveSeconds[playerid] > 10) return true;
  40.     return false;
  41. }
  42.  
  43. /*Usage Example:
  44.  
  45. CMD:inactive(playerid)
  46. {
  47.     if(IsPlayerInactive(playerid))
  48.     {
  49.         SendClientMessage(playerid, -1, "You are inactive!");
  50.     }
  51.     else
  52.     {
  53.         SendClientMessage(playerid, -1, "You are not inactive!");
  54.     }
  55.     return 1;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement