Jump to content

Recommended Posts

Preciso de uma ajuda numa função.. toda vez que to o comando de criar o veiculo com as coordenada ja na tabela da esse erro

vehicle_spawns.lua:3: bad argument #1 to 'pairs' (table expected, got number)

 

função server.

function spawnDayZVehicles()
  for i,vehs in pairs(vehiclesTable)do
	for i,spawn in pairs(#vehSpawns[vehs[1]]) do
	  local x,y,z = spawn[1],spawn[2],spawn[3]
	  local veh = createVehicle(vehs[2],x,y,z)
	  local vehCol = createColSphere(x,y,z,4)
	  attachElements(vehCol,veh,0,0,0)
	  setElementData(vehCol,"parent",veh)
	  setElementData(veh,"parent",vehCol)
	  setElementData(vehCol,"vehicle",true)
	  setElementData(vehCol,"MAX_Slots",vehs[8])
	  local engRand = math.random(0,vehs[3])
	  local tireRand = math.random(0,vehs[4])
	  local partRand = math.random(0,vehs[5])
	  local rotorRand = math.random(0,vehs[6])
	  local glaRand = math.random(0,vehs[7])
	  setElementData(vehCol,"Engine_inVehicle",engRand)
	  setElementData(vehCol,"Tire_inVehicle",tireRand)
	  setElementData(vehCol,"Parts_inVehicle",partRand)
	  setElementData(vehCol,"Rotor_inVehicle",rotorRand)
	  setElementData(vehCol,"Glass_inVehicle",glaRand)
	  setElementData(vehCol,"spawn",{vehs[2],x,y,z})
	  setElementData(vehCol,"fuel",10)
	  setElementData(vehCol,"ProtectionPercent",0)
	  setElementData(vehCol,"maxfuel",vehs[9])
	  setElementData(vehCol,"needengines",vehs[3])
	  setElementData(vehCol,"needtires",vehs[4])
	  setElementData(vehCol,"needparts",vehs[5])
	  setElementData(vehCol,"needrotor",vehs[6])
	  setElementData(vehCol,"needglass",vehs[7])
	  if tireRand >= 1 then
		setElementData(vehCol,"TireState",math.random(0,100))
	  else
		setElementData(vehCol,"TireState",100)
	  end
	  if engRand >= 1 then
		setElementData(vehCol,"EngineState",math.random(0,100))
	  else
		setElementData(vehCol,"EngineState",100)
	  end
	  if rotorRand >= 1 then
		setElementData(vehCol,"RotorState",math.random(0,100))
	  else
		setElementData(vehCol,"RotorState",100)
	  end
	  if partRand >= 1 then
		setElementData(vehCol,"PartsState",math.random(0,100))
	  else
		setElementData(vehCol,"PartsState",100)
	  end
	end
  end
end

 

Edited by felipebaidoloko
Link to comment
  • Other Languages Moderators

Tente fazer assim:

local theVehicles = {}
local vehicleTable = { --Sua tabela aqui. ID, PosX, PosY, PosZ, RotX, RotY, RotZ.
[1] = {602, 0, 0, 10, 0, 0, 180},
[2] = {522, 5, 5, 10, 0, 0, 180},
[3] = {490, -5, -5, 10, 0, 0, 180}
} --Exemplo de tabela.

for k, v in ipairs (vehicleTable) do
    theVehicles[k] = createVehicle (unpack (v)) --Cria todos os veículos da tabela nas posições e rotações da tabela.
    --O resto do código aqui.
end

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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