Luft08 27 Posted October 3, 2021 I want an ammo vehicle to blow up BIG when destroyed. I attached the Dammaged event handler. The Wiki says that it provides the following: params ["_unit", "_selection", "_damage", "_hitIndex", "_hitPoint", "_shooter", "_projectile"]; The docs further state that _unit is an object. My plan was to get the position of _unit and upon the _damage of the vehicle reaching 1 to spawn a Bo_GBU12_LGB at that position and immediately set its damage to 1. However I get an error telling me that _unit is an array not an object. code snippit: if(!isServer) exitWith {}; params ["_unit", "_selection", "_damage", "_hitIndex", "_hitPoint", "_shooter", "_projectile"]; private _el_0 = _unit select 0; // 0 Bravo 3-1-4 private _el_1 = _unit select 1; // hitpoint_lightfront_1_1 private _el_2 = _unit select 2; // Number each time shot It appears that _unit is the params array. What am I missing here?? Share this post Link to post Share on other sites
pierremgi 4739 Posted October 3, 2021 You should post your entire EH. 1 Share this post Link to post Share on other sites
Luft08 27 Posted October 3, 2021 3 hours ago, pierremgi said: You should post your entire EH. There's not much to post. if(!isServer) exitWith {}; params ["_unit", "_selection", "_damage", "_hitIndex", "_hitPoint", "_shooter", "_projectile"]; private _unitPos = getPos _unit; // -----------------------This throws an error. if(_damage == 1) then { // ------ This is wrong. _damage is NOT the total damage of the unit. for "_c" from 1 to 10 do { private _explosion = "Bo_GBU12_LGB" createVehicle _unitPos; _explosion setDamage 1; }; }; Share this post Link to post Share on other sites
beno_83au 1362 Posted October 3, 2021 You really should post your entire event handler, including: this addEventHandler ["Dammaged", { params ["_unit", "_selection", "_damage", "_hitIndex", "_hitPoint", "_shooter", "_projectile"]; }]; Whatever this is could be where your problem is. We can't see how you're adding the EH, but if it is being added correctly then inside the EH _unit will indeed be an object. _vehicle addEventHandler ["Dammaged",{ params ["_unit"]; if (damage _unit > 0.9) then { //spawn bomb }; }]; I think that's right. Mobile phone is hard..... 2 Share this post Link to post Share on other sites
Ibragim A 148 Posted October 4, 2021 It is clear from the first post that you are treating _unit as an array, not an object by using select command with it. As you yourself understood, the returned _damage parameter may be less than 1 at the time when the total damage has already reached 1. Therefore, in my opinion, you should use the Killed event handler instead of Dammaged, because your goal is to create an explosiont when the object is destroyed. The following should be added to the Init of your ammo object: this addEventHandler ["Killed", { params ["_unit", "_killer", "_instigator", "_useEffects"]; for "_c" from 1 to 10 do { _bomb = "Bo_GBU12_LGB" createVehicle (getPos _unit); }; }]; 2 Share this post Link to post Share on other sites
Luft08 27 Posted October 4, 2021 16 hours ago, Ibragim A said: It is clear from the first post that you are treating _unit as an array, not an object by using select command with it. As you yourself understood, the returned _damage parameter may be less than 1 at the time when the total damage has already reached 1. Therefore, in my opinion, you should use the Killed event handler instead of Dammaged, because your goal is to create an explosiont when the object is destroyed. The following should be added to the Init of your ammo object: this addEventHandler ["Killed", { params ["_unit", "_killer", "_instigator", "_useEffects"]; for "_c" from 1 to 10 do { _bomb = "Bo_GBU12_LGB" createVehicle (getPos _unit); }; }]; Thanks , I think you're right. With a few minor tweaks I got it working. It's cleaner and easier to understand. Because I'm scripting everything I couldn't put the code into an init field but I could just assign the EH directly to the vehicle. The vehicle is part of a convoy so I pushed the entire vehicle array ( [Vehicle, Crew, Group]) into another array and iterated through them looking for the ammo trucks and attaching the EH to just those. { private _veh = _x select 0; if(typeOf _veh == "gm_gc_army_ural4320_reammo") then { _veh addEventHandler["Killed", { params ["_unit", "_killer", "_instigator", "_useEffects"]; for "_c" from 1 to 10 do { private _bomb = "Bo_GBU12_LGB" createVehicle (getPos _unit); _bomb setDamage 1; }; }]; }; } forEach convoyArray; // [vehicle, crew, group] Works like a charm. Thank you to everyone replying to this thread. 1 Share this post Link to post Share on other sites