Lua help change mission / loadout/ base (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion



Message


Kennetho -> Lua help change mission / loadout/ base (2/16/2022 9:53:56 PM)

Hi guys,

I am new to building scenarios with lua.

I’ve build a huge 24 hours scenario NATO vs Russia in baltics. Build on top of the “No Brexit” live scen.
As it is 24 hours, some units needs to change mission and loadout from ground strike to AAW patrol.

Also some Russian squadrons home base are deep inside Russia and should change home base to land in Belarus.

Can you guys help with these luas?




KnightHawk75 -> RE: Lua help change mission / loadout/ base (2/17/2022 7:19:07 AM)

ScenEdit_HostUnitToParent will help you move units to a new base, from their current base.
http://commandlua.github.io/#ScenEdit_HostUnitToParent

ScenEdit_AssignUnitToMission will help you reassign units to new missions, or you can just set the .mission property if you already have the unit object.
http://commandlua.github.io/#ScenEdit_AssignUnitToMission

ScenEdit_SetLoadout will help you change the loadout or loadout related properties.
http://commandlua.github.io/#ScenEdit_SetLoadout

Sample function to re-base everyone at one base to another no matter if they are currently at home-base or not:
local function RelocateAllHostedUnitsToNewHost(sourcetbl,destinationtbl)
  local retval, alreadymoved, source,dest = false,{},nil,nil;
  retval,source = pcall(ScenEdit_GetUnit,sourcetbl);
  if (retval == false) or source == nil then print('invalid sourcetbl. param'); return false; end
  retval,dest = pcall(ScenEdit_GetUnit,destinationtbl);
  if (retval == false) or dest == nil then print('invalid destinationtbl. param'); return false; end

  --relocate the embarked units.
  for _,guid in ipairs(source.embarkedUnits.Aircraft) do
    ScenEdit_HostUnitToParent({HostedUnitNameOrID=guid,SelectedHostNameOrID=dest.guid});
    alreadymoved[guid]=true;
  end
  for _,guid in ipairs(source.embarkedUnits.Boats) do
    ScenEdit_HostUnitToParent({HostedUnitNameOrID=guid,SelectedHostNameOrID=dest.guid});
    alreadymoved[guid]=true;
  end
  --now assign units that are assigned to the base but not there (in the air etc), the new base without 'moving' them.
  for _,guid in ipairs(source.assignedUnits.Aircraft) do
    if alreadymoved[guid] == nil then
      ScenEdit_SetUnit({guid=guid,base=dest.guid});
      alreadymoved[guid]=true;
    end
  end
  for _,guid in ipairs(source.assignedUnits.Boats) do
    if alreadymoved[guid] == nil then
      ScenEdit_SetUnit({guid=guid,base=dest.guid});
      alreadymoved[guid]=true;
    end
  end
  return true;
end
RelocateAllHostedUnitsToNewHost({side="Blue",name="SUA__1"},{side="Blue",name="SUA__2"});

If you have specific questions about AssignUnitToMission or SetLoadout just ask.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.640625