Page 1 of 1

Delete An Entire Group Of Units

Posted: Wed Oct 30, 2019 4:52 am
by butch4343
Im looking for some help, I have a scenario am creating from an old Harpoon Gold Scenario.

In Harpoon airfields were single attackable units and in command they are not, I have worked out a way to destroy the whole base using LUA that is, have a single unit airfield called in this case wethersfield then create 20 hangars W1-12 group the lot together.

I then use a points based trigger to remove the airfield, and create the following script:

ScenEdit_DeleteUnit({side="NATO", unitname="Wethersfield1"})
ScenEdit_DeleteUnit({side="NATO", unitname="W1"})
ScenEdit_DeleteUnit({side="NATO", unitname="W2"})
ScenEdit_DeleteUnit({side="NATO", unitname="W3"})
ScenEdit_DeleteUnit({side="NATO", unitname="W4"})
ScenEdit_DeleteUnit({side="NATO", unitname="W5"})
ScenEdit_DeleteUnit({side="NATO", unitname="W6"})
ScenEdit_DeleteUnit({side="NATO", unitname="W7"})
ScenEdit_DeleteUnit({side="NATO", unitname="W8"})
ScenEdit_DeleteUnit({side="NATO", unitname="W9"})
ScenEdit_DeleteUnit({side="NATO", unitname="W10"})
ScenEdit_DeleteUnit({side="NATO", unitname="W11"})
ScenEdit_DeleteUnit({side="NATO", unitname="W12"})


Wethersfield1 is the single airfield unit in this case

This works really well, however its time consuming so I tried a second script to see if I could achieve the same effect on 1 line of code :

ScenEdit_DeleteUnit({side="NATO"name='Wethersfield'})

This code works but it deletes the group and leaves in place the units that made up the group which isnt exactly what I wanted to achieve. So is there a reasonably easy script I could use that will delete a Group AND its sub units in one go?

It would be much easier if Single Unit airfields were attackable lol
Kind Regards

Butch

RE: Delete An Entire Group Of Units

Posted: Wed Oct 30, 2019 9:15 am
by SeaQueen
It would be much easier if Single Unit airfields were attackable lol

Then you'd have to listen to me whine about how your scenario totally sucks because I don't get to weaponeer each and every DMPI for every single JDAM coming off my B-2.

RE: Delete An Entire Group Of Units

Posted: Wed Oct 30, 2019 10:47 pm
by Whicker
you can get the unitlist from the group and then go over it to delete each unit, then delete the group.
local u = ScenEdit_GetUnit({name='groupName'})
unitsToChange = u.group.unitlist
for i = 1, #unitsToChange
do
--delete the unit here - unit list is list of guids I think (guid=unitsToChange)
end --loop

--delete the group here? not sure if there would be a group left if there were no units so maybe not

RE: Delete An Entire Group Of Units

Posted: Thu Oct 31, 2019 5:50 am
by michaelm75au
You should be able to delete the group with the units.
ScenEdit_DeleteUnit({side="NATO", unitname="Wethersfield1"}, true)

The binary option allows you to delete the 'group' and the attached units. By default, deleting a 'group' will only remove the 'group' unit = un-group it.

The Editor method drop-down list shows this extra option, but not the documentation.

RE: Delete An Entire Group Of Units

Posted: Wed Nov 06, 2019 3:58 am
by butch4343
All,

Thanks for the really helpful replies, Ive just tried out the LUA codes and it works really well.

Thanks Again

Butch