Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if SERVER then
- --------------------------------------------------
- AFK_TIME = 1800
- AFK_WARN_TIME = 1500
- --------------------------------------------------
- util.AddNetworkString( "AfkTimerReset" )
- net.Receive( "AfkTimerReset", function( len, pl )
- if ( IsValid( pl ) and pl:IsPlayer() ) then
- pl.AnyKeyPressed = true
- timer.Simple(0, function() ply.AnyKeyPressed = false end)
- end
- end )
- hook.Add("PlayerInitialSpawn", "MakeAFKVar", function(ply)
- ply.NextAFK = CurTime() + AFK_TIME
- end)
- hook.Add("Think", "HandleAFKPlayers", function()
- for _, ply in pairs (player.GetAll()) do
- if ( ply:IsConnected() and ply:IsFullyAuthenticated() ) then
- if (!ply.NextAFK) then
- ply.NextAFK = CurTime() + AFK_TIME
- end
- local afktime = ply.NextAFK
- if (CurTime() >= afktime - AFK_WARN_TIME) and (!ply.Warning) then
- ply:ChatPrint("Warning: You will be kicked soon if you are inactive.")
- ply.Warning = true
- elseif (CurTime() >= afktime) and (ply.Warning) then
- ply.Warning = nil
- ply.NextAFK = nil
- ply:Kick("Kicked for being AFK for 30 minutes.\n")
- end
- end
- end
- end)
- hook.Add("KeyPress", "PlayerMoved", function(ply, key)
- if ply.AnyKeyPressed and ply.LastPos != ply:GetPos() then
- ply.LastPos = ply:GetPos()
- ply.NextAFK = CurTime() + AFK_TIME
- ply.Warning = false
- end
- end)
- else
- local function IsAnyKeyPressed()
- i=0
- while i<KEY_COUNT do
- if input.WasKeyPressed( i ) then return true end
- i=i+1
- end
- return false
- end
- hook.Add("PlayerTick", "PlayerPressedButton", function(ply)
- if IsAnyKeyPressed() then
- net.Start( "AfkTimerReset" )
- net.SendToServer()
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement