Advertisement
Guest User

Untitled

a guest
Nov 7th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. --------------------------------------------------
  2. AFK_TIME = 1200
  3.  
  4. AFK_WARN_TIME = 600
  5. --------------------------------------------------
  6.  
  7. hook.Add("PlayerInitialSpawn", "MakeAFKVar", function(ply)
  8. ply.NextAFK = CurTime() + AFK_TIME
  9. end)
  10.  
  11. hook.Add("Think", "HandleAFKPlayers", function()
  12. for _, ply in pairs (player.GetAll()) do
  13. if ( ply:IsConnected() and ply:IsFullyAuthenticated() ) then
  14. if (!ply.NextAFK) then
  15. ply.NextAFK = CurTime() + AFK_TIME
  16. end
  17.  
  18. local afktime = ply.NextAFK
  19. if (CurTime() >= afktime - AFK_WARN_TIME) and (!ply.Warning) then
  20. ply:ChatPrint("Warning: You will be kicked soon if you are inactive.")
  21.  
  22. ply.Warning = true
  23. elseif (CurTime() >= afktime) and (ply.Warning) then
  24. ply.Warning = nil
  25. ply.NextAFK = nil
  26. ply:Kick("Kicked for being AFK for 20 minutes.\n")
  27. end
  28. end
  29. end
  30. end)
  31.  
  32. hook.Add("KeyPress", "PlayerMoved", function(ply, key)
  33. ply.NextAFK = CurTime() + AFK_TIME
  34. ply.Warning = false
  35. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement