Jump to content

Duda con tables de coordinadas


Alexs

Recommended Posts

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
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
  • Recently Browsing   0 members

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