diff --git a/CSAR.lua b/CSAR.lua index 6e52a85..0874046 100644 --- a/CSAR.lua +++ b/CSAR.lua @@ -344,6 +344,10 @@ function csar.eventHandler:onEvent(_event) -- Catch multiple events here? if csar.takenOff[_event.initiator:getName()] == true or _unit:inAir() then + if csar.doubleEjection(_unit) then + return + end + trigger.action.outTextForCoalition(_unit:getCoalition(), "MAYDAY MAYDAY! " .. _unit:getTypeName() .. " shot down. No Chute!", 10) csar.handleEjectOrCrash(_unit, true) else @@ -384,6 +388,11 @@ function csar.eventHandler:onEvent(_event) return -- give up, pilot hasnt taken off end + if csar.doubleEjection(_unit) then + return + end + + local _spawnedGroup = csar.spawnGroup(_unit) csar.addSpecialParametersToGroup(_spawnedGroup) @@ -457,6 +466,24 @@ function csar.eventHandler:onEvent(_event) end end +csar.lastCrash = {} + +function csar.doubleEjection(_unit) + + if csar.lastCrash[_unit:getName()] then + local _time = csar.lastCrash[_unit:getTime()] + + if timer.getTime() - _time < 10 then + env.info("Caught double ejection!") + return true + end + end + + csar.lastCrash[_unit:getName()] = timer.getTime() + + return false +end + function csar.handleEjectOrCrash(_unit, _crashed) -- disable aircraft for ALL pilots