Arma 3 Scripting

BIS_fnc_holdActionAdd

  • Global argument
  • Local effect
  • Arma 3 v1.62

Function · Markdown · JSON · original wiki page

Description

Adds an action to an object which requires the user to hold a key to perform the action.

Available official icons as of Arma 3 v2.10:

0 spawn
{
    // EXECUTE IN EDEN EDITOR OR EDITOR PREVIEW!
    disableSerialization;

    private _display = findDisplay 313 createDisplay "RscDisplayEmpty";

    private _edit = _display ctrlCreate ["RscEdit", 645];
    _edit ctrlSetPosition [safezoneX + 50 * pixelW, safezoneY + 50 * pixelH, safezoneW - 500 * pixelW, 50 * pixelH];
    _edit ctrlSetBackgroundColor [0,0,0,1];
    _edit ctrlCommit 0;

    private _status = _display ctrlCreate ["RscEdit", 1337];
    _status ctrlSetPosition [safezoneX + safezoneW - 400 * pixelW, safezoneY + 50 * pixelH, 350 * pixelW, 50 * pixelH];
    _status ctrlSetBackgroundColor [0,0,0,1];
    _status ctrlCommit 0;
    _status ctrlEnable false;

    private _tv = _display ctrlCreate ["RscTreeSearch", -1];
    _tv ctrlSetFont "EtelkaMonospacePro";
    _tv ctrlSetFontHeight 0.05;
    _tv ctrlSetPosition [safezoneX + 50 * pixelW, safezoneY + 125 * pixelH, safezoneW - 100 * pixelW, safeZoneH - 175 * pixelH];
    _tv ctrlSetBackgroundColor [0,0,0,1];
    _tv ctrlCommit 0;

    _tv ctrlAddEventHandler ["treeSelChanged",
    {
        params ["_ctrlTV", "_selectionPath"];
        copyToClipboard (_ctrlTV tvText _selectionPath);
        playSound ("RscDisplayCurator_ping" + selectRandom ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10"]);
        (ctrlParent _ctrlTv) displayCtrl 1337 ctrlSetText "Path copied to clipboard!";
    }];

    private _counter = 0;
    {
        private _files = addonFiles [_x # 0, ".paa"];
        {
            if ("\actions" in _x || "\holdaction" in _x) then
            {
                _counter = _counter + 1;
                _status ctrlSetText format ["%1 textures found.", _counter];
                private _index = _tv tvAdd [[], _x];
                _tv tvSetPicture [[_index], _x];
            };
        } forEach _files;
    } foreach allAddonsInfo;

    _tv tvSortall [[], false];
};

Syntax

[target, title, idleIcon, progressIcon, conditionShow, conditionProgress, codeStart, codeProgress, codeCompleted, codeInterrupted, arguments, duration, priority, removeCompleted, showUnconscious, showWindow, radius, selection, memoryPoint] call BIS_fnc_holdActionAdd

Parameters:

Returns: Number - action ID

Examples

Example 1

[
    player,
    "Kill",
    "", "",
    "true", "true",
    { hint "Started!" },
    { systemChat str (_this select 3) },
    { player setDamage 1 },
    { hint "Afraid of death?" },
    [], 10, nil, true, false
] call BIS_fnc_holdActionAdd;

Example 2

// adds the action to every client and JIP, but also adds it when it was already removed. E.g., Laptop has already been hacked by a player
[
    _myLaptop,                                                        // Object the action is attached to
    "Hack Laptop",                                                    // Title of the action
    "\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa",    // Idle icon shown on screen
    "\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa",    // Progress icon shown on screen
    "_this distance _target < 3",                                    // Condition for the action to be shown
    "_caller distance _target < 3",                                    // Condition for the action to progress
    {},                                                                // Code executed when action starts
    {},                                                                // Code executed on every progress tick
    { _this call MY_fnc_hackingCompleted },                            // Code executed on completion
    {},                                                                // Code executed on interrupted
    [],                                                                // Arguments passed to the scripts as _this select 3
    12,                                                                // Action duration in seconds
    0,                                                                // Priority
    true,                                                            // Remove on completion
    false                                                            // Show in unconscious state
] remoteExec ["BIS_fnc_holdActionAdd", 0, _myLaptop];                // MP-compatible implementation

See also

BIS_fnc_holdActionRemove · BIS_fnc_holdKey

Community notes

R3vo

A repository with icons:

I've converted all of the icons from the Tasking Overhaul to follow the Hold Action format, as well as a few others I've made myself. They're available on GitHub.