Jump to content

Ayuda con el ScoreBoard


SantiagoOR123

Recommended Posts

bueno tengo una duda en el ScoreBoard.

Lo que sucede es que quiero editarlo para que me diga las horas que llevo de juego pero

soy nuevo y no se como hacerlo :? lo unico que hecho hasta el momento es:

local sizescoreboard = 60 

exports.scoreboard:scoreboardAddColumn("Horas", root, sizescoreboard) 

de hay no se que funciones debo agregar :/ ayuda porfavor.

Link to comment
  • MTA Team

Encontré esto navegando por el foro:

  
exports.scoreboard:addScoreboardColumn( 'Play Time' ) 
  
local t = { } 
local uTimers = { } 
  
function checkValues( source,arg1,arg2 ) 
    if arg1 > 60 then 
        t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1 
        t[ source ][ 'sec' ] = 0 
    elseif arg2 > 3600 then 
        t[ source ][ 'sec' ] = 0 
        t[ source ][ 'min' ] = 0 
        t[ source ][ 'hour' ] = tonumber( t[ source ][ 'hour' ] or 0 ) + 1 
    end 
end 
  
function onPlayerLogOut ( _,account ) 
    if ( account ) and not isGuestAccount ( account ) then 
        local sValue = getElementData( source,'Play Time' ) 
        setAccountData ( account, "Play Time", tostring( sValue ) ) 
    end 
    if isTimer( uTimers[ source ] ) then 
        killTimer( uTimers[ source ] ) 
    end 
    uTimers[ source ] = nil 
    t[ source ] = nil 
end 
    
function onPlayerQuit ( ) 
    local playeraccount = getPlayerAccount ( source ) 
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then 
        local sValue = getElementData( source,'Play Time' ) 
        setAccountData ( playeraccount, "Play Time", tostring( sValue ) ) 
    end 
    if isTimer( uTimers[ source ] ) then 
        killTimer( uTimers[ source ] ) 
    end 
    uTimers[ source ] = nil 
    t[ source ] = nil 
end 
  
function subFind( str,mod ) 
    if mod == 'hour' then 
        return str:sub( 1,str:find( ':' ) -1 ) 
    else 
        return str:sub( str:find( ':' ) + 1,str:len( ) ) 
    end 
end 
  
function onPlayerLogin (_, account ) 
    if account then 
        uTimers[ source ] = setTimer( 
            function( player,acc ) 
                local time = getAccountData ( acc, "Play Time" ) 
                if time then 
                    if not t[ player ] then 
                        t[ player ] = { 
                            ["hour"]    = tonumber( subFind( time,'hour' ) ), 
                            ["min"]     = tonumber( subFind( time ) ), 
                            ["sec"]     = 0 
                        } 
                    end 
                else 
                    if not t[ player ] then 
                        t[ player ] = { 
                            ["hour"]    = 0, 
                            ["min"]     = 0, 
                            ["sec"]     = 0 
                        } 
                    end 
                end 
                t[ player ][ 'sec' ] = tonumber( t[ player ][ 'sec' ] or 0 ) + 1 
                checkValues ( 
                    player, 
                    t[ player ][ 'sec' ] or 0, 
                    t[ player ][ 'min' ] or 0 
                )   
                setElementData ( 
                    player, 
                    "Play Time", 
                    tostring( t[ player ][ 'hour' ] or 0 )..':'..tostring( t[ player ][ 'min' ] or 0 ) 
                ) 
            end, 
        1000, 
        0 ,source,account ) 
    end 
end 
addEventHandler ( "onPlayerQuit", root, onPlayerQuit ) 
addEventHandler ( "onPlayerLogin", root, onPlayerLogin ) 
addEventHandler( 'onPlayerLogout',root, onPlayerLogOut ) 

Fíjate si te sirve...

Link to comment
  • Recently Browsing   0 members

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