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 >
|