Jump to content

Error


Arsilex

Recommended Posts

addCommandHandler("ran", 
function() 
    for k, i in pairs (tabladeRanks()) do 
        for g,player in ipairs(getElementsByType("player")) do 
            outputChatBox( tonumber(i)..": "..tonumber(k) ) 
            --setElementData(player, "Rank", i ) 
        end 
    end 
end) 
  
function tabladeRanks() 
local datat = {} 
    for k,player in ipairs(getElementsByType("player")) do 
        local top = datat[1] or 0 
        local low = datat[#datat] or math.huge 
        local pmon = tonumber(getElementData(player, "Exp") or 0) 
        if (pmon > top) then 
            table.insert(datat,1,player) 
        elseif (pmon < low) then 
            table.insert(datat,#datat+1,player) 
        end 
    end 
return datat 
end 

por que me da eso al poner /ran

attemt compare userdata whit number :S?

Link to comment

Proba esto:

addCommandHandler ( "ran", 
    function ( ) 
        for _, rank in ipairs ( tabladeRanks ( ) ) do 
            outputChatBox ( tonumber ( rank [ 1 ] )..": ".. getPlayerName ( rank [ 2 ] ) ) 
            --setElementData(player, "Rank", i ) 
        end 
    end 
) 
  
function tabladeRanks ( ) 
    local datat = { } 
    for k, player in ipairs ( getElementsByType ( "player" ) ) do 
        local top = ( datat [ 1 ] and datat [ 1 ] [ 1 ] or 0 ) 
        local low = datat [ #datat ] or math.huge 
        local pmon = tonumber ( getElementData ( player, "Exp" ) or 0 ) 
        if ( pmon > top ) then 
            table.insert ( datat, { 1, player } ) 
        elseif ( pmon < low ) then 
            table.insert ( datat, { #datat + 1, player } ) 
        end 
    end 
  
    return datat 
end 

Link to comment
addCommandHandler ( "ran", 
    function ( ) 
        for _, rank in ipairs ( tabladeRanks ( ) ) do 
            outputChatBox ( tonumber ( rank [ 1 ] )..": ".. getPlayerName ( rank [ 2 ] ) ) 
            --setElementData(player, "Rank", i ) 
        end 
    end 
) 
  
function tabladeRanks ( ) 
    local datat = { } 
    for k, player in ipairs ( getElementsByType ( "player" ) ) do 
        local top = ( datat [ 1 ] and datat [ 1 ] [ 1 ] or 0 ) 
        local low = ( datat [ #datat ] and datat [ #datat ] [ 1 ] or math.huge ) 
        local pmon = tonumber ( getElementData ( player, "Exp" ) or 0 ) 
        if ( pmon > top ) then 
            table.insert ( datat, { 1, player } ) 
        elseif ( pmon < low ) then 
            table.insert ( datat, { #datat + 1, player } ) 
        end 
    end 
  
    return datat 
end 

Link to comment
addCommandHandler ( "ran", 
    function ( ) 
        for _, rank in ipairs ( tabladeRanks ( ) ) do 
            outputChatBox ( tonumber ( rank [ 1 ] )..": ".. getPlayerName ( rank [ 2 ] ) ) 
            --setElementData(player, "Rank", i ) 
        end 
    end 
) 
  
function tabladeRanks ( ) 
    local datat = { } 
    for _, player in ipairs ( getElementsByType ( "player" ) ) do 
        table.insert ( 
            datat, 
            { 
                tonumber ( getElementData ( player, "Exp" ) or 0 ), 
                player 
            } 
        ) 
    end 
  
    table.sort ( 
        datat, 
        function ( a, b ) 
            return ( tonumber ( a [ 1 ] ) or 0 ) > ( tonumber ( b [ 1 ] ) or 0 ) 
        end 
    ) 
  
    return datat 
end 

Mucho mas facil con table.sort.

Link to comment
addCommandHandler ( "ran", 
    function ( ) 
        for _, rank in ipairs ( tabladeRanks ( ) ) do 
            outputChatBox ( tonumber ( rank [ 1 ] )..": ".. getPlayerName ( rank [ 2 ] ) ) 
            --setElementData(player, "Rank", i ) 
        end 
    end 
) 
  
function tabladeRanks ( ) 
    local datat = { } 
    for _, player in ipairs ( getElementsByType ( "player" ) ) do 
        table.insert ( 
            datat, 
            { 
                tonumber ( getElementData ( player, "Exp" ) or 0 ), 
                player 
            } 
        ) 
    end 
  
    table.sort ( 
        datat, 
        function ( a, b ) 
            return ( tonumber ( a [ 1 ] ) or 0 ) > ( tonumber ( b [ 1 ] ) or 0 ) 
        end 
    ) 
  
    return datat 
end 

Mucho mas facil con table.sort.

me dijero que con table.sort puede fallar e.e

y otra cosa como podria poner el setElementData rank en la posicion osea si eres el que mas tiene que seas rank 1 ?

Link to comment
addCommandHandler ( "ran", 
    function ( ) 
        for index, rank in ipairs ( tabladeRanks ( ) ) do 
            if ( isElement ( rank [ 2 ] ) ) then 
                setElementData ( rank [ 2 ], "Rank", index ) 
            end 
        end 
    end 
) 
  
function tabladeRanks ( ) 
    local datat = { } 
    for _, player in ipairs ( getElementsByType ( "player" ) ) do 
        table.insert ( 
            datat, 
            { 
                tonumber ( getElementData ( player, "Exp" ) or 0 ), 
                player 
            } 
        ) 
    end 
  
    table.sort ( 
        datat, 
        function ( a, b ) 
            return ( tonumber ( a [ 1 ] ) or 0 ) > ( tonumber ( b [ 1 ] ) or 0 ) 
        end 
    ) 
  
    return datat 
end 

Link to comment
  • Recently Browsing   0 members

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