2015-01-11 16:42:31 +00:00
/*
* Author: commy2
* Add an addAction event to a unit. Used to handle multiple addAction events and add a action to the mouse wheel menu. Global arguments, local effects. Does only work for player controlled units.
*
2015-09-18 06:23:18 +00:00
* Arguments:
* 0: Unit the action should be assigned to <OBJECT>
* 1: Menu title of the action <STRING>
* 2: Name of the action, e.g. "DefaultAction" <STRING>
* 3: Condition <CODE, STRING>
* 4: Code to execute by the action <CODE, STRING>
* 5: Condition for the menu action <CODE, STRING>
* 6: Code to execute from the menu <CODE, STRING>
* 7: Priority of the action (default: 0) <NUMBER>
2015-01-11 16:42:31 +00:00
*
2015-09-18 06:23:18 +00:00
* Return Value:
* ID of the action (used to remove it later) <NUMBER>
2015-09-18 23:50:17 +00:00
*
2015-09-18 06:23:18 +00:00
* Public: No
2015-01-11 16:42:31 +00:00
*/
2015-01-13 19:56:02 +00:00
#include "script_component.hpp"
2015-01-11 16:42:31 +00:00
2015-09-18 06:23:18 +00:00
params ["_unit", "_displayName", "_action", "_condition", "_statement", "_condition2", "_statement2", ["_priority", 0]];
2015-01-11 16:42:31 +00:00
2015-11-20 17:40:31 +00:00
if (_condition isEqualType "") then {
2015-05-14 18:02:42 +00:00
_condition = compile _condition;
2015-01-11 16:42:31 +00:00
};
2015-11-20 17:40:31 +00:00
if (_statement isEqualType "") then {
2015-05-14 18:02:42 +00:00
_statement = compile _statement;
2015-01-11 16:42:31 +00:00
};
2015-11-20 17:40:31 +00:00
if (_condition2 isEqualType "") then {
2015-05-14 18:02:42 +00:00
_condition2 = compile _condition2;
2015-01-11 16:42:31 +00:00
};
2015-11-20 17:40:31 +00:00
if (_statement2 isEqualType "") then {
2015-05-14 18:02:42 +00:00
_statement2 = compile _statement2;
2015-01-11 16:42:31 +00:00
};
2015-09-18 06:23:18 +00:00
private ["_name", "_actionsVar"];
2015-01-11 16:42:31 +00:00
2015-09-18 06:23:18 +00:00
_name = format ["ACE_ActionMenu_%1", _action];
2015-01-11 16:42:31 +00:00
_actionsVar = _unit getVariable [_name, [-1, [], []]];
2015-09-18 06:23:18 +00:00
_actionsVar params ["_id", "_actionIDs", "_actions"];
_id = _id + 1;
private ["_nameVar", "_addAction", "_actionID"];
2015-01-11 16:42:31 +00:00
_nameVar = format ["%1_ID%2", _name, _id];
missionNamespace setVariable [_nameVar, [_condition, _statement, _condition2, _statement2]];
_actionIDs pushBack _id;
_addAction = call compile format [
2015-05-14 18:02:42 +00:00
"[
2015-09-18 06:23:18 +00:00
'%2',
{if (inputAction '%1' == 0) then {if (_this call (%3 select 2)) then {_this call (%3 select 3)}} else {_this call (%3 select 1)}},
nil,
%4,
false,
true,
'%1',
""if (_this != ACE_player || {vehicle _this != _target}) exitWith {false}; [_target, _this] call (%3 select 0)""
2015-05-14 18:02:42 +00:00
]",
_action,
_displayName,
_nameVar,
_priority
2015-01-11 16:42:31 +00:00
];
_actionID = _unit addAction _addAction;
_actions pushBack [_actionID, _nameVar];
_unit setVariable [_name, [_id, _actionIDs, _actions], false];
_id