Florence201 Posted August 4, 2019 Share Posted August 4, 2019 So i'm in the process of campaign creation and i can't seem to track down in the User Manual, how to set a trigger/condition to pass fuel quantity as part of a radio transmission. Anyone know how to do this? Cheers :book: [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Hardcard Posted August 4, 2019 Share Posted August 4, 2019 (edited) 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 August 5, 2019 by Hardcard [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Florence201 Posted August 7, 2019 Author Share Posted August 7, 2019 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 More sharing options...
johnv2pt0 Posted August 8, 2019 Share Posted August 8, 2019 (edited) 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 August 8, 2019 by johnv2pt0 Link to comment Share on other sites More sharing options...
Hardcard Posted August 8, 2019 Share Posted August 8, 2019 @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 ) [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
johnv2pt0 Posted August 8, 2019 Share Posted August 8, 2019 Cool thanks Hardcard Link to comment Share on other sites More sharing options...
Hardcard Posted August 8, 2019 Share Posted August 8, 2019 (edited) @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 August 8, 2019 by Hardcard [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Florence201 Posted August 12, 2019 Author Share Posted August 12, 2019 (edited) @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 August 12, 2019 by Florence201 [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Hardcard Posted August 13, 2019 Share Posted August 13, 2019 (edited) 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 August 13, 2019 by Hardcard [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Florence201 Posted August 14, 2019 Author Share Posted August 14, 2019 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 More sharing options...
Hardcard Posted August 14, 2019 Share Posted August 14, 2019 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. By radio message, do you mean radio transmission (as in playing a prerecorded audio file)? [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Florence201 Posted August 14, 2019 Author Share Posted August 14, 2019 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 More sharing options...
Hardcard Posted August 14, 2019 Share Posted August 14, 2019 I'd like to be able make an entity on the ground a controller and have "Fence In with fuel transmitted". So, basically a ground unit sending you a message at fence in (including fuel quantity), is that it? [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Florence201 Posted August 15, 2019 Author Share Posted August 15, 2019 So, basically a ground unit sending you a message at fence in (including fuel quantity), is that it? The other way round. I want to fence in to a ground unit with fuel. [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Hardcard Posted August 15, 2019 Share Posted August 15, 2019 (edited) 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 August 15, 2019 by Hardcard [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Florence201 Posted August 15, 2019 Author Share Posted August 15, 2019 Hardcard: I'll try that out thanks [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Gunnar81 Posted August 19, 2019 Share Posted August 19, 2019 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 More sharing options...
Gunnar81 Posted August 19, 2019 Share Posted August 19, 2019 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 More sharing options...
Hardcard Posted August 19, 2019 Share Posted August 19, 2019 (edited) @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 August 19, 2019 by Hardcard [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Gunnar81 Posted August 19, 2019 Share Posted August 19, 2019 @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 More sharing options...
Hardcard Posted August 19, 2019 Share Posted August 19, 2019 Careful! I forgot to add the groupID parameter in the message trigger, check my edited post for the corrected syntax [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Gunnar81 Posted August 24, 2019 Share Posted August 24, 2019 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 More sharing options...
Hardcard Posted August 24, 2019 Share Posted August 24, 2019 Whenever you need a fuel reading for the specified aircraft, just run the script using a trigger (Do script should take care of this). [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Gunnar81 Posted August 25, 2019 Share Posted August 25, 2019 Ok thanks, makes sense. Link to comment Share on other sites More sharing options...
Recommended Posts