trigger to assign aircraft to a different mission when aircraft refueled

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
orca
Posts: 545
Joined: Wed Nov 06, 2013 4:59 pm

trigger to assign aircraft to a different mission when aircraft refueled

Post by orca »

I am trying to create a strike mission in which a group of aircraft meet at a "marshaling" area to refuel from tankers. I will use a support mission for the aircraft and the tankers for the "marshaling" mission. I then need to use LUA to create a trigger that runs when the aircraft reach full fuel state. The trigger will then be used to change the mission from "marshaling" to "strike".

Does anyone know how to use LUA for such a trigger?

Alternatively, if there are other ways to model such a "marshaling/refueling" mission followed by a strike mission please let me know.

Thanks
boogabooga
Posts: 1021
Joined: Wed Jul 18, 2018 12:05 am

RE: trigger to assign aircraft to a different mission when aircraft refueled

Post by boogabooga »

Watch your terminology, there are "triggers", there are "actions", and there are "conditions", and the three combine to create an "event".

You can't change a mission type, but you can create both missions and assign aircraft back and forth.
The boogabooga doctrine for CMO: Any intentional human intervention needs to be able to completely and reliably over-ride anything that the AI is doing at any time.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: trigger to assign aircraft to a different mission when aircraft refueled

Post by KnightHawk75 »

As for the general approach here two methods that immediately come to mind since there is no actual 'trigger' for fuel state you have to make your own.

1. The more complicated would be to monitor the overall fuel count (accounting for all tanks - wrapper.fuel[2001].current) on each marshaling aircraft involved say every 15sec, when they fall below x per aircraft type you then start monitoring say ever 5sec for when they are above y and then trigger the mission change and disable your monitoring when all aircraft have been changed.

2. Another generally easier way (depending..everything depends) would be you monitor each marshaling aircraft wrapper involved for condition_v state for when it == "ManoeuveringToRefuel", and when that happens do the mission change - it should then when done refueling follow the new mission. I've done that before. Side note, if you try doing a mission change during actual state of =="Refuelling" it'll cancel the refueling where as doing it in the state just before it, it doesn't cancel it in my experiences. An issue you may have though is if you are using mission-specifc based refueling assignments and you've now assigned the unit to a different mission, so make sure in that instance the strike mission is also allowed to use the marshalmission's tankers. I'd recommend every 5 seconds for the trigger time for the check action, if the tankers will be very close to the aircraft, else you could miss the 'Manoeuvering' state switch.

re:2 the action running like every 5 seconds would look maybe something like this.

Code: Select all

local function isUnitRefueling(u)
   if u.condition_v == "ManoeuveringToRefuel" then return true; end
   return false;
 end
 
 local function ChangeMissionForMissionMembersRefueling(missionSide, missionName,newMissionName);
   local marshalMission = ScenEdit_GetMission(missionSide,missionName);
   for _,v in pairs(marshalMission.unitlist) do
     u = SE_GetUnit({guid=v});
     if (u~=nil) and isUnitRefueling(u) == true then
       ScenEdit_AssignUnitToMission(u.guid,newMissionName);
     end
     u = nil;
   end
 end
 
 ChangeMissionForMissionMembersRefueling('Blue','MarshalMission','StrikeMission');

orca
Posts: 545
Joined: Wed Nov 06, 2013 4:59 pm

RE: trigger to assign aircraft to a different mission when aircraft refueled

Post by orca »

thanks. this works great!

Is it possible to have certain aircraft that change mission from marshalmission to strikemission to be marked as escorts?

In my example there are 15 Su-34 with missiles, 1 Su-34 with OECM, and 4 Su-35 with AAW loadout. I'd like to have the Su-34 oecm and the 4 Su-35 be marked as escorts.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: trigger to assign aircraft to a different mission when aircraft refueled

Post by KnightHawk75 »

ORIGINAL: orca

thanks. this works great!

Is it possible to have certain aircraft that change mission from marshalmission to strikemission to be marked as escorts?

In my example there are 15 Su-34 with missiles, 1 Su-34 with OECM, and 4 Su-35 with AAW loadout. I'd like to have the Su-34 oecm and the 4 Su-35 be marked as escorts.

Ok so here is the thing, Yes you can assign known aircraft to be escorts by setting a third option to true.

ScenEdit_AssignUnitToMission(u.guid,newMissionName,true); --false is the default

HOWEVER you can't via lua actually check if a unit is an escort before hand (that I've found). So if you know ahead of time say everything in one mission should just be swapped to the other one and assigned as escorts then yeah the above change adding the true is a simple change to accomplish that.

But if you needed to dynamically\selectively pick and choose, say you only wanted escorts currently assigned as escorts to one mission to be assigned to a new mission as escorts there you can't figure that out in lua, so you'd actually have to know the units you wanted moved (or jack up their names to help id them). Hope that's clear. I came across that little problem when extending that mass unit swap script last month. I trick might be just to add like _escort to the units name you're gonna move, then you can just just like if string.find(unitWrapper.name,"_escort",1,true) ~=nil then to check if it's one that should be moved, if it's not nil it matched.

added to the above here:

Code: Select all

 ...
     if (u~=nil) and isUnitRefueling(u) == true then
       if string.find(u.name,"_escort",1,true) ~=nil then
           ScenEdit_AssignUnitToMission(u.guid,newMissionName,true);
       else
           ScenEdit_AssignUnitToMission(u.guid,newMissionName);
       end 
     end
 ...
 
But test that and make sure it works as intended, I might have reverse the string.find param order.
Also in your very specific cause you could just check the loadoutid on units as that will ID them so to speak in your case. if u.loadoutid == 1234 or u.loadoutid ==12345 or loadoutid ==54321 then ...xyz.. else ..abc end. I think you get the picture.
Post Reply

Return to “Lua Legion”