Jump to content

scoreboard time played show


Wei

Recommended Posts

Ok here is my script but it is ticking on season but when player login doesn't get the time back

My Script: (PS. It's my first time working with saving)

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

Link to comment

What is that? LOL

                    if # tostring ( minutes ) == 1 then 
                        minutes = "0" .. minutes 
                    end 
                    if # tostring ( hours ) == 1 then 
                        hours = "0" .. hours 
                    end 
  

You should learn Lua.

Link to comment

Can Mod / Admin please lock this topic ? It makes me crazy when this Darken is typing funny things. Can't you read ?

THIS SCRIPT IS WORKING PERFECTLY!! AND THANKS TO SEB !!

And I wanna see your server if it's better than sebs one wich is still in development!!

Link to comment

Haha don't make me laugh dude, you don't know a fuck about Lua.

Can Mod / Admin please lock this topic ? It makes me crazy when this Darken is typing funny things. Can't you read ?

THIS SCRIPT IS WORKING PERFECTLY!! AND THANKS TO SEB !!

And I wanna see your server if it's better than sebs one wich is still in development!!

His server will be a shit like his script.

Link to comment
Haha don't make me laugh dude, you don't know a :o about Lua.

I don't know a shit of Lua and you don't know a shit of helping people ( I would be ashamed if I had 1400 post and all post without help.)I'm sure that in 1400 posts you didn't help eaven 2 people! If I would have that much post I would be a better Than you in helping and stuff like that!

Link to comment

Server:

addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
call ( getResourceFromName ( "scoreboard" ), "scoreboardAddColumn", "Online" ) 
  
addEventHandler ( "onResourceStart" , resourceRoot , 
    function ( ) 
        for index , player in ipairs ( getElementsByType ( "player" ) ) do 
            local pAccount = getPlayerAccount ( player ) 
            if not isGuestAccount ( pAccount ) then 
                local minutes = getAccountData ( pAccount , "Online.minutes" ) 
                if minutes then 
                    local hours = getAccountData ( pAccount , "Online.hours" ) 
                    if # tostring ( minutes ) == 1 then 
                        minutes = "0" .. minutes 
                    end 
                    if # tostring ( hours ) == 1 then 
                        hours = "0" .. hours 
                    end 
                    setElementData ( player , "Online" , hours .. " H " .. minutes .. " M" ) 
                    local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
                    setElementData ( player , "Online.timer" , timer ) 
                else 
                    setAccountData ( pAccount , "Online.minutes" , 0 ) 
      
              setAccountData ( pAccount , "Online.hours" , 0 ) 
                    setElementData ( player , "Online" , "00 H 00 M" ) 
                    local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
                    setElementData ( player , "Online.timer" , timer ) 
                end 
            else 
                setElementData ( player , "Online" , "N/A" ) 
            end 
        end 
    end 
) 
  
addEventHandler ( "onResourceStop" , resourceRoot , 
    function ( ) 
        for index , player in ipairs ( getElementsByType ( "player" ) ) do 
            local pAccount = getPlayerAccount ( player ) 
            if not isGuestAccount ( pAccount ) then 
                local timer = getElementData ( player , "Online.timer" ) 
                if isTimer ( timer ) then 
                    killTimer ( timer ) 
                end 
            end 
        end 
    end 
) 
  
addEventHandler ( "onPlayerLogin" , root , 
    function ( _ , pAccount ) 
        local minutes = getAccountData ( pAccount , "Online.minutes" ) 
        if minutes then 
            local hours = getAccountData ( pAccount , "Online.hours" ) 
            if # tostring ( minutes ) == 1 then 
                minutes = "0" .. minutes 
            end 
            if # tostring ( hours ) == 1 then 
                hours = "0" .. hours 
            end 
            setElementData ( source , "Online" , hours .. " H " .. minutes .. " M" ) 
            local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) 
            setElementData ( source , "Online.timer" , timer ) 
        else 
            setAccountData ( pAccount , "Online.minutes" , 0 ) 
            setAccountData ( pAccount , "Online.hours" , 0 ) 
            setElementData ( source , "Online" , "00 H 00 M" ) 
            local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) 
            setElementData ( source , "Online.timer" , timer ) 
        end 
    end 
) 
  
addEventHandler ( "onPlayerLogout" , root , 
    function ( pAccount ) 
        local timer = getElementData ( source , "Online.timer" ) 
        if isTimer ( timer ) then 
            killTimer ( timer ) 
        end 
    end 
) 
  
addEventHandler ( "onPlayerJoin" , root , 
    function ( ) 
        setElementData ( source , "Online" , "N/A" ) 
    end 
) 
  
addEventHandler ( "onPlayerQuit" , root , 
    function ( ) 
        local pAccount = getPlayerAccount ( source ) 
        if not isGuestAccount ( pAccount ) then 
            local timer = getElementData ( source , "Online.timer" ) 
            if isTimer ( timer ) then 
                killTimer ( timer ) 
            end 
        end 
    end 
) 
  
function updatePlayerOnline ( player ) 
    local pAccount = getPlayerAccount ( player ) 
    local minutes = getAccountData ( pAccount , "Online.minutes" ) 
    local hours = getAccountData ( pAccount , "Online.hours" ) 
    minutes = tostring ( tonumber ( minutes ) + 1 ) 
    if minutes == "60" then 
        hours = tostring ( tonumber ( hours ) + 1 ) 
        minutes = "00" 
    end 
    setAccountData ( pAccount , "Online.minutes" , tonumber ( minutes ) ) 
    setAccountData ( pAccount , "Online.hours" , tonumber ( hours ) ) 
    if # tostring ( minutes ) == 1 then minutes = "0" .. minutes end 
    if # tostring ( hours ) == 1 then hours = "0" .. hours end 
    setElementData ( player , "Online" , hours .. " H " .. minutes .. " M" ) 
    local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
    setElementData ( player , "Online.timer" , timer ) 
end 

It's Working in 100%. I was having this same problem :)

Link to comment
Server:
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
call ( getResourceFromName ( "scoreboard" ), "scoreboardAddColumn", "Online" ) 
  
addEventHandler ( "onResourceStart" , resourceRoot , 
    function ( ) 
        for index , player in ipairs ( getElementsByType ( "player" ) ) do 
            local pAccount = getPlayerAccount ( player ) 
            if not isGuestAccount ( pAccount ) then 
                local minutes = getAccountData ( pAccount , "Online.minutes" ) 
                if minutes then 
                    local hours = getAccountData ( pAccount , "Online.hours" ) 
                    if # tostring ( minutes ) == 1 then 
                        minutes = "0" .. minutes 
                    end 
                    if # tostring ( hours ) == 1 then 
                        hours = "0" .. hours 
                    end 
                    setElementData ( player , "Online" , hours .. " H " .. minutes .. " M" ) 
                    local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
                    setElementData ( player , "Online.timer" , timer ) 
                else 
                    setAccountData ( pAccount , "Online.minutes" , 0 ) 
      
              setAccountData ( pAccount , "Online.hours" , 0 ) 
                    setElementData ( player , "Online" , "00 H 00 M" ) 
                    local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
                    setElementData ( player , "Online.timer" , timer ) 
                end 
            else 
                setElementData ( player , "Online" , "N/A" ) 
            end 
        end 
    end 
) 
  
addEventHandler ( "onResourceStop" , resourceRoot , 
    function ( ) 
        for index , player in ipairs ( getElementsByType ( "player" ) ) do 
            local pAccount = getPlayerAccount ( player ) 
            if not isGuestAccount ( pAccount ) then 
                local timer = getElementData ( player , "Online.timer" ) 
                if isTimer ( timer ) then 
                    killTimer ( timer ) 
                end 
            end 
        end 
    end 
) 
  
addEventHandler ( "onPlayerLogin" , root , 
    function ( _ , pAccount ) 
        local minutes = getAccountData ( pAccount , "Online.minutes" ) 
        if minutes then 
            local hours = getAccountData ( pAccount , "Online.hours" ) 
            if # tostring ( minutes ) == 1 then 
                minutes = "0" .. minutes 
            end 
            if # tostring ( hours ) == 1 then 
                hours = "0" .. hours 
            end 
            setElementData ( source , "Online" , hours .. " H " .. minutes .. " M" ) 
            local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) 
            setElementData ( source , "Online.timer" , timer ) 
        else 
            setAccountData ( pAccount , "Online.minutes" , 0 ) 
            setAccountData ( pAccount , "Online.hours" , 0 ) 
            setElementData ( source , "Online" , "00 H 00 M" ) 
            local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) 
            setElementData ( source , "Online.timer" , timer ) 
        end 
    end 
) 
  
addEventHandler ( "onPlayerLogout" , root , 
    function ( pAccount ) 
        local timer = getElementData ( source , "Online.timer" ) 
        if isTimer ( timer ) then 
            killTimer ( timer ) 
        end 
    end 
) 
  
addEventHandler ( "onPlayerJoin" , root , 
    function ( ) 
        setElementData ( source , "Online" , "N/A" ) 
    end 
) 
  
addEventHandler ( "onPlayerQuit" , root , 
    function ( ) 
        local pAccount = getPlayerAccount ( source ) 
        if not isGuestAccount ( pAccount ) then 
            local timer = getElementData ( source , "Online.timer" ) 
            if isTimer ( timer ) then 
                killTimer ( timer ) 
            end 
        end 
    end 
) 
  
function updatePlayerOnline ( player ) 
    local pAccount = getPlayerAccount ( player ) 
    local minutes = getAccountData ( pAccount , "Online.minutes" ) 
    local hours = getAccountData ( pAccount , "Online.hours" ) 
    minutes = tostring ( tonumber ( minutes ) + 1 ) 
    if minutes == "60" then 
        hours = tostring ( tonumber ( hours ) + 1 ) 
        minutes = "00" 
    end 
    setAccountData ( pAccount , "Online.minutes" , tonumber ( minutes ) ) 
    setAccountData ( pAccount , "Online.hours" , tonumber ( hours ) ) 
    if # tostring ( minutes ) == 1 then minutes = "0" .. minutes end 
    if # tostring ( hours ) == 1 then hours = "0" .. hours end 
    setElementData ( player , "Online" , hours .. " H " .. minutes .. " M" ) 
    local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
    setElementData ( player , "Online.timer" , timer ) 
end 

It's Working in 100%. I was having this same problem :)

* BABY FACEPALM *

This is wrong. Also why 2 onResourceStart handlers? o.O

Link to comment
Go go go !

Dude, don't try to be good. You know, this code sucks, will never work. And you're a dumbass that trys to be better than others.

Test the script then comment !

You didn't eaven test it !

Cuz it works perfectly!

@Mefisto_PL

I have it allready. Thanks anyway!

Link to comment
Go go go !

Dude, don't try to be good. You know, this code sucks, will never work. And you're a dumbass that trys to be better than others.

Test the script then comment !

You didn't eaven test it !

Cuz it works perfectly!

@Mefisto_PL

I have it allready. Thanks anyway!

I'll test only if you want my pc to blow with these amount of errors.

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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