Arsilex Posted January 27, 2013 Share Posted January 27, 2013 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 ? Link to comment
Arsilex Posted January 27, 2013 Author Share Posted January 27, 2013 if (pmon > top) then Link to comment
Castillo Posted January 27, 2013 Share Posted January 27, 2013 Fijate que devuelve "pmon" y "top". Link to comment
Castillo Posted January 27, 2013 Share Posted January 27, 2013 Ambos son numeros, ese error no deberia aparecer, estas segurisimo de que es en esa linea? Link to comment
Arsilex Posted January 27, 2013 Author Share Posted January 27, 2013 si segurisimo (Ese money es el mio el de los demas yo creo que es que falla y da userdata) Link to comment
Castillo Posted January 27, 2013 Share Posted January 27, 2013 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
Arsilex Posted January 27, 2013 Author Share Posted January 27, 2013 attemt compare table whit number linea 16 Link to comment
Arsilex Posted January 27, 2013 Author Share Posted January 27, 2013 attemt to index field (?) (a nil value) Link to comment
Castillo Posted January 27, 2013 Share Posted January 27, 2013 Cierto, me olvide de algo, copialo nuevamente. Link to comment
Arsilex Posted January 27, 2013 Author Share Posted January 27, 2013 attemt compare number whit table linea 18 Link to comment
Castillo Posted January 27, 2013 Share Posted January 27, 2013 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
Arsilex Posted January 27, 2013 Author Share Posted January 27, 2013 attemt to index field (?) (a nil value) Link to comment
Castillo Posted January 27, 2013 Share Posted January 27, 2013 Copia mi ultimo codigo. Link to comment
Arsilex Posted January 27, 2013 Author Share Posted January 27, 2013 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 Link to comment
Castillo Posted January 28, 2013 Share Posted January 28, 2013 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
Arsilex Posted January 28, 2013 Author Share Posted January 28, 2013 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
Castillo Posted January 28, 2013 Share Posted January 28, 2013 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
Arsilex Posted January 28, 2013 Author Share Posted January 28, 2013 ok gracias castillo espero que me sirva e.e hasta ahora sirve Link to comment
Arsilex Posted January 28, 2013 Author Share Posted January 28, 2013 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 Link to comment
Recommended Posts