Lua Question: Units Detach/Join Group

Post new mods and scenarios here.

Moderator: MOD_Command

Post Reply
User avatar
AlGrant
Posts: 912
Joined: Tue Aug 18, 2015 4:38 am

Lua Question: Units Detach/Join Group

Post by AlGrant »


Is there a way in Lua to detach units from a group and assign them to a new group ?

In an AI controlled side I have a group with a carrier and a number of escorts, at some point I want to detach 3 of the escorts from the carrier Group and assign them to a new Group and then to a new mission.

I have managed to get the actions I want by having the carrier group composed of 2 smaller groups, one with the escorts made relative to the carrier and then simply assign to a new mission .... it works and gets the results I'm looking for but but is a bit messy, so wondering if I can tidy things up a bit with Lua.

I've no problems with checking the units are still active and assigning to a new mission, but can't seem to split them up if all part of the same group.

Cheers
Al

GOD'S EYE DISABLED.
User avatar
michaelm75au
Posts: 12455
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Lua Question: Units Detach/Join Group

Post by michaelm75au »

local unit=ScenEdit_GetUnit({name='USS Rentz', guid='ee495732-1637-463a-b6c9-e2564150c8bf'})
unit.group='new group'
print(unit)
Michael
User avatar
AlGrant
Posts: 912
Joined: Tue Aug 18, 2015 4:38 am

RE: Lua Question: Units Detach/Join Group

Post by AlGrant »


Thanks Michael, Much appreciated. I'll give that a run tonight.

Much easier and neater than my messy attempt.
GOD'S EYE DISABLED.
User avatar
AlGrant
Posts: 912
Joined: Tue Aug 18, 2015 4:38 am

RE: Lua Question: Units Detach/Join Group

Post by AlGrant »

Works perfectly...

I've now got an AI carrier TG conducting air attacks on another TG.
If the aircraft losses rise above a certain level (and they are likely to) then the carrier group will withdraw to safety whilst a SAG Group will detach to conduct a surf attack.
Far better than the carrier just sitting there as a big juicy target!

..... Thank again Michael

GOD'S EYE DISABLED.
User avatar
Gunner98
Posts: 5881
Joined: Fri Apr 29, 2005 12:49 am
Location: The Great White North!
Contact:

RE: Lua Question: Units Detach/Join Group

Post by Gunner98 »

AlGrant

Would it be possible to get a copy of your script for that - sounds like something I can certainly use.

Thanks

B
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
User avatar
AlGrant
Posts: 912
Joined: Tue Aug 18, 2015 4:38 am

RE: Lua Question: Units Detach/Join Group

Post by AlGrant »


I'll be away from my Command laptop until Sunday evening but can send you the script snippets once I get back.

I'll say straight off that I AM USELESS AT LUA [&:] so there's no Lua magic involed but with some help and tweaking a few existing scripts I have managed to get the AI side to do what I want! Amazingly some if it is actually starting to make sense

Basically I'm using a few Events and a Lua counter as found in Mikes example here: http://www.mikmyk.com/uncategorized/cmano-lua-key-values-counters-and-behaviors/ to count the destroyed aircraft and assign the CV group to a new mission area (for withdrawl) once a threshold is reached.

Then I've used michaelm's example above to switch out some of the escorts to a new group and send them to a new sea control mission to conduct a surface attack and cover the CV's retreat.

In the scenario I'm building the Argentine carrier only has a limited number of aircraft and losing a few leaves it a bit exposed.
So I'm getting here to withdraw to a safer area, I might try to reassign a few Argentine Navy A-4's from a shore base to get her back to fighting strength.

Al

GOD'S EYE DISABLED.
User avatar
Gunner98
Posts: 5881
Joined: Fri Apr 29, 2005 12:49 am
Location: The Great White North!
Contact:

RE: Lua Question: Units Detach/Join Group

Post by Gunner98 »

Acknowledged. I consider myself a Lua numpty! So anything I find useful gets scrounged into a document for use when I need it, as opposed to working through the code myself - which I will admit, is getting easier.

Thanks

Bart
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
Post Reply

Return to “Mods and Scenarios”