Jump to content

Help!


gokalpfirat

Recommended Posts

Now i dont get error but i cant see my online time at scoreboard

  
function joinTime ( ) 
    setElementData ( source, "joinTime", getTickCount() ) 
    setElementData (source, "joinS", 0 ) 
    setElementData (source, "joinM", 0 ) 
    setElementData (source, "joinH", 0 ) 
    setElementData (source, "joinD", 0 ) 
    setElementData (source, "Online Time", nil ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), joinTime ) 
function onResourceStart(res) 
call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Online Time") 
end 
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),onResourceStart) 
  
  
function control(source) 
endTime = getElementData(source,"joinTime") - getTickCount() 
if (endTime == 1000) then 
    setElementData (source, "joinS", tonumber(getElementData(source,"joinS"))+1 ) 
    setElementData ( source, "joinTime", getTickCount()-1000 ) 
    end 
    if (getElementData(source,"joinS") == 60) then 
        setElementData (source, "joinM", tonumber(getElementData(source,"joinM"))+1 ) 
        setElementData ( source, "joinS", tonumber(getElementData(source,"joinS"))-60 ) 
        end 
        if (getElementData(source,"joinM") == 60) then 
        setElementData (source, "joinH", tonumber(getElementData(source,"joinH"))+1 ) 
        setElementData ( source, "joinM", tonumber(getElementData(source,"joinM"))-60 ) 
        end 
                if (getElementData(source,"joinH") == 24) then 
        setElementData (source, "joinD", tonumber(getElementData(source,"joinD"))+1 ) 
        setElementData ( source, "joinH", tonumber(getElementData(source,"joinH"))-24 ) 
        end 
            end 
     
        function check(source) 
        Second = getElementData(source,"joinS") 
        Minute = getElementData(source,"joinM") 
        Hour = getElementData(source,"joinH") 
        Day = getElementData(source,"joinD") 
        if (Second >= 1) then  
        setElementData(source,"Online Time",Second.."second") 
        elseif (Minute >= 1) then 
        setElementData(source,"Online Time",Minute.."minute"..Second.."second") 
        elseif (Hour >= 1) then 
        setElementData(source,"Online Time",Hour.."Hour"..Minute.."minute"..Second.."second") 
        elseif (Day >= 1) then 
        setElementData(source,"Online Time",Day.."Day"..Hour.."Hour"..Minute.."minute"..Second.."second") 
        end 
        end 
         
        function all() 
for index , player in ipairs ( getElementsByType ( "player" ) ) do 
control(player) 
check(player) 
end 
end 
        setTimer(all,1000,0) 
         
         

Link to comment

Why are you making it that hard, you can calculate it much easier (not tested)

function onResourceStart() 
    call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Online Time") 
end 
addEventHandler("onResourceStart",resourceRoot,onResourceStart) 
  
function joinTime() 
    setElementData (source, "joinTime", getTickCount() ) 
    setElementData (source, "Online Time", "0 hours, 0 minutes, 0 seconds" ) 
end 
addEventHandler ( "onPlayerJoin", root, joinTime ) 
  
function all() 
    for index , player in ipairs ( getElementsByType ( "player" ) ) do 
        local s = getElementData(player,"joinTime") or getTickCount() 
        s = (s  - getTickCount())  / 1000 
        local string = string.format("%02d hours, %02 minutes, %02d seconds", s/3600, (s%3600)/60, s%60) 
        setElementData(player,"Online Time",string) 
    end 
end 
setTimer(all,1000,0) 

Link to comment

Try this:

function onResourceStart() 
    call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Online Time") 
    for index, player in pairs (getElementsByType("player")) do 
        setElementData (player, "joinTime", getTickCount() ) 
        setElementData (player, "Online Time", "0 hours, 0 minutes, 0 seconds" )         
    end 
end 
addEventHandler("onResourceStart",resourceRoot,onResourceStart) 
  
function joinTime() 
    setElementData (source, "joinTime", getTickCount() ) 
    setElementData (source, "Online Time", "0 hours, 0 minutes, 0 seconds" ) 
end 
addEventHandler ( "onPlayerJoin", root, joinTime ) 
  
function all() 
    for index , player in ipairs ( getElementsByType ( "player" ) ) do 
        local s = getElementData(player,"joinTime") or getTickCount() 
        s = (s  - getTickCount()) / 1000 
        local string = string.format("%02d hours, %02d minutes, %02d seconds", s/3600, s%3600/60, s%60) 
        setElementData(player,"Online Time",string) 
    end 
end 
setTimer(all,1000,0) 

I think SDK missed a "d" in " %02d minutes"

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...