Ulysses
Ulysses Stuff => Suggestions => Topic started by: SkuD on March 28, 2008, 08:15:22 PM
-
The Idea:
I would like to have the module UTime with UTeam and ulx to automatically determine what user group a player is put in. When a player hits a specified amount of play time they are automatically upgraded to next player grouping until they hit the max limit of groups a player can achieve.
I am definitely not an advanced coder but I can get my way around eventually. I can picture how the code should be but am a bit lost on how to link the files into one. If anyone has some free time to aid me with this I would appreciate the help and/or input.
-
If anyone can help with this, zakap can. He uses time based point systems for advancement on his server [gmod4president]
I'm not fully aware how he has it all set up, but know it can be done.
Now, as to whether he has time to assist or not, or perhaps make a release of his code, I do not know.
Also, does UTime work? I've not tried it since the update. Thought it was broken for some reason.
I know that zakap uses TheBigA's time script, which was written for him(zakap) originally to keep time and point count originally anyway.
-
Utime appears to be working fine. It gets some random startup errors that mean nothing, just the way that scripts are loaded on startup.
-
I did this once, but I just wrote a simple timer script for my server that checked players time every 30 seconds and promoted them if they needed to be promoted. I don't know how UTime stores it's times so I can't really help you there.
-
Thats pretty much what I was looking to accomplish. It appears it is or can be SQL database.
The function that holds the time appears to be this:
function onJoin( ply )
local uid = ply:UniqueID()
local row = sql.QueryRow( "SELECT totaltime, lastvisit FROM utime WHERE player = " .. uid .. ";" )
local time = 0
ply:SetUTime( time ), ply:SetUTimeStart( CurTime() )
With time being your total hours played and current being the session.
-
Here is something I threw together... If UTime stores player time the way I THINK it does this will work... if not, it will take a bit of minor tweaking.. I sent Meg a message, but I think he is asleep.
Megiddo if you see this... Player:GetUTime()... will this return the current seconds the player has? If not, what will? :)
Copy this code into a file and name it promotions.lua and put it in your Garrysmod/lua/autorun folder on your server.
if SERVER then
function UTimePromotions()
for k, v in pairs(player.GetAll()) do //This grabs a list of all the connected players and will step through them one at a time...
//Lets make sure they aren't in one of the protected groups
if v:IsUserGroup("admin") or v:IsUserGroup("superadmin") or v:IsUserGroup("confirmed minge") then
//Okay, they aren't in one of the protected groups, lets check their time...
else
local timecheck = v:GetUTime() //Returns the user's time in seconds (I hope)
--0/1/5/10/40 these are the times in hours you want to use.
--0/3600/18000/36000/144000 these are the same times in seconds.
--New User(default rank 0 hours)/Starter/Builder/Member/Pro
//Lets compare the users time to the set values to determine if the user should rank up or not.
//Starter Rank 3600 to 18000 seconds
if (timecheck >= 3600) and (timecheck < 18000) and !v:IsUserGroup("starter") then --Only returns true if they are within the time frame for this group and dont already have it.
game.ConsoleCommand("ulx adduser \"" ..v:GetName().. "\" starter\n")
end
//Builder Rank 18000 to 36000 seconds
if (timecheck >= 18000) and (timecheck < 36000) and !v:IsUserGroup("builder") then --Only returns true if they are within the time frame for this group and dont already have it.
game.ConsoleCommand("ulx adduser \"" ..v:GetName().. "\" builder\n")
end
//Member Rank 36000 to 144000 seconds
if (timecheck >= 36000) and (timecheck < 144000) and !v:IsUserGroup("member") then --Only returns true if they are within the time frame for this group and dont already have it.
game.ConsoleCommand("ulx adduser \"" ..v:GetName().. "\" member\n")
end
//Pro Rank 144000 and up seconds
if (timecheck >= 144000) and !v:IsUserGroup("pro") then --Only returns true if they are within the time frame for this group and dont already have it.
game.ConsoleCommand("ulx adduser \"" ..v:GetName().. "\" pro\n")
end
end
end
end
timer.Create( "UTime_AutoPromotions", 60, 0, UTimePromotions ) --Checks time every 60 seconds.
end
-
After looking at this code and trying it out, I am getting an error returned on line 22 its comparing a string to a number ie 18000. im assuming the same error will occur on the consecutive lines with this comparison. Would i be right in saying if i added quotation marks to the number would this fix it.
-
Megiddo if you see this... Player:GetUTime()... will this return the current seconds the player has? If not, what will? :)
Don't remember, sorry. Might look into it tonight though.
/me adds it to his overflowing todo list.
-
Just took a look, ply:GetUTime() will return the time that was stored in the db when they joined. ply:GetUTimeStart() will return the game time at which they joined. So, to get their total time you need to do
local totalTime = ply:GetUTime() + CurTime() - ply:GetUTimeStart()
-
Thanks spbogie. This should work then.
if SERVER then
function UTimePromotions()
for k, v in pairs(player.GetAll()) do //This grabs a list of all the connected players and will step through them one at a time...
//Lets make sure they aren't in one of the protected groups
if v:IsUserGroup("admin") or v:IsUserGroup("superadmin") or v:IsUserGroup("confirmed minge") then
//Okay, they aren't in one of the protected groups, lets check their time...
else
local timecheck = v:GetUTime() + CurTime() - v:GetUTimeStart()
--0/1/5/10/40 these are the times in hours you want to use.
--0/3600/18000/36000/144000 these are the same times in seconds.
--New User(default rank 0 hours)/Starter/Builder/Member/Pro
//Lets compare the users time to the set values to determine if the user should rank up or not.
//Starter Rank 3600 to 18000 seconds
if (timecheck >= 3600) and (timecheck < 18000) and !v:IsUserGroup("starter") then --Only returns true if they are within the time frame for this group and dont already have it.
game.ConsoleCommand("ulx adduser \"" ..v:GetName().. "\" starter\n")
end
//Builder Rank 18000 to 36000 seconds
if (timecheck >= 18000) and (timecheck < 36000) and !v:IsUserGroup("builder") then --Only returns true if they are within the time frame for this group and dont already have it.
game.ConsoleCommand("ulx adduser \"" ..v:GetName().. "\" builder\n")
end
//Member Rank 36000 to 144000 seconds
if (timecheck >= 36000) and (timecheck < 144000) and !v:IsUserGroup("member") then --Only returns true if they are within the time frame for this group and dont already have it.
game.ConsoleCommand("ulx adduser \"" ..v:GetName().. "\" member\n")
end
//Pro Rank 144000 and up seconds
if (timecheck >= 144000) and !v:IsUserGroup("pro") then --Only returns true if they are within the time frame for this group and dont already have it.
game.ConsoleCommand("ulx adduser \"" ..v:GetName().. "\" pro\n")
end
end
end
end
timer.Create( "UTime_AutoPromotions", 60, 0, UTimePromotions ) --Checks time every 60 seconds.
end
-
Great thanks