Script: addAction Helper

Party-approved programming
Post Reply
Black Mamba
Posts: 335
Joined: Sun May 27, 2012 12:11 pm

Script: addAction Helper

Post by Black Mamba »

Thought I'd put this here, as it is needed in another project I want to put out there.
Basically this is another script that emulates a CBA function: the ability to spawn code directly from the addAction command, instead of going and creating a new .sqf file anytime you create a new action.
The documentation is pretty light, but the basic premise is that whatever action you create, you always call the same script, this one, and use the arguments to pass the code you want executed.
What I usually do is register that code as a function beforehand, so I won't have a 25 lines command just to add a simple action.

Code: Select all

/*    BM_addAction.sqf
Removes the need for creating a new file any time you create a new action.
You can now spawn code directly from the addAction command.
Examples:
nul = _target addAction ["Action Text", "Custom\BM_addAction.sqf", [[arguments], {code to execute}], priority, showWindow, hideOnUse, shortcut, condition];
nul = _target addAction ["Action Text", "Custom\BM_addAction.sqf", {code to execute}, priority, showWindow, hideOnUse, shortcut, condition];
*/

private ["_target", "_caller", "_id", "_passed", "_args", "_code"];

_target = _this select 0;
_caller = _this select 1;
_id = _this select 2;
_passed = _this select 3;

switch (typeName _passed) do {
	case "ARRAY" : {
		_args = _passed select 0;
		_code = _passed select 1;
		[_target, _caller, _id, _args] call _code;
	};
	case "CODE" : {
		[_target, _caller, _id] call _passed;
	};
	default {player sidechat "BM_addAction only takes code and arrays!";};
};

Post Reply