Script to Add New Units to a Group

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
gpotter511
Posts: 52
Joined: Wed Oct 04, 2017 12:55 pm

Script to Add New Units to a Group

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

RE: Script to Add New Units to a Group

Post 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.
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

RE: Script to Add New Units to a Group

Post 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

Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
gpotter511
Posts: 52
Joined: Wed Oct 04, 2017 12:55 pm

RE: Script to Add New Units to a Group

Post 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.
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

RE: Script to Add New Units to a Group

Post 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.
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
Post Reply

Return to “Lua Legion”