Get a specific type of facility

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

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

Get a specific type of facility

Post by Parel803 »

Good evening,

Due to all the previous help I got a script to get all the facilities form one side

Code: Select all

-- Print ALL facilities:
gParel = {}

gParel.UnitFacilitySubType = {
[1001] = "None",
[2001] = "Runway",
[2002] = "Runway-Grade Taxiway",
[2003] = "Runway Access Point",
[3001] = "Building (Surface)",
[3002] = "Building (Reveted)",
[3003] = "Building (Bunker)",
[3004] = "Building (Underground)",
[3005] = "Structure (Open)",
[3006] = "Structure (Reveted)",
[4001] = "Underwater",
[5001] = "Mobile Vehicle(s)",
[5002] = "Mobile Personnel",
[6001] = "Aerostat Mooring",
[9001] = "Air Base",
}

gParel.UnitFacilityCategory = {
[0] = "None",
[1000] = "Infantry",
[2000] = "Armor",
[3000] = "Artillery Gun",
[4000] = "Artillery SSM",
[5000] = "AAA",
[6000] = "SAM",
[7000] = "Engineer",
[8000] = "Supply",
[9000] = "Surveillance",
[10000] = "Recon",
[11000] = "MechInfantry",
}

Code: Select all

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

-- 2: Facility on side
local s = VP_GetSide({Side="NAVO"}) -- use sidename for other sides
local unitlist = s:unitsBy('Facility');
for _,v in ipairs(unitlist) do
  local u = SE_GetUnit({guid=v.guid});
  if u ~=nil then
    print(catNumToString(gParel.UnitFacilitySubType,u.subtype) .. ';' .. catNumToString(gParel.UnitFacilityCategory,u.category) .. ';' .. tostring(u.classname) .. ';'  .. tostring(u.dbid) .. ';' .. tostring(v.name));
  else
    print((v.name)..';'..tostring(v.guid)..';' .. ' Error obtaining unit details.');
  end
  u = nil;
end
I now tried to print only the SAM category facilities.
Tried to replace: if u ~=nil then to if u ~= nil and u.category == 6000
Running this the console stays empty

Was wondering if someone sees what I'm doing wrong?

best regards GJ
User avatar
blu3s
Posts: 637
Joined: Fri Jul 08, 2022 9:45 am

Re: Get a specific type of facility

Post by blu3s »

It is possible that the SAM's you have in the scenario are not categorized as Ground Unit but as Facility unit, because the codes under your gParel.UnitFacilityCategory variable are from Ground Units and not Facility Units.

If you're SAM's are named with the world SAM in it, you can search it using string.match method, something like:

Code: Select all

if string.match(unit.name, "SAM") ~= nil

Parel803
Posts: 891
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: Get a specific type of facility

Post by Parel803 »

Thank you,
Going to try it out.

regards GJ
Post Reply

Return to “Lua Legion”