Jump to content

Noob Question - getFuel script


Rockrend

Recommended Posts

Hi all,

I'm very new to scipting and am keen to learn more. I have a question which I hope someone can help me out with. I've seen the following information regarding the getFuel script on the Hoggit page (https://wiki.hoggitworld.com/view/DCS_func_getFuel) and I'm not sure if I'm reading the example correctly. It states the following:

 

 

The following is the fuel returned for a flight of 4 F-15C. The flight lead has 0 external fuel tanks with each subsequent wingman adding a 610 Gal external fuel tank to their payload.

 

 

local flightFuel = {}

for i, unitObject in pairs(Group.getByName('flight'):getUnits()) do

flightFuel = Unit.getFuel(unitObject)

end

 

 

Returns the following:

Unit 1 Fuel: 1

Unit 2 Fuel: 1.3026511669159

Unit 3 Fuel: 1.6053023338318

Unit 4 Fuel: 1.9079535007477

 

 

Does this indicate that the script will display on screen the information about fuel state above (in red)? I've amended the 'flight' information with the correct name of a two aircraft group in the mission and it seems that the script is running correctly (no errors) but I can't work out if it's supposed to display anything on screen or not. Some assistance would be very much appreciated and I'm sorry for such a noob question.

 

 

Thanks in advance.

Link to comment
Share on other sites

No. The example script merely stores the fuel status of each unit in the group into the table "flightFuel", and only the amount of fuel at the time that section of script was executed.

 

You would have to add an output method to the script to print the fuel status to the screen.

Wayz Out

 

 

Intel Core i9 9900K | ASUS ROG Strix Z390E Gaming MB | G.Skill Ripjaws V 32gb DDR4-3200 | GeForce RTX 2080 Ti | Samsung 970 EVO Plus NVMe

HTC Vive Pro VR | Logitech G x56 HOTAS | Logitech G PRO Pedals

Link to comment
Share on other sites

No. The example script merely stores the fuel status of each unit in the group into the table "flightFuel", and only the amount of fuel at the time that section of script was executed.

 

You would have to add an output method to the script to print the fuel status to the screen.

 

Thanks very much for the reply, I appreciate it. Now, can anyone point me to where i can find the correct syntax to script an output method to print the fuel status. Thanks in advance.


Edited by Rockrend
Link to comment
Share on other sites

If all you are looking to do is simply display the fuel stats, you can use the following code:

 

 

for i, unitObject in pairs(Group.getByName('flight'):getUnits()) do
local fuelstring = string.format("Unit %i fuel : %f",i,Unit.getFuel(unitObject) )
trigger.action.outText(fuelstring, 30)
end

 

 

Bear in mind, this does away with the storage of the fuel status in the table "flightFuel" because it's unnecessary, unless you plan on using that data later.

 

 

As for triggering when to call this code, I'll leave that up to you....

  • Thanks 1

Wayz Out

 

 

Intel Core i9 9900K | ASUS ROG Strix Z390E Gaming MB | G.Skill Ripjaws V 32gb DDR4-3200 | GeForce RTX 2080 Ti | Samsung 970 EVO Plus NVMe

HTC Vive Pro VR | Logitech G x56 HOTAS | Logitech G PRO Pedals

Link to comment
Share on other sites

@Rockrend

 

If you're only interested in knowing the fuel status of a specific plane, you don't need to use that iterator.

 

You can do this instead:

 

 

 

--- OPTION A ---

 

FuelStatus = Unit.getByName("UNIT NAME of the plane in ME"):getFuel() -- This will get the fuel level of the specified plane, as shown in the first post

 

trigger.action.outText("Fuel level = "..FuelStatus , 10) -- This will send a 10 second message to everybody in the mission, indicating the fuel level of the specified plane

 

 

--- OPTION B ---

 

-- Now, instead of sending the message to all players in the mission, you can send the message to a specific group (messages can't be sent to specific clients, unfortunately)

 

FuelStatus = Unit.getByName("UNIT NAME of the plane in ME"):getFuel()

 

TargetGroupID = Group.getByName("Name of the target group in ME"):getID() -- This will get the ID of the group that's supposed to receive the message. DCS needs this ID to send messages to specific groups

 

trigger.action.outTextForGroup(TargetGroupID, "Fuel level = "..FuelStatus, 10)

 

 

--- OPTION C ---

 

--- a)

-- Finally, you can further improve this by including the name of the unit in the fuel status message (I'll change things a little bit, but the methods are the same)

 

UnitObject = Unit.getByName("UNIT NAME of the plane in ME")

 

UnitName = UnitObject:getName() -- This will return the ME unit name of the plane in string format

 

FuelStatus = UnitObject:getFuel()

 

TargetGroupID = Group.getByName("Name of the target group in ME"):getID()

 

trigger.action.outTextForGroup(TargetGroupID, UnitName.." fuel level = "..FuelStatus, 10) -- This group message will include the ME unit name of the plane, as well as its fuel status

 

--- b)

-- If you want to, you can dispense with unnecessary variables to make it shorter (though it'll be harder to understand if you are just starting)

 

UnitObject = Unit.getByName("UNIT NAME of the plane in ME")

 

trigger.action.outTextForGroup(Group.getByName("Name of the target group in ME"):getID(), UnitObject:getName().." fuel level = "..UnitObject:getFuel(), 10) -- This group message now contains most of the methods that we had stored in variables earlier

 

 

 


Edited by Hardcard
  • Thanks 1
Link to comment
Share on other sites

@Rockrend

 

If you're only interested in knowing the fuel status of a specific plane, you don't need to use that iterator.

 

Thanks very much for the reply. Seems like there is a dozen ways to skin this cat. It’s really great that the people in this part of the forum are so helpful and willing to share their knowledge.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...