Jump to content

Error


Arsilex

Recommended Posts

Posted
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?

rsilex.png.0e6ad382b3fdc3cbe6390e3e847572c9.png
Posted

Fijate que devuelve "pmon" y "top".

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Ambos son numeros, ese error no deberia aparecer, estas segurisimo de que es en esa linea?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Copialo de nuevo.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Cierto, me olvide de algo, copialo nuevamente.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Copia mi ultimo codigo.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

funciona pero no me lo ordena e.e

yo lo que quiero es que ordende de mayor a menor la persona que mas exp tenga sea rank 1 y la que menos 2 y asi e.e

rsilex.png.0e6ad382b3fdc3cbe6390e3e847572c9.png
Posted
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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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 ?

rsilex.png.0e6ad382b3fdc3cbe6390e3e847572c9.png
Posted
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 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

es posible hacer para que se guarde osea cuando el player que tiene rank 1 salga que no se le ponga rank 1 al del 2 sino que siga e.e hasta que no pase el exp del otro player

rsilex.png.0e6ad382b3fdc3cbe6390e3e847572c9.png
  • Recently Browsing   0 members

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