Page 1 of 1

SE_SelctedUnits()

Posted: Sun Apr 24, 2022 7:20 pm
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

Re: SE_SelctedUnits()

Posted: Sun Apr 24, 2022 11:12 pm
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

Re: SE_SelctedUnits()

Posted: Tue Apr 26, 2022 2:39 pm
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