tomekldc Posted June 5, 2019 Posted June 5, 2019 Hi, Here's the situation : I need to intercept an enenmy aircraft. I would like to create a trigger where the aircraft (controlled by an AI) is changing is course (going back to base) when I fire a missile at him. I can't find a trigger who says "missile fired" or "missile alive / spawn". Do you have an idea on how to do it ? Thanks for your help
Exorcet Posted June 5, 2019 Posted June 5, 2019 If you will be the only one to shoot, there is an EVENT option for triggers. One of the events is On shoot or something like that. The trigger will only activate when there is a shot fire. Sadly it doesn't care who does the shooting. You can be more specific with LUA scripting as you can create a shoot dependency based on specific aircraft. I haven't done this so off the top of my head I don't know exactly how the script would work. Awaiting: DCS F-15C Win 10 i5-9600KF 4.6 GHz 64 GB RAM RTX2080Ti 11GB -- Win 7 64 i5-6600K 3.6 GHz 32 GB RAM GTX970 4GB -- A-10C, F-5E, Su-27, F-15C, F-14B, F-16C missions in User Files
tomekldc Posted June 5, 2019 Author Posted June 5, 2019 Thank you for your help @Exorcet : it's a good start. i will be the only one firing missile. I found the EVENT "On Shot" as you mentionned. Now I'll try to change the course of the AI with this event. Thanks again.
Sedlo Posted June 5, 2019 Posted June 5, 2019 Put this code in as a DO SCRIPT near the start of your mission... Handler = {} function Handler:onEvent(event) if event.id == world.event.S_EVENT_SHOT and event.initiator == Unit.getByName('yourUNITNAME goes here') then trigger.action.setUserFlag('501', true) end end world.addEventHandler(Handler) Give your AI a couple of TRIGGERED ACTION, one being SWITCH WAYPOINT (to whatever one you want it to go to when you shoot), maybe a ROE Weapons Hold, and a REACTION TO THREAT as None. Now, set a condition that when flag 501 becomes true, you make the action AI TASK PUSH, and set the SWITCH WAYPOINT, ROE Hold, and REACTION TO THREAT NONE in the drop down.. Of course, you can make the flag whatever value you want it to be, and don't forget to put the UNIT Name of your aircraft in the code above (not the GROUP NAME). My Youtube Channel MY DCS MISSIONS
Hardcard Posted June 6, 2019 Posted June 6, 2019 (edited) @Sedlo Tomekldc wants those AI planes to turn around only when he fires at them. As it's written, your script will trigger flag 501 every time Tomekldc's client fires a missile (regardless of the target). Since event SHOT doesn't yield a target object, we need to get a bit creative, getting the target object from the missile itself. This script should do the trick (I've tested it, seems to work): local Client = Unit.getByName("Unit name of the client aircraft in ME") local Target = Unit.getByName("Unit name of the chosen AI aircraft in ME") local Handler = {} function Handler:onEvent(event) if event.id == world.event.S_EVENT_SHOT and event.initiator == Client and event.weapon:getTarget() ~= nil then local Missile_Target = event.weapon:getTarget() -- This will give us the target object of the missile that has been fired by the client if Missile_Target == Target then -- Checks whether the missile's target object is our chosen AI aircraft trigger.action.setUserFlag('501', true) end end end world.addEventHandler(Handler) Edited June 6, 2019 by Hardcard [sIGPIC][/sIGPIC]
tomekldc Posted June 6, 2019 Author Posted June 6, 2019 @Sedlo Tomekldc wants those AI planes to turn around only when he fires at them. As it's written, your script will trigger flag 501 every time Tomekldc's client fires a missile (regardless of the target). Since event SHOT doesn't yield a target object, we need to get a bit creative, getting the target object from the missile itself. This script should do the trick (I've tested it, seems to work): local Client = Unit.getByName("Unit name of the client aircraft in ME") local Target = Unit.getByName("Unit name of the chosen AI aircraft in ME") local Handler = {} function Handler:onEvent(event) if event.id == world.event.S_EVENT_SHOT and event.initiator == Client and event.weapon ~= nil then local Missile_Target = event.weapon:getTarget() -- This will give us the target object of the missile that has been fired by the client if Missile_Target == Target then -- Checks whether the missile's target object is our chosen AI aircraft trigger.action.setUserFlag('501', true) end end end world.addEventHandler(Handler) Thanks @Hardcard and @Sedlo, There's something wrong with my mission. By the way for the moment, I'm using a Su-25T (with Air-To-Air Missiles) ; I'll switch in a while to a real Air-Air Fighter (the M-2000). If I understand what you're saying inside the Mission Editor in the Triggers Panel, I need to: - Create a trigger : [TRIGGERS] CONTINUOUS ACTION("missileFiredAtAI_1", ON MISSION START) ; [CONDITIONS] None; [ACTIONS] DO SCRIPT (local Client = ... ) - Create a trigger [TRIGGERS] CONTINUOUS ACTION("AI_1_Escape", NO EVENT) ; [CONDITIONS] FLAG IS TRUE (501); [ACTIONS] AI TASK PUSH (Switch Way point, MESSAGE TO ALL, perform a task or whatever) Is that all correct ? Thanks for your help.
Solution Hardcard Posted June 6, 2019 Solution Posted June 6, 2019 (edited) There's something wrong with my mission. By the way for the moment, I'm using a Su-25T (with Air-To-Air Missiles) Mmm... I need to test the script with IR missiles then, it should still work, but need to make sure. EDIT: Confirmed, it works with IR missiles as well. If I understand what you're saying inside the Mission Editor in the Triggers Panel, I need to: - Create a trigger : [TRIGGERS] CONTINUOUS ACTION("missileFiredAtAI_1", ON MISSION START) ; [CONDITIONS] None; [ACTIONS] DO SCRIPT (local Client = ... ) Negative, the script trigger must be either MISSION START or ONCE (no conditions, no events). Get rid of the continuous action trigger. Also, I recommend that you save the script as a lua file (you can do that with Notepad++, for instance) and then run it in ME with the DO SCRIPT FILE action. Scripting directly in those tiny ME boxes is a great way to lose your sanity :megalol: - Create a trigger [TRIGGERS] CONTINUOUS ACTION("AI_1_Escape", NO EVENT) ; [CONDITIONS] FLAG IS TRUE (501); [ACTIONS] AI TASK PUSH (Switch Way point, MESSAGE TO ALL, perform a task or whatever) I guess that'd work, but use a SWITCHED CONDITION trigger instead of a CONTINUOUS ACTION trigger... Edited June 6, 2019 by Hardcard [sIGPIC][/sIGPIC]
feefifofum Posted June 7, 2019 Posted June 7, 2019 Path of least resistance = MISSILE INSIDE ZONE trigger. THE GEORGIAN WAR - OFFICIAL F-15C DLC
Recommended Posts