Jump to content

Pass Fuel Quantity


Florence201

Recommended Posts

The DCS scripting engine doesn't handle fuel quantity in the way you're probably assuming.

 

Fuel quantity is expressed as a decimal value (I think it's the percentage of the internal tank capacity divided by 100):

 

 

Internal fuel tanks at 100% = 1

 

Internal fuel tanks at 50% = 0.5

 

Internal fuel tanks empty = 0

 

Internal fuel tanks at 100% + external fuel tanks = >1 (the value will vary depending on the type of external fuel tanks the plane is carrying)

 

 

 

What are you trying to achieve, exactly?


Edited by Hardcard
Link to comment
Share on other sites

The DCS scripting engine doesn't handle fuel quantity in the way you're probably assuming.

 

Fuel quantity is expressed as a decimal value (I think it's the percentage of the internal tank capacity divided by 100):

 

 

Internal fuel tanks at 100% = 1

 

Internal fuel tanks at 50% = 0.5

 

Internal fuel tanks empty = 0

 

Internal fuel tanks at 100% + external fuel tanks = >1 (the value will vary depending on the type of external fuel tanks the plane is carrying)

 

 

 

What are you trying to achieve, exactly?

 

 

Trying to "check In"with fuel quantity in a campaign i'm almost finished designing.

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Something like this? Only thing is it will spit out lots of decimal places which I don't know how to truncate

 

--example uses a F-14 which has a total internal fuel load capacity of 16,200lbs

if trigger.misc.getUserFlag("1", true) then

local PlayerFuel = Unit.getByName("whatever"):getFuel()
trigger.action.outText("Tanker, Player1-1, checking in with ".. PlayerFuel*16200 .." lbs.", 10)
trigger.action.setUserFlag("1", false)

end

 

EDIT: If you're using MIST already or if you simply include it you can use a built in rounding utility so it would look like this

 

--example uses a F-14 which has a total internal fuel load capacity of 16,200lbs

if trigger.misc.getUserFlag("1", true) then

local PlayerFuel = Unit.getByName("whatever"):getFuel()
trigger.action.outText("Tanker, Player1-1, checking in with "..  (mist.utils.round(PlayerFuel*16200)) .." lbs.", 10)
trigger.action.setUserFlag("1", false)

end

 

If anyone knows how to truncate using just base lua I'd love to learn!


Edited by johnv2pt0
Link to comment
Share on other sites

@Florence201

 

I'll post a script I wrote a few days ago, it basically does the same as johnv2pt0's snippet...but for all flyable aircraft currently available in DCS (it provides the values in both lbs an kg and rounds them up as well) :thumbup:

 

 

johnv2pt0

 

You don't need to use MIST or MOOSE in order to round up values.

 

In this particular case, since we're only interested in integer values, we can simply use the following:

math.floor( [i][color="Red"]number you want to round up [/color][/i]+ 0.5 )

Link to comment
Share on other sites

@Florence201

 

Here's the script I mentioned, it should do the trick (the only required field is marked in red, don't remove the quotation marks):

 

local function GetFuelWeight(Pilot_Name)

      if Unit.getByName(Pilot_Name) then
  
         local DCS_Unit = Unit.getByName(Pilot_Name)
         local Aircraft_Type = DCS_Unit:getDesc().typeName
         local Aircraft_Max_Internal_Fuel = DCS_Unit:getDesc().fuelMassMax
         local Fuel_Multiplier = DCS_Unit:getFuel()
        
         local Fuel_Kg = math.floor( Aircraft_Max_Internal_Fuel * Fuel_Multiplier + 0.5)
         local Fuel_Lbs = math.floor( Fuel_Kg * 2.2046 + 0.5)
             
         return Pilot_Name, Aircraft_Type, Fuel_Kg, Fuel_Lbs      
            
  
      elseif Unit.getByName(Pilot_Name) == nil then
  
             trigger.action.outText(Pilot_Name.." couldn't be found!",10)
            
      end
end

local Pilot_Name, Aircraft_Type, Fuel_Kg , Fuel_Lbs = GetFuelWeight("[color="Red"]PILOT name of the aircraft in ME[/color]")  [color="Blue"]-- This variable contains 4 different values from the referenced aircraft: Pilot_Name, Aircraft_Type, Fuel_Kg and Fuel_Lbs. Use them at your discretion[/color]

trigger.action.outText("*** "..Pilot_Name.." - "..Aircraft_Type.." ***".."\nRemaining Fuel (Kg) = "..Fuel_Kg.."\nRemaining Fuel (lbs) = "..Fuel_Lbs, 10)  

 

It should work with all aircraft in DCS (flyable or not) :thumbup:

 

Keep in mind that you'll need to include the variable in a scheduler if you need to get updated fuel readings periodically.

 

For instance, you could add this at the end of the script:

Loop = 1

local function Scheduler(Loop , time)
 
 local Pilot_Name, Aircraft_Type, Fuel_Kg , Fuel_Lbs = GetFuelWeight("[color="Red"]PILOT name of the aircraft in ME[/color]")

 trigger.action.outText("*** "..Pilot_Name.." - "..Aircraft_Type.." ***".."\nRemaining Fuel (Kg) = "..Fuel_Kg.."\nRemaining Fuel (lbs) = "..Fuel_Lbs, 10)  
   
   if Loop == 1 then
      return time + 1
   end
end

timer.scheduleFunction(Scheduler, Loop , timer.getTime() + 1)


Edited by Hardcard
Link to comment
Share on other sites

@Florence201

 

Here's the script I mentioned, it should do the trick (the only required field is marked in red, don't remove the quotation marks):

 

local function GetFuelWeight(Pilot_Name)

      if Unit.getByName(Pilot_Name) then
  
         local DCS_Unit = Unit.getByName(Pilot_Name)
         local Aircraft_Type = DCS_Unit:getDesc().typeName
         local Aircraft_Max_Internal_Fuel = DCS_Unit:getDesc().fuelMassMax
         local Fuel_Multiplier = DCS_Unit:getFuel()
        
         local Fuel_Kg = math.floor( Aircraft_Max_Internal_Fuel * Fuel_Multiplier + 0.5)
         local Fuel_Lbs = math.floor( Fuel_Kg * 2.2046 + 0.5)
             
         return Pilot_Name, Aircraft_Type, Fuel_Kg, Fuel_Lbs      
            
  
      elseif Unit.getByName(Pilot_Name) == nil then
  
             trigger.action.outText(Pilot_Name.." couldn't be found!",10)
            
      end
end

local Pilot_Name, Aircraft_Type, Fuel_Kg , Fuel_Lbs = GetFuelWeight("[color="Red"]PILOT name of the aircraft in ME[/color]")  [color="Blue"]-- This variable contains 4 different values from the referenced aircraft: Pilot_Name, Aircraft_Type, Fuel_Kg and Fuel_Lbs. Use them at your discretion[/color]

trigger.action.outText("*** "..Pilot_Name.." - "..Aircraft_Type.." ***".."\nRemaining Fuel (Kg) = "..Fuel_Kg.."\nRemaining Fuel (lbs) = "..Fuel_Lbs, 10)  

 

It should work with all aircraft in DCS (flyable or not) :thumbup:

 

Keep in mind that you'll need to include the variable in a scheduler if you need to get updated fuel readings periodically.

 

For instance, you could add this at the end of the script:

Loop = 1

local function Scheduler(Loop , time)
 
 local Pilot_Name, Aircraft_Type, Fuel_Kg , Fuel_Lbs = GetFuelWeight("[color="Red"]PILOT name of the aircraft in ME[/color]")

 trigger.action.outText("*** "..Pilot_Name.." - "..Aircraft_Type.." ***".."\nRemaining Fuel (Kg) = "..Fuel_Kg.."\nRemaining Fuel (lbs) = "..Fuel_Lbs, 10)  
   
   if Loop == 1 then
      return time + 1
   end
end

timer.scheduleFunction(Scheduler, Loop , timer.getTime() + 1)

 

Hardcard.

 

I'll give that a go. I only need fuel readings twice, One at Fence in and the other at Fence out. Do i need to replace all in quotations marks with just the pilots name in capitals?


Edited by Florence201

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

I only need fuel readings twice, One at Fence in and the other at Fence out.

 

I guess you could set up a trigger at Fence in and another at Fence out, using DO SCRIPT or DO SCRIPT FILE action to run the script each time (the latter option requires that you save the script as a .lua file, ofc).

 

 

Do i need to replace all in quotations marks with just the pilots name in capitals?

 

You must replace the field marked in red with the EXACT pilot name the aircraft is using in Mission Editor.

In other words, the two values must be identical (I recommend the ctrl + c / ctrl + v method for this)


Edited by Hardcard
Link to comment
Share on other sites

I guess you could set up a trigger at Fence in and another at Fence out, using DO SCRIPT or DO SCRIPT FILE action to run the script each time (the latter option requires that you save the script as a .lua file, ofc).

 

 

 

 

You must replace the field marked in red with the EXACT pilot name the aircraft is using in Mission Editor.

In other words, the two values must be identical (I recommend the ctrl + c / ctrl + v method for this)

 

Now my next big thing is to somehow create a ground element that you can talk to and make the jet pass fuel quantity in a radio message.

 

Thanks for the code though, works a treat in a message window. :lol:

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

By radio message, do you mean radio transmission (as in playing a prerecorded audio file)?

 

I'd like to be able make an entity on the ground a controller and have "Fence In with fuel transmitted".

 

Currently have pre-recorded "radio transmissions" set, but obviously can't include fuel.

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Right, sorry :doh:

 

I guess you could use this, then (required fields marked in red):

local MyPlane = Unit.getByName("[color="Red"]PILOT name of the aircraft in ME[/color]")

local function GetFuelWeight(MyPlane)

         local PilotCallsign = MyPlane:getCallsign()
         local Aircraft_Type = MyPlane:getDesc().typeName
         local Aircraft_Max_Internal_Fuel = MyPlane:getDesc().fuelMassMax
         local Fuel_Multiplier = MyPlane:getFuel()
        
         local Fuel_Kg = math.floor( Aircraft_Max_Internal_Fuel * Fuel_Multiplier + 0.5)
         local Fuel_Lbs = math.floor( Fuel_Kg * 2.2046 + 0.5)
             
         return PilotCallsign, Aircraft_Type, Fuel_Kg, Fuel_Lbs      
end


local PilotCallsign, Aircraft_Type, Fuel_Kg , Fuel_Lbs = GetFuelWeight(MyPlane)  [color="blue"]-- This variable contains 4 different values from the referenced aircraft: PilotCallsign, Aircraft_Type, Fuel_Kg and Fuel_Lbs. Use them at your discretion[/color]

trigger.action.outTextForGroup(MyPlane:getGroup():getID(), PilotCallsign.." : Fence [color="DarkOrange"]in[/color], remaining fuel "..Fuel_Lbs, 10) [color="Blue"]-- This message emulates the transmission to the ground controller[/color]

   
[color="blue"]-- Then you can use a simple logic check to set stuff in motion, for example...[/color] 

   if Fuel_Lbs >= [color="Red"]value[/color] then
  
     [color="blue"]-- Do stuff when remaining fuel quantity is either at or over a given value, for instance, set flag 666 to 1[/color]
     trigger.action.setUserFlag( "666", 1 )

   elseif Fuel_Lbs < [color="red"]value[/color] then

     [color="Blue"] -- Do stuff when remaining fuel quantity is under a given value, for instance, set flag 666 to 2[/color]
      trigger.action.setUserFlag( "666", 2 )
   end

 

Run the script at Fence In... for Fence Out, simply copy-paste this script and change the value marked in orange (change "in" for "out")


Edited by Hardcard
Link to comment
Share on other sites

Sorry Florence201, not trying to hijack your thread here, but I was wondering if Hardcard could answer a question for me that is slightly similar? I am trying to create a condition for a trigger where the condition checks for a certain fuel amount which would activate the action (for example a radio message etc). Is this possible with some kind of script? I can't seem to figure out how else to do it in the editor.

Link to comment
Share on other sites

Sorry Florence201, not trying to hijack your thread here, but I was wondering if Hardcard could answer a question for me that is slightly similar? I am trying to create a condition for a trigger where the condition checks for a certain fuel amount which would activate the action (for example a radio message etc). Is this possible with some kind of script? I can't seem to figure out how else to do it in the editor.

 

If I would have just looked 2 posts up I would see that Hardcard already had something posted in there...:megalol: nm guys. Thanks

Link to comment
Share on other sites

@Gunnar81

 

Sure, you can use the above script for that.

 

Its structure is pretty simple:

 

1- Airplane unit declaration

 

2- Function that will return the airplane's internal fuel weight (in either lbs or kg) when called / executed

 

3- Variable that will call / execute the function and store its returned values

 

4- Fuel quantity checks that can used for a variety of purposes.

 

 

This should do the trick for you (required values marked in red, if you want to use kg values, use Fuel_Kg instead of Fuel_Lbs in the check):

local MyPlane = Unit.getByName("[color="Red"]PILOT name of the aircraft in ME[/color]")

local function GetFuelWeight(MyPlane)

         local PilotCallsign = MyPlane:getCallsign()
         local Aircraft_Type = MyPlane:getDesc().typeName
         local Aircraft_Max_Internal_Fuel = MyPlane:getDesc().fuelMassMax
         local Fuel_Multiplier = MyPlane:getFuel()
        
         local Fuel_Kg = math.floor( Aircraft_Max_Internal_Fuel * Fuel_Multiplier + 0.5)
         local Fuel_Lbs = math.floor( Fuel_Kg * 2.2046 + 0.5)
             
         return PilotCallsign, Aircraft_Type, Fuel_Kg, Fuel_Lbs      
end


local PilotCallsign, Aircraft_Type, Fuel_Kg , Fuel_Lbs = GetFuelWeight(MyPlane) [color="Blue"] -- This variable contains 4 different values from the referenced aircraft: PilotCallsign, Aircraft_Type, Fuel_Kg and Fuel_Lbs. Use them at your discretion[/color]
 
[color="blue"]-- Then you can use a simple logic check to set stuff in motion, for example... [/color]

   if Fuel_Lbs == [color="red"]value[/color] then
      trigger.action.outTextForGroup(MyPlane:getGroup():getID() ,"[color="Red"]Content of the text message[/color]", 10) [color="Blue"]-- This message will be sent when fuel quantity is equal to the chosen amount[/color]
   end


Edited by Hardcard
Link to comment
Share on other sites

@Gunnar81

 

Sure, you can use the above script for that.

 

Its structure is pretty simple:

 

1- Airplane unit declaration

 

2- Function that will return the airplane's internal fuel weight (in either lbs or kg) when called / executed

 

3- Variable that will call / execute the function and store its returned values

 

4- Fuel quantity checks that can used for a variety of purposes.

 

 

This should do the trick for you (required values marked in red, if you want to use kg values, use Fuel_Kg instead of Fuel_Lbs in the if check):

local MyPlane = Unit.getByName("[color="Red"]PILOT name of the aircraft in ME[/color]")

local function GetFuelWeight(MyPlane)

         local PilotCallsign = MyPlane:getCallsign()
         local Aircraft_Type = MyPlane:getDesc().typeName
         local Aircraft_Max_Internal_Fuel = MyPlane:getDesc().fuelMassMax
         local Fuel_Multiplier = MyPlane:getFuel()
        
         local Fuel_Kg = math.floor( Aircraft_Max_Internal_Fuel * Fuel_Multiplier + 0.5)
         local Fuel_Lbs = math.floor( Fuel_Kg * 2.2046 + 0.5)
             
         return PilotCallsign, Aircraft_Type, Fuel_Kg, Fuel_Lbs      
end


local PilotCallsign, Aircraft_Type, Fuel_Kg , Fuel_Lbs = GetFuelWeight(MyPlane) [color="Blue"] -- This variable contains 4 different values from the referenced aircraft: PilotCallsign, Aircraft_Type, Fuel_Kg and Fuel_Lbs. Use them at your discretion[/color]
 
[color="blue"]-- Then you can use a simple logic check to set stuff in motion, for example... [/color]

   if Fuel_Lbs == [color="red"]value[/color] then
      trigger.action.outTextForGroup("[color="Red"]Content of the text message[/color]", 10) [color="Blue"]-- This message will be sent when fuel quantity is equal to the chosen amount[/color]
   end

 

That's great! :) Thanks a lot. I will give it a try.:thumbup:

Link to comment
Share on other sites

Hey Hardcard, I am just getting around to trying your script. Thanks again for producing it. I am really green at working with them so I am a little unsure of how to input it into the editor. Do I use the first portion of the script as a LUA predicate in conditions and then use 'Do Script' with the action portion of your script as the Action in the ME?

 

Like I said, uber scripting noob, but i'd like to learn more so I can up my mission making game. I've got some pretty good ideas for some campaigns etc.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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