I asked it to write a Lua script to randomly spawn downed pilots when an aircraft is shot down and this is what it wrote
Code: Select all
-- Define a function that creates a downed pilot unit
function createDownedPilot(lat, lon)
local new_unit = Unit.getByName('Downed Pilot')
if new_unit == nil then
new_unit = Unit.create('Downed Pilot')
new_unit:getGroup():setTask({
id = 'Nothing',
params = {}
})
new_unit:setCoalition('NEUTRAL')
end
new_unit:setPosition(lat, lon)
end
-- Define a function that handles downed pilots when an aircraft is destroyed
function downedPilotOnCrash(event)
if event.id == world.event.S_EVENT_CRASH then
local unit = event.initiator
local pos = unit:getPosition().p
local chance = math.random(1, 10) -- 10% chance of spawning a downed pilot
if chance == 1 then
createDownedPilot(pos.lat, pos.lon)
end
end
end
-- Register the downedPilotOnCrash function to be called when a unit is destroyed
world.addEventHandler(downedPilotOnCrash)
Would this work, provided I change the ID number to a real unit? I know almost nothing about Lua