Group

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
Parel803
Posts: 941
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Group

Post by Parel803 »

Is it possible to make a group of ship from lua or change the formation/leader of a existing group? If so could someone please point me in the right direction. Haven't found other threads with search on it.
with regards
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Group

Post by KnightHawk75 »

fb.asp?m=4824759

Prior example I posted for adding bunch of ships that are grouped (you can ignore the associated aircraft portions to the carrier if it doesn't apply)

As for the formation\leader it can be done by setting the lead property (http://commandlua.github.io/#wrapper_Group) on the group wrapper I believe with the guid of the unit you want to be lead, the formation aspects like relativity, position,etc can be modified on the specific member unit wrapper for each member in the member unit's .formation properties\table.

fb.asp?m=4825664

Let me know if you still get stumped trying to do something.

Parel803
Posts: 941
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

RE: Group

Post by Parel803 »

thank you for you're time and help. I'm gonna try it.
with regards
Parel803
Posts: 941
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

RE: Group

Post by Parel803 »

Thx again. Got some stuff working but not all I like to. I'm no prorgrammer or something like that just try to copy-paste and trial-error stuff.

local u1, u2, u3, u4;
local grpName = 'TG 10.1'
u1 = ScenEdit_AddUnit({type = 'Ship', name = 'RDAM', dbid = 825, side = 'Blue', Latitude="N9.30.00",Longitude="E109.30.00", heading=090, speed=12});
u1.group = grpName;
u2 = ScenEdit_AddUnit({type = 'Ship', name = 'TRMP', dbid = 891, side = 'Blue', Latitude="N9.31.00",Longitude="E109.31.00", heading=090, speed=12});
u2.group = grpName;
u3 = ScenEdit_AddUnit({type = 'Ship', name = 'ZLND', dbid = 2496, side = 'Blue', Latitude="N9.30.00",Longitude="E109.29.00", heading=090, speed=12});
u3.group = grpName;
u4 = ScenEdit_AddUnit({type = 'Ship', name = 'VSPK', dbid = 2522, side = 'Blue', Latitude="N9.29.00",Longitude="E109.31.00", heading=090, speed=12});
u4.group = grpName;

u2.formation = {type='fixed', bearing=040, distance=4, sprint='false'}
u3.formation = {type='fixed', bearing=270, distance=2, sprint='false'}
u4.formation = {type='fixed', bearing=105, distance=2, sprint='false'}

Don't understnad how to use the group wrapper and change the lead unit.
If you you something stupid, let me know. I can handle that as an ex navy chief :-)
with regards
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Group

Post by KnightHawk75 »

Nope, nothing stupid. I've added an example that shows changing the lead from the default of u1 to u4.
The print statements aren't needed they are just to help you when playing around to see the change.

Code: Select all

 local u1, u2, u3, u4;
 local grpName = 'TG 10.1'
 u1 = ScenEdit_AddUnit({type = 'Ship', name = 'RDAM', dbid = 825, side = 'Blue', Latitude="N9.30.00",Longitude="E109.30.00", heading=090, speed=12});
 u1.group = grpName;
 u2 = ScenEdit_AddUnit({type = 'Ship', name = 'TRMP', dbid = 891, side = 'Blue', Latitude="N9.31.00",Longitude="E109.31.00", heading=090, speed=12});
 u2.group = grpName;
 u3 = ScenEdit_AddUnit({type = 'Ship', name = 'ZLND', dbid = 2496, side = 'Blue', Latitude="N9.30.00",Longitude="E109.29.00", heading=090, speed=12});
 u3.group = grpName;
 u4 = ScenEdit_AddUnit({type = 'Ship', name = 'VSPK', dbid = 2522, side = 'Blue', Latitude="N9.29.00",Longitude="E109.31.00", heading=090, speed=12});
 u4.group = grpName;
 
 
 local g = ScenEdit_GetUnit({guid=u1.group.guid}); --get the group object wrapper using guid obtained from one of the member units group properties.
 --local g = ScenEdit_GetUnit({side="Blue", name=grpName}); --alternate way but I use the above when I can. 
 --print(g.group); --dump the basic group objects properties. (there are more than what gets listed but they are in fields that dont print)
 --print(g.group.unitlist); --dump the list of unit guids that are members of this group. (ie the 4 above created units) 
 print('current lead: ' .. g.group.lead); --list the guid of the current group lead which likley is first member or u1 in this case.
 g.group.lead = u4.guid --operating on the group object's lead field (not shown in dump) set the group lead to the guid of ship 4. 
 print('new lead: ' .. g.group.lead); --show guid of the new lead (should see change).
 
 --probably best to set the formations after the lead is changed.
 u1.formation = {type='fixed', bearing=040, distance=4, sprint='false'}
 u2.formation = {type='fixed', bearing=270, distance=2, sprint='false'}
 u3.formation = {type='fixed', bearing=105, distance=2, sprint='false'} 
 
Parel803
Posts: 941
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

RE: Group

Post by Parel803 »

Great thank you very much,
with regards
Post Reply

Return to “Lua Legion”