SE_SelctedUnits()

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
User avatar
vettim89
Posts: 3668
Joined: Fri Jul 13, 2007 11:38 pm
Location: Toledo, Ohio

SE_SelctedUnits()

Post by vettim89 »

I was wondering how this particular function can be used. The documentation says it returns a table of selected units

as an example the following code

Code: Select all

local sub=ScenEdit_SelectedUnits()
print(sub)
yields this if I select a single submarine

{ units = { [1] = { name = 'K-517', guid = 'W7ZXL3-0HMGVOQVLS72K' } } }

Now the special action I want to create is if the player selects a single submarine they can then deploy a RHIB with a Spetsnaz team aboard. In order to do this I need to access the submarines location and altitude. The date is obviously there but I lack the coding skills to parse it out. What would be the proper syntax to index the array to get the guid. Also any hint to error out in case the player has selected more than one unit
"We have met the enemy and they are ours" - Commodore O.H. Perry
wirthlin
Posts: 22
Joined: Sat Dec 26, 2020 11:22 pm

Re: SE_SelctedUnits()

Post by wirthlin »

vettim89 wrote: Sun Apr 24, 2022 7:20 pm I was wondering how this particular function can be used. The documentation says it returns a table of selected units

as an example the following code

Code: Select all

local sub=ScenEdit_SelectedUnits()
print(sub)
yields this if I select a single submarine

{ units = { [1] = { name = 'K-517', guid = 'W7ZXL3-0HMGVOQVLS72K' } } }

Now the special action I want to create is if the player selects a single submarine they can then deploy a RHIB with a Spetsnaz team aboard. In order to do this I need to access the submarines location and altitude. The date is obviously there but I lack the coding skills to parse it out. What would be the proper syntax to index the array to get the guid. Also any hint to error out in case the player has selected more than one unit
Here's one way to do something like that:

Code: Select all

local sub=ScenEdit_SelectedUnits()

print(#sub.units)
print(sub)
if #sub.units > 1 then
    ScenEdit_MsgBox ("More than 1 unit selected",1)
else
-- Get information on the first one selected.
    local myunit=ScenEdit_GetUnit(sub.units[1])
    print(myunit)
end
Then just pull the information you need from myunit. Hope this helps.

R
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: SE_SelctedUnits()

Post by KnightHawk75 »

Code: Select all

local sunits =ScenEdit_SelectedUnits()
if ((sunits ~=nil) and sunits.units ~=nil) and #sunits.units > 0 then
  if #sunits.units > 1 then
    ScenEdit_MsgBox ("More than 1 unit selected.",1);
  else
    local myunit=ScenEdit_GetUnit({guid=sunits.units[1].guid});
    local u = ScenEdit_CreateUnit({side="SOME-SIDENAME",type="Ship",dbid=3124,name="RHIB deployed by " .. myunit.name, latitude=(myunit.latitude + .0001),longitude=(myunit.longitude - .0001),heading=0}) ;
  end
else
    ScenEdit_MsgBox ("No unit was selected.",1);
end
off cuff, did not test snippet in game
Post Reply

Return to “Lua Legion”