ACE3/addons/common/functions/fnc_execPersistentFnc.sqf
2015-09-20 20:25:25 +02:00

54 lines
1.7 KiB
Plaintext

/*
* 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).
*
* 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
*
* Deprecated
*/
#include "script_component.hpp"
GVAR(remoteFnc) = _this;
params ["_arguments", "_function", "_unit", "_name"];
_function = call compile _function;
//["Remote", [_arguments, _this select 1, _name], {format ["%1 call %2 id: %3", _this select 0, _this select 1, _this select 2]}, false] call FUNC(log);
// execute function on every currently connected machine
[[_arguments, _unit], _this select 1, 2] call FUNC(execRemoteFnc);
// save persistent function for JIP
private ["_persistentFunctions", "_index"];
_persistentFunctions = _unit getVariable ["ACE_PersistentFunctions", []];
// find index to overwrite function with the same name, add to end otherwise
_index = count _persistentFunctions;
{
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 {
ACE_PersistentFunctions = _persistentFunctions;
publicVariable "ACE_PersistentFunctions";
} else {
_unit setVariable ["ACE_PersistentFunctions", _persistentFunctions, true];
};