Mission now autostarts when all players have taken off

This commit is contained in:
Ambroise Garel 2025-09-11 11:12:57 +02:00
parent 81b0be5645
commit 814fbccb00
3 changed files with 41 additions and 30 deletions

View File

@ -93,7 +93,7 @@ Please also note that PvP is not supported at the moment and that the mission wi
- [ ] Weather report
- [ ] Administrative settings
- [x] Use of "Client" slot instead of "Player" slot even in single-player missions, allowing the player to respawn on death/ejection instead of having to start the whole mission again
- [ ] Single-player mission autostart on player take off
- [x] Mission now autostarts (if it wasn't started yet) when all players have taken off
- Quality of life/minor tweaks
- [ ] AI wingmen "Two was shot down!" call when witnessing another wingman killed
- [ ] AI wingmen "Winchester!" call when out of ammo

View File

@ -10,31 +10,6 @@ TUM.intermission = {}
do
local missionZonesMarkers = {}
local function doCommandStartMission()
local players = DCSEx.world.getAllPlayers()
if #players == 0 then
trigger.action.outText("No player slots occupied. At least one client slot must be occupied by a player to start the mission.", 5)
trigger.action.outSound("UI-Error.ogg")
return
end
if not TUM.settings.getValue(TUM.settings.id.MULTIPLAYER) then
for _,p in ipairs(players) do
if p:inAir() then
trigger.action.outText("Cannot start a single player mission while the player is in the air. Please land before starting the mission.", 5)
trigger.action.outSound("UI-Error.ogg")
return
end
end
end
trigger.action.outText("Generating mission and loading assets, this can take some time...", 5)
-- Add a little delay for the "Generating mission..." message be printed out. Once generation begins, the main DCS thread will be to busy to output anything.
timer.scheduleFunction(TUM.mission.beginMission, false, timer.getTime() + 1)
end
local function setSetting(args)
if not args.id or not args.value then return end
@ -74,6 +49,32 @@ do
end
end
function TUM.intermission.doCommandStartMission(allowEvenInAir)
allowEvenInAir = allowEvenInAir or false
local players = DCSEx.world.getAllPlayers()
if #players == 0 then
trigger.action.outText("No player slots occupied. At least one client slot must be occupied by a player to start the mission.", 5)
trigger.action.outSound("UI-Error.ogg")
return
end
if not allowEvenInAir and not TUM.settings.getValue(TUM.settings.id.MULTIPLAYER) then
for _,p in ipairs(players) do
if p:inAir() then
trigger.action.outText("Cannot start a single player mission while the player is in the air. Please land before starting the mission.", 5)
trigger.action.outSound("UI-Error.ogg")
return
end
end
end
trigger.action.outText("Generating mission and loading assets, this can take some time...", 5)
-- Add a little delay for the "Generating mission..." message be printed out. Once generation begins, the main DCS thread will be to busy to output anything.
timer.scheduleFunction(TUM.mission.beginMission, false, timer.getTime() + 1)
end
function TUM.intermission.removeMissionZonesMarkers()
for _,id in ipairs(missionZonesMarkers) do
trigger.action.removeMark(id)
@ -107,7 +108,7 @@ do
createSubMenu(TUM.settings.id.WINGMEN, settingsMenu)
createSubMenu(TUM.settings.id.AI_CAP, settingsMenu)
TUM.playerCareer.createMenu()
missionCommands.addCommand("➤ Begin mission", rootMenu, doCommandStartMission, nil)
missionCommands.addCommand("➤ Begin mission", rootMenu, TUM.intermission.doCommandStartMission, false)
TUM.debugMenu.createMenu() -- Append debug menu to other menus (if debug mode enabled)
end

View File

@ -193,10 +193,20 @@ do
-- @param event The DCS World event
-------------------------------------
function TUM.mission.onEvent(event)
if missionStatus == TUM.mission.status.NONE then return end
if not event.initiator then return end
if Object.getCategory(event.initiator) ~= Object.Category.UNIT then return end
if not event.initiator:getPlayerName() then return end
if Object.getCategory(event.initiator) ~= Object.Category.UNIT then return end -- Initiator is not an unit
if not event.initiator:getPlayerName() then return end -- Initiator is not a player
-- Start mission (it wasn't started yet) when all players have taken off
if event.id == world.event.S_EVENT_TAKEOFF then
if missionStatus == TUM.mission.status.NONE and #DCSEx.world.getPlayersOnGround(TUM.settings.getPlayerCoalition()) == 0 then
TUM.intermission.doCommandStartMission(true)
-- Force wingman spawning because the "on player takeoff spawn wingman" function won't be called as mission wasn't started yet when the "take off" even was raised
timer.scheduleFunction(TUM.wingmen.create, nil, timer.getTime() + 3)
end
end
if missionStatus == TUM.mission.status.NONE then return end
-- All objectives complete and all players on the ground? Mission is complete
if event.id == world.event.S_EVENT_RUNWAY_TOUCH or event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT or event.id == world.event.S_EVENT_PLAYER_LEAVE_UNIT then