Mature Posted February 23, 2020 Share Posted February 23, 2020 Hello, I'm creating a STAFF system that, basically, when the administrator enters the server, creates an event, with a count to see how many hours he was online, but I have a problem when he leaves the client to inform the hours. Client addEventHandler( "onClientPlayerQuit", getRootElement(), function () if localPlayer == source then if isTimer(timerAdmin) then triggerServerEvent("RZK:Attime", resourceRoot, localPlayer, 0, hour, minute) killTimer(timerAdmin) end if isTimer(timerExtra) then triggerServerEvent("RZK:Attime", resourceRoot, localPlayer, 1, (hour + 4), minute) killTimer(timerExtra) end end end) Server addEvent("RZK:Attime", true) addEventHandler("RZK:Attime", resourceRoot, function (thePlayer, typ, h, m) if thePlayer and h and m and typ then local gid = getElementData(thePlayer, "char:id") if typ == 0 then local ad = dbQuery(sql, "SELECT * FROM Admin WHERE ID=?", gid) local rd = dbPoll(ad, -1) if #rd ~= 0 then dbExec(sql, "UPDATE Admin SET H = ?, M = ? WHERE ID = ?", h, m, gid) end end if typ == 1 then local ad = dbQuery(sql, "SELECT * FROM Admin WHERE ID=?", gid) local rd = dbPoll(ad, -1) if #rd ~= 0 then dbExec(sql, "UPDATE Admin SET H = ?, M = ? WHERE ID = ?", h, m, gid) end end end end) How can I fix this? Link to comment
Infinity# Posted February 23, 2020 Share Posted February 23, 2020 (edited) timerClient on client.Lua is not identified Edited February 23, 2020 by Infinity# Link to comment
Mature Posted February 23, 2020 Author Share Posted February 23, 2020 5 minutes ago, Infinity# said: timerClient on client.Lua is not identified Do you have any light to give me? What can I do? Link to comment
Infinity# Posted February 23, 2020 Share Posted February 23, 2020 Just now, Hazardinho said: Do you have any light to give me? What can I do? You should run a timer to see how long a player stays on the server for and when the player quits to stop the timer. Link to comment
Mature Posted February 23, 2020 Author Share Posted February 23, 2020 Just now, Infinity# said: Você deve executar um cronômetro para ver por quanto tempo um jogador permanece no servidor e quando sai para interromper o cronômetro. Can you give me an example please? Link to comment
Infinity# Posted February 23, 2020 Share Posted February 23, 2020 (edited) local timeTable = {} local timePlayers = {} function startTimeStamp() if not timeTable[source] then timeTable[source] = {["hours"]=0,["minutes"]=0,["seconds"]=0} end table.insert(source, timePlayers) setElementData(source, "onlineTime", "0:0:0") end addEventHandler("onPlayerLogin", root, startTimeStamp) function deleteTimeStamp() if timeTable[source] then timeTable[source] = nil end for i, v in ipairs(timePlayers) do if source == v then table.remove(timePlayers, i) end end end addEventHandler("onPlayerLogout", root, deleteTimeStamp) addEventHandler("onPlayerQuit", root, deleteTimeStamp) setTimer(function() for _, players in ipairs(timePlayers) do if isElement(players) and getElementType(players) == "player" and timeTable[players] then timeTable[players]["seconds"] = tonumber(timeTable[players]["seconds"] or 0) + 1 if tonumber(timeTable[players]["seconds"]) > 59 then timeTable[players]["minutes"] = tonumber(timeTable[players]["minutes"] or 0) + 1 timeTable[players]["seconds"] = 0 end if tonumber(timeTable[players]["minutes"]) > 59 then timeTable[players]["minutes"] = 0 timeTable[players]["hours"] = tonumber(timeTable[players]["hours"] or 0) + 1 end local hours = timeTable[players]["hours"] or 0 local minutes = timeTable[players]["minutes"] or 0 local seconds = timeTable[players]["seconds"] or 0 setElementData(source, "onlineTime", "".. string.format("%02d",tostring(hours)) ..":".. string.format("%02d",tostring(minutes)) ..":".. string.format("%02d",tostring(seconds)) .."") end end end, 1000, 0) Worked on a small code for you. This goes on server.Lua (You can implement it into your own code. You are free to take it) If you wish to implement it into your database let me know. I can write that small code for you. Edited February 23, 2020 by Infinity# Forgot to mention, this code is untested. I wrote it off the head. (+ Updated code. Second edit) Link to comment
Mature Posted February 23, 2020 Author Share Posted February 23, 2020 (edited) 34 minutes ago, Infinity# said: local timeTable = {} local timePlayers = {} function startTimeStamp() if not timeTable[source] then timeTable[source] = {["hours"]=0,["minutes"]=0,["seconds"]=0} end table.insert(source, timePlayers) setElementData(source, "onlineTime", "0:0:0") end Trabalhou em um pequeno código para você. Isso acontece no server.Lua (você pode implementá-lo em seu próprio código. Você é livre para aceitá-lo) Se você deseja implementá-lo em seu banco de dados, informe-me. Eu posso escrever esse pequeno código para você. Thanks, a question, how will this update per second not affect the server? because you are pulling a table every second, I worry about that, in your opinion, what do you think? Edited February 23, 2020 by Hazardinho Link to comment
Infinity# Posted February 23, 2020 Share Posted February 23, 2020 Won't affect the server at all. Is pulling from a table with stored players in it. So if X amount of players in the table, same X amount gets pulled. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now