Jump to content

Problema al sumar


andresmak

Recommended Posts

Posted

Tengo un problema al sumar un dinero pero ese dinero es de todas las cuantas de los jugadores del servidor y que se un solo resultado.

Yo creo que se debe utilizar con table.sort pero no estoy seguro si es haci para sumarlo

local tableList = {} 
 for i, v in ipairs(getAccounts()) do 
        table.insert(tableList,{cash = getAccountData(v, "cash")}) 
        table.sort(tableList,           
        function(a,b) 
              return (tonumber(a.cash) or 0) + (tonumber(b.cash) or 0) 
        end) 
 end 

si es haci o es de otra forma, alguien me podria ayudar si es tan amable?

Gracias!

Posted
local accounts = getAccounts ( ) 
table.sort ( accounts, 
    function (a, b ) 
        return ( tonumber ( getAccountData ( a, "cash" ) ) or 0 ) + ( tonumber ( getAccountData ( b, "cash" ) ) or 0 ) 
    end 
) 

Creo que eso deberia funcionar.

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

Puede que lo hiciera, pero mi codigo es mucho mas eficiente.

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.

  • Recently Browsing   0 members

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