exports["scoreboard"]:scoreboardAddColumn("sure", getRootElement(), 70, "Süre")
exports["scoreboard"]:scoreboardAddColumn("ping", getRootElement(), 30, "Ping")
local t = {}
setTimer(function()
for _, v in pairs(getElementsByType("player")) do
setElementData(v, "ping", getPlayerPing(v))
end
end, 50, 0)
function checkValues(source, arg1, arg2)
if arg2 >= 59 then
t[source]['min'] = tonumber(t[source]['min'] or 0)+1
t[source]['sec'] = 0
end
if arg1 >= 59 then
t[source]['min'] = 0
t[source]['hour'] = tonumber(t[source]['hour'] or 0)+1
end
return arg1, arg2
end
setTimer(function()
for _, v in pairs(getElementsByType("player")) do
if not t[v] then
t[v] = {
["hour"] = 0,
["min"] = 0,
["sec"] = 0
}
end
t[v]['sec'] = tonumber(t[v]['sec'] or 0)+1
local min, sec = checkValues(v, t[v]['min'] or 0, t[v]['sec'] or 0)
local hour = tonumber(t[v]['hour'] or 0)
if hour <= 9 then
hour = "0"..hour
end
if min <= 9 then
min = "0"..min
end
if sec <= 9 then
sec = "0"..sec
end
setElementData(v, "sure", tostring(hour)..':'..tostring(min)..':'..tostring(sec))
end
end, 1000, 0)
function onPlayerQuit()
local playeraccount = getPlayerAccount(source)
if (playeraccount) and not isGuestAccount(playeraccount) then
localhour = tonumber(t[source]['hour'] or 0)
localmin = tonumber(t[source]['min'] or 0)
localsec = tonumber(t[source]['sec'] or 0)
setAccountData(playeraccount, "sure-hour", tostring(hour))
setAccountData(playeraccount, "sure-min", tostring(min))
setAccountData(playeraccount, "sure-sec", tostring(sec))
setAccountData(playeraccount, "sure", getElementData(source, 'sure'))
end
t[source] = nil
end
addEventHandler("onPlayerQuit", root, onPlayerQuit)
function onPlayerLogin(_, playeraccount)
localtime = getAccountData(playeraccount, "sure")
localhou = getAccountData(playeraccount, "sure-hour")
localmin = getAccountData(playeraccount, "sure-min")
localsec = getAccountData(playeraccount, "sure-sec")
if time then
setElementData(source, "sure", time)
t[source]["hour"] = tonumber(hou)
t[source]["min"] = tonumber(min)
t[source]["sec"] = tonumber(sec)
else
setElementData(source, "sure", 0)
setAccountData(playeraccount, "sure", 0)
end
end
addEventHandler("onPlayerLogin", root, onPlayerLogin)