johnnyboy 3741 Posted October 25, 2018 Hi guys, I need a little script that makes hat or helmet fly off when unit shot in head. I know I saw a video of this once, so somebody has scripted it. But I just did a search and can't find anything. I can write one, but if one exists already that will save me an hour or so (and I'm putting all my time into polishing up new Razing Cane mission). Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted October 25, 2018 Ah, I remember that one: Cheers 1 Share this post Link to post Share on other sites
pierremgi 4737 Posted October 25, 2018 No need for an addon: in init field of the unit: this addEventHandler ["handledamage", { if ((_this select 1) == "head" && headgear (_this select 0) != "") exitWith { _h = headgear (_this select 0); removeHeadgear (_this select 0); _g = goggles (_this select 0); removeGoggles (_this select 0); _nv = ((assignedItems (_this select 0)) select {_x find "NV" > -1}) select 0; (_this select 0) unlinkItem _nv; _w = createVehicle ["WeaponHolderSimulated_scripted",ASLtoATL eyePos (_this select 0),[],0,"CAN_COLLIDE"]; _w addItemCargoGlobal [_h,1]; _w addItemCargoGlobal [_g,1]; _w addItemCargoGlobal [_nv,1]; _w setVelocity [5 * sin ((_this select 3) getdir (_this select 0)), 5 * cos ((_this select 3) getDir (_this select 0)), 0.3]; _w addTorque [random 0.02, random .02, random .02]; 0 } }]; 7 5 Share this post Link to post Share on other sites
johnnyboy 3741 Posted October 25, 2018 11 minutes ago, pierremgi said: No need for an addon: in init field of the unit Awesome! Merci Pierre!!! Share this post Link to post Share on other sites
cb65 85 Posted October 25, 2018 1 hour ago, pierremgi said: No need for an addon: in init field of the unit: @pierremgi thanks mate works really well :-) Will this work in multiplayer if applied to players ? Share this post Link to post Share on other sites
Dedmen 2588 Posted October 31, 2018 On 25.10.2018 at 9:36 PM, pierremgi said: _nv = ((assignedItems (_this select 0)) select {_x find "NV" > -1}) select 0; How about https://community.bistudio.com/wiki/hmd ? 4 Share this post Link to post Share on other sites
HazJ 1288 Posted October 31, 2018 eZ Good work all! 1 Share this post Link to post Share on other sites
wogz187 1085 Posted February 18, 2021 Little late to the party but here's my two cents, this addEventHandler ["handledamage", { params ["_unit","_part","_dam","_shooter"]; if (_part == "head" && _dam > 0.4 && headgear _unit != "" && local _unit) exitWith { _unit removeEventHandler ["handleDamage", _thisEventHandler]; private _holder = createVehicle ["WeaponHolderSimulated",ASLtoATL eyePos _unit, [], 0, "CAN_COLLIDE"]; { _unit unlinkItem _x; _holder addItemCargoGlobal [_x,1] }forEach [headgear _unit, goggles _unit, hmd _unit]; _holder setVelocity [5 * sin (_shooter getdir _unit), 5 * cos (_shooter getDir _unit), 0.3]; _holder addTorque [random 0.02, random .02, random .02]; } }]; Have fun! 1 1 Share this post Link to post Share on other sites
Play3r 143 Posted September 5, 2021 On 2/18/2021 at 9:04 PM, wogz187 said: Little late to the party but here's my two cents, this addEventHandler ["handledamage", { params ["_unit","_part","_dam","_shooter"]; if (_part == "head" && _dam > 0.4 && headgear _unit != "" && local _unit) exitWith { _unit removeEventHandler ["handleDamage", _thisEventHandler]; private _holder = createVehicle ["WeaponHolderSimulated",ASLtoATL eyePos _unit, [], 0, "CAN_COLLIDE"]; { _unit unlinkItem _x; _holder addItemCargoGlobal [_x,1] }forEach [headgear _unit, goggles _unit, hmd _unit]; _holder setVelocity [5 * sin (_shooter getdir _unit), 5 * cos (_shooter getDir _unit), 0.3]; _holder addTorque [random 0.02, random .02, random .02]; } }]; Have fun! can this work for all EAST units if it is put inside a ForEach Loop ?? Like this { this addEventHandler ["handledamage", { params ["_unit","_part","_dam","_shooter"]; if (_part == "head" && _dam > 0.4 && headgear _unit != "" && local _unit) exitWith { _unit removeEventHandler ["handleDamage", _thisEventHandler]; private _holder = createVehicle ["WeaponHolderSimulated",ASLtoATL eyePos _unit, [], 0, "CAN_COLLIDE"]; { _unit unlinkItem _x; _holder addItemCargoGlobal [_x,1] }forEach [headgear _unit, goggles _unit, hmd _unit]; _holder setVelocity [5 * sin (_shooter getdir _unit), 5 * cos (_shooter getDir _unit), 0.3]; _holder addTorque [random 0.02, random .02, random .02]; } }] }foreach Allunits select {side _x == EAST}; I can't make it work this way Share this post Link to post Share on other sites
wogz187 1085 Posted September 5, 2021 @Play3r, Here's a more recent version that handles weapon dropping, Spoiler this addEventHandler ["handledamage", { params ["_unit","_part","_dam","_shooter"]; if (!alive _unit) exitWith {_unit removeEventHandler ["handleDamage", _thisEventHandler]}; if (_unit getVariable ["parts_handle", false]) exitWith {false}; private _parts= ["arms", "hands", "head"]; if (_part in _parts) then { private _holder = createVehicle ["WeaponHolderSimulated",ASLtoATL eyePos _unit, [], 0, "CAN_COLLIDE"]; if !(_part == "head" && _dam > 0.4 && currentWeapon _unit != "" && local _unit) then { _holder addItemCargoGlobal [currentWeapon _unit,1]; _unit removeWeapon (currentWeapon _unit); }; if (_part == "head" && _dam > 0.4 && headgear _unit != "" && local _unit) then { _holder addItemCargoGlobal [headgear _unit,1]; { _unit unlinkItem _x; }forEach [goggles _unit, hmd _unit, headgear _unit]; }; _holder setVelocity [5 * sin (_shooter getdir _unit), 5 * cos (_shooter getDir _unit), 0.3]; _holder addTorque [random 0.02, random 0.02, random 0.02]; }; _unit setVariable ["parts_handle", true]; _unit spawn {sleep 1; _this setVariable ["parts_handle", false]}; }]; from @omri2050's script goodies discord It will work in a loop, { _x addEventHandler... }foreach allUnits select {side _x == EAST}; Change "this" to "_x" inside forEach. Have fun! 1 1 Share this post Link to post Share on other sites
pierremgi 4737 Posted September 5, 2021 { _x addEventHandler... ; _x setVariable ["EHforDrop",TRUE]; } foreach allUnits select {side _x == EAST && isNil {_x getVariable "EHforDrop"} }; if you're spawning east units. 1 1 Share this post Link to post Share on other sites