Sedlo Posted June 19, 2018 Share Posted June 19, 2018 Hello! Here's the situation: I want to be able to set a trigger to make a flag true when a player fires an AIM-7M Sparrow missile, but I've not had any luck. Right now, I kind of have a way to do it by loading the player aircraft with AIM-7Ms, with the AI having AIM-7Fs, and with the trigger to fire with Missile in Zone. What I want is to outfit everyone with AIM-7Ms, but the trigger to set the flag true when the player fires only. I searched the forums, and found a script that I modified so that whenever the player fires the gun, it sets a flag to true. This seems to work awesomely: Handler = {} function Handler:onEvent(event) if event.id == world.event.S_EVENT_SHOOTING_START and event.initiator == Unit.getByName('COLT 51 PLAYER') then trigger.action.setUserFlag('7777', true) end end world.addEventHandler(Handler) Now, when I set the event.id to S_Event_Shot, and try to add the AIM-7M as the weapon, I get a lua error in game. This is the code I was trying: local rifleHandler = {} function rifleHandler:onEvent(event) if event.id == world.event.S_EVENT_SHOT then local _initiator = event.initiator local _initname = _initiator:getName() local _weapon = event.weapon local _weaponname = _weapon:getTypeName() if _initname == "COLT 51 PLAYER" then if _weaponname == "AIM-7M," then trigger.action.setUserFlag(7777, true) end world.addEventHandler(rifleHandler) Can anyone give me a hand? I'm not sure if I've got some sort of mental block when it comes to code, but most of it is Greek to me. I've got MIST loaded a few seconds after startup, if that helps at all. My ultimate goal is that when the player fires a AIM-7M, will result in the game showing a text message to coalition (Colt 51, FOX-1!) , and it plays a sound (Fox1.ogg). My Youtube Channel MY DCS MISSIONS Link to comment Share on other sites More sharing options...
Sedlo Posted June 20, 2018 Author Share Posted June 20, 2018 OK, I think I'm getting closer.... Except the Weapon.GuidanceType = {RADAR_SEMI_ACTIVE} doesn't seem to make the trigger weapon specific... It fires when any missile is fired at all. Handler = {} function Handler:onEvent(event) Weapon.GuidanceType = {RADAR_SEMI_ACTIVE} if event.id == world.event.S_EVENT_SHOT and event.initiator == Unit.getByName('COLT 51 PLAYER') then trigger.action.setUserFlag('7777', true) end end world.addEventHandler(Handler) My Youtube Channel MY DCS MISSIONS Link to comment Share on other sites More sharing options...
catt42 Posted June 20, 2018 Share Posted June 20, 2018 (edited) OK, I think I'm getting closer.... Except the Weapon.GuidanceType = {RADAR_SEMI_ACTIVE} doesn't seem to make the trigger weapon specific... It fires when any missile is fired at all. Handler = {} function Handler:onEvent(event) Weapon.GuidanceType = {RADAR_SEMI_ACTIVE} if event.id == world.event.S_EVENT_SHOT and event.initiator == Unit.getByName('COLT 51 PLAYER') then trigger.action.setUserFlag('7777', true) end end world.addEventHandler(Handler) Hi Sedlo, This should work. If it doesn't it's because I'm writing it on my phone on the beach, but I will get back to you when I'm home Handler = {} function Handler:onEvent(event) if event.id == world.event.S_EVENT_SHOT and event.initiator == Unit.getByName('COLT 51 PLAYER') then _weapon = event.weapon:getDesc() _weapon_category =_weapon.missileCategory _weapon_guidance = _weapon.guidance if _weapon_category ==1 then - - 1 for a2a missile if _weapon_guidance == 4 then - - 4 for fox1, 2 for fox2, 3 for fox3, works with any missile trigger.action.setUserFlag('7777', true) end end ebd end Edited June 20, 2018 by catt42 Link to comment Share on other sites More sharing options...
Sedlo Posted June 23, 2018 Author Share Posted June 23, 2018 Catt42, thanks! I am getting an error message in one of the lines, but otherwise the script works great! Thanks! My Youtube Channel MY DCS MISSIONS Link to comment Share on other sites More sharing options...
catt42 Posted June 24, 2018 Share Posted June 24, 2018 Catt42, thanks! I am getting an error message in one of the lines, but otherwise the script works great! Thanks! Yes, the comments weren't properly formatted for some reason. Now it should work. Handler = {} function Handler:onEvent(event) if event.id == world.event.S_EVENT_SHOT and event.initiator == Unit.getByName('COLT 51 PLAYER') then _weapon = event.weapon:getDesc() _weapon_category =_weapon.missileCategory _weapon_guidance = _weapon.guidance if _weapon_category ==1 then -- 1 for a2a missile if _weapon_guidance == 4 then -- 4 for fox1, 2 for fox2, 3 for fox3, works with any missile trigger.action.setUserFlag('7777', true) end end end end world.addEventHandler(Handler) And here you'll find reference for all the categories, guidance types, etc (note: Weapon.GuidanceType is incorrect, use weapon.guidance instead) https://wiki.hoggitworld.com/view/DCS_Class_Weapon Link to comment Share on other sites More sharing options...
Sedlo Posted June 24, 2018 Author Share Posted June 24, 2018 That's awesome, thanks very much for this! My Youtube Channel MY DCS MISSIONS Link to comment Share on other sites More sharing options...
Recommended Posts