Arma 3 Scripting

Command in Interaction

addAction

Also available as Markdown and JSON, or read the original wiki page.

Description

Adds an entry to the action menu of an object. The action can only be activated when in proximity to the object and looking at it. Adding an action to the player makes that action available to the player at all times. For event handling of user interaction see inGameUISetEventHandler.

Syntax

object addAction [title, script, arguments, priority, showWindow, hideOnUse, shortcut, condition, radius, unconscious, selection, memoryPoint]

Parameters:

Returns: Number - the added action's ID. Action can be removed with removeAction (see also removeAllActions). IDs are incrementing, the first given action to each unit has the ID 0, the second the ID 1, etc. IDs are also passed to the called script (see the script parameter)

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!", name player] }];
player addAction ["String Exec", "hint 'this is also compiled'"];

Example 2

_actionID = player addAction ["Exec the file", "scriptFile.sqf"];

scriptFile.sqf:

hint str _this;

Example 3

// create object on the server and add action to the object on every client
if (isServer) then
{
    private _object = "some_obj_class" createVehicle [1234, 1234, 0];
    [_object, ["Greetings!", { hint "Hello!"; }]] remoteExec ["addAction"]; // Note: does not return action id
};

Example 4

Default parameters:

this addAction
[
    "title",
    {
        params ["_target", "_caller", "_actionId", "_arguments"];
    },
    nil,
    1.5,
    true,
    true,
    "",
    "true",
    50,
    false,
    "",
    ""
];

Example 5

Default parameters with comments:

this addAction
[
    "title",    // title
    {
        params ["_target", "_caller", "_actionId", "_arguments"]; // script
    },
    nil,        // arguments
    1.5,        // priority
    true,        // showWindow
    true,        // hideOnUse
    "",            // shortcut
    "true",        // condition
    50,            // radius
    false,        // unconscious
    "",            // selection
    ""            // memoryPoint
];

Multiplayer

The command will be ignored on dedicated servers, probably because no UI exists.

See also

actionIDs · actionParams · setUserActionText · inGameUISetEventHandler · showHUD · inputAction · removeAction · removeAllActions · action · shownAction · BIS_fnc_holdActionAdd

Community notes

Dedmen

If you want to replicate vanilla Actions like "Treat yourself" where the scroll menu only shows text and it displays the icon mid-screen you can use

private _actionId = player addAction ["Heal", {}];
player setUserActionText [_actionId, "Heal", "<img size='2' image='\a3\ui_f\data\IGUI\Cfg\Actions\heal_ca'/>"];
PierreMGI

addAction on unit or player stays on corpse after kill. So this action is lost for the new body after respawn. If you want a persistent addAction, you need to add it in the respawn script (onPlayerRespawn.sqf or addMissionEventHandler "entityRespawned" or addMPEventHandler "MPrespawn"... You can use removeAllActions on corpse.