Galwran Posted June 3, 2013 Share Posted June 3, 2013 Hi. I'm making a mission in which SAM units will shut down and relocate when ever a HARM or KH-58 is fired at them. As you might have guessed from the title, I cannot set such a condition for the flag to turn TRUE. Everything else works just fine. Sure, I can make the flag turn TRUE whenever SEAD planes are within a certain zone, but that is not the same thing. Also, I of course know the names of the SEAD units, so it would be OK for the SAMs to shut down even when the SEAD unit fires any weapon at any target. Please help :helpsmilie: Link to comment Share on other sites More sharing options...
Galwran Posted June 3, 2013 Author Share Posted June 3, 2013 Hi. I'm making a mission in which SAM units will shut down and relocate when ever a HARM or KH-58 is fired at them. As you might have guessed from the title, I cannot set such a condition for the flag to turn TRUE. Everything else works just fine. Sure, I can make the flag turn TRUE whenever SEAD planes are within a certain zone, but that is not the same thing. Also, I of course know the names of the SEAD units, so it would be OK for the SAMs to shut down even when the SEAD unit fires any weapon at any target. Please help :helpsmilie: A quick addition: it would be also be nice to override the radar shutdown if the said unit has fire a missile during a 20 second period (so that the shot is not lost) Link to comment Share on other sites More sharing options...
pakfront Posted June 3, 2013 Share Posted June 3, 2013 You probably want an world EventHandler that responds to S_EVENT_SHOT. Inside the handler function, you can check what type of weapon was fired, and where, and if it is a threat to the SAM site, you can set your flag True. I hhtink you will find this post helpful: http://forums.eagle.ru/showpost.php?p=1623759&postcount=39 Link to comment Share on other sites More sharing options...
Galwran Posted June 3, 2013 Author Share Posted June 3, 2013 You probably want an world EventHandler that responds to S_EVENT_SHOT. Inside the handler function, you can check what type of weapon was fired, and where, and if it is a threat to the SAM site, you can set your flag True. I hhtink you will find this post helpful: http://forums.eagle.ru/showpost.php?p=1623759&postcount=39 Thanks. Now I have two problems. The first one, and the knowledge that I suck at programming :smartass: Tried this, didn't work. Looks like something is missing... this is supposed to set the flag 88 TRUE when a betab-500 is dropped. do -- THE EVENT HANDLER local shotHandler = function(event) if event.id == world.event.S_EVENT_SHOT then if event.weapon then local wpn = LuaClass.createFor(Unit, event.weapon.id_) if wpn:isExist() then local wpnName = wpn:getTypeName() if wpnName and type(wpnName) == 'string' and (wpnName:find('BetAB_500')) then trigger.action.setUserFlag('88', true) end end end end end end Link to comment Share on other sites More sharing options...
pakfront Posted June 3, 2013 Share Posted June 3, 2013 you have to register the event handler with MIst so will run your function periodically. So, make sure you have done a doscriptfile on the mist lua, then in your script, after the code you have above, make sure to add: mist.addEventHandler(shotHandler) Link to comment Share on other sites More sharing options...
Galwran Posted June 3, 2013 Author Share Posted June 3, 2013 you have to register the event handler with MIst so will run your function periodically. So, make sure you have done a doscriptfile on the mist lua, then in your script, after the code you have above, make sure to add: mist.addEventHandler(shotHandler) Will try in a couple days when I'm back, thanks Link to comment Share on other sites More sharing options...
MBot Posted June 4, 2013 Share Posted June 4, 2013 (edited) If you do not want to deal with MIst, you can use the following code stand alone: ARM_ShotHandler = {} function ARM_ShotHandler:onEvent(event) if event.id == world.event.S_EVENT_SHOT then local wpn = event.weapon local wpnType = wpn:getTypeName() if wpnType == “AGM-88” or wpnType == “Kh-58” then *do your code here* end end end world.addEventHandler(ARM_ShotHandler) This will capture each time a AGM-88 or Kh-58 is shot and you can add your code what you want to happen then. Not sure if the type names "AGM-88" and "Kh-58" are correct like that (I assume), the spelling needs to be right though. If you want to do specific actions depending on the targeted unit you could introduce event.target (in the same way as event.weapon) and then build additional conditions depending on this. Edited June 4, 2013 by MBot Link to comment Share on other sites More sharing options...
SNAFU Posted June 5, 2013 Share Posted June 5, 2013 Mbot, would you then address the unit, which caused the event with somthing like: . . . if event.id == world.event.S_EVENT_SHOT then local wpnorigin = event.unit lcoal wpnorigingrp = wpnorigin:getGroup() . . . Would this in case of the event, set wpnorigingrp to the group, which caused the event? [sIGPIC][/sIGPIC] Unsere Facebook-Seite Link to comment Share on other sites More sharing options...
MBot Posted June 5, 2013 Share Posted June 5, 2013 Basically yes, but I think you would have to use: local wpnorigin = event.initiator lcoal wpnorigingrp = wpnorigin:getGroup() Link to comment Share on other sites More sharing options...
Grimes Posted June 5, 2013 Share Posted June 5, 2013 event.initiator is the unit that caused a shot event. event.initator:getGroup() should do the trick. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum Link to comment Share on other sites More sharing options...
SNAFU Posted June 5, 2013 Share Posted June 5, 2013 (edited) Thank you 2, will do so. Just had the idea to enforce ROE with this by trying the event händler: ROEViolationHandler = {} function ROEViolationHandler:onEvent(event) if event.id == world.event.S_EVENT_SHOT then local ROEViolation = event.initator:getGroup() if ROEInForce == "Weapons Safe" then ROEViolation:destroy() end end end world.addEventHandler(ROEViolationHandler) And sorry Galwran for hijacking, but I thought my questions fit the thread. Edited June 5, 2013 by SNAFU then [sIGPIC][/sIGPIC] Unsere Facebook-Seite Link to comment Share on other sites More sharing options...
Fisherman82 Posted April 19, 2017 Share Posted April 19, 2017 If you do not want to deal with MIst, you can use the following code stand alone: ARM_ShotHandler = {} function ARM_ShotHandler:onEvent(event) if event.id == world.event.S_EVENT_SHOT then local wpn = event.weapon local wpnType = wpn:getTypeName() if wpnType == “AGM-88” or wpnType == “Kh-58” then *do your code here* end end end world.addEventHandler(ARM_ShotHandler) This will capture each time a AGM-88 or Kh-58 is shot and you can add your code what you want to happen then. Not sure if the type names "AGM-88" and "Kh-58" are correct like that (I assume), the spelling needs to be right though. If you want to do specific actions depending on the targeted unit you could introduce event.target (in the same way as event.weapon) and then build additional conditions depending on this. Im trying to find somekind of script to count the number of Mavericks fired in a mission by increasing a flag to the same value. Could this script be used for that somehow? In the DO SCRIPT box without MIST or MOOSE? I tried myself by adding a code where it says *do your code here* but I could not get it to work. Does anybody know how to do it? Link to comment Share on other sites More sharing options...
Veteran66 Posted May 19, 2017 Share Posted May 19, 2017 this will not work for me: ARM_ShotHandler = {} function ARM_ShotHandler:onEvent(event) if event.id == world.event.S_EVENT_SHOT then local wpn = event.weapon local wpnType = wpn:getTypeName() if wpnType == “MG_131” then MESSAGE:New("Plane shot Gun",15,"Alert!"):ToAll() end end end world.addEventHandler(ARM_ShotHandler) German WW2 Radio calls Mod: https://www.digitalcombatsimulator.com/en/files/2161798/ Link to comment Share on other sites More sharing options...
FlightControl Posted May 27, 2017 Share Posted May 27, 2017 Use moose ... Look at these examples: https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/master-release-2.1/EVT%20-%20Event%20Handling [TABLE][sIGPIC][/sIGPIC]| Join MOOSE community on: DISCORD :thumbup: Website of the MOOSE LUA Framework. MOOSE framework Downloads. Check out Example Missions to try out and learn. MOOSE YouTube Channel for live demonstrations and tutorials. [/TABLE] Link to comment Share on other sites More sharing options...
Recommended Posts