Page 1 of 1
Activate Mission Based on *Weapon* Detection?
Posted: Sat Apr 14, 2018 5:13 am
by gpotter511
Evening all -
I'm trying to create an event where the various Actions are triggered not by the detection of a unit, but by the detection of a certain type of ballistic missile. At scenario start, the platform carrying said weapon will be docked at a base.
I see the option exists to set a trigger based on a weapon, but the only option available under the dropdown reads, "None".
Any suggestions for how to go about this, or alternative paths that would achieve the same result?
Thanks!
Geoff
RE: Activate Mission Based on *Weapon* Detection?
Posted: Sat Apr 14, 2018 6:46 pm
by TitaniumTrout
You can use the weapon detected trigger and then a condition to check for altitude or speed. You could use this to differentiate from a SAM or AAM, or a cruise missile or dumb bomb.
Code: Select all
local unit = ScenEdit_UnitX()
print(unit.speed)
local minSpeed = 350
if unit.speed <= minSpeed then
return true
else
return false
end
Code: Select all
local unit = ScenEdit_UnitX()
print(unit.altitude)
local minAlt = 3000
if unit.altitude < minAlt then
return true
else
return false
end
I made a test scenario and fired a HARM into a zone. This is the function and the return :
Code: Select all
>> local unit = ScenEdit_UnitX()
print(unit)
unit {
type = 'Weapon',
subtype = '2001',
name = 'AGM-88C HARM #7',
side = 'OPFOR',
guid = 'cd94f9a5-b3d8-4cc8-b0d4-c08319d51b38',
proficiency = 'Regular',
latitude = '15.8438326179163',
longitude = '16.7833819762904',
altitude = '10469.97',
heading = '180.4915',
speed = '1964',
throttle = 'Cruise',
autodetectable = 'False',
mounts = '0',
unitstate = 'Unassigned',
fuelstate = 'None',
weaponstate = 'None',
}
That's the variables you have to work with. Type won't change, you could compare subtypes if you know which to look for. Otherwise speed or altitude is a good one.
RE: Activate Mission Based on *Weapon* Detection?
Posted: Sat Apr 14, 2018 9:14 pm
by michaelm75au
For more unit variables, look in the Command Lua wiki.
RE: Activate Mission Based on *Weapon* Detection?
Posted: Sun Apr 22, 2018 2:18 pm
by gpotter511
Thanks very much to both of you for this!
I started by attempting to replicate the outcome you described above, but I'm having trouble accomplishing that. I ran the script exactly as above while an F/A-18 fired an AGM-88E HARM into the zone, and the result was "ERROR: [string "Console"]:2: attempt to index local 'unit' (a nil value)". Efforts to replace "unit.speed" and "unit.altitude" with something else, e.g. the name of the weapon, were met with errors regarding a "malformed number". Can you advise?
Additionally - what is the expected sequence using the above script? Is this script what achieves the detection as part of the Event Condition, or does this script contribute to something else?
Thanks,
Geoff
RE: Activate Mission Based on *Weapon* Detection?
Posted: Sun Apr 22, 2018 5:32 pm
by TitaniumTrout
So first you need to make the trigger. Nothing happens in regards to Lua (or any event) unless it's executed via a trigger or a special action. Once you have a trigger you need to associate with an event. Then once the trigger is actuated it will run whatever script or action you decide. I'll walk you through it.
I created two sides, OPFOR and BLUFOR. OPFOR has a radar and a bunker. The above trigger sets a detection zone, type.
I then create an action. All I want is a message box to pop up depending on what the altitude is. Then I make a message box to tell me what I'm seeing. You can also use the Lua Console after the trigger has fired and enter it there.
Finally I stick each into an event.
I fire a pair of Storm Shadows from a Tornado GR4. Once the radar detects them, and it's inside the set zone, I get the above info.
RE: Activate Mission Based on *Weapon* Detection?
Posted: Sun Apr 22, 2018 8:54 pm
by gpotter511
Thanks for taking the time to lay this out, Titanium Trout. I was making the error of using this script as a Condition, on the premise that a detected weapon trigger, modified by the condition of this Lua script, would tell Command to trigger an "Activate Mission" action. The idea is to have the detection of an SLBM attack by OPFOR trigger an ICBM counterattack by BLUFOR.
In order to achieve that result - would it make the most sense to pair an action spitting out this message with a second action activating the counterattack mission?
Thanks,
Geoff
RE: Activate Mission Based on *Weapon* Detection?
Posted: Mon Apr 23, 2018 8:24 am
by TitaniumTrout
You could do it simply, without Lua, using the trigger above and a Mission Status Action. This changes a mission from passive to active or vice-versa. The problem is if an AAM missile overflew the trigger area it would fire and the ICBM's would launch. Whoops.
So then you need a way to compare name, or altitude, or speed, then use ScenEdit_SetMission to set it active.