ya.. right after I posted this source.. I replaced the game.consolecommand with ULib.kick.. because the concommand way was giving me trouble with reasons cutting off.. or if the players name was jack smith it was saying the reason was smith.. LOL.. so I just decided to use the ULib way. Thanks anyways. Also.. this code is buggy.. im debugging it now.
Here is a finished working version.. only thing I need to impliment is
-Name changes (afk)PlayerName ?? dunno if we want this? suggestions?
-SubText under name.. is this even possible in GMod10?
-Variable kick times based on server population.
--UAfk - By Zach Petty (MrPresident) for the use on gman4president.com G4P GarrysMod servers.
--Original concept by Megiddo of Team Ulysses
--Completely rewritten for the new lua and ULib
--
--BEGIN CONFIGURATION--
--
--UAfk enabled? Should this addon start enabled?--
local uafkenabled = 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 uafktime = 120
--
--Should the User be kicked if they staf afk after being flagged as AFK?--
local uafkick = true
--
--Should admins be immune to the afk kick if it is enabled?--
local uafkimmune = true
--
--
--END CONFIGURATION.. DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING--
if SERVER then
--ADDS THE CONSOLE COMMAND TO SET THE AFK TIMER--
function uafktimevar( ply, command, args )
if !ply:IsSuperAdmin() then
ULib.tsay(ply, "Only Superadmin can change this variable", true)
return
end
if tonumber(args[1]) >= 1 then
uafktime = args[1]
for i, v in ipairs(player.GetAll()) do
ULib.tsay(v, "Admin: " ..ply:GetName().. " has set the afk timer to " ..uafktime.. " seconds", true)
timer.Create( "G4P_AFKTimer", uafktime, 0, AFKCheck ) --Checks status every period you designate.
end
else
ULib.tsay(ply, "Value must be numerical and higher than 0", true)
end
end
concommand.Add("uafk_time",uafktimevar)
--ADDS THE CONSOLE COMMAND TO SET KICK FLAGS--
function uafkkickvar( ply, command, args )
if !ply:IsSuperAdmin() then
ULib.tsay(ply, "Only Superadmin can change this variable", true)
return
end
if args[1] == "0" then
uafkick = false
for i, v in ipairs(player.GetAll()) do
ULib.tsay(v, "Admin: " ..ply:GetName().. " has turned AFK Kicking off!", true)
end
elseif args[1] == "1" then
uafkick = true
for i, v in ipairs(player.GetAll()) do
ULib.tsay(v, "Admin: " ..ply:GetName().. " has turned AFK Kicking on!", true)
end
else
ULib.tsay(ply, "You must enter 1 for True or 0 for False!", true)
return
end
end
concommand.Add("uafk_kickenabled",uafkkickvar)
--ADDS THE CONSOLE COMMAND TO SET ADMIN IMMUNITY--
function uafkadminvar( ply, command, args )
if !ply:IsSuperAdmin() then
ULib.tsay(ply, "Only Superadmin can change this variable", true)
return
end
if args[1] == "0" then
uafkimmune = false
for i, v in ipairs(player.GetAll()) do
ULib.tsay(v, "Admin: " ..ply:GetName().. " has turned Admin Immunity off!", true)
end
elseif args[1] == "1" then
uafkimmune = true
for i, v in ipairs(player.GetAll()) do
ULib.tsay(v, "Admin: " ..ply:GetName().. " has turned Admin Immunity on!", true)
end
else
ULib.tsay(ply, "You must enter 1 for True or 0 for False!", true)
return
end
end
concommand.Add("uafk_adminimmune",uafkadminvar)
--ADDS THE CONSOLE COMMAND TO SET IF IS ENABLED--
function uafkenabledvar( ply, command, args )
if !ply:IsSuperAdmin() then
ULib.tsay(ply, "Only Superadmin can change this variable", true)
return
end
if args[1] == "0" then
uafkenabled = false
for i, v in ipairs(player.GetAll()) do
ULib.tsay(v, "Admin: " ..ply:GetName().. " has disabled UAFK!", true)
end
elseif args[1] == "1" then
uafkenabled = true
for i, v in ipairs(player.GetAll()) do
ULib.tsay(v, "Admin: " ..ply:GetName().. " has enabled UAFK!", true)
end
else
ULib.tsay(ply, "You must enter 1 for True or 0 for False!", true)
return
end
end
concommand.Add("uafk_enabled",uafkenabledvar)
pangles = {} --Initialize the Table
function AFKCheck()
if uafkenabled == false then return end
local curangle = "0" --Default value for this variable
for i, v in ipairs(player.GetAll()) do
curangle = v:GetAngles() --Gets the current angle of the player in the loop
if pangles[v:UniqueID()].angle == curangle then --Does this new angle match the angle stored?
if pangles[v:UniqueID()].afk == "1" then
if uafkick == true then
if uafkimmune == true then
if v:IsAdmin() then
ULib.tsay(v, "Still afk, but immune to being kicked", true)
else
--game.ConsoleCommand("ulx kick " ..v:GetName().. " UAfk:AutoKick\n") --Kick the player if
ULib.kick(v, "UAFK: AutoKick Timeout")
end
else
--game.ConsoleCommand("ulx kick " ..v:GetName().. " UAfk:AutoKick\n") --Kick the player if
ULib.kick(v, "UAFK: AutoKick Timeout")
end
else
ULib.tsay(v, "Still Afk... Kick has been turned off though.", true)
end
elseif pangles[v:UniqueID()].afk == "0" then
pangles[v:UniqueID()].afk = "1"
ULib.tsay(v, "You are flagged as AFK, if you do not move in " ..uafktime.. " seconds you will be kicked", true)
end
else
pangles[v:UniqueID()].afk = "0"
--ULib.tsay(v, "Current Angle varies from saved angle. Timers Reset.", true)
end
pangles[v:UniqueID()].angle = v:GetAngles() --Store new angle value for the user in the loop
--ULib.tsay(v, "Test: " ..tostring(pangles[v:UniqueID()].angle)) -- Just my test callback to catch when the timer updates and what the angle is being stored as. Leave this commented out.
end
end
timer.Create( "G4P_AFKTimer", uafktime, 0, AFKCheck ) --Checks status every period you designate.
function PlayerSpawn( ply ) -- Sets default data for a player when he joins.
pangles[ply:UniqueID()] = { angle=Angle( 0, 0, 0 ), afk="0"}
end
hook.Add( "PlayerInitialSpawn", "afkspawnhook", PlayerSpawn );
end
[code]
whew.. finished working edition..
The console commands are...
uafk_enabled (0/1) - turns this module off or on
uafk_adminimmune (0/1) - Admins immune to kick?
uafk_kickenabled (0/1) - Should this script kick users.. if it is off.. it'll just constantly remind them they are afk (to be used in a future version when other visual options are enabled to show everyone if a player is afk)
uafk_time (<integer>) - How often (IN SECONDS) should the script check to see if a player has changed angles[/code]