Jump to content
Sign in to follow this  
Big Dawg KS

Alternative AddAction Syntax

Recommended Posts

Most of us are familiar with the following example of addAction:

player addAction ["Say Hello","hello.sqf"];

In OFP, if we wanted to the actions to be seen/hidden we needed to constantly remove and readd the actions. This involved a lot of complex and sometimes unreliable code. Also, if we wanted to pass additional arguments to the script, we needed to use some sort of global variable or some other workaround.

Those days are over.

AddAction now has this alternative syntax which will make our lives much easier.

Alternative Syntax:

[i]unit[/i] addAction [i][action, script filename, arguments, priority, showWindow, hideOnUse, shortcut, condition][/i]

Condition

Many times we use actions like event handlers. Every time something happens, we want an action to become available. For example, a repair vehicle action should only be available when the vehicle becomes damaged. No longer will we use removeAction for this.

The new addAction syntax allows us to specify a condition. What is the condition? It's code (uncompiled, thus needs to be in quotes and not {}s) that evaluates to a boolean. When it's true, the action appears in the action menu and users can select and activate it. When the condition evaluates to false, it hides the action and it becomes unselectable. The condition can even access some arguments; _target and _this. You can use the _target variable in your condition to refer to the object to which the action is attached, and _this is the would be activating unit of the action.

So let's use the above example with the vehicle repair:

myVeh addAction ["Repair Vehicle","repair.sqf",[],1,false,true,"","damage _target > 0.3"];

The "Repair Vehicle" action will become available every time the vehicle receives 30% or more damage, and will go away when it has less.

You can also use the condition to limit who the action is shown to. For example:

player addAction ["Call Artillery","callArty.sqf",[],1,false,true,"","_this == _target"];

Only the player to whom the action was added can now see and use the action (so for example his AI group members can't).

Additional Arguments

Say you have a script that has additional paramaters than just those arguments passed by default by addAction. No problem. We can pass these additional arguments to our script with the new addAction syntax.

Ex:

_args1 = [artyBat1,"HE",5,artyTarg1];
_args2 = [artyBat2,"Smoke",10,artyTarg1];
player addAction ["Call Artillery (HE)","callArty.sqf",_args1,1,false,true,"","_this == _target"];
player addAction ["Call Artillery (Smoke","callArty.sqf",_args2,1,false,true,,"","_this == _target"];

These additional arguments should be appended to _this (IIRC). So your script would start like this:

_object = _this select 0;
_actor = _this select 1;
_ID = _this select 2;
_artyBattery = _this select 3;
_type = _this select 4;
_numRounds = _this select 5;
_target = _this select 6;

hideOnUse

Setting this to true will not hide the action itself. Rather, it simply hides the action menu (list of actions) after you activate the action. It should show again when you use the scroll/select keys. Seems pretty trivial, but perhaps it has it's uses.

The reason I wanted to share this is because I still see people constantly using the add/removeAction method whenever they want to hide/show actions. Since we have these new features, we should make use of them. The additonal arguments is actually something that I needed way back in OFP when I first started scripting, boy would it have been nice to have. If I needed it way back then, then there's a chance someone else might need it now and not be aware of it. Hopefully this will not only inform newcommers but get the veterans to break their old and no longer necessary habits.

Edited by Big Dawg KS

Share this post


Link to post
Share on other sites

You can also use the "_target" variable in your condition which is set to the object you attached the action to. Not really necessary, but it can make your condition a bit shorter.

I didn't know that you could also use the "_this" array in the condition, thanks for the tip :)

Share this post


Link to post
Share on other sites
You can also use the "_target" variable in your condition which is set to the object you attached the action to. Not really necessary, but it can make your condition a bit shorter.

I didn't know that you could also use the "_this" array in the condition, thanks for the tip :)

Actually, I'm not sure if you can. To be honest, I'm writing this from memory, so I'm probably wrong on a few points. And now that you mention it, it might just be _target and another reserved variable (I'm pretty sure there was one for the unit performing the action) and not the _this array. Please correct me if you see anything incorrect.

Edited by Big Dawg KS

Share this post


Link to post
Share on other sites

I'm still lost on this, if I have an action that I want to show until used how would I set it up without remove action.

True/false seem to have no effect that I've noticed.

act = this addaction ["test","thisscript.sqf",[],1,false,true,"",""];

Share this post


Link to post
Share on other sites

I'm not exactly sure myself what hideOnUse does. You have other options. In this case, if you never ever need to use the action again, then just use removeAction. However, if you don't want to remove it you can use the condition:

showAction = true;

act = this addaction ["test","thisscript.sqf",[],1,false,true,"","showAction"];

thisscript.sqf

showAction = false;

The condition should be used to hide/show a repeatable action. RemoveAction should be used to remove an action you no longer intend to use.

If you guys are able to find more information on how the rest of these parameters work, document them here and I'll edit my post.

Edited by Big Dawg KS

Share this post


Link to post
Share on other sites

hideOnUse is to hide the action menu if you've used the action

Share this post


Link to post
Share on other sites

Thanks guys, I've started to use the condition once or twice.

I see now the hideonuse simply turns off the action menu until it's selected again, I thought it meant remove it totally after being used which isn't the case.

Now showwindow does what, again I can't see any effect.

Share this post


Link to post
Share on other sites
hideOnUse is to hide the action menu if you've used the action

Ah. See, even the little things matter. :p Added to first post.

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  

×