General > Developers Corner
Bringing back UAfk.. but not with that name of course! =)
MrPresident:
right now it sets a players table by uniqueID when they join the server and checks angles every 2.5 minutes. If they havn't changed their angle since the last check, it'll flag them as afk..which at this point only sends them a message and sets a variable.. nothing visual. If they STILL havn't moved by the next check.. they will be kicked from the server.
This addon requires ULib to run as it uses some ULibrary functions. (nothing that couldn't be rewritten easily.. but why bother?!)
I plan on adding in some settings variables.. such as letting the configuring person set the time till kick and probably the option not to kick.
Something visual.. I'll have to look in to the text under the name thing.. I'm sure I could get a name change worked out like in UAfk.
Ideas? Comments?
Oh yeah..here is what I have so far.. it is working.. and I'm actually using it on my server now. I'm sure there might be some bugs.. but nothing I could find in SP.. so now Im guineapigging my Dedi.
--- Code: ---if SERVER then
pangles = {} --Initialize the Table
function AFKCheck()
local curangle = "0" --Default value for this variable
for i, v in ipairs(player.GetAll()) do
curangle = tostring(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
pangles[v:UniqueID()].afk = "0"
pangles[v:UniqueID()].angle = "0"
game.ConsoleCommand("ulx kick " ..v:GetName().. " AFK - Auto Kick\n") --Kick the player if they have not moved since last check.
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 2:30 you will be kicked", true)
end
elseif pangles[v:UniqueID()].angle == curangle then
pangles[v:UniqueID()].afk = "0"
end
pangles[v:UniqueID()].angle = tostring(v:GetAngles()) --Store new angle value for the user in the loop
--v:ConCommand("say Test")
end
end
timer.Create( "G4P_AFKTimer", 150, 0, AFKCheck ) --Checks status every 2.5 Minutes.
end
function PlayerSpawn( ply ) -- Sets default data for a player when he joins.
pangles[ply:UniqueID()] = { angle="0", afk="0"}
end
hook.Add( "PlayerInitialSpawn", "afkspawnhook", PlayerSpawn );
--- End code ---
**Save this to a lua file and throw it in your LUA/Autorun folder if you want to use it...**
I lightly commented it for my own personal use.. and there are some testing commented out lines in there you might find.. they do nothing for the function.. just things I used to test it.
JamminR:
Nice work Pres. Make it an addon for ULib (Ulib has a modules folder too)
As you add more features, perhaps have it auto adjust the time it waits to do kicks.
2.5 min if server > 85% full, 10 min if less, something like that.
I look forward to seeing it reach the releases section here and on FP.
MrPresident:
As far as making this into a module for ULib, is there somethign I have to do to it? or would this be loaded correctly if I placed it into the ULib/Modules folder?
And as for the kick time adjustment, like that idea, perhaps set up a config at the start of the file
--Kick Time Configuration (Time in minutes)--
--Time to wait if server is 75% full or more--
local ktime75 = 5
--Time to wait if server is less than 75% full--
local ktime = 10
--End Configuration
ktime75 = ktime75*60 --Gets the time in seconds (what the script will use)
ktime = ktime*60 --Ditto^^
Then just having one higherlevel if than call performing one function if the connected players / Max Players >= .75 and < .75.
are the ULib function calls to get connected player count and max player count the same now as they were in the last version of ULX?
Megiddo:
Good work! One suggestion would be to store the current angle as an angle object instead of a string, as it will take less memory that way.
To make it a ULib module, just stick it in the module folder. It will execute on both server and client though, so take care.
--- Quote from: zakap on December 20, 2007, 08:48:45 AM ---are the ULib function calls to get connected player count and max player count the same now as they were in the last version of ULX?
--- End quote ---
ULib doesn't have any such functions?
MrPresident:
Hmm.. I could have sworn I saw a function like that when I was looking at the old code for UAfk.. maybe not.. I'll look again. Also, the code I have is speperated completely by if SERVER and if CLIENT statements.. so running on both shouldn't be an issue.
Navigation
[0] Message Index
[#] Next page
Go to full version