External ORBAT

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
Parel803
Posts: 936
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

External ORBAT

Post by Parel803 »

Good afternoon,

I'm making an ORBAT for all sides in excel. Using what I found:

Code: Select all

local s = VP_GetSide({Side="NATO"})
for k,v in pairs(s:unitsBy('Aircraft')) do
print((v.name)..';'..tostring(v.guid)..';')
end
Thanks for that.

Is there a way to get the class and type also in a ORBAT view?
Any other ideas on making an ORBAT are very welcome.

Realizing ground is new, it may not be working in this case.

best regards GJ
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: External ORBAT

Post by KnightHawk75 »

Yeah, but you'll have to enumerate through and 'get' each unit for the class data, the type you actually already have since you're doing a unitsBy(typename), but assuming you where not....

Code: Select all

local s = VP_GetSide({Side="NATO"})
local unitlist = s:unitsBy('Aircraft');
for _,v in ipairs(unitlist) do  --ipairs marginally faster as well when available (again org is fine too).
  local u = SE_GetUnit({guid=v.guid});  -- grab the unit so you can extract details per-unit you may want.
  if u ~=nil then
    --tostrings here while not always needed is more about preventing errors than necessity in this specific instance. 
    print((v.name)..';'..tostring(v.guid)..';' .. tostring(u.type) .. ';' .. tostring(u.classname)); --add stuff you want.
    --print(string.format("%s;%s;%s;%s",v.name,v.guid,u.type,u.classname));  -- example alternate
  else
    print((v.name)..';'..tostring(v.guid)..';' .. ' Error obtaining unit details.');
  end 
  u = nil;
end
I'll be darned where\what post, but somewhere floating around in the lua forums I think I posted some code to extract/print most the orbat data at some point, or was helping someone add to their existing code for it, along with indenting etc, but here you just want delimited for import elsewhere.
Parel803
Posts: 936
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: External ORBAT

Post by Parel803 »

Knighthawk,
Again thanks you for your time and help. Gonna try this evening.
best regards GJ

Works great, thanks
Parel803
Posts: 936
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: External ORBAT

Post by Parel803 »

Again very nice and interesting and I'm still struggling with it. Might be a damaged old brain.

A question:
Would it be possible to get e.g. the sensors with the units in an ORBAT? With a max range?

Trying slowly to build an ORBAT I was used to when still in the military.

Is there a possible connection to get data from the DB when asked dat on unit(s)?

best regards GJ
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: External ORBAT

Post by KnightHawk75 »

You can't get most data from the DB... but I recall sensors is one of the few items implemented in querydb. That said the max range is available in the unit.sensors table in each sensor entry so it shouldn't much of a problem that to orbat output per say, the data is there, question might be how do you export it in a importable\delimited way along with the unit, or maybe you just do it separate?
Parel803
Posts: 936
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: External ORBAT

Post by Parel803 »

KH,

Thanks for your time and answer, going to play with it. Might going to ask for help in the future if that is oké.

best regards GJ
Parel803
Posts: 936
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: External ORBAT

Post by Parel803 »

Good evening,

Not yet looking at the DB but to do next.
A Question before that:
I used in tha print line: .. tostring(u.category) .. ';' .. tostring(u.subtype) and getting the correct numbers.
Is there a way to get the description insteas of the numbers?
Exported it to excel and that works nice.

best regards GJ
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: External ORBAT

Post by KnightHawk75 »

Unfortunately _enumTable_.xyz does not contain categories or subtypes, just general types so you'd have to create your own list and lookup function, which will add some over head. I do have a older list of all categories and and subtypes in the contants file of that emmy-lua stuff I did.

It's not going to directly help cause it's in the opposite sort of form you need (ie's based on name to number not number to name) but you could sort of grab what you need and reverse it.

ie reform some of the lists to bunch of different
local aircraftCatTable= {
[1001]="None",
[2001]="Fixed_Wing",
..etc..etc..
}

then since you have 'type' for each type you look up you know which table to feed to something like this:
local function catNumToString(catTable, n)
if catTable[n] ~=nil then return catTable[n]; else return tostring(n); end
end

so then instead of tostring(u.category) in the print line you're doing catNumToString(aircraftCatTable,u.category) ...

IDK if any of that makes sense to you.
Attachments
CMO__Constants.zip
(7.92 KiB) Downloaded 17 times
Parel803
Posts: 936
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: External ORBAT

Post by Parel803 »

KH,
Thank you for your time and the answer.

Did not get it to work :-|
Maybe I'm doing something incorrect in function naming?? But tried to change stuff but felt like I'm getting further and further from the thruth.

Code: Select all

local aircraftCatTable={
  [1001]="None",
  [2001]="Fixed_Wing",
  [2002]="Fixed_Wing_CarrierCapable",
  [2003]="Helicopter",
  [2004]="Tiltrotor",
  [2006]="Airship",
  [2007]="Seaplane",
  [2008]="Amphibian"
  }
local function catNumToString(catTable, n)
  if catTable[n] ~=nil then return catTable[n]; else return tostring(n); end
end
  
  local s = VP_GetSide({Side="Blue"})
  local unitlist = s:unitsBy('Aircraft'); 
  
  for _,v in ipairs(unitlist) do  
    local u = SE_GetUnit({guid=v.guid});  
    if u ~=nil then
      print((v.name)..';' .. tostring(u.classname) .. ';' .. tostring(u.loadoutdbid) .. ';' .. catNumToString(aircraftCatTable,u.category)) 
    else
      print((v.name)..';'..tostring(v.guid)..';' .. ' Error obtaining unit details.');
    end 
    u = nil;
  end
Result was: Magic #1;E-3A Sentry;8076;2001
Hoping you see my error.

best regards GJ
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

Re: External ORBAT

Post by michaelm75au »

Use 'tonumber(u.category)'.
The 'category' is being returned as a string and not as a number as specified in Docs.

If a 'number' doesn't work, try the tonumber() method. If it works, it probably me incorrectly added wrong type to Docs.
Michael
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: External ORBAT

Post by KnightHawk75 »

Parel803 wrote: Sun Jan 15, 2023 8:25 am ...

THAT's my bad.... I forgot the category number comes back as a string and needs to be converted...
Note the revision below where I convert n tonumber() in catNumToString() before the 'lookup'. works for me now.

Code: Select all

local aircraftCatTable={
  [1001]="None",
  [2001]="Fixed_Wing",
  [2002]="Fixed_Wing_CarrierCapable",
  [2003]="Helicopter",
  [2004]="Tiltrotor",
  [2006]="Airship",
  [2007]="Seaplane",
  [2008]="Amphibian"
  }
local function catNumToString(catTable, n)
  n = tonumber(n);
  if catTable[n] ~=nil then return catTable[n]; else return tostring(n); end
end
  
  local s = VP_GetSide({Side="Blue"})
  local unitlist = s:unitsBy('Aircraft'); 
  
  for _,v in ipairs(unitlist) do  
    local u = SE_GetUnit({guid=v.guid});  
    if u ~=nil then
      print((v.name)..';' .. tostring(u.classname) .. ';' .. tostring(u.loadoutdbid) .. ';' .. catNumToString(aircraftCatTable,u.category)) 
    else
      print((v.name)..';'..tostring(v.guid)..';' .. ' Error obtaining unit details.');
    end 
    u = nil;
  end

Edit: or what Michael said..sry we posted about the same time.
Parel803
Posts: 936
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: External ORBAT

Post by Parel803 »

Thank you both,
It good fun playing with this, despite it is very complex.
regards GJ
Parel803
Posts: 936
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: External ORBAT

Post by Parel803 »

Got that working and added some extra fields.
Now trying with the mounts and weapons and I read this form you people on other threads.

I'm getting the mounts and weapons on these mounts. Tried also to get the weapons that are in the loadout.
Managed to get the loadout name but when I tried to add text to it, it erros on the firt empty one. Probebly should use an extra loop of some sort? But cannot get it to work. Apologise if this are stupid questions, it all copy/paste & trial/errror here.Do not wanna waste peoples time.

What I have so far:
local WpnTypeTable={
[1001] = 'None',
[2001] = 'GuidedWeapon',
[2002] = 'Rocket',
[2003] = 'IronBomb',
[2004] = 'Gun',
[2005] = 'Decoy_Expendable',
[2006] = 'Decoy_Towed',
[2007] = 'Decoy_Vehicle',
[2008] = 'TrainingRound',
[2009] = 'Dispenser',
[2010] = 'ContactBomb_Suicide',
[2011] = 'ContactBomb_Sabotage',
[2012] = 'GuidedProjectile',
[3001] = 'SensorPod',
[3002] = 'DropTank',
[3003] = 'BuddyStore',
[3004] = 'FerryTank',
[4001] = 'Torpedo',
[4002] = 'DepthCharge',
[4003] = 'Sonobuoy',
[4004] = 'BottomMine',
[4005] = 'MooredMine',
[4006] = 'FloatingMine',
[4007] = 'MovingMine',
[4008] = 'RisingMine',
[4009] = 'DriftingMine',
[4011] = 'DummyMine',
[4101] = 'HeliTowedPackage',
[5001] = 'RV',
[6001] = 'Laser',
[8001] = 'HGV',
[9001] = 'Cargo',
[9002] = 'Troops',
[9003] = 'Paratroops',
}

local s = VP_GetSide({Side="Blue"})
local unitlist = s:unitsBy('Aircraft');

local function catNumToString(catTable, n)
n = tonumber(n);
if catTable[n] ~=nil then return catTable[n]; else return tostring(n); end
end

for _,v in ipairs(unitlist) do
local u = SE_GetUnit({guid=v.guid});
local lo = ScenEdit_GetLoadout({name=v.name}) -- deze added
if u ~=nil then
for k,v in pairs(u.mounts) do
print("Unit: " .. (u.name) .. " (" .. tostring(u.classname) .. ")");
print (lo.name) -- deze kan verder geen tekst hebben wnat loopt op nil dan vast. zonde .. loopt het door
print(" * Mount nr".. k .. ": mount name: " .. tostring(v.mount_name) .. " - mount guid: " .. tostring(v.mount_guid))
if v.mount_weapons ~=nil then
for i,j in ipairs(v.mount_weapons) do
print(" ~ Weapon nr" .. i .. ": weapon name: " .. j.wpn_name .. " - wpn_type: " .. catNumToString(WpnTypeTable,j.wpn_type) .. " - Current Nr: " .. j.wpn_current .. " - Weapon DBID: " .. j.wpn_dbid)
end
else
print(" No weapons on this mount.")
end
end

end
print ("")
end
Did not manage to put something in with weapons (or is it best to use Loadout?)

best regards GJ
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: External ORBAT

Post by KnightHawk75 »

Managed to get the loadout name but when I tried to add text to it, it erros on the firt empty one. Probably should use an extra loop of some sort?
I would wrap the loadout dumping in another helper. The following seems to work for me without stopping and should better handle nil\loadouts that are 'none'.

Code: Select all

local WpnTypeTable={
[1001] = 'None',
[2001] = 'GuidedWeapon',
[2002] = 'Rocket',
[2003] = 'IronBomb',
[2004] = 'Gun',
[2005] = 'Decoy_Expendable',
[2006] = 'Decoy_Towed',
[2007] = 'Decoy_Vehicle',
[2008] = 'TrainingRound',
[2009] = 'Dispenser',
[2010] = 'ContactBomb_Suicide',
[2011] = 'ContactBomb_Sabotage',
[2012] = 'GuidedProjectile',
[3001] = 'SensorPod',
[3002] = 'DropTank',
[3003] = 'BuddyStore',
[3004] = 'FerryTank',
[4001] = 'Torpedo',
[4002] = 'DepthCharge',
[4003] = 'Sonobuoy',
[4004] = 'BottomMine',
[4005] = 'MooredMine',
[4006] = 'FloatingMine',
[4007] = 'MovingMine',
[4008] = 'RisingMine',
[4009] = 'DriftingMine',
[4011] = 'DummyMine',
[4101] = 'HeliTowedPackage',
[5001] = 'RV',
[6001] = 'Laser',
[8001] = 'HGV',
[9001] = 'Cargo',
[9002] = 'Troops',
[9003] = 'Paratroops',
}

local s = VP_GetSide({Side="US"})
local unitlist = s:unitsBy('Aircraft');

local function catNumToString(catTable, n)
    n = tonumber(n);
    if catTable[n] ~=nil then return catTable[n]; else return tostring(n); end
end

local function dumpLoadoutWeapons(lo,indent)
    if indent == nil then indent = 2;end
    local ind = string.rep(" ",indent)
    if (lo ==nil) or lo.name ==nil then print(ind.. "Loadout: None");
    else
        print(ind.. "Loadout: " .. tostring(lo.name));
        for k,v in ipairs(lo.weapons)do
            print(ind.. "  [" .. tostring(k) .."] " ..tostring(v.wpn_current).. " - wpn_name: " .. tostring(v.wpn_name) .. " - wpn_type: " .. catNumToString(WpnTypeTable, v.wpn_type));
        end
    end
end

for _,v in ipairs(unitlist) do
    local u = SE_GetUnit({guid=v.guid});
    local lo = ScenEdit_GetLoadout({name=v.name}) -- deze added
    if u ~=nil then
        for k,v in pairs(u.mounts) do
            print("Unit: " .. (u.name) .. " (" .. tostring(u.classname) .. ")");
            dumpLoadoutWeapons(lo,2);
            print(" * Mount nr".. k .. ": mount name: " .. tostring(v.mount_name) .. " - mount guid: " .. tostring(v.mount_guid))
            if v.mount_weapons ~=nil then
                for i,j in ipairs(v.mount_weapons) do
                    print(" ~ Weapon nr" .. i .. ": weapon name: " .. j.wpn_name .. " - wpn_type: " .. catNumToString(WpnTypeTable,j.wpn_type) .. " - Current Nr: " .. j.wpn_current .. " - Weapon DBID: " .. j.wpn_dbid)
                end
            else
                print(" No weapons on this mount.")
            end
        end
    end
    print ("")
end
Last edited by KnightHawk75 on Mon Jan 16, 2023 10:11 am, edited 1 time in total.
Parel803
Posts: 936
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: External ORBAT

Post by Parel803 »

KH,
Again thx, works great.
Changed the order of print a little. Very nice from you all.
regards GJ
Post Reply

Return to “Lua Legion”