Jump to content
Sign in to follow this  
williampett

How do I remove an Action?

Recommended Posts

Hi,

I am trying to remove an action using the script

unitName removeAction index;

here is what I have tried:

_player= if (player hasWeapon "M9") then
{
_action1 = gunbuyer1 addAction ["Sell M9 (£900)","sellM9.sqf"];
}
else {
gunbuyer1 removeAction _action1;
};

I have tried to find out how to do this but what I found has not helped.

What I want to happen is that when the M9 has been removed from the player (The "sellM9.sqf" script does this) is for the code to remove the action.

Share this post


Link to post
Share on other sites

When you activate an addAction there are four arguments that you automatically get within the script it calls. The arguments will be passed as an array _this to the script. The first argument is the object that had the action. The second argument is the player that activated the action. The third is the ID of the action (what you're looking for in this case) and the fourth is the 3rd part of the action call.

// myFlagpole addAction ["Do something", "myScript.sqf", [3, "Tomatoes"]];

_object = _this select 0;
_player = _this select 1;
_actionID = _this select 2;
_args = _this select 3;

_object removeAction _actionID;

_fruitCount = _args select 0;
_fruit = _args select 1;
_player hint format["I would like to have %1 %2 please!", _fruitCount, _fruit];

In that example you'd use the action on the flagpole. The action would be removed for your player (since it's local) and you'd get a hint saying "I would like 3 Tomatoes please!"

For your example with the M9 you could just use conditions.

gunbuyer1 addAction ["Sell M9 (£900)","sellM9.sqf",[],1,false,true,"","_this hasWeapon 'M9'"];

That way you won't even see the action unless you have an M9. In the condition field there _this is the player and _target would be the object.

Edited by kylania

Share this post


Link to post
Share on other sites

Thank You for the Help! It also helped me understand a few other things as well! :)

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  

×