Delete An Entire Group Of Units

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
butch4343
Posts: 327
Joined: Thu Mar 26, 2015 2:09 pm

Delete An Entire Group Of Units

Post 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
User avatar
SeaQueen
Posts: 1436
Joined: Sat Apr 14, 2007 4:20 am
Location: Washington D.C.

RE: Delete An Entire Group Of Units

Post 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.
Whicker
Posts: 665
Joined: Tue Jun 19, 2018 9:54 pm

RE: Delete An Entire Group Of Units

Post 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
User avatar
michaelm75au
Posts: 12464
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Delete An Entire Group Of Units

Post 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.
Michael
butch4343
Posts: 327
Joined: Thu Mar 26, 2015 2:09 pm

RE: Delete An Entire Group Of Units

Post by butch4343 »

All,

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

Thanks Again

Butch
Post Reply

Return to “Lua Legion”