ACE3/addons/common/functions/fnc_execPersistentFnc.sqf

52 lines
1.5 KiB
Plaintext
Raw Normal View History

/*
* Author: commy2
* Execute a function on every machine. Function will also be called upon JIP (postInit). The arguments are stored in (_this select 0), while the assigned namespace is stored in (_this select 1).
*
2015-09-20 18:25:25 +00:00
* Arguments:
* 0: Function arguments <ARRAY>
* 1: Function to execute, has to be defined on the remote machine first <STRING>
* 2: Namespace to save that variable in <OBJECT, NAMESPACE>
* 3: Name. Will overwrite previously defined functions with that name <STRING>
*
* Return Value:
* None
*
* Public: No
*
2015-09-20 18:25:25 +00:00
* Deprecated
*/
2015-01-13 19:56:02 +00:00
#include "script_component.hpp"
GVAR(remoteFnc) = _this;
2015-09-20 18:25:25 +00:00
params ["_arguments", "_function", "_unit", "_name"];
2015-10-04 02:34:46 +00:00
TRACE_4("params", _arguments, _function, _unit, _name);
2015-09-20 18:25:25 +00:00
_function = call compile _function;
// execute function on every currently connected machine
2015-01-11 18:20:14 +00:00
[[_arguments, _unit], _this select 1, 2] call FUNC(execRemoteFnc);
// save persistent function for JIP
private _persistentFunctions = _unit getVariable ["ACE_PersistentFunctions", []];
// find index to overwrite function with the same name, add to end otherwise
private _index = count _persistentFunctions;
{
2015-05-14 18:06:06 +00:00
if (_x select 2 == _name) exitWith {
_index = _forEachIndex;
};
} forEach _persistentFunctions;
// set new value
_persistentFunctions set [_index, [_arguments, _function, _name]];
// broadcast variable
if (typeName _unit == "NAMESPACE") then {
2015-05-14 18:06:06 +00:00
ACE_PersistentFunctions = _persistentFunctions;
publicVariable "ACE_PersistentFunctions";
} else {
2015-05-14 18:06:06 +00:00
_unit setVariable ["ACE_PersistentFunctions", _persistentFunctions, true];
};