Jump to content
Sweedn

Detect if player has weapon/launcher

Recommended Posts

Hello people. I'm looking for a efficient way to detect if a player has a special type of weapon in his inventory, as primary or secondary weapon.

if (isDedicated) then { 
sleep 0.001; 
_launcher = ["rhs_weap_M136_hp","rhs_weap_M136_hedp","rhs_weap_M136"]; 
	{
		if (SecondaryWeapon player _launcher ) then
			{
				hint "Player sec weapon found"; 
			};
	}
};

In this case, I'm looking for detection of one of three type of RHS launchers, if a player has one of it in his inventory.

Am I missing something here ?

Share this post


Link to post
Share on other sites

How bout:

_launcher = ["rhs_weap_M136_hp","rhs_weap_M136_hedp","rhs_weap_M136"];

{
	if (_x in _launcher) then
	{
		hint format ["Player has a: %1",_x];
	};
} forEach weapons player;

Share this post


Link to post
Share on other sites

First : If isdedicated is for server side. Not for client (player)

 

 

_launcher = ["rhs_weap_M136_hp","rhs_weap_M136_hedp","rhs_weap_M136"];

        if (SecondaryWeapon player in _launcher ) then
            {
                hint "Player sec weapon found";
            };
 

Share this post


Link to post
Share on other sites

Thanks for both quick responses. But neither seems to work for me (code put in init.sqf or called via execVM, no changes). Should I mention I would like to have the detection with launchers in game too ? I mean, if I'm picking up a launcher on the ground, during a mission ?

Share this post


Link to post
Share on other sites

Should I mention I would like to have the detection with launchers in game too ?

 

Yes, that is a bit helpful :P, try this out, probably not the best option (by best I mean optimized), but atm I don't have the time to really sit down and think about it:

[
	"checkLauncherEH",
	"onEachFrame",
	{
		_launcher = ["rhs_weap_M136_hp","rhs_weap_M136_hedp","rhs_weap_M136"];

		{
			if (_x in _launcher) then
			{
				hint format ["Player has a: %1",_x];
			};
		} forEach weapons player;
	}
] call BIS_fnc_addStackedEventHandler;

Put this in the initPlayerLocal.sqf

Share this post


Link to post
Share on other sites

I was so confused why and how my code wasn't working that I forgot about the only one check of init.sqf... Thank you, I will now check for further optimizations.

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

×