Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

[Answered] Return to Base

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Tech Support >> [Answered] Return to Base Page: [1]
Login
Message << Older Topic   Newer Topic >>
[Answered] Return to Base - 6/15/2021 3:53:32 PM   
kritter

 

Posts: 329
Joined: 12/3/2007
Status: offline
Is there a way to have all aircraft on a mission return to base programmatically? On a trigger I want the mission to end and all aircraft return to base. I can deactivate the mission but I do not see how to get all the aircraft to return to base. The ScenEdit_SetUnit command looks like it will return one aircraft but not all. The other problem is I do not know which aircraft are on the mission when the trigger happens.

Any Ideas?

< Message edited by WSBot -- 6/16/2021 1:29:43 PM >
Post #: 1
RE: Return to Base - 6/16/2021 4:40:40 AM   
KnightHawk75

 

Posts: 1210
Joined: 11/15/2018
Status: offline
quote:

Is there a way to have all aircraft on a mission return to base programmatically?

Yes, very simply.
Basically same as this http://www.matrixgames.com/forums/fb.asp?m=4988001 with the "action" being different.

The snippet would be this if you know the mission name ahead of time.
local missionX = ScenEdit_GetMission("TheSideTheMissionIsContainedOn","MissionNameHereX")
if (missionX ~=nil) and missionX.unitlist ~=nil then
  for key,value in pairs(missionX.unitlist) do  --each value is just a guid in this case. 
    ScenEdit_SetUnit({guid=value, RTB=true}); -- issue RTB on each unit in the mission. 
  end
end

Extended answer:
If there are mission members that could be on the ground when this is issued though you should check if airborne first. Here is some more full featured code that contains error trapping and is in more reusable form, these are local function samples but you can\should make them global if reusing them a bunch, it's way more code but it also will not cause any popup errors if something goes wrong or if called with bad data, and will not issue RTB order to units on the ground which can cause issues sometimes.
-- function to always find out if a unit is airborne regardless of elevation.
local function isAircraftAirborne(u)
    if ((u.condition_v == "Airborne") or u.condition_v == "RTB") or u.condition_V == "Landing_PreTouchdown" or
     u.condition_v == "ManoeuveringToRefuel" or u.condition_v == "Refuelling" or u.condition_v == "OffloadingFuel" or 
     u.condition_v == "DeployingDippingSonar" or u.condition_v == "EmergencyLanding" or  u.condition_v == "BVRAttack" or 
     u.condition_v == "BVRCrank" or u.condition_v == "Dogfight" or u.condition_v == "BVRDrag" or u.condition_v == "TransferringCargo" then
      return true;
    end
    return false;
end
 --sample to issue RTB order, for safety only on airborne aircraft.
local function issueRTBOrderOnAircraft(value)
  local retval,u = pcall(ScenEdit_GetUnit,{guid=value}) -- go get this unit's wrapper.
  if ((retval == true) and u ~= nil) then
    if (u.type == 'Aircraft') and isAircraftAirborne(u) == true then --check if airborne first.
      retval,u = pcall(ScenEdit_SetUnit,{guid=u.guid, RTB=true}); -- issue RTB on each unit in the mission. 
      if (retval == true) and u ~=nil then --remove this if you don't want it logged
        print("RTB order has been given to unit " .. tostring(u.name));
      else
        print("Failed to RTB unit " .. tostring(u.name) .. ' ' ..tostring(u));
      end
    else 
      --print("Skipping, unit is not an aircraft or not airborne. " .. tostring(u.name));
    end
  else
    print("There was a problem obtaining unit with guid " ..tostring(value));
  end
  u,retval = nil,false;
end
--this function loops though all members of a mission and calls a function for-each.
local function forEachMissionMemberDo(missionside,missionname,func1)
  if missionside ==nil or missionname==nil or func1 == nil then print("invalid parameters, aborted.");end
  local retval,missionX = pcall(ScenEdit_GetMission,missionside,missionname);
  if((retval == true) and missionX ~=nil) and missionX.unitlist ~=nil then
    for key,value in pairs(missionX.unitlist) do  --each value is just a guid in this case.
      func1(value) --pass that value onto whatever function was named.
    end
  else
    print("Could not obtain the list of members for mission " ..tostring(missionname) .. " on side " .. tostring(missionside));
  end
end

-- call the above.
forEachMissionMemberDo('TheSideNameHere','TheMissionNameHere',issueRTBOrderOnAircraft);




< Message edited by KnightHawk75 -- 6/16/2021 4:51:36 AM >

(in reply to kritter)
Post #: 2
RE: Return to Base - 6/16/2021 1:24:51 PM   
kritter

 

Posts: 329
Joined: 12/3/2007
Status: offline
Thanks for the help, I was hoping there was a simpler way than running through each aircraft like a set mission with a RTB parameter.

Thanks

(in reply to KnightHawk75)
Post #: 3
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Tech Support >> [Answered] Return to Base Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.213