Jump to content
Sign in to follow this  
Meatball0311

removeHeadGear not working

Recommended Posts

while { vlite } do
{ 
	_helmet = headgear player;
	
	if (headgear player in _H_SOC_OPSCORE_MARITIME_D01) then
	{
		removeHeadgear player;
		player addHeadgear "H_SOC_OPSCORE_MARITIME_D01_VLite_L_Green";
	}
	else
	{
		sleep 0.025;
	};
};

Helmet is not getting removed and new helmet is not getting placed on unit.

Share this post


Link to post
Share on other sites

Most simple way using your format if all you want to do is remove the headgear if it is "H_SOC_OPSCORE_MARITIME_D01"

while { vlite } do
{ 	
	if (headgear player isEqualTo "H_SOC_OPSCORE_MARITIME_D01") then
	{
		player addHeadgear "H_SOC_OPSCORE_MARITIME_D01_VLite_L_Green";
	}
	else
	{
		sleep 0.025;
	};
};

The isEqualTo command is a very fast command for comparing things, but they have to be an exact match (case sensitivity could be an issue with your helmet name). You could alternatively use the == operator, which doesn't care about capitalization, but is slightly slower.

 

Some general feedback as well:

 

_helmet = headgear player;

Unnecessary unless you needed to know the previous headgear somewhere else in the script. From what you showed _headgear is not used.

 

 if (headgear player in _H_SOC_OPSCORE_MARITIME_D01) then

This if check is expecting _H_SOC_OPSCORE_MARITIME_D01 to be an array and then is checking if the player's headgear is inside of it. In this case I'm thinking you only want to check if a player is wearing single helmet that is "H_SOC_OPSCORE_MARITIME_D01". You can learn more about the "in" command here, case sensitivity can be an issue as well depending on your usage of "in". If you wanted to have a check for prohibited headgear from a list you could do something like this:

_prohibitedHeadgear = ["H_Cap_red", "H_Cap_press"];
while { vlite } do
{ 
	if (headgear player in _prohibitedHeadgear) then
	{
		player addHeadgear "H_SOC_OPSCORE_MARITIME_D01_VLite_L_Green";
	}
	else
	{
		sleep 0.025;
	};
}; 

Lastly,

removeHeadgear player;

player addHeadgear "H_SOC_OPSCORE_MARITIME_D01_VLite_L_Green";

No need to use removeHeadgear since addHeadgear replaces the currently equipped item.

 

If this loop would be running constantly you would want to change to using an event handler, for this situation I think the take event handler would work well. I have also just made a short video with an example of its use if you'd like to take a look.

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

×