Alexs Posted July 31, 2012 Share Posted July 31, 2012 Hola a Todos, acababa el spawn de Paintball y queria saber si esto deberia funcionar: function getDefinitions( startedMap ) local mapRoot = getResourceRootElement( startedMap ) local spawnred = getElementsByType ( "spawnred" , mapRoot ) local spawnblue = getElementsByType ( "spawnblue" , mapRoot ) for key, rojo in pairs( spawnred ) do posr = getElementData ( rojo, "position" ) rotred = getElementData ( rojo, "rotation" ) insert.table(posred, posr) end for key, azul in pairs( spawnblue ) do posb = getElementData ( azul, "position" ) rotblue = getElementData ( azul, "rotation" ) insert.table(posblue, posb) end for teamr, rojos in pairs ( getPlayersInTeam ( Rojos )) do spawnPlayer(rojos,math.random(#posred),rotred,170) end for teamb, azules in pairs ( getPlayersInTeam ( Blue )) do spawnPlayer(azules,math.random(#posblue),rotblue,188) end end addEventHandler("onGamemodeMapStart", getRootElement(), getDefinitions) El caso es que hay muchos elementos de "spawnred" y "spawnblue" y quiero que al comenzar el mapa spawneen aleatoriamente entre ellos ya que si no quedarian congelados uno en el otro, esto serviria para eso? Link to comment
Castillo Posted July 31, 2012 Share Posted July 31, 2012 function getDefinitions ( startedMap ) local mapRoot = getResourceRootElement ( startedMap ) local spawnred = getElementsByType ( "spawnred", mapRoot ) local spawnblue = getElementsByType ( "spawnblue", mapRoot ) for teamr, rojos in pairs ( getPlayersInTeam ( Rojos ) ) do local randomPoint = math.random ( #getElementsByType ( "spawnred", mapRoot ) ) local x, y, z = unpack ( getElementData ( getElementsByType ( "spawnred", mapRoot ) [ randomPoint ], "position" ) ) local rot = getElementData ( getElementsByType ( "spawnred", mapRoot ) [ randomPoint ], "rotation" ) spawnPlayer ( rojos, x, y, z, rot, 170 ) end for teamb, azules in pairs ( getPlayersInTeam ( Blue ) ) do local randomPoint = math.random ( #getElementsByType ( "spawnblue", mapRoot ) ) local x, y, z = unpack ( getElementData ( getElementsByType ( "spawnblue", mapRoot ) [ randomPoint ], "position" ) ) local rot = getElementData ( getElementsByType ( "spawnblue", mapRoot ) [ randomPoint ], "rotation" ) spawnPlayer ( azules, x, y, z, rot, 188 ) end end addEventHandler ( "onGamemodeMapStart", getRootElement(), getDefinitions ) Suponiendo que "position" sea una tabla con 3 argumentos, deberia funcionar creo yo. Link to comment
Alexs Posted July 31, 2012 Author Share Posted July 31, 2012 Error en la linea 9: bad argument #1 to pairs, expected table got boolean Error en la linea 11: bad argument #1 to unpack, expected table got userdata Link to comment
Castillo Posted July 31, 2012 Share Posted July 31, 2012 Me equivoque en algo, copia el codigo de nuevo. Link to comment
Alexs Posted July 31, 2012 Author Share Posted July 31, 2012 Gracias, cuando pueda lo testeo y reposteo para que se mueva hacia arriba y sepan que lo probe Link to comment
Recommended Posts