Jump to content
Smart Games

Cant pick up item from GroundWeaponHolder_Scripted

Recommended Posts

Thats the function:

fnc_check =
	{
		params ["_whitelist"];
		private ["_primaryweapon","_handgunweapon","_launcher","_pw","_hw","_lw","_veh"];

		_primaryweapon = primaryWeapon player;
    	_handgunweapon = handgunWeapon player;
    	_launcher = secondaryWeapon player;

    	_pw = 0;
    	_hw = 0;
    	_lw = 0;

    	{
    		if (_x == _primaryweapon) then
    			{
    				_pw = _pw + 1;
    			}
    	} forEach _whitelist;

    	{
    		if (_x == _handgunweapon) then
    			{
    				_hw = _hw + 1;
    			}
    	} forEach _whitelist;

    	{
    		if (_x == _launcher) then
    			{
    				_lw = _lw + 1;
    			}
    	} forEach _whitelist;


    	if (count primaryWeapon player >= 3) then
    		{
    			if (_pw == 0) then
    				{
    					_veh = createVehicle ["GroundWeaponHolder_Scripted", position player, [], 0, "CAN_COLLIDE"];
    					player action ["DropWeapon", _veh, primaryWeapon player];
    				};
    		};

    	if (count handgunWeapon player >= 3) then
    		{
    			if (_hw == 0) then
    				{
    					_veh = createVehicle ["GroundWeaponHolder_Scripted", position player, [], 0, "CAN_COLLIDE"];
    					player action ["DropWeapon", _veh, handgunWeapon player];
    				};
    		};

    	if (count secondaryWeapon player >= 3) then
    		{
    			if (_lw == 0) then
    				{
    					_veh = createVehicle ["GroundWeaponHolder_Scripted", position player, [], 0, "CAN_COLLIDE"];
    					player action ["DropWeapon", _veh, secondaryWeapon player];
    				};
    		};
	};
};

 

Its very difficult to find the right position to pick up the item. I tried to chance the height of the weaponholder - didnt work.

Any Ideas, thanks!

Share this post


Link to post
Share on other sites
1 hour ago, Smart Games said:

Its very difficult to find the right position to pick up the item.

Any Ideas, thanks!

Spawn just one weaponHolder and place all non whitelisted weapons in it?

Spoiler

fnc_check = {
	if !( canSuspend ) exitWith { _this spawn fnc_check };
	
	params[ "_whitelist" ];
	
	private _wh = objNull;
	
	{
		_x params[ "_weapon" ];
		
		//If we have a weapon && its not in the whitelist
		if ( _weapon != "" && { _whitelist findIf{ _x == _weapon } isEqualTo -1 } ) then {
			
			//If a weapon holder has not been spawned
			if ( isNull _wh ) then {
				
				//Create weapon holder
				_wh = createVehicle[ "GroundWeaponHolder_Scripted", position player, [], 0, "CAN_COLLIDE" ];
			};
			
			//Place players weapon in holder
			player action[ "DropWeapon", _wh, _weapon ];
			
			//Wait for action to finish
			waitUntil{ !( player hasWeapon _weapon ) };
		};
	}forEach [
		primaryWeapon player,
		handgunWeapon player, 
		secondaryWeapon player
	];
    	
};

[ [] ] spawn fnc_check; //Test drop all weapons as whitelist is empty

 

 

  • Like 2

Share this post


Link to post
Share on other sites

I will try it, thanks.

 

@Larrow, do you know an other way to make the player drop equipment to the ground without removing it?

Share this post


Link to post
Share on other sites

You are creating one weaponholder right on top of another. This is going to cause lots of problems as well as preventing the deletion of a weaponholder.

 

Also out of curiousity why do you count letters in weapon class names, why they have to be >= 3?

Share this post


Link to post
Share on other sites
6 hours ago, killzone_kid said:

You are creating one weaponholder right on top of another. This is going to cause lots of problems as well as preventing the deletion of a weaponholder.

 

I can confirm that, it actually CRASHES Arma 3 for me. And a hard crash that requires a full reboot on windows 10.

 

I solved this by having my script:

Drop the primaryWeapon to the _wh.

Delete the secondaryWeapon. (if present).

Put the handgunWeapon inside the backpack/uniform/vest. (If no space left just delete it). (if present).

Share this post


Link to post
Share on other sites
16 hours ago, Larrow said:

Spawn just one weaponHolder and place all non whitelisted weapons in it?


I use this for simulating a weapon drop, do you think it might cause me troubles using "WeaponHolderSimulated" createVehicle [0,0,0]; instead of createVehicle[ "GroundWeaponHolder_Scripted", position player, [], 0, "CAN_COLLIDE" ]; ?

Spoiler

 


weaponDrop = {
params ["_unit"];
	if !(currentWeapon _unit isEqualTo "") then {
		private _weaponHolder = objNull;
		private _weapon = currentWeapon _unit;
		_unit removeWeapon _weapon;
		if ( isNull _weaponHolder ) then {
			_weaponHolder = "WeaponHolderSimulated" createVehicle [0,0,0];
			_weaponHolder addWeaponCargoGlobal [_weapon,1];
			_weaponHolder setPos (_unit modelToWorld [0,.2,1.2]);
			_weaponHolder disableCollisionWith _unit;
			_dir = random(360);
			_speed = 1.5;
			_weaponHolder setVelocity [_speed * sin(_dir), _speed * cos(_dir),4];
		};
	};
};

 

 

 

 

PS: Your fnc_check is only dropping the currentWeapon and not all primary, secondary and handgun weapons for me. Am I doing something wrong? I am running it like this:

Spoiler

 


vDropAllWeapons = {

	params[ "_dropingUnit" ];
	
	private _wh = objNull;
	
	{
	_weapon = currentWeapon _dropingUnit;
		_x params [ "_weapon" ];
		
		//If we have a weapon && its not in the whitelist
		if ( _weapon != "") then {
			
			//If a weapon holder has not been spawned
			if ( isNull _wh ) then {
				
				//Create weapon holder
				_wh = createVehicle[ "GroundWeaponHolder_Scripted", position _dropingUnit, [], 1, "CAN_COLLIDE" ];
			};
			
			//Place players weapon in holder
			_dropingUnit action[ "DropWeapon", _wh, _weapon ];
			
			//Wait for action to finish
			waitUntil{!( _dropingUnit hasWeapon _weapon ) };
		};
	}forEach [
		primaryWeapon _dropingUnit,
		handgunWeapon _dropingUnit, 
		secondaryWeapon _dropingUnit
	];

};

 

 

 

 

Share this post


Link to post
Share on other sites
10 hours ago, LSValmont said:

Your fnc_check is only

And then shows a modified script to my original 😄

 

10 hours ago, LSValmont said:

is only dropping the currentWeapon and not all primary, secondary and handgun weapons for me. Am I doing something wrong?

Well no, should work fine, even though you have dropped a nonsensical currentWeapon reference in there, as the params will overwrite the previous local var ( _weapon ).

It does not drop all pri ,sec, hand weapons, just the current equipped ones. For instance its is not going to drop a gun that is in your backpack etc.

Spoiler

vDropAllWeapons = { 
	params[ "_dropingUnit" ];
	
	private _wh = objNull;
	
	{
		_x params [ "_weapon" ];
		
		//If we have a weapon
		if ( _weapon != "" ) then {
			
			//If a weapon holder has not been spawned
			if ( isNull _wh ) then {
				//Create weapon holder
				_wh = createVehicle[ "GroundWeaponHolder_Scripted", position _dropingUnit, [], 1, "CAN_COLLIDE" ];
			};
			
			//Place players weapon in holder
			_dropingUnit action[ "DropWeapon", _wh, _weapon ];
			
			//Wait for action to finish
			waitUntil{ !( _dropingUnit hasWeapon _weapon ) };
		};
	}forEach [
		primaryWeapon _dropingUnit,
		handgunWeapon _dropingUnit,
		secondaryWeapon _dropingUnit
	];
	
};

[player] spawn vDropAllWeapons

 

 

  • Like 1

Share this post


Link to post
Share on other sites
3 hours ago, Larrow said:

And then shows a modified script to my original 😄

 

Well no, should work fine, even though you have dropped a nonsensical currentWeapon reference in there, as the params will overwrite the previous local var ( _weapon ).

It does not drop all pri ,sec, hand weapons, just the current equipped ones. For instance its is not going to drop a gun that is in your backpack etc.

 

 

Thank you Larrow, I didn't know that _weapon was like a magic variable? Since it is not here https://community.bistudio.com/wiki/Magic_Variables and _weapon was not defined previously on the fnc I was running I thought I had to do it somewhere. That is good to know!

 

Yes it was slightly modified because I was not using a weapon white listing but it was your fnc's soul... =p

 

So I had a soldier equipped with a primary, a secondary (launcher) and a pistol, all on their respective slots (not on backpack/vest etc) and still only dropped currentWeapon but probably because of the modification I made to your fnc. I will try again a little bit later when I am home.

Share this post


Link to post
Share on other sites
12 minutes ago, LSValmont said:

Thank you Larrow, I didn't know that _weapon was like a magic variable?

Its not _x is, which _x is the current player weapon being checked from the array.

This...

{
	_x params[ "_weapon" ];

}forEach [
    primaryWeapon _dropingUnit,
    handgunWeapon _dropingUnit,
    secondaryWeapon _dropingUnit
];

...is the same as...

{
	_weapon = _x;

}forEach [
    primaryWeapon _dropingUnit,
    handgunWeapon _dropingUnit,
    secondaryWeapon _dropingUnit
];

...other than params privates the variable making sure nothing called _weapon in a higher scope is being overwritten.

_x is the magic variable representing the current value being iterated from the array. _weapon is just assigned the value of _x.

  • Thanks 1

Share this post


Link to post
Share on other sites
13 minutes ago, LSValmont said:

Thank you Larrow, I didn't know that _weapon was like a magic variable?

Its not.

 

13 minutes ago, LSValmont said:

and _weapon was not defined previously on the fnc I was running

But it was:

13 hours ago, LSValmont said:

_weapon = currentWeapon _dropingUnit;

_x params [ "_weapon" ];

 

You first set _weapon, then you call params to set _weapon again. making your first _weapon= useless.

  • 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

×