Page 1 of 1

Script to Add New Units to a Group

Posted: Sat Jul 21, 2018 3:29 pm
by gpotter511
Can anyone suggest a LUA command or script to add a series of new units to a newly-formed group?

That is - upon a given Trigger, a LUA script-based Action should fire that adds a series of units, and those units would then be combined into a group.

Thanks!

RE: Script to Add New Units to a Group

Posted: Sat Jul 21, 2018 4:12 pm
by Whicker
are they going to be ground/facility units? naval units? air units seem like they are different as they are only groups when in the air.

Group is part of Unit, it should not be too hard to create units and have them be in the same group.

Can you give an example of a few of the units? is the group already existing or being formed by the same lua that creates the units? not sure it matters though.

RE: Script to Add New Units to a Group

Posted: Sat Jul 21, 2018 4:29 pm
by tjhkkr
ORIGINAL: gpotter511

Can anyone suggest a LUA command or script to add a series of new units to a newly-formed group?
That is - upon a given Trigger, a LUA script-based Action should fire that adds a series of units, and those units would then be combined into a group.
Thanks!

LUA scripts to do this are not all that hard to make...
I have this one at my computer at work; sorry I do not have CMANO in front of me to make sure it works...

This one assigns from 2 to 7 North Vietnamese units and assigns them to a rail transport mission.
It also randomly assigns a proficiency level for the unit.
But you can assign any Database id to it you want.

The latitude and longitude are lati and longi for a random starting place (in North Vietnam in this case).

Again, I am not sure if this script is 100%... it was one I JUST HAPPENED TO HAVE.
But as you can see, there is not much coding involved.


a = 0
numNewUnits = math.random(2,7)
Key = 1

repeat
a = a + 1
string.name = 'VC' .. workKey
UnitProf = math.random(1,5); UnitProf = UnitProf - 1

r = math.random(1, 17)
r = r - 9
r = r / 100
longi =107.15 + r

r = math.random(1, 17); r = r - 9
r = r / 100
lati =16.7 + r

string.strLati = lati; string.strLongi = longi

ScenEdit_AddUnit({type = 'facility', name = string.name, heading = 0, dbid = 275, side = 'North Vietnam', Latitude= string.strLati ,Longitude= string.strLongi, autodetectable="false",holdfire="false",proficiency=UnitProf})
ScenEdit_AssignUnitToMission(string.name, 'Rail Transport NW')

workKey = workKey + 1
until a >= numNewUnits


RE: Script to Add New Units to a Group

Posted: Sat Jul 21, 2018 5:31 pm
by gpotter511
Thanks very much for the replies and the suggested code.

The units in question are Facilities being added to a new group via the same Lua script that creates them. Composed of a combination of BTR/BRDMs + Infantry Sections.

RE: Script to Add New Units to a Group

Posted: Sat Jul 21, 2018 8:26 pm
by tjhkkr
ORIGINAL: gpotter511

Thanks very much for the replies and the suggested code.
The units in question are Facilities being added to a new group via the same Lua script that creates them. Composed of a combination of BTR/BRDMs + Infantry Sections.

One thing you can do is to define them and then use the teleport method to get them there.
I do that quite a bit for 'fog of war' -- a general position for say an Iranian Silkworm unit... within a box, and then in the first couple of second teleport them in...
So another possibility there to accomplish your goal.