nebuluski Posted June 8, 2018 Posted June 8, 2018 Hi I wonder if someone can help me, as I am trying to detect when a particular missile type hits a ship and add 1 to a counter (flag). I have tried doing this with triggers using the "unit hits" condition, but need to filter this due to CIWS round strikes on the ships from the surrounding supporting ships (being registered) trying to knock down the incoming missiles! Any help or pointers would be appreciated! Cheers Rig: MSI Mag X570 Tomahawk| AMD 5600 | 32 GB DDR3 | M2 NVME Gen4 1TB SSD | Samsung EVo 850 2TB, 500 & 256 GB SSD | Gigabyte AORUS GTX 1080Ti | Samsung 24" (1920x1200) | 2 x Iiyama 22" T2250MTS touch screen (1920x1080) | 2 x 6.4" LCD | Cougar MFDs | Thrustmaster Warthog | CH Pro Pedals | Windows 10 [sIGPIC][/sIGPIC]
Zayets Posted June 10, 2018 Posted June 10, 2018 You will need to use these two events : world.event.S_EVENT_SHOT and world.event.S_EVENT_SHOT and world.event.S_EVENT_HIT. You will create a function (or two, depending on what you need to achieve) like this: function MaverickFired:onEvent(event) if event.id == world.event.S_EVENT_SHOT then ... logic in here to get the fired weapon and increment fire counter with 1 end end function ShipHit:onEvent(event) if event.id == world.event.S_EVENT_HIT then ... logic in here to get the unit being hit and increment hit counter with 1 end end world.addEventHandler(MaverickFired) world.addEventHandler(ShipHit) and don't forget to init these events by creating an empty object for both functions otherwise they will raise an error when you add the event to the world. See what you get and then let me know, it should not be really difficult. Alternatively, you can use bomb in zone (make a zone around your ship which is just as big as the ship) and have a continous trigger to increment everytime a bomb is fired in that area. [sIGPIC]OK[/sIGPIC]
nebuluski Posted June 11, 2018 Author Posted June 11, 2018 Thanks I will look into this approach. Rig: MSI Mag X570 Tomahawk| AMD 5600 | 32 GB DDR3 | M2 NVME Gen4 1TB SSD | Samsung EVo 850 2TB, 500 & 256 GB SSD | Gigabyte AORUS GTX 1080Ti | Samsung 24" (1920x1200) | 2 x Iiyama 22" T2250MTS touch screen (1920x1080) | 2 x 6.4" LCD | Cougar MFDs | Thrustmaster Warthog | CH Pro Pedals | Windows 10 [sIGPIC][/sIGPIC]
nebuluski Posted June 14, 2018 Author Posted June 14, 2018 This is what I used to achieve what I needed: do ShipHit = {} function ShipHit:onEvent(event) if (event.id == world.event.S_EVENT_HIT) then env.info("Something has been hit") local wpnType = event.weapon:getTypeName() env.info("weapon used was:" .. wpnType) if wpnType == "KH-31A" then local tgtunit = event.target:getName() env.info("Target hit was:" .. tgtunit) if tgtunit == "Stennis" then local Stenniscounter = trigger.misc.getUserFlag('100') trigger.action.setUserFlag('100', Stenniscounter + 1) end if tgtunit == "Normandy" then local Normandycounter = trigger.misc.getUserFlag('101') trigger.action.setUserFlag('101', Normandycounter + 1) end if tgtunit == "FFG1" or "FFG2" or "FFG3" or "FFG4" then local FFGcounter = trigger.misc.getUserFlag('102') trigger.action.setUserFlag('102', FFGcounter + 1) end end end end world.addEventHandler(ShipHit) end; Rig: MSI Mag X570 Tomahawk| AMD 5600 | 32 GB DDR3 | M2 NVME Gen4 1TB SSD | Samsung EVo 850 2TB, 500 & 256 GB SSD | Gigabyte AORUS GTX 1080Ti | Samsung 24" (1920x1200) | 2 x Iiyama 22" T2250MTS touch screen (1920x1080) | 2 x 6.4" LCD | Cougar MFDs | Thrustmaster Warthog | CH Pro Pedals | Windows 10 [sIGPIC][/sIGPIC]
Recommended Posts