Jump to content
johnnyboy

Script to make helmet/hat fly off when shot in head?

Recommended Posts

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

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
  }
}];
  • Like 7
  • Thanks 5

Share this post


Link to post
Share on other sites
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
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

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!

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
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

@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!

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
{
  _x addEventHandler... ;
  _x setVariable ["EHforDrop",TRUE];
} foreach allUnits select {side _x == EAST && isNil {_x getVariable "EHforDrop"} };

if you're spawning east units.

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×