DCS Mission Editor Question

The code as it works for detecting a client takeoff -
From here, a client name can be used in an if…then to activate/start other a/c
Another Event could be used besides a Takeoff Event.

--- detect client names & takeoff
--- this adds all mission defined Type = Client to tables called aircraftClientRedNames and aircraftClientBlueNames

--- 1st create the tables
-- Mission Start event, Create Client Tables
-- Do Script
aircraftClientBlueNames = {}
aircraftClientRedNames = {}

--- then
-- Mission Start event, Append Client Names
-- Do Script
do
 local function contains(tbl, val)
  for _,v in ipairs(tbl) do
   if v == val then return true end
  end
  return false
 end
 for uName, uData in pairs(mist.DBs.humansByName) do
  if(contains({'red'}, uData.coalition)) then
   if not(contains(aircraftClientRedNames, uName)) then
    table.insert(aircraftClientRedNames, uName)
   end
  end
  if(contains({'blue'}, uData.coalition)) then
   if not(contains(aircraftClientBlueNames, uName)) then
    table.insert(aircraftClientBlueNames, uName)
   end
  end
 end
end

--- end append client names

--- Mission Start, Detect Client Takeoff
--- this sets flag 10008 or 50008
do
 local function detectClientTakeoff(event)
  local function contains(tbl, val)
   for _,v in ipairs(tbl) do
    if v == val then return true end
   end
   return false
  end
  if(event.id == world.event.S_EVENT_TAKEOFF and event.initiator) then
   local airborneUnitName = event.initiator:getName()
   local airbornePlayerName = event.initiator:getPlayerName() --Added Variable to store PlayerName.
   local callsign = event.initiator:getCallsign() --Added Variable to store the Callsign.
   local airborneCallsign = string.sub(callsign, 1, string.len(callsign)-2) .. ' ' .. string.sub(callsign, string.len(callsign)-1, string.len(callsign)-1) .. '-' .. string.sub(callsign, string.len(callsign))
   --Modified the above line to add the space and dash back with string manipulation. Dodge11 -> Dodge 1-1
   if(contains(aircraftClientRedNames, airborneUnitName)) then
    trigger.action.setUserFlag(10008, true)
    trigger.action.outText('Red pilot ' .. airbornePlayerName .. ', callsign: ' .. airborneCallsign .. ' just tookoff in ' .. airborneUnitName .. '!', 5)
	--Modified the above line to include the new variables.
   end
   if(contains(aircraftClientBlueNames, airborneUnitName)) then
    trigger.action.setUserFlag(50008, true)
    trigger.action.outText('Blue pilot ' .. airbornePlayerName .. ', callsign: ' .. airborneCallsign .. ' just tookoff in ' .. airborneUnitName .. '!', 5)
	--Modified the above line to include the new variables.
   end
  end
 end
 mist.addEventHandler(detectClientTakeoff)
end
--- end detect client takeoff

…and that is where I think I had my issues with a similar mission. Thanks! :grin:

1 Like

If anyone would like to discuss this client detection code or get a mission that uses it, then pm me. I am happy to share.

1 Like