ULX

Author Topic: Utime -- Show how long your players have been connected this session and total  (Read 554771 times)

0 Members and 4 Guests are viewing this topic.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
As far as I see it TehBigA, I released mine two days ago where you released yours an hour ago. ;)
Experiencing God's grace one day at a time.

Offline TehBigA

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Sorry that I had the bug checks run for 3 days prior to release, ask president he said i should wait and guess what i found a bunch of bugs esp a rare one that cause a reinstall of the script, and now look what i get because you just had to "use mine as a template" http://forums.facepunchstudios.com/showthread.php?t=473802 thanks a bunch

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
guys. Please..

Here is the bottom line..

We released the origonal script.
Megiddo made one from scratch when it was suggested for him to have one on his server.

We decided to improve ours, and I told Megiddo what we were doing. (which was probably a bad Idea, but I didn't think that it would lead to this.)
We did a private release on my server to test the script for bugs. JamminR can confirm this, because I invited him to my server to see teh script in action a few days after we installed it. (this was I believe before Megiddo released his version).
Megiddo Decided what we were doing was a good idea.. and decided to add it to his script as well. (though I dont believe he'd ever even seen our script in action.. let alone have access to the code. (if they are similar.. it's probably just a coincidence))
Megiddo released his script.. which prompted us to release ours.

Now people think it was us who stole ideas and code from Megiddo which is complete BS.
No one stole anything from anyone. They are two completely seperate scripts which were released at the same time. END OF STORY..

Now.. lets just drop the accusations.. and move on.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
And, just for assurance sake, I did _not_ mention to Megiddo that Big had added color adjustment.
I actually thought it funny when I saw that he'd added them.
Geez. It's a time script. It's not the nobel prize.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Lt.Smith

  • Newbie
  • *
  • Posts: 32
  • Karma: 4
Moving on works for me, because I need a little help, please. I hate asking for other people to do stuff for me, but I can't figure out what I've done wrong...

Here's the edited code:

Code: [Select]
-- Written by Team Ulysses, http://ulyssesmod.net/


module( "Utime", package.seeall )
if not SERVER then return end

require( "mysql" )
 
host = "hostname"
username = "username"
password = "password"
database = "database"
port = "1234"
 
local db, error = mysql.connect(host, username, password, database, port)
if !db then print(tostring(error) .. " in connection \n") return end

function onJoin( ply )
local uid = ply:UniqueID()

totaltime, isok, error = mysql.query(db, "SELECT totaltime FROM utime WHERE player = " .. uid .. ";")
if !isok then
print(tostring(error) .. " in selecting totaltime \n");
end

lastvisit, isok, error = mysql.query(db, "SELECT lastvisit FROM utime WHERE player = " .. uid .. ";")
if !isok then
print(tostring(error) .. " in selecting lastvisit \n");
end

local time = 0

if (lastvisit) AND (totaltime) then
ULib.tsay( ply, "[UTime]Welcome back " .. ply:Nick() .. ", you last played on this server " .. os.date( "%c", lastvisit ) )
var, isok, error =  mysql.query(db, "UPDATE utime SET lastvisit = " .. os.time() .. " WHERE player = " .. uid .. ";")
if !isok then
print(tostring(error) .. " in updating lastvisit! \n")
end
time = totaltime
else
ULib.tsay( ply, "[UTime]Welcome to our server " .. ply:Nick() .. "!" )
var, isok, error = mysql.query(db, "INSERT into utime ( player, totaltime, lastvisit ) VALUES ( " .. uid .. ", 0, " .. os.time() .. " );")
if !isok then
print(tostring(error) .. "in creating profile! \n")
end
end
ply:SetUTime( time )
ply:SetUTimeStart( CurTime() )
end
hook.Add( "PlayerInitialSpawn", "UTimeInitialSpawn", onJoin )

function updatePlayer( ply )
var, isok, error = mysql.query(db, "UPDATE utime SET totaltime = " .. math.floor( ply:GetUTime() + CurTime() - ply:GetUTimeStart() ) .. " WHERE player = " .. ply:UniqueID() .. ";" )
if !isok then
print(tostring(error) .. " in updating player! \n")
end
end
hook.Add( "PlayerDisconnected", "UTimeDisconnect", updatePlayer )

function updateAll()
local players = player.GetAll()

for _, ply in ipairs( players ) do
if ply and ply:IsConnected() then
updatePlayer( ply )
end
end
end
timer.Create( "UTimeTimer", 67, 0, updateAll )

I realise this is huge... but ok. I'd very much appreciate someone looking over it and pointing out my mistakes. :)

Previously the problem was that on initial spawn it always went for this part of the if statement:
Code: [Select]
if row then
ULib.tsay( ply, "[UTime]Welcome back " .. ply:Nick() .. ", you last played on this server " .. os.date( "%c", lastvisit ) )
var, isok, error =  mysql.query(db, "UPDATE utime SET lastvisit = " .. os.time() .. " WHERE player = " .. uid .. ";")
if !isok then
print(tostring(error) .. " in updating lastvisit! \n")
end
time = totaltime

but I changed the query into two seperate ones (lastvisit and totaltime) and now the script does, well, nothing. The counter appears clientside and all that jazz but all the gnarly bits seem to be laughing at me.

Thanks for any help,

Smith
« Last Edit: January 05, 2008, 06:52:13 PM by Lt.Smith »

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
what errors are you getting?

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
I apologize for any misunderstandings as well. I honestly had no intention of making any further enhancements to Utime until I wanted something to practice context menus on (never worked with them before and I want to make sure I can do them perfectly for a possible upcoming script). I didn't really have any other script to choose for practice besides Utime, and Utime was ideal because it used complex context menus tied into variables but was still something you could code in a few hours (time is something I never seem to have enough of these days).

Anyways, I did take a look at Time Spent's code, and they're so completely different you'd have to be brain-dead to think they were based off each other. Utime is written in the same style as ULib and ULX, where TS is broken up into more chunks with heavier, more dense coding in a completely different style.

So, what I'm getting at is that I make it a professional objective to never say anything bad about other related scripts if I can help it, and that is certainly the case here as well. I hope you will offer the same courteously Big A.

Thanks! :)
Experiencing God's grace one day at a time.

Offline Lt.Smith

  • Newbie
  • *
  • Posts: 32
  • Karma: 4
what errors are you getting?
That's the mystery, I'm not getting any. Are there any obvious syntax errors I made?

That's interesting, I don't have a lua_log on the server.  ??? Looks like I have more to fix.
« Last Edit: January 06, 2008, 04:01:25 AM by Lt.Smith »

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
if you are running this on a dedicated server that you dont have the console directly in front of you, than it can be hard to see the loading lua errors sometimes. Try running this script on a listen server or even single player and see if you get any errors at startup.

Offline Lt.Smith

  • Newbie
  • *
  • Posts: 32
  • Karma: 4
I checked the Lua logs, fixed one bug where Lua doesn't know what if (blah) AND (lol) then means. For the rest the script is not throwing any errors and I think I've figured out why. If the db doesn't connect the script returns. Nothing shows up when I join, so it has to be that the db isn't connecting properly and the hooks aren't being, well, hooked.

Amazing, I asked for help and came to the right conclusion myself. ;D

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
I checked the Lua logs, fixed one bug where Lua doesn't know what if (blah) AND (lol) then means. For the rest the script is not throwing any errors and I think I've figured out why. If the db doesn't connect the script returns. Nothing shows up when I join, so it has to be that the db isn't connecting properly and the hooks aren't being, well, hooked.

Amazing, I asked for help and came to the right conclusion myself. ;D

That's not a bad thing =)
We need more people around here who are willing to do a little research and work on their own rather than just ask and demand that all of their issues be dealt with by other people.

Offline Avien

  • Full Member
  • ***
  • Posts: 168
  • Karma: 4
Tried this with the new gmod and i get the following errors:

autorun/cl_utime.lua:136: attempt to call method 'GetCursorAimVector' (a nil value)
ReadUsermessageString: String Not Pooled!

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
You'll get errors on startup but they're completely harmless, it runs flawlessly regardless. :)
Experiencing God's grace one day at a time.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
correct me if I'm wrong, but it's because its checking the aim vectors (who you might be looking at) before the client is actually loaded because of the way the New Garrys mod loads the code and runs it before the client is loaded.

Offline Avien

  • Full Member
  • ***
  • Posts: 168
  • Karma: 4
You'll get errors on startup but they're completely harmless, it runs flawlessly regardless. :)

That is not true.  When looking at people the utimer at the top left is completely black and blank.