flywaldair (Skynet dev.) Posted January 19, 2020 Posted January 19, 2020 I have set up a mission with a static f14 on the runway. The f14 is added, and clearly the function triggers once the plane is destroyed. How can i get the id of the unit destroyed in the checkHit function? According to the reference event.initiator is a reference to the unit, however I can not get the id of the unit in that context. function addStaticF14Iran(coordinate, unitid, heading) local f14 = { ["type"] = "F-14A", ["unitId"] = unitid, ["livery_id"] = "IIAF Asia minor", ["y"] = coordinate.y, ["x"] = coordinate.x, ["name"] = "Shiraz F-14 Static "..unitid, ["displayName"] = "F-14 "..unitid, ["category"] = "Planes", ["canCargo"] = false, ["heading"] = heading, } coalition.addStaticObject(country.id.IRAN, f14) end local parkingC01 = {x = 381258.60570657, y = -354104.74459296} local parkingHeading = 0.47123889803847 addStaticF14Iran(parkingC01, 2001, parkingHeading) function checkHit(event) if event.id == world.event.S_EVENT_DEAD then trigger.action.outText("DEAD: ",10) trigger.action.outText("EVENT: "..event.initiator.id, 10) end end mist.addEventHandler(checkHit) Skynet: an Integrated Air Defence System for DCS. Download here! The best flying school in Switzerland mfgz.ch :music_whistling::music_whistling::pilotfly: Follow my flying adventures on YouTube:)
Hardcard Posted January 19, 2020 Posted January 19, 2020 You can try event.initiator:getID() instead, but chances are you'll get nil (since the object will be dead) Alternatively, take the id from a HIT event instead: function checkHit(event) if event.id == world.event.S_EVENT_HIT then trigger.action.outText("HIT: ",10) trigger.action.outText("EVENT: "..event.target:getID(), 10) end end mist.addEventHandler(checkHit) [sIGPIC][/sIGPIC]
flywaldair (Skynet dev.) Posted January 20, 2020 Author Posted January 20, 2020 Thanks, but that did not work. I mean I get internal IDs. but they are not coresponding with unit Ids. Does someone know how to get a reference on the object that just died with such an event? According to the reference I should get a Unit in event.initiator: https://wiki.hoggitworld.com/view/DCS_event_dead Skynet: an Integrated Air Defence System for DCS. Download here! The best flying school in Switzerland mfgz.ch :music_whistling::music_whistling::pilotfly: Follow my flying adventures on YouTube:)
Hardcard Posted January 21, 2020 Posted January 21, 2020 (edited) According to your snippet, you're spawning a custom static object, not a unit object, that's an important difference. IIRC, event handlers and spawned custom statics don't mix well, but it has been a while since I last messed with this stuff. I do remember that some static types simply aren't accessible (like infantry, for instance) What are you trying to accomplish, specifically? What do you need the ids for? See if you can get a description table from the initiator, with any luck you'll find the displayName in there. But, as I said, that might be tricky if the object is dead, so try using a HIT event instead (use the target, not the initiator in that case). Edited January 21, 2020 by Hardcard [sIGPIC][/sIGPIC]
Recommended Posts