addAction: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (added colons after the parameter names)
(wip)
Line 11: Line 11:
____________________________________________________________________________________________
____________________________________________________________________________________________


| Adds an entry to the action menu of an object (scroll wheel menu). The action can only be activated when in proximity to the object (eg: building). Adding an action to the player obviously makes that action available to the player at all times. <br><br>
| {{Feature arma3| This command syntax is for Arma 3 only. For TKOH version see [[addAction TKOH]]}}
Adds an entry to the action menu of an object (scroll wheel menu). The action can only be activated when in proximity to the object (eg: building). Adding an action to the player obviously makes that action available to the player at all times. The appearance of onscreen text could be further tweaked with [[setUserActionText]]. For event handling of user interaction see [[inGameUISetEventHandler]]<br><br>


This command has [[local]] effect. Created action is only available on the computer where command was executed. To make action available to all players, command must be executed on all connected clients.<br><br>
This command has [[local]] effect. Created action is only available on the computer where command was executed. To make action available to all players, command must be executed on all connected clients (see [[remoteExec]])<br><br>


Note: [[addAction]] will be ignored on dedicated server, probably because no UI.  |= Description
Note: [[addAction]] is ignored on dedicated server, because of no user interface.  |= Description
____________________________________________________________________________________________
____________________________________________________________________________________________


| unit '''addAction''' [title, script, arguments, priority, showWindow, hideOnUse, shortcut, condition, positionInModel, radius, radiusView, showIn3D, available, textDefault, textToolTip] |= Syntax
| unit '''addAction''' [title, script, arguments, priority, showWindow, hideOnUse, shortcut, condition, radius, unconscious] |= Syntax


|p1= <dl>
|p1= <dl>
Line 34: Line 35:
</ul></dd>
</ul></dd>
<dt>arguments:</dt>
<dt>arguments:</dt>
<dd>''(optional)'': [[Anything]] - Arguments to pass to the script (will be ''_this select 3'' inside the script). If [[Array]] is used as an argument for example, its 1st element reference would be ''_this select 3 select 0''. Default value: [[nil]]</dd>
<dd>''(Optional)'': [[Anything]] - Arguments to pass to the script (will be ''_this select 3'' inside the script). If [[Array]] is used as an argument for example, its 1st element reference would be ''_this select 3 select 0''. Default value: [[nil]]</dd>
<dt>priority:</dt>
<dt>priority:</dt>
<dd>''(optional)'': [[Number]] - Priority value of the action. Actions will be arranged in descending order according to this value. Every game action has a preset priority value. Value can be negative or decimal fraction. Actions with same values will be arranged in order which they were made, newest at the bottom. The bigger the number the higher the action will be positioned on the menu. Typical range is 0 (low priority. Eg: 'Get out') to 6 (high priority. Eg: 'Auto-hover on'). Default value: 1.5</dd>
<dd>''(Optional)'': [[Number]] - Priority value of the action. Actions will be arranged in descending order according to this value. Every game action has a preset priority value. Value can be negative or decimal fraction. Actions with same values will be arranged in order which they were made, newest at the bottom. The bigger the number the higher the action will be positioned on the menu. Typical range is 0 (low priority. Eg: 'Get out') to 6 (high priority. Eg: 'Auto-hover on'). Default value: 1.5</dd>
<dt>showWindow:</dt>
<dt>showWindow:</dt>
<dd>''(optional)'': [[Boolean]] - If set to [[true]], players see "Titletext" at mid-lower screen, as they approach the object. Only the title text for the action with highest priority and 'showWindow true' will be shown. Setting it to [[false]] disables the feature. Default value: [[true]]</dd>
<dd>''(Optional)'': [[Boolean]] - If set to [[true]], players see "Titletext" at mid-lower screen, as they approach the object. Only the title text for the action with highest priority and 'showWindow true' will be shown. Setting it to [[false]] disables the feature. Default value: [[true]]</dd>
<dt>hideOnUse:</dt>
<dt>hideOnUse:</dt>
<dd>''(optional)'': [[Boolean]] - If set to [[true]], it will hide the action menu after selecting that action. If set to [[false]], it will leave the action menu open and visible after selecting that action, leaving the same action highlighted, for the purpose of allowing you to reselect that same action quickly, or to select another action. Default value: [[true]]</dd>
<dd>''(Optional)'': [[Boolean]] - If set to [[true]], it will hide the action menu after selecting that action. If set to [[false]], it will leave the action menu open and visible after selecting that action, leaving the same action highlighted, for the purpose of allowing you to reselect that same action quickly, or to select another action. Default value: [[true]]</dd>
<dt>shortcut:</dt>
<dt>shortcut:</dt>
<dd>''(optional)'': [[String]] - One of the [[:Category:Key Actions|key names]] defined in bin.pbo (e.g. "moveForward"). Adding available shortcut will bind corresponding keyboard key to this action. Shortcut availability can be tested with [[inputAction]] command. Default value: ""</dd>
<dd>''(Optional)'': [[String]] - One of the [[:Category:Key Actions|key names]] defined in bin.pbo (e.g. "moveForward"). Adding available shortcut will bind corresponding keyboard key to this action. Shortcut availability can be tested with [[inputAction]] command. Default value: ""</dd>
<dt>condition:</dt>
<dt>condition:</dt>
<dd>''(optional)'': [[String]] - script code that must return [[true]] for the action to be shown. Special variables passed to the script code are ''_target'' (unit to which action is attached to) and ''_this'' (caller/executing unit). Default value: "true"
<dd>''(Optional)'': [[String]] - script code that must return [[true]] for the action to be shown. Special variables passed to the script code are ''_target'' (unit to which action is attached to) and ''_this'' (caller/executing unit). Default value: "true"
<div style="margin-left:2em;">'''NOTE:''' <u>condition</u> is evaluated on each frame in non-scheduled environment. If action is added to some object and not to [[player]], <u>condition</u> will only get evaluated IF player is closer than 15m to the object AND is looking at the object. If action is added to [[player]], the <u>condition</u> is evaluated all the time.</div></dd>
<div style="margin-left:2em;">'''NOTE:''' <u>condition</u> is evaluated on each frame in non-scheduled environment. If action is added to some object and not to [[player]], <u>condition</u> will only get evaluated IF player is closer than 15m to the object AND is looking at the object. If action is added to [[player]], the <u>condition</u> is evaluated all the time.</div></dd>
<dt>positionInModel:</dt>
<dd>''(optional, [[:Category:Take_On|TKOH]] only)'': [[String]] - Name of the named selection in the model for positioning the action in 3D space, typically a memory point. Default: ""</dd>
<dt>radius:</dt>
<dt>radius:</dt>
<dd>''(optional, [[:Category:Take_On|TKOH]] only)'': [[Number]] - Distance in meters the unit activating the action must be within to activate it. -1 disables this radius</dd>
<dd>''(Optional)'': [[Number]] - Distance in meters the unit activating the action must be within to activate it. -1 disables this radius. Default value: 15</dd>
<dt>radiusView:</dt>
<dt>unconscious:</dt>
<dd>''(optional, [[:Category:Take_On|TKOH]] only)'': [[Number]] - Maximum distance in meters the cursor can be away from the 3D action to activate it. -1 disables this radius</dd>
<dd>''(Optional)'': [[Boolean]] - if [[true]] will be shown to incapacitated player (see [[setUnconscious]], [[lifeState]]). Default value: [[false]]</dd></dl>|=
<dt>showIn3D:</dt>
<dd>''(optional, [[:Category:Take_On|TKOH]] only)'': [[Number]] - Condition for showing the action in 3D space (combine by adding up)
<ul><li>1 - show</li>
<li>2 - draw if unit is pilot</li>
<li>4 - draw if unit is inside vehicle</li>
<li>8 - draw if unit is outside vehicle</li>
<li>16 - draw if not in external camera</li>
<li>32 - draw if not in internal camera</li>
<li>64 - draw if not in gunner camera (turret optics)</li></ul></dd>
<dt>available:</dt>
<dd>''(optional, [[:Category:Take_On|TKOH]] only)'': [[Number]] - Condition for being able to activate the action (combine by adding up)
<ul><li>0 - disabled</li>
<li>1 - unit is pilot or copilot</li>
<li>2 - unit is inside target</li>
<li>4 - unit is not inside target</li></ul></dd>
<dt>textDefault:</dt>
<dd>''(optional, [[:Category:Take_On|TKOH]] only)'': [[String]] - [[Structured Text]] which is shown as the 3D action (so it can be an icon), or in the center of the screen when the action is highlighted in the action menu for a 2D action</dd>
<dt>textToolTip:</dt>
<dd>''(optional, [[:Category:Take_On|TKOH]] only)'': [[String]] - [[Structured Text]] which is faded in under the ''textDefault'' when hovering over the action in 3D space</dd>
</dl>|=


| [[Number]]
| [[Number]]
Line 78: Line 57:
____________________________________________________________________________________________
____________________________________________________________________________________________
   
   
|x1= Short and sweet:<code>[[player]] [[addAction]] ["A Useless Action", ""];
|x1= Short and sweet:<code>[[player]] [[addAction]] ["A Useless Action That Does Nothing", {}];
[[player]] [[addAction]] ["<t color='#FF0000'>This Useless Action Is RED</t>", ""];
[[player]] [[addAction]] ["<t color='#FF0000'>This Useless Action Is RED</t>", {hint "RED"}];
[[player]] [[addAction]] ["Hint Hello!", { [[hint]] [[format]] ["Hello %1!", [[_this]] [[select]] 3] }, [[name]] [[player]]];
[[player]] [[addAction]] ["Hint Hello!", { [[hint]] [[format]] ["Hello %1!", [[_this]] [[select]] 3] }, [[name]] [[player]]];
[[player]] [[addAction]] ["string exec", "hint 'this is also compiled'"];</code> |= Example 1
[[player]] [[addAction]] ["String Exec", "hint 'this is also compiled'"];</code> |= Example 1


|x2= Actionception:<code>actions = [];
|x2= [[SQF]] file example: <code>_act = player [[addAction]] ["Exec the file", "somescript.sqf"]</code>
actions [[set]] [0, [[player]] [[addAction]] ["Actionception", {
somescript.sqf:
[[if]] ([[count]] actions == 1) [[then]] {
<code>hint str _this;</code> |= Example 2
actions [[set]] [1, [[player]] [[addAction]] [" Actionception ", {
[[if]] ([[count]] actions == 2) [[then]] {
actions [[set]] [2, [[player]] [[addAction]] ["  Actionception  ", {
[[if]] ([[count]] actions == 3) [[then]] {
actions [[set]] [3, [[player]] [[addAction]] ["  Actionception  ", {
{
[[player]] [[removeAction]] [[Magic Variables|_x]];
} [[forEach]] actions;
}, [], 10, [[false]], [[true]]]];
};
}, [], 10, [[false]], [[false]]]];
};
}, [], 10, [[false]], [[false]]]];
};
}, [], 10, [[false]], [[false]]]];</code> |= Example 2


|x3= [[SQS]] example: <code>_genAct = generator [[addAction]] ["Switch on generator", "activate_generator.sqs"]</code>
|x3= [[SQS]] file example: <code>_genAct = generator [[addAction]] ["Switch on generator", "activate_generator.sqs"]</code>
activate_generator.sqs:
activate_generator.sqs:
<code>_gen = [[_this]] [[select]] 0
<code>_gen = [[_this]] [[select]] 0
_caller = [[_this]] [[select]] 1
_caller = [[_this]] [[select]] 1
Line 112: Line 75:


This example shows an action called "Switch on generator" added to an object with the name 'generator'. As soon as the player gets close to this object, he can execute the given action via the action menu. Then the script 'activate_generator.sqs' is executed, which in our example only removes the action from the generator. |= Example 3
This example shows an action called "Switch on generator" added to an object with the name 'generator'. As soon as the player gets close to this object, he can execute the given action via the action menu. Then the script 'activate_generator.sqs' is executed, which in our example only removes the action from the generator. |= Example 3
|x4= [[:Category:Take_On|TKOH]] example:<code>_heli [[addAction]] [
"Test",
"myTest.sqf",
"",
1,
true,
true,
"",
"true",
"display1",
2,
0.25,
9,
0,
"<img image='\HSim\UI_H\data\ui_action_autohover_ca.paa' size='1.8' shadow=0 />",
"<nowiki><br /></nowiki>My test tooltip"
]</code> |= Example 4


____________________________________________________________________________________________
____________________________________________________________________________________________


|pr= Due to a bug in OFP actions added via addAction don't get updated properly after mounting vehicles. When you have several actions available while mounting a vehicle and drive away from the actions' position, they'll still be shown in the menu until you dismount and remount the vehicle.
| [[removeAction]], [[removeAllActions]], [[setUserActionText]], [[inputAction]], [[action]], [[inGameUISetEventHandler]] |= See also
 
There are work-arounds mentioned on the OFPEC Forums |=
 
| [[removeAction]], [[removeAllActions]], [[setUserActionText]], [[inputAction]], [[action]] |= See also


}}
}}
Line 203: Line 144:
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
<dt class="note">[[User:Killzone Kid|Killzone Kid]]</dt>
<dd class="note">
<dd class="note">
Actionception:<code>actions = [];
actions [[set]] [0, [[player]] [[addAction]] ["Actionception", {
[[if]] ([[count]] actions == 1) [[then]] {
actions [[set]] [1, [[player]] [[addAction]] [" Actionception ", {
[[if]] ([[count]] actions == 2) [[then]] {
actions [[set]] [2, [[player]] [[addAction]] ["  Actionception  ", {
[[if]] ([[count]] actions == 3) [[then]] {
actions [[set]] [3, [[player]] [[addAction]] ["  Actionception  ", {
{
[[player]] [[removeAction]] [[Magic Variables|_x]];
} [[forEach]] actions;
}, [], 10, [[false]], [[true]]]];
};
}, [], 10, [[false]], [[false]]]];
};
}, [], 10, [[false]], [[false]]]];
};
}, [], 10, [[false]], [[false]]]];</code>
Function to remove user actions with unknown ids:
Function to remove user actions with unknown ids:
<code>KK_fnc_removeUnknownUserActions <nowiki>=</nowiki> {
<code>KK_fnc_removeUnknownUserActions <nowiki>=</nowiki> {

Revision as of 14:19, 16 June 2016

Hover & click on the images for description

Description

Description:
Arma 3
This command syntax is for Arma 3 only. For TKOH version see addAction TKOH

Adds an entry to the action menu of an object (scroll wheel menu). The action can only be activated when in proximity to the object (eg: building). Adding an action to the player obviously makes that action available to the player at all times. The appearance of onscreen text could be further tweaked with setUserActionText. For event handling of user interaction see inGameUISetEventHandler

This command has local effect. Created action is only available on the computer where command was executed. To make action available to all players, command must be executed on all connected clients (see remoteExec)

Note: addAction is ignored on dedicated server, because of no user interface.
Groups:
Uncategorised

Syntax

Syntax:
unit addAction [title, script, arguments, priority, showWindow, hideOnUse, shortcut, condition, radius, unconscious]
Parameters:
unit:
Object - unit, vehicle or static object
title:
String - The action name which is displayed in the action menu, may contain XML like syntax. Because of that < and > symbols will be interpreted as opening and closing XML tags. To avoid this use &lt; for < and &gt; for >. The title text can be changed with setUserActionText
script:
String or Code - Either path to the script file, relative to the mission folder or string with code or (since Take On Helicopters) the actual script code. If the string is a path to script file, the script file *must* have extension .SQS or .SQF (in Arma), or .SQS (in OFP). The script, whether it is a file or a code, will run in scheduled environment, i.e. it is ok to use sleep.
  • Parameters array passed to the script upon activation in _this variable is: [target, caller, ID, arguments]
  • target (_this select 0): Object - the object which the action is assigned to
  • caller (_this select 1): Object - the unit that activated the action
  • ID (_this select 2): Number - ID of the activated action (same as ID returned by addAction)
  • arguments (_this select 3): Anything - arguments given to the script if you are using the extended syntax
arguments:
(Optional): Anything - Arguments to pass to the script (will be _this select 3 inside the script). If Array is used as an argument for example, its 1st element reference would be _this select 3 select 0. Default value: nil
priority:
(Optional): Number - Priority value of the action. Actions will be arranged in descending order according to this value. Every game action has a preset priority value. Value can be negative or decimal fraction. Actions with same values will be arranged in order which they were made, newest at the bottom. The bigger the number the higher the action will be positioned on the menu. Typical range is 0 (low priority. Eg: 'Get out') to 6 (high priority. Eg: 'Auto-hover on'). Default value: 1.5
showWindow:
(Optional): Boolean - If set to true, players see "Titletext" at mid-lower screen, as they approach the object. Only the title text for the action with highest priority and 'showWindow true' will be shown. Setting it to false disables the feature. Default value: true
hideOnUse:
(Optional): Boolean - If set to true, it will hide the action menu after selecting that action. If set to false, it will leave the action menu open and visible after selecting that action, leaving the same action highlighted, for the purpose of allowing you to reselect that same action quickly, or to select another action. Default value: true
shortcut:
(Optional): String - One of the key names defined in bin.pbo (e.g. "moveForward"). Adding available shortcut will bind corresponding keyboard key to this action. Shortcut availability can be tested with inputAction command. Default value: ""
condition:
(Optional): String - script code that must return true for the action to be shown. Special variables passed to the script code are _target (unit to which action is attached to) and _this (caller/executing unit). Default value: "true"
NOTE: condition is evaluated on each frame in non-scheduled environment. If action is added to some object and not to player, condition will only get evaluated IF player is closer than 15m to the object AND is looking at the object. If action is added to player, the condition is evaluated all the time.
radius:
(Optional): Number - Distance in meters the unit activating the action must be within to activate it. -1 disables this radius. Default value: 15
unconscious:
(Optional): Boolean - if true will be shown to incapacitated player (see setUnconscious, lifeState). Default value: false
Return Value:
Number The ID of the action is returned. IDs are incrementing. The first given action to each unit has got the ID 0, the second the ID 1 etc. ID's are also passed to the called script and used to remove an action with removeAction

Examples

Example 1:
Short and sweet:player addAction ["A Useless Action That Does Nothing", {}]; player addAction ["<t color='#FF0000'>This Useless Action Is RED</t>", {hint "RED"}]; player addAction ["Hint Hello!", { hint format ["Hello %1!", _this select 3] }, name player]; player addAction ["String Exec", "hint 'this is also compiled'"];
Example 2:
SQF file example: _act = player addAction ["Exec the file", "somescript.sqf"] somescript.sqf: hint str _this;
Example 3:
SQS file example: _genAct = generator addAction ["Switch on generator", "activate_generator.sqs"] activate_generator.sqs: _gen = _this select 0 _caller = _this select 1 _id = _this select 2 ; remove the action once it is activated _gen removeAction _id This example shows an action called "Switch on generator" added to an object with the name 'generator'. As soon as the player gets close to this object, he can execute the given action via the action menu. Then the script 'activate_generator.sqs' is executed, which in our example only removes the action from the generator.

Additional Information

See also:
removeActionremoveAllActionssetUserActionTextinputActionactioninGameUISetEventHandler

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note

Notes

Posted on August 2, 2006 - 10:10
hardrock
An easy way to keep track of and remove actions is to store the IDs of the actions in variables. This can be accomplished by doing the following: _myaction = player addAction ["Hello", "hello.sqs"]; This stores the action's ID in the local variable "_myaction" and assists in keeping track of the action ID. To remove the above action, you would use the following line: player removeAction _myaction;
Posted on 17:35, 24 August 2013 (CEST)
Killzone_Kid
In Arma 3 addAction does not work on animals. This is intended behavior.

Bottom Section

Posted on June 19, 2014 - 15:01 (UTC)
Krzmbrzl00
If executing actual script code like this: _unit addAction [ "yourAction", { hint "A line of code" } ];
you can have a user action that uses and/or affects variables used elsewhere in the script that adds the action.
But beware!
The variable(s) must be global otherwise it won't work! i.e.
Fail
_variable = false;
_unit addAction [ "action", { _variable = true } ];
Succeed
variable = false;
_unit addAction [ "action", { variable = true } ];
Posted on August 15, 2014 - 13:10 (UTC)
SilentSpike
Be aware that function names are essentially just global variables for code, so you can use function names as the script parameter.
Posted on March 10, 2015 - 09:55 (UTC)
Killzone Kid
Actionception:actions = []; actions set [0, player addAction ["Actionception", { if (count actions == 1) then { actions set [1, player addAction [" Actionception ", { if (count actions == 2) then { actions set [2, player addAction [" Actionception ", { if (count actions == 3) then { actions set [3, player addAction [" Actionception ", { { player removeAction _x; } forEach actions; }, [], 10, false, true]]; }; }, [], 10, false, false]]; }; }, [], 10, false, false]]; }; }, [], 10, false, false]]; Function to remove user actions with unknown ids: KK_fnc_removeUnknownUserActions = { for "_i" from 0 to (player addAction ["",""]) do { if !(_i in _this) then { player removeAction _i; }; }; }; To test: for "_i" from 0 to 9 do { player addAction ["Action #" + str _i, { [0,5,6] call KK_fnc_removeUnknownUserActions; }]; }; Removes all user actions but 0, 5 and 6.