Jump to content

[HELP] Finishing


Mature

Recommended Posts

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
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 by Infinity#
Forgot to mention, this code is untested. I wrote it off the head. (+ Updated code. Second edit)
Link to comment
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 by Hazardinho
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...