Author Topic: Linking the two.  (Read 5453 times)

0 Members and 1 Guest are viewing this topic.

Offline SkuD

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
Linking the two.
« 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.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Linking the two.
« Reply #1 on: March 28, 2008, 08:32:02 PM »
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.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline SkuD

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
Re: Linking the two.
« Reply #2 on: March 28, 2008, 08:34:21 PM »
Utime appears to be working fine.  It gets some random startup errors that mean nothing, just the way that scripts are loaded on startup.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Linking the two.
« Reply #3 on: March 29, 2008, 04:35:39 AM »
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.

Offline SkuD

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
Re: Linking the two.
« Reply #4 on: March 29, 2008, 01:49:12 PM »
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:    

Code: [Select]
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.
« Last Edit: March 29, 2008, 01:51:03 PM by SkuD »

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Linking the two.
« Reply #5 on: March 31, 2008, 12:14:22 AM »
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.


Code: [Select]
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

Offline blacksythe

  • Newbie
  • *
  • Posts: 38
  • Karma: -1
Re: Linking the two.
« Reply #6 on: April 15, 2008, 02:00:13 PM »
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.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Linking the two.
« Reply #7 on: April 15, 2008, 03:26:25 PM »
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.
* Megiddo adds it to his overflowing todo list.
Experiencing God's grace one day at a time.

Offline spbogie

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 456
  • Karma: 41
Re: Linking the two.
« Reply #8 on: April 17, 2008, 08:08:37 AM »
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
Code: [Select]
local totalTime = ply:GetUTime() + CurTime() - ply:GetUTimeStart()
I have not failed. I've just found 10,000 ways that won't work. - Thomas A. Edison
I reject your reality and substitute my own. - Adam Savage

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Linking the two.
« Reply #9 on: April 17, 2008, 02:02:01 PM »
Thanks spbogie. This should work then.

Code: [Select]
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

Offline blacksythe

  • Newbie
  • *
  • Posts: 38
  • Karma: -1
Re: Linking the two.
« Reply #10 on: April 17, 2008, 02:44:00 PM »
Great thanks