• UTime help needed
    17 replies, posted
Hello, So im trying to insert your total playtime into my Applejack HUD. [code]table.insert( text, {"Play Time: "..timeToStr( localplayer:GetUTimeTotalTime() ), "icon16/time.png"} );[/code] This doesnt work Nor this [code]table.insert( text, {"Play Time: "..timeToStr( LocalPlayer():GetUTimeTotalTime() ), "icon16/time.png"} );[/code] Can someone help me
Is text a table?
Yes, because these are the other table.inserts [code] table.insert( text, {"Name: "..lpl:GetNetworkedString("RPName"), "gui/silkicons/user"} ); table.insert( text, {"Money: $"..string.Comma((lpl._Money or 0)), "gui/silkicons/coins"} ); table.insert( text, {"Salary: $"..(lpl._Salary or 0), "gui/silkicons/money"} ); table.insert( text, {"Job: "..lpl:GetNetworkedString("Job"), "gui/silkicons/wrench"} ); table.insert( text, {"Gender: "..(lpl._Gender or "Male"), "gui/silkicons/heart"} ); table.insert( text, {"Description: "..lpl:GetNetworkedString("Description"), "gui/silkicons/status_offline"}); table.insert( text, {"Clan: "..lpl:GetNetworkedString("Clan"), "gui/silkicons/group"} );[/code]
[code] [ERROR] gamemodes/evocityrp/gamemode/cl_init.lua:636: '}' expected near 'LocalPlayer' 1. unknown - gamemodes/evocityrp/gamemode/cl_init.lua:0 Couldn't Load Init Script: 'evocityrp/gamemode/cl_init.lua' [/code]
Could we see a snippet of the code where the error has occured (line 636 of cl_init.lua ) as it may not be an error on line 636, it could be forgetting to close something on the line before it
[code]table.insert( text, {"Play Time: "..timeToStr( LocalPlayer():GetUTimeTotalTime() ), "icon16/time.png"} );[/code]
A snippet... so a few lines before and after the error occured. Check the line before that, Im presuming that you have a lot of table.inserts together, maybe you forgot to close one of them.
:snip: Nvm lua highlight was weird
[code] -- Insert the player's information into the text table. table.insert( text, {"Name: "..lpl:GetNetworkedString("RPName"), "gui/silkicons/wrench"} ); table.insert( text, {"Money: $"..string.Comma((lpl._Money or 0)), "gui/silkicons/star"} ); table.insert( text, {"Job: "..lpl:GetNetworkedString("Job"), "gui/silkicons/wrench"} ); table.insert( text, {"Salary: $"..(lpl._Salary or 0), "gui/silkicons/folder_go"} ); table.insert( text, {"Gender: "..(lpl._Gender or "Male"), "gui/silkicons/heart"} ); table.insert( text, {"Description: "..lpl:GetNetworkedString("Description"), "gui/silkicons/status_offline"}); table.insert( text, {"Clan: "..lpl:GetNetworkedString("Clan"), "gui/silkicons/group"} ); table.insert( text, {"Play Time: "..timeToStr( LocalPlayer():GetUTimeTotalTime() ), "icon16/time.png"} ); [/code]
Edit: Oh wow, thanks highlighter You messed up something else somewhere, that code is completely fine as it is.
@bigdogmat , Could u check the original Utime code and remove UlX dependencies for me? Im new to Lua and have No clue on how to.
[QUOTE=HassanCohmdan;51354023]@bigdogmat , Could u check the original Utime code and remove UlX dependencies for me? Im new to Lua and have No clue on how to.[/QUOTE] What? UTime doesn't rely on ULX at all
It has ULib Dependencies. Thats what I meant.
[QUOTE=HassanCohmdan;51354088]It has ULib Dependencies. Thats what I meant.[/QUOTE] No, it does not
[code] -- Written by Team Ulysses, http://ulyssesmod.net/ module( "Utime", package.seeall ) if not SERVER then return end utime_welcome = CreateConVar( "utime_welcome", "1", FCVAR_ARCHIVE ) if not sql.TableExists( "utime" ) then sql.Query( "CREATE TABLE IF NOT EXISTS utime ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, player INTEGER NOT NULL, totaltime INTEGER NOT NULL, lastvisit INTEGER NOT NULL );" ) sql.Query( "CREATE INDEX IDX_UTIME_PLAYER ON utime ( player DESC );" ) end function onJoin( ply ) local uid = ply:UniqueID() local row = sql.QueryRow( "SELECT totaltime, lastvisit FROM utime WHERE player = " .. uid .. ";" ) local time = 0 if row then if utime_welcome:GetBool() then ULib.tsay( ply, "[UTime]Welcome back " .. ply:Nick() .. ", you last played on this server " .. os.date( "%c", row.lastvisit ) ) end sql.Query( "UPDATE utime SET lastvisit = " .. os.time() .. " WHERE player = " .. uid .. ";" ) time = row.totaltime else if utime_welcome:GetBool() then ULib.tsay( ply, "[UTime]Welcome to our server " .. ply:Nick() .. "!" ) end sql.Query( "INSERT into utime ( player, totaltime, lastvisit ) VALUES ( " .. uid .. ", 0, " .. os.time() .. " );" ) end ply:SetUTime( time ) ply:SetUTimeStart( CurTime() ) end hook.Add( "PlayerInitialSpawn", "UTimeInitialSpawn", onJoin ) function updatePlayer( ply ) sql.Query( "UPDATE utime SET totaltime = " .. math.floor( ply:GetUTimeTotalTime() ) .. " WHERE player = " .. ply:UniqueID() .. ";" ) 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 ) [/code] Why does this contain ULib tables then?
[QUOTE=HassanCohmdan;51354291]:snip: Why does this contain ULib tables then?[/QUOTE] Never noticed them, and you could've easily done this yourself if you looked up what `ULib.tasy` did. Replace it with this, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/ChatPrint]Player:ChatPrint[/url]
Can you remove them for me? I probably fuck up xD [editline]11th November 2016[/editline] I fixed it. I had to place the UTime function in the cl_init.lua [code] function timeToStr( time ) local tmp = time local s = tmp % 60 tmp = math.floor( tmp / 60 ) local m = tmp % 60 tmp = math.floor( tmp / 60 ) local h = tmp % 24 tmp = math.floor( tmp / 24 ) local d = tmp % 7 local w = math.floor( tmp / 7 ) return string.format( "%02ih %02im %02is", h, m, s ) end [/code]
Sorry, you need to Log In to post a reply to this thread.