LUA to change Hosted Units after using ScenEdit_SetUnitSide to change the base unit.

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

LUA to change Hosted Units after using ScenEdit_SetUnitSide to change the base unit.

Post by tjhkkr »

A thanks to michaelm75au

Once you change a group/base/base ship over from one side to another with ScenEdit_SetUnitSide, there is need to change the hosted units over as well. I learned that the hard way.
michaelm75au provided a LUA example for how to achieve that.

Example of how to affect the hosted units:

-- find the wrapper for the airfield
local unit = ScenEdit_GetUnit( {name='RAAF Darwin/Darwin International', guid='aeeca904-d5de-4850-a208-bddd7c2f41b0'})
print(unit.hostedUnits )
-- loop thru the hosted aircraft
for i =1, #unit.hostedUnits['Aircraft']
do
-- get the wrapper for the aircraft
local u = ScenEdit_GetUnit( { guid=unit.hostedUnits['Aircraft'] } )
-- change the side of the unit
u = ScenEdit_SetUnitSide( {side=u.side, name=u.guid, newside= 'Neutral' })
-- response should be true/false if it worked
end
-- change side of the base
ScenEdit_SetUnitSide( {side=unit.side, name=unit.guid, newside= 'Neutral' })
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
User avatar
michaelm75au
Posts: 12463
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: LUA to change Hosted Units after using ScenEdit_SetUnitSide to change the base unit.

Post by michaelm75au »

You can do the same for hosted boats. Use ['Boats']?? instead of '[Aircraft']
Print (unit.hostedUnits ) for a port with ships and you should be able to verify the tag.
Michael
Post Reply

Return to “Lua Legion”