Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Lua help change mission / loadout/ 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 >> Mods and Scenarios >> Lua Legion >> Lua help change mission / loadout/ base Page: [1]
Login
Message << Older Topic   Newer Topic >>
Lua help change mission / loadout/ base - 2/16/2022 9:53:56 PM   
Kennetho


Posts: 39
Joined: 3/24/2018
From: Denmark
Status: offline
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?
Post #: 1
RE: Lua help change mission / loadout/ base - 2/17/2022 7:19:07 AM   
KnightHawk75

 

Posts: 1450
Joined: 11/15/2018
Status: offline
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.

< Message edited by KnightHawk75 -- 2/17/2022 8:26:33 AM >

(in reply to Kennetho)
Post #: 2
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Lua help change mission / loadout/ 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.672