Jump to content

Recommended Posts

Hello,

 

I would like know how i can detect when a player drop an item for delete it.

I have try with "addEventHandler Put" but the return of item is type string and DeleteVehicle use type object..

 

Thank you! 

(Sorry for my bad english)

Share this post


Link to post
Share on other sites
19 hours ago, djdan9741 said:

I have try with "addEventHandler Put" but the return of item is type string and DeleteVehicle use type object..

An item is not an OBJECT so deleteVehicle will not work anyway.

player addEventHandler[ "Put", {
	params[ "_unit", "_container", "_item" ];
	
	//Only if its dropped on the floor AND is an item
	if ( { _container isKindOf _x }count [ "weaponHolder", "weaponHolderSimulated" ] > 0 && { _item isKindOf[ "ItemCore", configFile >> "CfgWeapons" ] } ) then {
		
		//Get item contents of weaponHolder
		_itemContents = itemCargo _container call BIS_fnc_consolidateArray;
		
		//Find the dropped item type in contents
		_index = _itemContents findIf{ _x select 0 == _item };
		
		//Remove 1 from items count
		_itemContents select _index set[ 1, ( _itemContents select _index select 1 ) - 1 ];
		
		//Clear container of all items
		clearItemCargoGlobal _container;
		
		//Add back modified contents
		{
			_container addItemCargoGlobal _x;
		}forEach _itemContents;
		
	};
}];

 

  • Like 3

Share this post


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

An item is not an OBJECT so deleteVehicle will not work anyway.


player addEventHandler[ "Put", {
	params[ "_unit", "_container", "_item" ];
	
	//Only if its dropped on the floor AND is an item
	if ( { _container isKindOf _x }count [ "weaponHolder", "weaponHolderSimulated" ] > 0 && { _item isKindOf[ "ItemCore", configFile >> "CfgWeapons" ] } ) then {
		
		//Get item contents of weaponHolder
		_itemContents = itemCargo _container call BIS_fnc_consolidateArray;
		
		//Find the dropped item type in contents
		_index = _itemContents findIf{ _x select 0 == _item };
		
		//Remove 1 from items count
		_itemContents select _index set[ 1, ( _itemContents select _index select 1 ) - 1 ];
		
		//Clear container of all items
		clearItemCargoGlobal _container;
		
		//Add back modified contents
		{
			_container addItemCargoGlobal _x;
		}forEach _itemContents;
		
	};
}];

 

 

Thank you for your answer,

I have try your script but it does not work.

 

I have this error: Incorrect number in expression.

 

Share this post


Link to post
Share on other sites
23 hours ago, djdan9741 said:

I have try your script but it does not work.

Code works fine as I tested it before posting. Check what you have copied has no hidden characters( known forum bug ) OR rewrite it from scratch.

Share this post


Link to post
Share on other sites
On 4/21/2020 at 9:22 AM, Larrow said:

An item is not an OBJECT so deleteVehicle will not work anyway.


player addEventHandler[ "Put", {
	params[ "_unit", "_container", "_item" ];
	
	//Only if its dropped on the floor AND is an item
	if ( { _container isKindOf _x }count [ "weaponHolder", "weaponHolderSimulated" ] > 0 && { _item isKindOf[ "ItemCore", configFile >> "CfgWeapons" ] } ) then {
		
		//Get item contents of weaponHolder
		_itemContents = itemCargo _container call BIS_fnc_consolidateArray;
		
		//Find the dropped item type in contents
		_index = _itemContents findIf{ _x select 0 == _item };
		
		//Remove 1 from items count
		_itemContents select _index set[ 1, ( _itemContents select _index select 1 ) - 1 ];
		
		//Clear container of all items
		clearItemCargoGlobal _container;
		
		//Add back modified contents
		{
			_container addItemCargoGlobal _x;
		}forEach _itemContents;
		
	};
}];

 

nice code ; thx !! question were do I put this ?? in the Init of the player ? or in the mission folder?? I have tried in the init of player, I take gear form a box and it still drop it on the floor .... Help plz 

Share this post


Link to post
Share on other sites

I'd recommend making an "initPlayerLocal.sqf".
However, if the mission includes respawning, you might want to use "OnPlayerRespawn.sqf" instead.

  • Like 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

×