How to change a full side to a new side?

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
User avatar
Kennetho
Posts: 65
Joined: Sat Mar 24, 2018 7:23 am
Location: Denmark

How to change a full side to a new side?

Post by Kennetho »

Hi there,

Can you help with a LUA script to get a full side to change to a new side?
I need the full side to change including bases.

Old side: USMC
New Side: CENTCOM

I have been trying for weeks to get this to work trying different codes and even chatGBT.

Please help

K
morphin
Posts: 756
Joined: Fri Apr 26, 2002 6:51 pm
Location: Switzerland

Re: How to change a full side to a new side?

Post by morphin »

This code is NOT from me......


local oldside = "Pakistan" --set name of old side
local newside = "China" --set name of new side, must exist

function changesSidesGroups(newSide, oldSide) --function number one
local a = VP_GetSide({Side =oldSide}) -- get all units from old side

local groups = {} --create empty array(table) to store group guids
for i = 1, #a.units do -- loops thru all units on the side
local u = ScenEdit_GetUnit({guid = a.units.guid}) --convert VP guid to Unit wrapper
if u.type == 'Group' then -- check if group, if so add the group guid to the table
table.insert(groups, u.guid)
print(u.name.. " side: "..u.side ) --testing by printing to console
end --closes if statement
end --closes loop
for i = 1, #groups do --loop thru new table of group guids
print(groups) --testing by printing to console
ScenEdit_SetUnitSide({side=oldSide, guid=groups, newside=newSide}) --change side from old to new
end --closes loop
changeSidesUnits(newSide, oldSide) -- call second function to change units that are not in groups
end --closes function
function changeSidesUnits(newSide,oldSide) --function number two for non grouped units
local a2 = VP_GetSide({Side =oldSide}) -- get all units from old side - won't include groups as they are already done
local units = {} --create another empty table
for i = 1, #a2.units do --loop thru units and push them into the table
table.insert(units, a2.units.guid)
end --closes loop

for i = 1, #units do --loop thru table of units
print(units) --testing by printing to console
ScenEdit_SetUnitSide({side=oldSide, guid=units, newside=newSide}) --change side
end --closes loop
end -- closes second function


changesSidesGroups(newside, oldside) --call function number one to do all the magic stuff, it will call function number two.
User avatar
Kennetho
Posts: 65
Joined: Sat Mar 24, 2018 7:23 am
Location: Denmark

Re: How to change a full side to a new side?

Post by Kennetho »

Thanks
Post Reply

Return to “Lua Legion”