Lua Command for Creating a Group? (Full Version)

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



Message


ProdigyofMilitaryPride -> Lua Command for Creating a Group? (5/25/2020 6:57:51 AM)

Anyone got any recommendations? Hints or tips? Thanks.




michaelm75au -> RE: Lua Command for Creating a Group? (5/25/2020 7:07:46 AM)

There is a dedicated sub-forum for Lua questions - Lua legion under Modding. I think there are some answers to this there.




KnightHawk75 -> RE: Lua Command for Creating a Group? (5/25/2020 9:58:14 AM)

@ProdigyofMilitaryPride - What issues are you having\running into assigning units to groups?

while creating:
see https://www.matrixgames.com/forums/tm.asp?m=4816227

After:
local u;
u = ScenEdit_GetUnit({side='someside',name='somename'})
u.group = 'my new or existing groupname';

Doing a bunch with similar names 1-6:
local u;
for i=1,6 do
u = ScenEdit_GetUnit({side='someside',name='somename #' .. i})
u.group = 'my new or existing groupname';
end
Note: If the unit type is an aircraft, remember the models & loadouts need to be the same.






ProdigyofMilitaryPride -> RE: Lua Command for Creating a Group? (5/25/2020 7:57:24 PM)

Thanks for that. I'll keep the aircraft note in mind, too.




orca -> RE: Lua Command for Creating a Group? (5/31/2020 5:25:08 PM)

Would this work if the units are already in a different preexisting group? ie would it change the unit from being in the original group to being in the new group?

If no how do you remove a unit from a group?




michaelm75au -> RE: Lua Command for Creating a Group? (6/1/2020 12:46:56 AM)

A unit can only belong to one group. So changing a unit's group is a simple as changing the '.group'.
To remove a unit from a group, just blank out the unit's '.group'. [ <unit_wrapper_variable>.group = '' from memory]





KnightHawk75 -> RE: Lua Command for Creating a Group? (6/1/2020 7:03:57 AM)

quote:

ORIGINAL: orca

Would this work if the units are already in a different preexisting group? ie would it change the unit from being in the original group to being in the new group?

If no how do you remove a unit from a group?

local u;
u = ScenEdit_GetUnit({side='someside',name='somename'})
u.group = ""; -- removed from existing. (you may be able to skip this step but dont lol.)
u.group = "MyNewGroup"; -- added to another (if it doesn't exist yet it should be created automagically)




jkgarner -> RE: Lua Command for Creating a Group? (6/4/2020 10:32:08 PM)

Is it possible to assign a unit to group when you create it with ScenEdit_AddUnit() by setting the group='somegroup' in the unit descriptor?
If this works, must the group exist before the first unit is assigned thusly, or will the group be created with the AddUnit call?




KnightHawk75 -> RE: Lua Command for Creating a Group? (6/5/2020 12:18:07 AM)

Far as I know, nope.




caohailiang -> RE: Lua Command for Creating a Group? (6/13/2020 8:00:12 AM)

a follow up question with this:
how do i generate a unique group id each time?
what i did was initializing the group id when scenario is loaded, every time after the group id is assigned, groupid=groupid+1. but you will start to get duplicated group names if the scenario is saved and loaded, since the groupid will be re-initialized at origin value.
thanks!




michaelm75au -> RE: Lua Command for Creating a Group? (6/13/2020 8:41:00 AM)

You could look thru the unit names for the matching group name, and use the last 'number' found as the starting number, or keep the last issued number in the KeyStore (which is saved as part of the scenario) with ScenEdit_SetKeyValue/ScenEdit_GetKeyValue.




caohailiang -> RE: Lua Command for Creating a Group? (6/14/2020 4:41:42 AM)

thanks! it works now




orca -> RE: Lua Command for Creating a Group? (8/12/2020 12:40:28 AM)


quote:

ORIGINAL: KnightHawk75

quote:

ORIGINAL: orca

Would this work if the units are already in a different preexisting group? ie would it change the unit from being in the original group to being in the new group?

If no how do you remove a unit from a group?

local u;
u = ScenEdit_GetUnit({side='someside',name='somename'})
u.group = ""; -- removed from existing. (you may be able to skip this step but dont lol.)
u.group = "MyNewGroup"; -- added to another (if it doesn't exist yet it should be created automagically)


Thanks I am able to get this to work. But I want to ensure that I don't get an error if the unit no longer exists in the scenario (ie is destroyed). Is there a script utilizing something like below? I tried but the name must be a string. Any other way to do this?

local u:
if u = ScenEdit_GetUnit({side='someside',name=u}) ~= nil then
u.group = ""; -- removed from existing. (you may be able to skip this step but dont lol.)
u.group = "MyNewGroup"; -- added to another (if it doesn't exist yet it should be created automagically)
end




michaelm75au -> RE: Lua Command for Creating a Group? (8/12/2020 7:13:34 AM)

local u = ScenEdit_GetUnit({name='Group_2612', guid='cd015e09-d208-4e67-9af0-3e8e0412209c'})
if u == nil then
-- unit destroyed
else
-- do something
end




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
1.609375