Set Group as Auto-detectable

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
WillpowerDisturbance
Posts: 60
Joined: Sat Jan 15, 2022 5:15 pm

Set Group as Auto-detectable

Post by WillpowerDisturbance »

Hi, I'm somewhat new to coding and very new to Lua so I apologize if this is something that I've missed in the Lua documentation. I'm working on a scenario where I want to make the part of the blue force auto-detectable to the red force due to a lack or ISR assets In this case I want to make the CSG auto-detectable but not the escorting subs. I know I this can be done manual through the editor and through Lua based on the unit but not for a group.

Is there a way to use Lua to get all of the units of a group into an array? The github documentation hints at this but I'm not sure how to do it.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Set Group as Auto-detectable

Post by KnightHawk75 »

Is there a way to use Lua to get all of the units of a group into an array?
Yup.

Code: Select all

local g = ScenEdit_GetUnit({guid="abcefg-hijklmnop"}) -- guid of the group.
print(g.group.unitlist) -- print the table of unit guids that are members of the group.
or alternatively if you have any unit wrapper of a group member already you can check it's .group.unitlist for the same data.

Sample of what you may be looking for..

Code: Select all

function setAllGroupMembersAutodetectble(theguid,thevalue)
  if thevalue==nil then thevalue=false; end --default to false
  if theguid ~=nil then 
    local g = ScenEdit_GetUnit({guid=theguid});
    for i=1,#g.group.unitlist do
      ScenEdit_SetUnit({guid=g.group.unitlist[i], Autodetectable=thevalue}); 
      --you could alternatively here getunit the unit guid and change via .autodetectable on the unit wrapper 
      --if say you had to do other things to the unit, otherwise this is likely more performant.  
    end
  else
    print('Error: Missing group guid parameter.');
  end
end

setAllGroupMembersAutodetectble('4FH7PU-0HMJC9U05N0HE',true);
WillpowerDisturbance
Posts: 60
Joined: Sat Jan 15, 2022 5:15 pm

Re: Set Group as Auto-detectable

Post by WillpowerDisturbance »

KnightHawk75 wrote: Sat Jul 23, 2022 2:08 am
Is there a way to use Lua to get all of the units of a group into an array?
Yup.
Thanks for the help! I shortened it a bit since I don't have a unit wrapper.

Are there any good Command oriented Lua tutorials?

Code: Select all

    local g = ScenEdit_GetUnit({guid='8FWFDR-0HMJ6HD8U4QAL'});
    for i=1,#g.group.unitlist do
      ScenEdit_SetUnit({guid=g.group.unitlist[i], autodetectable="True"}); 
    end
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Set Group as Auto-detectable

Post by KnightHawk75 »

from the lua resources post some video tutorials on some of the basics:

TitaniumTrout Event Editor Basic Tutorials
https://www.matrixgames.com/forums/view ... 1#p4621981

Whicker's Command Lua video tutorials
https://www.matrixgames.com/forums/view ... 3#p4403433

Other than that I would just say well...this whole sub forum but of course lots of it is buried, though the newer forum software makes it a little easier to do advanced searches now than the past if you have some idea what it is you're looking for - but when in doubt just ask. ;)
WillpowerDisturbance
Posts: 60
Joined: Sat Jan 15, 2022 5:15 pm

Re: Set Group as Auto-detectable

Post by WillpowerDisturbance »

Thanks!!
Post Reply

Return to “Lua Legion”