Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. if SERVER then
  2.  
  3. --------------------------------------------------
  4. AFK_TIME = 1800
  5.  
  6. AFK_WARN_TIME = 1500
  7. --------------------------------------------------
  8.  
  9. util.AddNetworkString( "AfkTimerReset" )
  10.  
  11. net.Receive( "AfkTimerReset", function( len, pl )
  12. if ( IsValid( pl ) and pl:IsPlayer() ) then
  13. pl.AnyKeyPressed = true
  14. timer.Simple(0, function() ply.AnyKeyPressed = false end)
  15. end
  16. end )
  17.  
  18. hook.Add("PlayerInitialSpawn", "MakeAFKVar", function(ply)
  19. ply.NextAFK = CurTime() + AFK_TIME
  20. end)
  21.  
  22. hook.Add("Think", "HandleAFKPlayers", function()
  23. for _, ply in pairs (player.GetAll()) do
  24. if ( ply:IsConnected() and ply:IsFullyAuthenticated() ) then
  25.  
  26. if (!ply.NextAFK) then
  27. ply.NextAFK = CurTime() + AFK_TIME
  28. end
  29.  
  30. local afktime = ply.NextAFK
  31. if (CurTime() >= afktime - AFK_WARN_TIME) and (!ply.Warning) then
  32. ply:ChatPrint("Warning: You will be kicked soon if you are inactive.")
  33.  
  34. ply.Warning = true
  35. elseif (CurTime() >= afktime) and (ply.Warning) then
  36. ply.Warning = nil
  37. ply.NextAFK = nil
  38. ply:Kick("Kicked for being AFK for 30 minutes.\n")
  39. end
  40. end
  41. end
  42. end)
  43.  
  44. hook.Add("KeyPress", "PlayerMoved", function(ply, key)
  45. if ply.AnyKeyPressed and ply.LastPos != ply:GetPos() then
  46. ply.LastPos = ply:GetPos()
  47. ply.NextAFK = CurTime() + AFK_TIME
  48. ply.Warning = false
  49. end
  50. end)
  51.  
  52. else
  53.  
  54. local function IsAnyKeyPressed()
  55. i=0
  56. while i<KEY_COUNT do
  57. if input.WasKeyPressed( i ) then return true end
  58. i=i+1
  59. end
  60. return false
  61. end
  62.  
  63. hook.Add("PlayerTick", "PlayerPressedButton", function(ply)
  64. if IsAnyKeyPressed() then
  65. net.Start( "AfkTimerReset" )
  66. net.SendToServer()
  67. end
  68. end)
  69.  
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement