Jump to content

Setable hours


xJ4ckk

Recommended Posts

Please guys i need your help, i need a function to set players time (Only hours not minutes)

-------------------------------------------------------------------------------------------------------------------

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 , "Playtime" , hours .. ":" .. minutes .. "" )
                    local timer = setTimer ( actualizarJugadorOn , 60000 , 1 , player )
                    setElementData ( player , "Online.timer" , timer )
                else
                    setAccountData ( pAccount , "Online.minutes" , 0 )
     
              setAccountData ( pAccount , "Online.hours" , 0 )
                    setElementData ( player , "Playtime" , "00:00 " )
                    local timer = setTimer ( actualizarJugadorOn , 60000 , 1 , player )
                    setElementData ( player , "Online.timer" , timer )
                end
            else
                setElementData ( player , "Playtime" , "" )
            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 , "Playtime" , hours .. ":" .. minutes .. "" )
            local timer = setTimer ( actualizarJugadorOn , 60000 , 1 , source )
            setElementData ( source , "Online.timer" , timer )
        else
            setAccountData ( pAccount , "Online.minutes" , 0 )
            setAccountData ( pAccount , "Online.hours" , 0 )
            setElementData ( source , "Playtime" , "00:00" )
            local timer = setTimer ( actualizarJugadorOn , 60000 , 1 , source )
            setElementData ( source , "Online.timer" , timer )
        end
    end
)
 
addEventHandler ( "onPlayerJoin" , root ,
    function ( )
        setElementData ( source , "Playtime" , "" )
    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 actualizarJugadorOn ( 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 , "Playtime" , hours .. ":" .. minutes .. "" )
    local timer = setTimer ( actualizarJugadorOn , 60000 , 1 , player )
    setElementData ( player , "Online.timer" , timer )
end

Link to comment

I mean the Playtime on the Scoreboard bra

 

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 , "Playtime" , hours .. ":" .. minutes .. "" )
                    local timer = setTimer ( actualizarJugadorOn , 60000 , 1 , player )
                    setElementData ( player , "Online.timer" , timer )
                else
                    setAccountData ( pAccount , "Online.minutes" , 0 )
     
              setAccountData ( pAccount , "Online.hours" , 0 )
                    setElementData ( player , "Playtime" , "00:00 " )
                    local timer = setTimer ( actualizarJugadorOn , 60000 , 1 , player )
                    setElementData ( player , "Online.timer" , timer )
                end
            else
                setElementData ( player , "Playtime" , "" )
            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 , "Playtime" , hours .. ":" .. minutes .. "" )
            local timer = setTimer ( actualizarJugadorOn , 60000 , 1 , source )
            setElementData ( source , "Online.timer" , timer )
        else
            setAccountData ( pAccount , "Online.minutes" , 0 )
            setAccountData ( pAccount , "Online.hours" , 0 )
            setElementData ( source , "Playtime" , "00:00" )
            local timer = setTimer ( actualizarJugadorOn , 60000 , 1 , source )
            setElementData ( source , "Online.timer" , timer )
        end
    end
)
 
addEventHandler ( "onPlayerJoin" , root ,
    function ( )
        setElementData ( source , "Playtime" , "" )
    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 actualizarJugadorOn ( 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 , "Playtime" , hours .. ":" .. minutes .. "" )
    local timer = setTimer ( actualizarJugadorOn , 60000 , 1 , player )
    setElementData ( player , "Online.timer" , timer )
end

 

Edited by xJ4ckk
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...