Jump to content
Sign in to follow this  

When switching weapons delete the weapon that gets placed on the ground

Recommended Posts


I've been playing with Put and Take event handlers to try and achieve functionality that's stated in the topic.

For starters Put EH seems to only fire when you drop your weapon on the ground (groundWeaponHolder) or put the weapon into a container (box, vehicle) directly from your inventory.
It doesn't fire when switching to a weapon that is on the ground even though (at least how I see it) you are still dropping your current weapon into a "groundWeaponHolder".
Does anyone have an idea why this EH doesn't fire in that case?
I used this shortie to test Put EH:

player addEventHandler ["Put", {_unit = _this select 0; _content = _this select 1; _weapon = _this select 2; hint "This EH seems to be working";}];

Take EH on the other hand seems to work just fine for detecting the weapon pick up operation. But other than testing with simple hint that the EH fires when needed I haven't been able to come up with anything I'm looking to achieve.

Now the ultimate question is: by using either of the aforementioned EHs how to delete the weapon that gets put on the ground during weapon switching operation?

Share this post

Link to post
Share on other sites

This serena's version of a script that prevents picking up weapons from killed units could be of use when paired with Take event handler. What I think I understand from the serena's version is that it sets the dropped weapon's damage to 1. And apparently a damaged weapon can not be used/picked up anymore.

I've been testing that script with Take EH like so:

_unit addEventHandler ["Take", {
    private _vct = _this select 0;
    if (_vct isKindOf "CAManBase") then {
        _vct spawn {
            sleep 0.5;
            private _hls = nearestObjects [_this, ["WeaponHolderSimulated"], 5];
            while {count _hls > 0} do {
                private _hlx = {if (vectorMagnitude velocity _x == 0) exitWith {_forEachIndex}} forEach _hls;
                if (isNil {_hlx})
                     then {sleep 0.1}
                    else {_hls deleteAt _hlx setDamage 1}

and it does work but only when a unit kills another unit and then picks up the dead unit's weapon. When the unit's current weapon ends on the ground during the switching operation it gets damaged and thus can not be picked up anymore.

Could someone shove me in the right direction that why the script doesn't work when a unit drops its weapon on the ground directly from its inventory. When another unit comes to pick up the weapon (and in the process drops its current weapon) why this dropped weapon doesn't get damaged the same way?

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
Sign in to follow this