Jump to content

Ajuda Por favor


Recommended Posts

Como consigo classificar essa tabela de acordo com:

  
getElementData ( element, "alivetime" ) 
  

de cada player?

  
  
local sw, sh = guiGetScreenSize() 
  
scoreboardColumns = { 
    { name = "Nick", width = 200, data = function (element) return getPlayerName ( element ) end }, 
    { name = "Kills", width = 100, data = function (element) return ( getElementData ( element, "murders" ) or 0 ).. "/"..( getElementData ( element, "murders_total" ) or 0 ) end }, 
    { name = "Zombies Killed", width = 80, data = function (element) return ( getElementData ( element, "zombieskilled" ) or 0 ).. "/"..( getElementData ( element, "zombieskilled_total" ) or 0 ) end }, 
    { name = "Tempo Vivo", width = 80, data = function (element) return formatTimeFromMinutes(getElementData ( element, "alivetime" ) or 1 ).."/"..formatTimeFromMinutes(getElementData ( element, "alivetime_total" ) or 1 ) end }, 
    { name = "Grupo", width = 80, data = function (element) return getElementData ( element, "gang" ) or "Nenhum" end }, 
} 
  
local serverName = "MTA Standalone BR" 
local topsize = 60 
local playersize = topsize-30 
local panelsize = playersize*10 
  
function calculateWidth() 
    local width = 0 
    for key, value in ipairs( scoreboardColumns ) do 
        width = width + value.width 
    end 
    return width + 60 
end  
  
local max_players = 0 
local ploff = 0 
local width = calculateWidth() 
local baseX = sw/2-width/2 
local baseY = sh/2-(panelsize+topsize)/2 
  
addEventHandler( "onClientRender", root, 
    function() 
        if getKeyState( "capslock" ) == false then ploff = 0; return end 
        if getElementData(getLocalPlayer(),"logedin") then 
            dxDrawRectangle ( baseX, baseY, width, topsize, tocolor(32,32,32) ) 
            dxDrawText ( serverName, baseX+20, baseY+10, baseX+width, baseY+topsize, tocolor(255,255,255), 0.9, "default-bold" ) 
             
            dxDrawRectangle ( baseX, baseY+topsize, width, panelsize, tocolor(0,0,0,150) ) 
             
            dxDrawLine ( baseX, baseY+30, baseX+width, baseY+30, tocolor(100,100,100),0.8 ) 
            dxDrawLine ( baseX, baseY+30, baseX, baseY+panelsize+topsize, tocolor(100,100,100),0.8 ) 
            dxDrawLine ( baseX, baseY+panelsize+topsize, baseX+width, baseY+panelsize+topsize, tocolor(100,100,100),0.8 ) 
             
            dxDrawLine ( baseX+40, baseY+30, baseX+40, baseY+panelsize+topsize, tocolor(100,100,100),0.8 ) 
            dxDrawText ( "№", baseX, baseY+60, baseX+40, baseY+topsize-30, tocolor(255,255,255), 1, "default-bold", "center", "center" ) 
            local xoff = 60 
            for i, v in ipairs ( scoreboardColumns ) do 
                dxDrawLine ( baseX+xoff+v.width, baseY+30, baseX+xoff+v.width, baseY+panelsize+topsize, tocolor(100,100,100),0.8 ) 
                dxDrawText ( v.name, baseX+xoff, baseY+60, baseX+xoff+v.width, baseY+topsize-30, tocolor(255,255,255), 1, "default-bold", "center", "center" ) 
                xoff = xoff+v.width 
            end 
            local playersTable = getElementsByType ( "player" ) 
         
            dxDrawText ( "Onlines: "..tostring(#playersTable).."/"..tostring(max_players), baseX+20, baseY+10, baseX+width-20, baseY+topsize, tocolor(255,255,255), 0.9, "default-bold", "right" ) 
  
            local maxNum = #playersTable 
            if maxNum > 10 then 
                maxNum = 10 
            end 
            for i = 1, maxNum do 
                dxDrawLine ( baseX, baseY+topsize+playersize*i, baseX+width, baseY+topsize+playersize*i, tocolor(100,100,100),0.8 ) 
                dxDrawText ( i+ploff, baseX, baseY+topsize+playersize*(i-1), baseX+40, baseY+topsize+playersize*i, tocolor(255,255,255), 1, "default-bold", "center", "center" ) 
                if playersTable[i+ploff] == localPlayer then 
                    dxDrawRectangle ( baseX, baseY+topsize+playersize*(i-1), width, playersize, tocolor(112,112,112,100) ) 
                end 
                local xoff = 60 
                for c, d in ipairs ( scoreboardColumns ) do 
                    local data = d.data(playersTable[i+ploff]) 
                    local r,g,b = 255,255,255 
                    if d.name == "grupo" and data == "Nenhum" then 
                        r,g,b = 0,255,0 
                        data = "sem grupo" 
                    end 
                    dxDrawText ( data, baseX+xoff, baseY+topsize+playersize*(i-1), baseX+xoff+d.width, baseY+topsize+playersize*i, tocolor(r,g,b), 1, "default-bold", "center", "center" ) 
                    xoff = xoff+d.width 
                end 
            end 
        end 
    end 
) 
  
function PlayerScrollMenu (key,keyState,arg) 
    if getElementData(localPlayer,"logedin") and getKeyState( "tab" ) then 
        if ( keyState == "down" ) then 
            if arg == "up" then 
                if ploff > 0 then 
                    ploff=ploff-1 
                end 
            elseif arg == "down" then 
                local playersTable = getElementsByType ( "player" ) 
                if ploff < #playersTable-10 then 
                    ploff = ploff+1 
                end 
            end 
        end 
    end 
end 
bindKey ( "mouse_wheel_up", "down", PlayerScrollMenu, "up" ) 
bindKey ( "mouse_wheel_down", "down", PlayerScrollMenu, "down" ) 
  
function formatTimeFromMinutes(value) 
    if value then 
        local hours = math.floor(value/60) 
        local minutes = math.round(((value/60) - math.floor(value/60))*100/(100/60)) 
        if minutes < 10 then minutes = "0"..minutes end 
        value = hours..":"..minutes 
        return value 
    end 
    return false 
end 
  
function math.round(number, decimals, method) 
    decimals = decimals or 0 
    local factor = 10 ^ decimals 
    if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor 
    else return tonumber(("%."..decimals.."f"):format(number)) end 
end 
  
function sendMaxPlayersOnServer (players) 
    max_players = players 
end 
addEvent("sendMaxPlayersOnServer",true) 
addEventHandler("sendMaxPlayersOnServer",getLocalPlayer(),sendMaxPlayersOnServer) 
  
  
  
  

Link to comment
tenta muda

getElementData ( element, "alivetime" ) 

para

getElementData ( getLocalPlayer(  ), "alivetime" ) 

Não é isso brunob22...

Exemplo:

Bruno alivetime=3

Marco alivetime=1

Joao alivetime=2

No meu sistema de ranking sai aleatório a ordem que aparece os players no painel do TAB, porém gostaria de colocar para quem tem o maior valor de getElementData ( element, "alivetime" ) aparecer em 1° e assim suscetivamente, ordem decrescente ficando assim:

1° Bruno

2° Joao

3° Marco

Link to comment

Você só precisa ordenar a tabela que contem os jogadores, já que você definiu ela como playersTable na linha 53 basta usar:

table.sort ( playersTable, function ( a, b ) return getElementData ( a, "alivetime" ) > getElementData ( b, "alivetime" ) end ) 

... logo abaixo, você pode ver mais sobre a função table.sort aqui.

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