Jump to content

[HELP] I can't figure it out


JasperRieken

Recommended Posts

Posted

It actually works, if it's the same, it's the one I'm using.

Anyway, don't post the script here again please.

Posted (edited)

this is what i've got

ServerSide: 
function addASecond() 
        local serial = getPlayerSerial(player) 
        local oldData = executeSQLSelect( "TimePlayed", "TimePlayed","serial = '" .. serial .. "'") 
            newData = tonumber(oldData[1]["TimePlayed"]) + 1 
        setElementData(player,"TimePlayed",tonumber(getElementData(player,"TimePlayed"))+1)   
    executeSQLUpdate ( "TimePlayed", "TimePlayed = '"..newData.."'","serial = '" .. serial .. "'") 
end 
addEventHandler ( "onClientRender", getRootElement(), addASecond) 
  
ClientSide: 
function Columns() 
    exports.dxscoreboard:scoreboardAddColumn("TimePlayed") 
    setElementData(localPlayer,"TimePlayed",0) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), Columns) 

Edited by Guest
Posted
this is what i've got

ServerSide:

function addASecond()

local serial = getPlayerSerial(player)

local oldData = executeSQLSelect( "TimePlayed", "TimePlayed","serial = '" .. serial .. "'")

newData = tonumber(oldData[1]["TimePlayed"]) + 1

setElementData(player,"TimePlayed",tonumber(getElementData(player,"TimePlayed"))+1)

executeSQLUpdate ( "TimePlayed", "TimePlayed = '"..newData.."'","serial = '" .. serial .. "'")

end

addEventHandler ( "onClientRender", getRootElement(), addASecond)

ClientSide:

function Columns()

exports.dxscoreboard:scoreboardAddColumn("TimePlayed")

setElementData(localPlayer,"TimePlayed",0)

end

addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), Columns)

use


tags. Easier to read.

Posted

this is what i've got

ServerSide: 
function addASecond() 
        local serial = getPlayerSerial(player) 
        local oldData = executeSQLSelect( "TimePlayed", "TimePlayed","serial = '" .. serial .. "'") 
            newData = tonumber(oldData[1]["TimePlayed"]) + 1 
        setElementData(player,"TimePlayed",tonumber(getElementData(player,"TimePlayed"))+1)   
    executeSQLUpdate ( "TimePlayed", "TimePlayed = '"..newData.."'","serial = '" .. serial .. "'") 
end 
addEventHandler ( "onClientRender", getRootElement(), addASecond) 
  
ClientSide: 
function Columns() 
    exports.dxscoreboard:scoreboardAddColumn("TimePlayed") 
    setElementData(localPlayer,"TimePlayed",0) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), Columns) 

Posted

I won't offend anyone but, that's just a total mess, wtf? using onClientRender on a server side script and combined with SQLITE functions? that's just stupid and non-sense.

-- server side:

exports.dxscoreboard:scoreboardAddColumn("Time played") 
  
function updateTimePlayed() 
    setTimer(updateTimePlayed,1000,1) 
    for index, player in ipairs(getElementsByType("player")) do 
        local timePlayed = getElementData(player, "Time played") 
        if (not timePlayed) then setElementData(player, "Time played","0:0:0") end 
        local hours, mins, secs = unpack(split(timePlayed, ":")) 
        local hours = tonumber(hours) 
        local mins = tonumber(mins) 
        local secs = tonumber(secs) 
        if (hours and mins and secs) then 
            local newsec = secs + 1 
            if ( newsec >= 60 ) then 
                newsec = 0 
                mins = mins + 1 
            end 
            if ( mins >= 60 ) then 
                mins = 0 
                hours = hours + 1 
            end 
            setElementData ( player, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) 
        end 
    end 
end 
setTimer(updateTimePlayed,1000,1) 

  • 4 months later...
Posted

Take it and don't worry

  
    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 .. ":" .. minutes .. "" ) 
                        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:00 " ) 
                        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 .. ":" .. minutes .. "" ) 
                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:00 " ) 
                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 .. ":" .. minutes .. "" ) 
        local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) 
        setElementData ( player , "Online.timer" , timer ) 
    end 
  

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