Freghar 73 Posted March 2, 2016 Hello, can I somehow perform a piece of code whenever a new vehicle (unit, non-agent preferably) is created, either via the Curator or as createVehicle? The use case is to be able to add a Killed EH for the unit, to add the hideBody menu action, as there's apparently no universal Killed EH that would trigger for any vehicle without prior registration for that vehicle. Reading the wiki, I found https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Init, but I seem to be unable to register any EHs from description.ext, so I presume this is limited to addons. I also found https://forums.bistudio.com/topic/185201-apply-onkilledsqf-to-ai-spawned-from-a-module/ , where people suggest looping all units, which is certainly doable, although very inefficient, has to be performed repeatedly and creates a race condition (vehicle killed before the Killed EH is added). Also, I don't have any way of checking if that Killed EH is already registered for a vehicle. Any ideas, please? Can I use CBA's XEH for this somehow? Some of them seem to be usable from description.ext, although they seem to be limited to mission start. Thank you. Share this post Link to post Share on other sites
dreadedentity 278 Posted March 2, 2016 CuratorObjectPlaced For createVehicle, if you are using scripts to spawn objects, it should be trivial to edit the script and add an event handler right below the object creation Share this post Link to post Share on other sites
Freghar 73 Posted March 2, 2016 CuratorObjectPlaced For createVehicle, if you are using scripts to spawn objects, it should be trivial to edit the script and add an event handler right below the object creation Thanks, I kind of started investigating the XEH idea as soon as I wrote it and it turns out to be pretty simple: class Extended_Init_Eventhandlers { class CAManBase { class XEH_MyOwnXEHTest { init = "0 = (_this select 0) spawn { sleep 5; deleteVehicle _this; }"; }; }; }; I wonder, though, if this could be done without CBA. Share this post Link to post Share on other sites
dreadedentity 278 Posted March 2, 2016 I wonder, though, if this could be done without CBA. CuratorObjectPlaced Use this Share this post Link to post Share on other sites
Freghar 73 Posted March 2, 2016 Use thisThis unfortunately doesn't help me with mods which use createVehicle directly (and which I don't want to / can not edit). Needless to say, the XEH I posted does exactly what I wanted - it even triggers for crew in a Curator-spawned vehicle, which is awesome. Share this post Link to post Share on other sites
Freghar 73 Posted March 2, 2016 For anyone interested, it turns out there was actually a XEH for when any (from editor, Curator, createVehicle, ..) unit is killed, class Extended_Killed_Eventhandlers { class CAManBase { class XEH_HideBodyAction { killed = "(_this select 0) call your_fnc_hidebody;" }; }; }; params ["_corpse"]; _corpse addAction [ "Hide Body", { params ["_target", "_caller"]; hideBody _target; _caller playActionNow "MedicOther"; }, nil, 0.1, true, true, "", "(_target distance _this) < 2" ]; Too bad attachTo doesn't work on corpses, that would have been much better for hiding bodies away.Thanks for helping anyway, I appreciate it. :) Share this post Link to post Share on other sites
Lala14 135 Posted March 2, 2016 why not combine while and vehicles and as well as setVariable and getVariable and you should be sweet. Share this post Link to post Share on other sites
Larrow 2801 Posted March 2, 2016 addMissionEventHandler [ "EntityKilled", { params [ "_killed", "_killer" ]; if ( typeOf _killed isKindOf "Man" ) then { _killed addAction [ "Hide Body", { params ["_target", "_caller"]; hideBody _target; _caller playActionNow "MedicOther"; }, nil, 0.1, true, true, "", "(_target distance _this) < 2" ]; }; }]; 1 Share this post Link to post Share on other sites
terox 316 Posted March 2, 2016 create an addon with a base man class and have that base man class init some code. However having a CreateUnit, CreateVehicle EH would really help and be extremely useful, especially for HC. This was raised as a suggestion for a new scripting command, but quickly dismissed with the attitude of "Create an addon for base class man and add some init code" They also mentioned using XEH. If your running 3rd party addons then write an addon that taps into XEH, this would probably only need to be dome on the HC and server Share this post Link to post Share on other sites
Freghar 73 Posted March 2, 2016 addMissionEventHandler [ "EntityKilled", { params [ "_killed", "_killer" ]; if ( typeOf _killed isKindOf "Man" ) then { _killed addAction [ "Hide Body", { params ["_target", "_caller"]; hideBody _target; _caller playActionNow "MedicOther"; }, nil, 0.1, true, true, "", "(_target distance _this) < 2" ]; }; }];Thanks, I missed that - it seems these (Killed/Respawned) are fairly new (1.55), cool. :) 1 Share this post Link to post Share on other sites