Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Lua Command for Creating a Group?

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Lua Command for Creating a Group? Page: [1]
Login
Message << Older Topic   Newer Topic >>
Lua Command for Creating a Group? - 5/25/2020 6:57:51 AM   
ProdigyofMilitaryPride

 

Posts: 86
Joined: 4/17/2015
Status: offline
Anyone got any recommendations? Hints or tips? Thanks.

_____________________________

"The courageous must protect freedom." - Dwight D. Eisenhower
"Anything built by human hands can be destroyed. This is no exception." - Kei "Edge" Nagase, Ace Combat 5: The Unsung War
Post #: 1
RE: Lua Command for Creating a Group? - 5/25/2020 7:07:46 AM   
michaelm75au


Posts: 13070
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
There is a dedicated sub-forum for Lua questions - Lua legion under Modding. I think there are some answers to this there.

_____________________________

Michael

(in reply to ProdigyofMilitaryPride)
Post #: 2
RE: Lua Command for Creating a Group? - 5/25/2020 9:58:14 AM   
KnightHawk75

 

Posts: 645
Joined: 11/15/2018
Status: offline
@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.




< Message edited by KnightHawk75 -- 5/25/2020 10:13:54 AM >

(in reply to michaelm75au)
Post #: 3
RE: Lua Command for Creating a Group? - 5/25/2020 7:57:24 PM   
ProdigyofMilitaryPride

 

Posts: 86
Joined: 4/17/2015
Status: offline
Thanks for that. I'll keep the aircraft note in mind, too.

_____________________________

"The courageous must protect freedom." - Dwight D. Eisenhower
"Anything built by human hands can be destroyed. This is no exception." - Kei "Edge" Nagase, Ace Combat 5: The Unsung War

(in reply to KnightHawk75)
Post #: 4
RE: Lua Command for Creating a Group? - 5/31/2020 5:25:08 PM   
orca

 

Posts: 469
Joined: 11/6/2013
Status: online
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?

(in reply to ProdigyofMilitaryPride)
Post #: 5
RE: Lua Command for Creating a Group? - 6/1/2020 12:46:56 AM   
michaelm75au


Posts: 13070
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
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]



_____________________________

Michael

(in reply to orca)
Post #: 6
RE: Lua Command for Creating a Group? - 6/1/2020 7:03:57 AM   
KnightHawk75

 

Posts: 645
Joined: 11/15/2018
Status: offline
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)

< Message edited by KnightHawk75 -- 6/1/2020 7:04:50 AM >

(in reply to orca)
Post #: 7
RE: Lua Command for Creating a Group? - 6/4/2020 10:32:08 PM   
jkgarner

 

Posts: 76
Joined: 4/30/2020
Status: offline
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?

(in reply to KnightHawk75)
Post #: 8
RE: Lua Command for Creating a Group? - 6/5/2020 12:18:07 AM   
KnightHawk75

 

Posts: 645
Joined: 11/15/2018
Status: offline
Far as I know, nope.

(in reply to jkgarner)
Post #: 9
RE: Lua Command for Creating a Group? - 6/13/2020 8:00:12 AM   
caohailiang

 

Posts: 30
Joined: 6/7/2020
Status: offline
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!

(in reply to KnightHawk75)
Post #: 10
RE: Lua Command for Creating a Group? - 6/13/2020 8:41:00 AM   
michaelm75au


Posts: 13070
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
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.

_____________________________

Michael

(in reply to caohailiang)
Post #: 11
RE: Lua Command for Creating a Group? - 6/14/2020 4:41:42 AM   
caohailiang

 

Posts: 30
Joined: 6/7/2020
Status: offline
thanks! it works now

(in reply to michaelm75au)
Post #: 12
RE: Lua Command for Creating a Group? - 8/12/2020 12:40:28 AM   
orca

 

Posts: 469
Joined: 11/6/2013
Status: online

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

(in reply to KnightHawk75)
Post #: 13
RE: Lua Command for Creating a Group? - 8/12/2020 7:13:34 AM   
michaelm75au


Posts: 13070
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
local u = ScenEdit_GetUnit({name='Group_2612', guid='cd015e09-d208-4e67-9af0-3e8e0412209c'})
if u == nil then
-- unit destroyed
else
-- do something
end


_____________________________

Michael

(in reply to orca)
Post #: 14
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Lua Command for Creating a Group? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.129