Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Simple OOB listing using Lua in 1.11.sr7

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Simple OOB listing using Lua in 1.11.sr7 Page: [1]
Login
Message << Older Topic   Newer Topic >>
Simple OOB listing using Lua in 1.11.sr7 - 2/11/2017 12:00:35 AM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
With the additional Lua in this build, you can create some OOB listings.Change the side's name to the one needed. The results are also in the new Lua history (Logs folder) if too long for the Lua output window.

-- get all units on a side
-- extract the base they are assigned to
-- report by base
local s = VP_GetSide({name='strategic air command'})
local function split(str, pat)
local t = {}
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
return t
end
local function sortName(a,b)
return(ScenEdit_GetUnit({guid=a}).name<ScenEdit_GetUnit({guid=b}).name)
end
local function orderedPairs(t,f)
local array = {}
for n in pairs(t) do array[#array +1] = n end
table.sort(array,f)
local index = 0
return function ()
index = index + 1
return array[index],t[array[index]]
end
end
-- main logic
local base = {}
for k,v in pairs(s.units)
do
local unit = ScenEdit_GetUnit({guid=v.guid})
if unit.base ~= nil then
local b = unit.base
if b.group ~= nil then
-- has a parent group; use it rather than the group members
if base[b.group.guid] == nil and b.group.guid ~= v.guid then
base[b.group.guid] = v.guid
elseif b.group.guid ~= v.guid then
base[b.group.guid] = base[b.group.guid] .. ',' .. v.guid
end
elseif base[b.guid] == nil and b.guid ~= v.guid then
base[b.guid] = v.guid
elseif b.guid ~= v.guid then
base[b.guid] = base[b.guid] .. ',' .. v.guid
end
elseif unit.group ~= nil then
local b = unit.group
if base[b.guid] == nil and b.guid ~= v.guid then
base[b.guid] = v.guid
elseif b.guid ~= v.guid then
base[b.guid] = base[b.guid] .. ',' .. v.guid
end
else
-- units not based somewhere
if base['xindependent'] == nil then
base['xindependent'] = v.guid
else
base['xindependent'] = base['xindependent'] .. ',' .. v.guid
end
end
end
local k,v
for k,v in orderedPairs(base)
do
print('\n')
if k == 'xindependent' then
print('Un-based units');
else
print('Base: ' .. ScenEdit_GetUnit({guid=k}).name);
end
local k1,v1
local t = split(v,',')
if t ~= nil then
-- group like names together
table.sort(t, sortName)
for k1,v1 in pairs(t)
do
if v1 == k then next(t) end
local unit = ScenEdit_GetUnit({guid=v1})
if unit.condition ~= nil then
print(string.format(" %s (%s)",unit.name, unit.condition));
else
print(string.format(" %s ",unit.name));
end
end
end
end

< Message edited by mikmyk -- 2/11/2017 12:03:58 AM >


_____________________________

Michael
Post #: 1
Example - 2/11/2017 12:01:22 AM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
Base: RAF Upper Heyford
40th Bombardment Wing #1 (Readying)
40th Bombardment Wing #10 (Readying)
40th Bombardment Wing #11 (Readying)
40th Bombardment Wing #12 (Readying)
40th Bombardment Wing #13 (Readying)
40th Bombardment Wing #14 (Readying)
40th Bombardment Wing #15 (Readying)
40th Bombardment Wing #16 (Readying)
40th Bombardment Wing #17 (Readying)
40th Bombardment Wing #18 (Readying)
40th Bombardment Wing #19 (Readying)
40th Bombardment Wing #2 (Readying)
40th Bombardment Wing #20 (Readying)
40th Bombardment Wing #21 (Airborne)
40th Bombardment Wing #22 (Airborne)
40th Bombardment Wing #23 (Readying)
40th Bombardment Wing #24 (Readying)
40th Bombardment Wing #25 (Readying)
40th Bombardment Wing #26 (Readying)
40th Bombardment Wing #27 (Readying)
40th Bombardment Wing #28 (Readying)
40th Bombardment Wing #29 (Readying)
40th Bombardment Wing #3 (Readying)
40th Bombardment Wing #30 (Readying)
40th Bombardment Wing #31 (Readying)
40th Bombardment Wing #32 (Readying)
40th Bombardment Wing #35 (Airborne)
40th Bombardment Wing #4 (Readying)
40th Bombardment Wing #7 (Readying)
40th Bombardment Wing #9 (Readying)


Base: RAF Fairford
310th Bombardment Wing #1 (Readying)
310th Bombardment Wing #10 (Readying)
310th Bombardment Wing #11 (Readying)
310th Bombardment Wing #12 (Readying)
310th Bombardment Wing #13 (Airborne)
310th Bombardment Wing #14 (Readying)
310th Bombardment Wing #15 (Refuelling)
310th Bombardment Wing #16 (Readying)
310th Bombardment Wing #17 (Readying)
310th Bombardment Wing #18 (Readying)
310th Bombardment Wing #2 (Readying)
310th Bombardment Wing #22 (Readying)
310th Bombardment Wing #23 (Readying)
310th Bombardment Wing #24 (Readying)
310th Bombardment Wing #25 (Airborne)
310th Bombardment Wing #26 (Airborne)
310th Bombardment Wing #27 (Airborne)
310th Bombardment Wing #28 (Airborne)
310th Bombardment Wing #29 (Readying)
310th Bombardment Wing #30 (Refuelling)
310th Bombardment Wing #31 (Readying)
310th Bombardment Wing #32 (Readying)
310th Bombardment Wing #33 (Parked)
310th Bombardment Wing #34 (Airborne)
310th Bombardment Wing #35 (Parked)
310th Bombardment Wing #4 (Refuelling)
310th Bombardment Wing #6 (Airborne)
310th Bombardment Wing #7 (Airborne)
310th Bombardment Wing #8 (Airborne)
310th Bombardment Wing #9 (Readying)


Base: RAF Kinloss
106th Air Refueling Group #1 (Parked)
106th Air Refueling Group #10 (Readying)
106th Air Refueling Group #11 (Parked)
106th Air Refueling Group #12 (Airborne)
106th Air Refueling Group #13 (Airborne)
106th Air Refueling Group #14 (Airborne)
106th Air Refueling Group #15 (Readying)
106th Air Refueling Group #16 (Airborne)
106th Air Refueling Group #17 (Parked)
106th Air Refueling Group #18 (Parked)
106th Air Refueling Group #19 (Parked)
106th Air Refueling Group #2 (Parked)
106th Air Refueling Group #20 (Airborne)
106th Air Refueling Group #21 (Airborne)
106th Air Refueling Group #22 (Airborne)
106th Air Refueling Group #23 (Airborne)
106th Air Refueling Group #24 (Airborne)
106th Air Refueling Group #25 (Parked)
106th Air Refueling Group #26 (Readying)
106th Air Refueling Group #27 (Airborne)
106th Air Refueling Group #28 (Readying)
106th Air Refueling Group #29 (Returning to base)
106th Air Refueling Group #3 (Parked)
106th Air Refueling Group #30 (Offloading fuel)
106th Air Refueling Group #31 (Parked)
106th Air Refueling Group #32 (Readying)
106th Air Refueling Group #33 (Readying)
106th Air Refueling Group #34 (Parked)
106th Air Refueling Group #35 (Airborne)
106th Air Refueling Group #36 (Airborne)
106th Air Refueling Group #37 (Readying)
106th Air Refueling Group #38 (Parked)
106th Air Refueling Group #39 (Parked)
106th Air Refueling Group #4 (Parked)
106th Air Refueling Group #5 (Parked)
106th Air Refueling Group #6 (Parked)
106th Air Refueling Group #7 (Parked)
106th Air Refueling Group #8 (Parked)
106th Air Refueling Group #9 (Parked)


Un-based units
RAF Fairford
RAF Kinloss
RAF Upper Heyford


_____________________________

Michael

(in reply to michaelm75au)
Post #: 2
RE: Example - 2/11/2017 12:03:48 AM   
Rory Noonan

 

Posts: 2816
Joined: 12/18/2014
From: Brooklyn, NY
Status: offline
You magnificent bastard.

Thank you!

(in reply to michaelm75au)
Post #: 3
RE: Example - 2/11/2017 12:09:02 AM   
michaelm75au


Posts: 13500
Joined: 5/5/2001
From: Melbourne, Australia
Status: offline
You could also set this up as a Special Event to be run whenever needed - should just print to the log. But the script console window still needs to open in the background.

< Message edited by michaelm -- 2/11/2017 5:58:31 AM >


_____________________________

Michael

(in reply to Rory Noonan)
Post #: 4
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Simple OOB listing using Lua in 1.11.sr7 Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

2.125