Lua Question: Units Detach/Join Group (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios



Message


AlGrant -> Lua Question: Units Detach/Join Group (7/14/2017 10:22:25 AM)


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





michaelm75au -> RE: Lua Question: Units Detach/Join Group (7/14/2017 1:09:28 PM)

local unit=ScenEdit_GetUnit({name='USS Rentz', guid='ee495732-1637-463a-b6c9-e2564150c8bf'})
unit.group='new group'
print(unit)




AlGrant -> RE: Lua Question: Units Detach/Join Group (7/14/2017 1:26:04 PM)


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

Much easier and neater than my messy attempt.




AlGrant -> RE: Lua Question: Units Detach/Join Group (7/14/2017 7:50:38 PM)

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





Gunner98 -> RE: Lua Question: Units Detach/Join Group (7/14/2017 8:04:54 PM)

AlGrant

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

Thanks

B




AlGrant -> RE: Lua Question: Units Detach/Join Group (7/15/2017 9:28:08 AM)


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





Gunner98 -> RE: Lua Question: Units Detach/Join Group (7/15/2017 9:39:42 AM)

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




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
1.429688