Readout for different fuel types?
Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command
Readout for different fuel types?
Hello,
I'm currently playing a scenario with many different tankers in use, and most of these have multiple different types of fuel on board. Unfortunately, the unit display doesn't show the quantities of each different type remaining on the ship.
Is there a Lua way (for a complete Lua beginner) to get a readout of the current quantities of oil, gas, diesel, and aviation fuel on a specific ship? (Ideally, click on ship, run script, get readout?)
Many thanks,
Andrew
I'm currently playing a scenario with many different tankers in use, and most of these have multiple different types of fuel on board. Unfortunately, the unit display doesn't show the quantities of each different type remaining on the ship.
Is there a Lua way (for a complete Lua beginner) to get a readout of the current quantities of oil, gas, diesel, and aviation fuel on a specific ship? (Ideally, click on ship, run script, get readout?)
Many thanks,
Andrew
RE: Readout for different fuel types?
This is a great idea. A special action would work but I have no idea what the script would look like.
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
- michaelm75au
- Posts: 12457
- Joined: Sat May 05, 2001 8:00 am
- Location: Melbourne, Australia
RE: Readout for different fuel types?
Something like this but it can be cleaned up and made 'pretty':
Results
local s = ScenEdit_SelectedUnits()
for k,v in pairs(s.units) do
print(string.format("Fuel status for %s ( guid: %s)", v.name, v.guid))
local u = ScenEdit_GetUnit({name=v.guid})
local f = u.fuel
--print(f)
for type,level in pairs(f) do
print(string.format("%-16.16s current: %s maximum: %s available: %.02f %%", level.name, level.current, level.max, (level.current/level.max)*100))
end
print('-------------');print('\n')
end
Results
Fuel status for AOE 421 Sagami ( guid: 004aa55d-d553-428d-a727-26853737c8f4)
DieselFuel current: 1999978.125 maximum: 2000000 available: 99.99890625 %
OilFuel current: 7150000.0 maximum: 7150000 available: 100.0 %
AviationFuel current: 100000.0 maximum: 100000 available: 100.0 %
-------------
Fuel status for SS 583 Harushio ( guid: 3a5f2a57-36e2-48f6-9352-00b819789a18)
DieselFuel current: 60000.0 maximum: 60000 available: 100.0 %
Battery current: 6000.0 maximum: 6000 available: 100.0 %
-------------
Michael
RE: Readout for different fuel types?
Awesome! I'll give it a try tomorrow.
-
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Readout for different fuel types?
Pretty version I scraped together for you (I already had the nuts and bolts).

Copy the attached SA_SelectedUnits_PrettyFuelReport.lua into a repeatable Special Action on your side.
The only thing you need to change is at the very bottom to use the correct side name.
--first param is the side you want the message generated too, true\false is if you want color coding or not.
BuildTable('RedSide',true)
note:
If you want to screw around with different numbers for red\orange\green you can just adjust the numbers in prettyFuelTableEntry()'s local redPct,orangepct,greenpct = 20.0,40.0,40.0 line. Obviously you can change the color codes and formatting as well in the stylesheet if you want to tweek the looks.

Copy the attached SA_SelectedUnits_PrettyFuelReport.lua into a repeatable Special Action on your side.
The only thing you need to change is at the very bottom to use the correct side name.
--first param is the side you want the message generated too, true\false is if you want color coding or not.
BuildTable('RedSide',true)
note:
If you want to screw around with different numbers for red\orange\green you can just adjust the numbers in prettyFuelTableEntry()'s local redPct,orangepct,greenpct = 20.0,40.0,40.0 line. Obviously you can change the color codes and formatting as well in the stylesheet if you want to tweek the looks.
- Attachments
-
- SA_Selecte..elReport.zip
- (108.42 KiB) Downloaded 63 times
RE: Readout for different fuel types?
Great stuff. I'll put this in the next update for the scenario - and a few others that I can think of.
Is there a way that the Special Action could be applied to one selected unit? For instance, have an AOR selected, hit the SA and get a readout for just that one ship?
Thanks
Is there a way that the Special Action could be applied to one selected unit? For instance, have an AOR selected, hit the SA and get a readout for just that one ship?
Thanks
Check out our novel, Northern Fury: H-Hour!: http://northernfury.us/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
And our blog: http://northernfury.us/blog/post2/
Twitter: @NorthernFury94 or Facebook https://www.facebook.com/northernfury/
-
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Readout for different fuel types?
ORIGINAL: Gunner98
Is there a way that the Special Action could be applied to one selected unit? For instance, have an AOR selected, hit the SA and get a readout for just that one ship?
Thanks
Yea, just select the 1 unit and press the action.??[:)]
At present it does whatever you have selected, be that 1, be that 20, and it handles selected groups too.
--
Now, if you want to specifically limit it to a particular pre-set unit or set of units, if that's what you meant, you can change where it's getting the list from and just feed it your own list of guids. All it really needs is a table of unit\group guids who's entries a 'guid' field.
To do that easiest with touching the least amount of code is create your own list.
So let's assume gBDude.SceneGlobals table exists just for spit-balling example.
Create a table with what you want it to process looking just like a selectedUnits table.
gBDude.SceneGlobals.SomeListFormatedLikeSelectedUnits = {
units{
{guid="guid1",name="bla bla"},
{guid="guid2",name='bla bla'},
...etc etc..}
};
Then in processSelectedUnits()
all you'd have to change is
local sUnits=ScenEdit_SelectedUnits() to local sUnits=gBDude.SceneGlobals.SomeListFormatedLikeSelectedUnits
or
You could just change the first nil check and the first 'for' to operate on gBDude.SceneGlobals.SomeListFormatedLikeSelectedUnits instead of 'sUnits.units'
Now if you wanted to adjust it to take said table as parameter you could also do that but you'll have to pass the parameter into buildtable, and then have it pass it on to processselectunits, and add the params in both function declarations etc and maybe another adjustment or two I'm nothing thinking about atm. I figure the first two ways are the most simple.
RE: Readout for different fuel types?
This is working great - a superb edition to a long-duration logistics-driven scenario. Many thanks!
RE: Readout for different fuel types?
I like this function and tried it out, works great. Want it to use with pre-determined units. But I'm doing something wrong. tried to change accordingly the orders but got:
'Please select one or more units first.'
I made this:
gBDude={}
gBDude.SceneGlobals={}
gBDude.SceneGlobals.SomeListFormatedLikeSelectedUnits={
{name='F 802 De Zeven Provinciën', guid='P7ML9T-0HMECC07850U3'},
{name='P 840 Holland', guid='P7ML9T-0HMED2D1QP4KD'},
{name='F 930 Leopold I [Karel Doorman]', guid='P7ML9T-0HMED2D1QP8E0'}
};
local function processSelectedUnits(pcolor)
local sUnits=gBDude.SceneGlobals.SomeListFormatedLikeSelectedUnits
local tbl ={};
if(sUnits.units ~=nil) then
local u,g; local counter=0;
for k,v in pairs(sUnits.units) do --loop though selected unit table
u = ScenEdit_GetUnit({guid=v.guid}); --get the unit.
if ((u~=nil) and u.type ~='Group') then --are we valid and not a group?
table.insert(tbl,prettyFuelTableEntry(u,pcolor)); counter = counter + 1;
elseif((u~=nil) and u.type =='Group') then --are we valid and also a group?
g = u.group.unitlist; --simply array of unit guids of members.
for l,m in pairs(g) do
u = ScenEdit_GetUnit({guid=m}); --get the unit.
if ( (u ~= nil) and u.type ~='Group') then -- are we valid and not also another group?
table.insert(tbl,prettyFuelTableEntry(u,pcolor)); counter = counter + 1;
else
ScenEdit_MsgBox('Could not obtain the object for one of selected units with guid: ' ..tostring(m), 1);
end
u=nil;
end
else
ScenEdit_MsgBox('Could not obtain the object for one of selected units with guid: ' ..tostring(v.guid), 1);
end
u=nil;
end
ScenEdit_MsgBox(string.format('Completed fuel report on %s units',tostring(counter)), 1);
else
ScenEdit_MsgBox('Please select one or more units first.', 1);
end
sUnits=nil;
return tbl;
end
It all goes beyond my comprehension, hope you spot my mistake.
best regards GJ and best wishes for 2022
'Please select one or more units first.'
I made this:
gBDude={}
gBDude.SceneGlobals={}
gBDude.SceneGlobals.SomeListFormatedLikeSelectedUnits={
{name='F 802 De Zeven Provinciën', guid='P7ML9T-0HMECC07850U3'},
{name='P 840 Holland', guid='P7ML9T-0HMED2D1QP4KD'},
{name='F 930 Leopold I [Karel Doorman]', guid='P7ML9T-0HMED2D1QP8E0'}
};
local function processSelectedUnits(pcolor)
local sUnits=gBDude.SceneGlobals.SomeListFormatedLikeSelectedUnits
local tbl ={};
if(sUnits.units ~=nil) then
local u,g; local counter=0;
for k,v in pairs(sUnits.units) do --loop though selected unit table
u = ScenEdit_GetUnit({guid=v.guid}); --get the unit.
if ((u~=nil) and u.type ~='Group') then --are we valid and not a group?
table.insert(tbl,prettyFuelTableEntry(u,pcolor)); counter = counter + 1;
elseif((u~=nil) and u.type =='Group') then --are we valid and also a group?
g = u.group.unitlist; --simply array of unit guids of members.
for l,m in pairs(g) do
u = ScenEdit_GetUnit({guid=m}); --get the unit.
if ( (u ~= nil) and u.type ~='Group') then -- are we valid and not also another group?
table.insert(tbl,prettyFuelTableEntry(u,pcolor)); counter = counter + 1;
else
ScenEdit_MsgBox('Could not obtain the object for one of selected units with guid: ' ..tostring(m), 1);
end
u=nil;
end
else
ScenEdit_MsgBox('Could not obtain the object for one of selected units with guid: ' ..tostring(v.guid), 1);
end
u=nil;
end
ScenEdit_MsgBox(string.format('Completed fuel report on %s units',tostring(counter)), 1);
else
ScenEdit_MsgBox('Please select one or more units first.', 1);
end
sUnits=nil;
return tbl;
end
It all goes beyond my comprehension, hope you spot my mistake.
best regards GJ and best wishes for 2022
RE: Readout for different fuel types?
Wow. I was out of commission when this KH posted this. Vedddy niiiice!
Mike
Mike
Don't call it a comeback...
-
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
RE: Readout for different fuel types?
ORIGINAL: Parel803
I like this function and tried it out, works great. Want it to use with pre-determined units. But I'm doing something wrong. tried to change accordingly the orders but got:
'Please select one or more units first.'
I made this:
...
It all goes beyond my comprehension, hope you spot my mistake.
best regards GJ and best wishes for 2022
I've not had a chance to eye ball this in-game yet, but from what you explain I maybe your table of units isn't in the same format\structure as a 'selected units' table. As I recall it would look like this:
gBDude.SceneGlobals.SomeListFormatedLikeSelectedUnits={
units={
{name='F 802 De Zeven Provinciën', guid='P7ML9T-0HMECC07850U3'},
{name='P 840 Holland', guid='P7ML9T-0HMED2D1QP4KD'},
{name='F 930 Leopold I [Karel Doorman]', guid='P7ML9T-0HMED2D1QP8E0'}}
}
ie things are in sub-table 'units' (groups sub-table can exist as well), it's why that variable is named the way it is. [:)] Try that, let me know if you still get a failure.
ThanksORIGINAL: BDukes
Wow. I was out of commission when this KH posted this. Vedddy niiiice!
Mike

RE: Readout for different fuel types?
thanks agian for your time and answer
best regards GJ
and it works great, thx
best regards GJ
and it works great, thx
Re: Readout for different fuel types?
Best wishes
I made it to have all units on a type. Probable not in the best way but (trial & error) working
Used:
-- Delete TABLE and and add:
local s = VP_GetSide({Side="NATO"})
local ThisUnitList = s:unitsBy('Ship');
-- change for... line to:
for k,v in pairs(ThisUnitlist do --loop though selected unit table
A new question:
Would this be possible to have with Weapons and Magazines.If so were to start? Really no clue.
best regards GJ
I made it to have all units on a type. Probable not in the best way but (trial & error) working
Used:
-- Delete TABLE and and add:
local s = VP_GetSide({Side="NATO"})
local ThisUnitList = s:unitsBy('Ship');
-- change for... line to:
for k,v in pairs(ThisUnitlist do --loop though selected unit table
A new question:
Would this be possible to have with Weapons and Magazines.If so were to start? Really no clue.
best regards GJ
-
- Posts: 1850
- Joined: Thu Nov 15, 2018 7:24 pm
Re: Readout for different fuel types?
You mean generate (for selected units or certain units) a list of what weapons they have and a total of how many are available and how many of said weapon are "on mag", stuff like that, in theory sure. I think you'd just have the change the unit processing to grab that data you want from unit.magazines and unit.mounts, and if aircraft account for loadout as well. Could do per unit as you go or do them all at once and build a table of the data, then adjust the html generation as needed to fit how you want it represented\formatted.Would this be possible to have with Weapons and Magazines.If so were to start? Really no clue.
Re: Readout for different fuel types?
KH,
Sounds a bit beyond my comprehension but gonna try it out. Did not got it working so far.
But yes I want a player to see how many weapons are left of pre-determined units.
thanks again for all the answers,
regards GJ
Sounds a bit beyond my comprehension but gonna try it out. Did not got it working so far.
But yes I want a player to see how many weapons are left of pre-determined units.
thanks again for all the answers,
regards GJ