So long story short. I have 3 locations (Helipads) that I want to spawn helicopters on to. But I want to check the helipad first off. So if a DoesEntityExist() come back as true, then skip the helipad and cycle to the next one, if a vacant one is found. Spawn the helicopter, otherwise notify that the spawns are all blocked.
This is my current code, currently I’m trying to make it print a message, On the elseif, it prints all 3 coords of the helipads, whereas the string im trying to call is giving me this error:
"attempt to index a nil value (global ‘x’)
helipads = {
{x = -2180.76, y = 3202.30, z = 35.00, heading = 330.79},
{x = -2159.49, y = 3190.64, z = 35.00, heading = 326.20},
{x = -2184.85, y = 3175.46, z = 35.00, heading = 330.63}
}
local landVehicleSpawnClearCheck = GetClosestVehicle(landVehicleSpawnLocation.x, landVehicleSpawnLocation.y, landVehicleSpawnLocation.z, 50.0, 0, 23) --23 checks when not inside a vehicle.
for k, v in pairs (helipads) do
local helipadSpawnClearCheck = GetClosestVehicle(v.x, v.y, v.z, 15.0, 0, 12294)
if DoesEntityExist(helipadSpawnClearCheck) then
print("Helipad " ..v " Blocked")
elseif not DoesEntityExist(helipadSpawnClearCheck) then
print(v.x, v.y, v.z)
end
end
I’ve tried reading general lua documentation on tables and loops and still got no further, I’ve tried naming the tables so that rather than it being a few arrays within the table, I put 1 = {x,y,z}, 2 ={x,y,z} but this errored as it seems you cannot assign an int to an array within a table?
Thanks in advance.