Jump to content
commanderx

How to recognize if unit has a specific item?

Recommended Posts

Hi,

I would like to script a mission where BluFor units has to search for a specific item and bring it back to base. The item should be a normal map or something like that. How to achieve that I recognize that a BluFor unit has this specific map and not just any map? Any suggestions?

Best regards

Kai

Share this post


Link to post
Share on other sites

(("ITEMCLASSNAME" in (vestItems player + uniformItems player + backpackItems player + assignedItems player))

But you can't really check for a specific item, only for an itemclass in general.

For example you can only check if the player has the class "itemMaps" in his inventory. You cannot check if it's the specific "itemMap"-Item that you gave him at a specific instance.

I'd recommend this mod for things like that: http://forums.bistudio.com/showthread.php?159535-Scorch-s-Inventory-Items

Share this post


Link to post
Share on other sites

Thank you. That´s too bad but rather than installing a mod I will take something like a special backpack or so.

Share this post


Link to post
Share on other sites

Magazines have unique ids already, weapons are on the way too. Maybe some other items in the future, but for now you can only id magazines.

Share this post


Link to post
Share on other sites

Where is the map you have to find stored? On an enemy, in a crate/container, just on the floor?

You could use a variable on the container and a TAKE event on the player. TAKE currently has an issue with a few items, I personally know that it does not fire for UAV terminals for example. This would only work if there is one of said item type within the container. It is the container that denotes if the map inside is the correct one.

For example create a new mission and place down a player, preview the mission and run the code below from the debug console..

h = [] spawn {

_pos = [ player, 5, getDir player ] call BIS_fnc_relPos;
_crate1 = createVehicle [ "Box_NATO_Ammo_F", _pos, [], 0, "CAN_COLLIDE" ];
_crate1 addItemCargoGlobal [ "ItemMap", 1 ];

_pos = [ player, 5, ( getDir player ) + 10 ] call BIS_fnc_relPos;
_crate2 = createVehicle [ "Box_NATO_Ammo_F", _pos, [], 0, "CAN_COLLIDE" ];
_crate2 addItemCargoGlobal [ "ItemMap", 1 ];

_theCrate = [ _crate1, _crate2 ] call BIS_fnc_selectRandom;
_theCrate setVariable [ "loot", true, true ];

player addEventHandler [ "Take", {

	_player = _this select 0;
	_container = _this select 1;
	_item = _this select 2;

	if ( _item isEqualTo "ItemMap" ) then {
		if ( _container getVariable [ "loot", false ] ) then {
			hint "You have found the secret map";
		}else{
			hint "This is the wrong map";
		};
	};

}];

};

Its not ideal but could be a decent work around dependent on what you need.

  • Like 1

Share this post


Link to post
Share on other sites

Hey, thanks for the extensive example. Works fine but the problem is, that the players have to bring back the item to the base. So this is definitely an example I can use in the future, but not now.

Share this post


Link to post
Share on other sites
that the players have to bring back the item to the base
? It only needs tweaking slightly to get your desired effect. It was just an example of detecting a correct item pick up.

Again map is in one of the containers, Red arrow is base.

h = [] spawn {

waitUntil { time > 5 };

_pos = [ player, 10, ( getDir player ) + 180 ] call BIS_fnc_relPos;
_arrow = createVehicle [ "Sign_Arrow_F", _pos, [], 0, "NONE" ];
_trig = createVehicle [ "EmptyDetector", _pos, [], 0, "NONE" ];
_trig setTriggerArea [ 5, 5, 0, false ];
_trig  setTriggerActivation [ "WEST", "PRESENT", true];
_trig setTriggerStatements [
	"this && player in thislist",
	"if ( player getVariable [ 'SecretMap', false ] ) then {
		hint 'Well Done you have retrieved the map';
		[ 'task1', 'Succeeded' ] call BIS_fnc_taskSetState;
	}; ",
	""
];

_pos = [ player, 5, getDir player ] call BIS_fnc_relPos;
_crate1 = createVehicle [ "Box_NATO_Ammo_F", _pos, [], 0, "CAN_COLLIDE" ];
_crate1 addItemCargoGlobal [ "ItemMap", 1 ];

_pos = [ player, 5, ( getDir player ) + 10 ] call BIS_fnc_relPos;
_crate2 = createVehicle [ "Box_NATO_Ammo_F", _pos, [], 0, "CAN_COLLIDE" ];
_crate2 addItemCargoGlobal [ "ItemMap", 1 ];

_theCrate = [ _crate1, _crate2 ] call BIS_fnc_selectRandom;
_theCrate setVariable [ "loot", true, true ];

[ player, "task1", [ "Find the secret Map", "Find the secret Map", "" ], _theCrate, true, 1, true ] call BIS_fnc_taskCreate;

player addEventHandler [ "Take", {

	_player = _this select 0;
	_container = _this select 1;
	_item = _this select 2;

	if ( _item isEqualTo "ItemMap" ) then {
		if ( _container getVariable [ "loot", false ] ) then {
			player setVariable [ "SecretMap", true ];
			hint "You have found the map";
			_container setVariable [ "loot",  false, true ];
		}else{
			hint "This is not the correct map";
			if ( player getVariable [ "secretMap", false ] ) then {
				player setVariable [ "secretMap", false ];
				_container setVariable [ "loot", true ];
				player sideChat "You have dropped the secret map";
			};
		};
	};

}];

player addEventHandler [ "Put", {

	_player = _this select 0;
	_container = _this select 1;
	_item = _this select 2;


	if ( _item isEqualTo "ItemMap" ) then {
		if ( player getVariable [ "SecretMap", false ] ) then {
			player setVariable [ "SecretMap", false ];
			_container setVariable [ "loot", true, true ];
			player sideChat "You have dropped the secret map";
		};
	};

}];

};

Edited by Larrow
with added task

Share this post


Link to post
Share on other sites

Super, thank you. I´m just unfamiliar with event handlers. But it´s more than a good start for me. I´ll give that a try :-)

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

×