Does someone knows/have a code for kick afkers after 5 minutes?
I would appreciate that, cause i have almost everytime have 20+ on the server, and when it gets 35+, it begins to lagg, and i know it is afkers, but dont know where (or they will be in spawn)
So yea :)
[lua] if SERVER then
--AAfk - By Zach Petty (MrPresident) for the use on gman4president.com G4P GarrysMod servers.
--Original concept by Meggido of Team Ulysses
--Completely rewritten for the new lua and ULib
--
--BEGIN CONFIGURATION--
--
--aafk enabled? Should this addon start enabled?--
local aafkenabled = true
--
--AFK Timer (In Seconds) NOTE: If Kick Flag is turned on below, they will be kicked in twice the time you set for the afk flag--
local aafktime = 150
--
--Should the User be kicked if they stay afk after being flagged as AFK?--
local aafkick = true
--
--Should admins be immune to the afk kick if it is enabled?--
local aafkimmune = false
--
--How many users need to be connected before teh script starts kicking. (This requires aafk_kickenabled to be on.)
--If this is 0, then all afk users will be kicked if they stay afk, otherwise the script will not kick a user for being afk
--unless the server has this specified number of players connected. This is good for having the script only kick if the server
--is full.
local aafkicknumber = 0 --Default 0, if set to 0, the script will kick everytime someone is afk if aafk_kickenabled is on.
--
--
--END CONFIGURATION.. DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING--
local oname = {}
function aafkCheckAdmin( ply ) --Admin Check--
if not ply:IsValid() then
return true
end
if ply:IsSuperAdmin() then
return true
end
return false
end
--ADDS THE CONSOLE COMMAND TO SET THE AFK TIMER--
function aafkicknumbervar( ply, command, args )
if !aafkCheckAdmin(ply) then
ULib.console(ply, "Only Superadmin can change this variable", true)
return
end
local aname = "Default"
if ply:IsValid() then
aname = ply:GetName()
else
aname = "Console"
end
if args[1] == nil then
ULib.console(ply, "Value must be numerical and higher than or equal to 0", true)
end
if tonumber(args[1]) >= 0 then
aafkicknumber = tonumber(args[1])
local text = "Admin: " ..aname.. " has set the afk Kick Number to " ..aafkicknumber.. " players."
ULib.console( ply, text )
ULib.tsay(nil, text, true)
else
ULib.console(ply, "Value must be numerical and higher than or equal to 0", true)
end
end
concommand.Add("aafk_kicknumber",aafkicknumbervar)
--ADDS THE CONSOLE COMMAND TO SET THE AFK TIMER--
function aafktimevar( ply, command, args )
if !aafkCheckAdmin(ply) then
ULib.console(ply, "Only Superadmin can change this variable", true)
return
end
local aname = "Default"
if ply:IsValid() then
aname = ply:GetName()
else
aname = "Console"
end
if args[1] == nil then
ULib.console(ply, "Value must be numerical and higher than 0", true)
end
if tonumber(args[1]) >= 1 then
aafktime = tonumber(args[1])
timer.Create("AAFKCheck", aafktime, 0, AFKCheck) --Checks status every period you designate.
local text = "Admin: " ..aname.. " has set the afk timer to " ..aafktime.. " seconds"
ULib.console( ply, text )
ULib.tsay(nil, text, true)
else
ULib.console(ply, "Value must be numerical and higher than 0", true)
end
end
concommand.Add("aafk_time",aafktimevar)
--ADDS THE CONSOLE COMMAND TO SET KICK FLAGS--
function aafkkickvar( ply, command, args )
if !aafkCheckAdmin(ply) then
ULib.console(ply, "Only Superadmin can change this variable", true)
return
end
local aname = "Default"
if ply:IsValid() then
aname = ply:GetName()
else
aname = "Console"
end
if args[1] == "0" then
local text = "Admin: " ..aname.. " has turned AFK Kicking off!"
ULib.console( ply, text )
aafkick = false
--SetGlobalBool("aafkick", false)
for i, v in ipairs(player.GetAll()) do
ULib.tsay(v, "Admin: " ..aname.. " has turned AFK Kicking off!", true)
end
elseif args[1] == "1" then
local text = "Admin: " ..aname.. " has turned AFK Kicking on!"
ULib.console( ply, text )
aafkick = true
--SetGlobalBool("aafkick", true)
for i, v in ipairs(player.GetAll()) do
ULib.tsay(v, "Admin: " ..aname.. " has turned AFK Kicking on!", true)
end
else
ULib.console(ply, "You must enter 1 for True or 0 for False!", true)
return
end
end
concommand.Add("aafk_kickenabled",aafkkickvar)
--ADDS THE CONSOLE COMMAND TO SET ADMIN IMMUNITY--
function aafkadminvar( ply, command, args )
if !aafkCheckAdmin(ply) then
ULib.console(ply, "Only Superadmin can change this variable", true)
return
end
local aname = "Default"
if ply:IsValid() then
aname = ply:GetName()
else
aname = "Console"
end
if args[1] == "0" then
local text = "Admin: " ..aname.. " has turned Admin Immunity off!"
ULib.console( ply, text )
aafkimmune = false
--SetGlobalBool("aafkimmune", false)
for i, v in ipairs(player.GetAll()) do
ULib.tsay(v, "Admin: " ..aname.. " has turned Admin Immunity off!", true)
end
elseif args[1] == "1" then
local text = "Admin: " ..aname.. " has turned Admin Immunity on!"
ULib.console( ply, text )
aafkimmune = true
--SetGlobalBool("aafkimmune", true)
for i, v in ipairs(player.GetAll()) do
ULib.tsay(v, "Admin: " ..aname.. " has turned Admin Immunity on!", true)
end
else
ULib.console(ply, "You must enter 1 for True or 0 for False!", true)
return
end
end
concommand.Add("aafk_adminimmune",aafkadminvar)
--ADDS THE CONSOLE COMMAND TO SET IF IS ENABLED--
function aafkenabledvar( ply, command, args )
if !aafkCheckAdmin(ply) then
ULib.console(ply, "Only Superadmin can change this variable", true)
return
end
local aname = "Default"
if ply:IsValid() then
aname = ply:GetName()
else
aname = "Console"
end
if args[1] == "0" then
local text = "Admin: " ..aname.. " has disabled aafk!"
ULib.console( ply, text )
aafkenabled = false
--SetGlobalBool("aafkenabled", false)
for i, v in ipairs(player.GetAll()) do
ULib.tsay(v, "Admin: " ..aname.. " has disabled aafk!", true)
end
elseif args[1] == "1" then
local text = "Admin: " ..aname.. " has enabled aafk!"
ULib.console( ply, text )
aafkenabled = true
--SetGlobalBool("aafkenabled", true)
for i, v in ipairs(player.GetAll()) do
ULib.tsay(v, "Admin: " ..aname.. " has enabled aafk!", true)
end
else
ULib.console(ply, "You must enter 1 for True or 0 for False!", true)
return
end
end
concommand.Add("aafk_enabled",aafkenabledvar)
function AFKChatHook(ply, text, public)
local args = string.Explode(" ", text)
if ply:GetNetworkedBool("afk") == true then
ply:ConCommand("aafk_return 1q2w3e4r\n")
ply:ConCommand("setinfo name " ..ply:GetNetworkedString("savedname").."\n")
else
if string.upper(args[1]) == "!AFK" then
ply:SetNetworkedBool("afk", true)
if aafkick == true then
ply:SetNetworkedInt("ccount", 1)
local Text = "You are flagged as AFK, AFK Kicking is enabled, you will be kicked the next time the server checks for afk players."
ply:SendLua("GAMEMODE:AddNotify(\""..Text.."\", NOTIFY_GENERIC, 5); surface.PlaySound(\"npc/attack_helicopter/aheli_damaged_alarm1.wav\")")
else
local Text = "You are flagged as AFK!"
ply:SendLua("GAMEMODE:AddNotify(\""..Text.."\", NOTIFY_GENERIC, 5); surface.PlaySound(\"npc/attack_helicopter/aheli_damaged_alarm1.wav\")")
end
ULib.tsay(nil, tostring(ply:GetName()).. " is now afk", true)
oname[ply:UniqueID()].name = tostring(ply:GetName())
ply:SetNetworkedString("savedname", ply:GetName())
local afkname
if string.Left(tostring(ply:GetName()), 5) == "<AFK>" then --Somehow.. for some reason they already have AFK in as the start of their name.. we dont want it there twice.. =)
afkname = oname[ply:UniqueID()].name
else
afkname = "<AFK>" ..oname[ply:UniqueID()].name..""
end
ply:ConCommand("setinfo name " ..afkname.."\n")
return ""
else
local chatc = ply:GetNetworkedInt("ccount")
chatc = chatc + 1
ply:SetNetworkedInt("ccount", chatc)
--ULib.tsay(ply, tostring(p
Second line
--AAfk - By Zach Petty (MrPresident) [b]for the use on gman4president.com G4P GarrysMod servers[/b].
Sorry, you need to Log In to post a reply to this thread.