i have this script:
exports.scoreboard:addScoreboardColumn('Játszott idő')
local t = { }
function checkValues( source,arg1,arg2)
if (arg2 >= 60) then
t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1
t[ source ][ 'sec' ] = 0
end
if (arg1 >= 60) then
t[ source ][ 'min' ] = 0
t[ source ][ 'hours' ] = tonumber( t[ source ][ 'hours' ] or 0 ) + 1
end
return arg1, arg2
end
setTimer(
function( )
for _, v in pairs( getElementsByType( "player" ) ) do
if (not t[ v ]) then
t[ v ] = {
["hours"] = 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 hours = tonumber( t[ v ][ 'hours' ] or 0 )
setElementData(
v,
"Játszott idő",
tostring( hours )..' óra '..tostring( min )..' perc'
)
end
end,
1000, 0
)
function onPlayerQuit ( )
local playeraccount = getPlayerAccount ( source )
if ( playeraccount ) and not isGuestAccount ( playeraccount ) then
local sValue = getElementData( source,'Játszott idő' )
local hours = tonumber( t[ source ][ 'hours' ] or 0 )
local min = tonumber( t[ source ][ 'min' ] or 0 )
local sec = tonumber( t[ source ][ 'sec' ] or 0 )
setAccountData ( playeraccount, "Játszott idő-hours", tostring(hours) )
setAccountData ( playeraccount, "Játszott idő-min", tostring(min) )
setAccountData ( playeraccount, "Játszott idő-sec", tostring(sec) )
setAccountData ( playeraccount, "Játszott idő", tostring(sValue) )
end
t[ source ] = nil
end
function onPlayerLogin (_, playeraccount )
if ( playeraccount ) then
local time = getAccountData ( playeraccount, "Játszott idő" )
local hou = getAccountData ( playeraccount, "Játszott idő-hours")
local min = getAccountData ( playeraccount, "Játszott idő-min")
local sec = getAccountData ( playeraccount, "Játszott idő-sec")
if ( time ) then
setElementData ( source, "Játszott idő", time )
t[ source ]["hours"] = tonumber(hou)
t[ source ]["min"] = tonumber(min)
t[ source ]["sec"] = tonumber(sec)
else
setElementData ( source, "Játszott idő",0 )
setAccountData ( playeraccount, "Játszott idő",0 )
end
end
end
addEventHandler ( "onPlayerQuit", root, onPlayerQuit )
addEventHandler ( "onPlayerLogin", root, onPlayerLogin )
and i want add a function, what get players played time, and when reach xy played time (for example 30), then do something (for example output a text to chat box)
How is it possible?