I work a lot with DCS Mission Editor, and started learning LUA about two weeks ago. As an excercise, I wrote a simple script allowing to call my flight for fuel reports. I found it useful in long range fighter sweeps or caps. To use it in a mission, two triggers have to be created:
1. ONCE trigger, with condition TIME MORE(5) and two actions
- adding a radio item for report call, flag 1 value 1
- do script with code below:
------- Initialization -------
player = world.getPlayer()
local playerFlight = Unit.getGroup(player)
planesInFlight = Group.getUnits(playerFlight)
2. REPETITIVE ACTION trigger, with condition FLAG IS TRUE(1) and two actions:
- do script with code below:
------- Fuel report -------
for i = 1, #planesInFlight do
if Unit.isExist(planesInFlight[i]) then
if Unit.getID(planesInFlight[i]) ~= Unit.getID(player) then
trigger.action.outText(Unit.getCallsign(planesInFlight[i]) .. " fuel state: " .. math.floor(100 * Unit.getFuel(planesInFlight[i])) .. "%", 10)
end
end
end
- set flag 1 back to 0
What's the purpose of it? If a plane has full internal tanks, getFuel returns 1. If it has also external tanks, the returned value is above 1. I converted it to percents, it's more readable.
Normally, my wingmen drop tanks during defensive maneuvers, having a missile fired at. It can be too late for them. Of course, I can order them to drop external tanks earlier. But having their fuel state reported, I can order them to do it just as they have 100% or less. This reduces drag and can save some fuel.
I use "Drop ordnance command". Unfortunately, I can't find how to make them drop payload from specific pylons.
Why did I use nested IFs? When I used one if with two expressions connected by AND, the script crashed, I don't know why. It happened after I lost a wingman in combat and call my fuel report.
Here is a simple mission I created to test my scripts.
02 Scripting tests.miz