2015-02-12 12:23:38 +00:00
/*
2015-09-19 21:18:07 +00:00
* Author: commy2 and joko // Jonas
2015-10-21 20:52:21 +00:00
* Sets a public variable, but wait a certain amount of time to transfer the value over the network. Changing the value by calling this function again resets the windup timer.
2015-02-12 12:23:38 +00:00
*
2015-09-19 21:18:07 +00:00
* Arguments:
* 0: Object the variable should be assigned to <OBJECT>
* 1: Name of the variable <STRING>
* 2: Value of the variable <ANY>
2015-10-21 20:52:21 +00:00
* 3: Windup time <NUMBER> (default: 1)
2015-02-12 12:23:38 +00:00
*
2015-09-19 21:18:07 +00:00
* Return Value:
* None
*
* Public: No
2015-02-12 12:23:38 +00:00
*/
#include "script_component.hpp"
2015-09-19 21:18:07 +00:00
params ["_object", "_varName", "_value", ["_sync", 1]];
2015-02-12 12:23:38 +00:00
// set value locally
_object setVariable [_varName, _value];
2015-09-20 09:02:15 +00:00
// Exit if in SP
if (!isMultiplayer) exitWith {};
2015-02-12 12:23:38 +00:00
2015-12-14 12:08:19 +00:00
private _idName = format ["ACE_setVariablePublic_%1", _varName];
2015-09-20 09:02:15 +00:00
2015-09-19 21:18:07 +00:00
if (_idName in GVAR(setVariableNames)) exitWith {};
2015-02-12 14:56:57 +00:00
2015-12-14 12:08:19 +00:00
private _syncTime = ACE_diagTime + _sync;
2015-02-12 12:23:38 +00:00
2015-09-19 21:18:07 +00:00
GVAR(setVariableNames) pushBack _idName;
GVAR(setVariablePublicArray) pushBack [_object, _varName, _syncTime, _idName];
if (isNil QGVAR(setVariablePublicPFH)) exitWith {};
GVAR(setVariablePublicPFH) = [{
{
_x params ["_object", "_varName", "_syncTime", "_idName"];
if (ACE_diagTime > _syncTime) then {
// set value public
_object setVariable [_varName, _object getVariable _varName, true];
2015-11-18 13:10:01 +00:00
GVAR(setVariablePublicArray) deleteAt (GVAR(setVariablePublicArray) find _x);
GVAR(setVariableNames) deleteAt (GVAR(setVariableNames) find _x);
2015-09-19 21:18:07 +00:00
};
2015-11-18 13:10:01 +00:00
nil
} count +GVAR(setVariablePublicArray);
2015-09-19 21:18:07 +00:00
if (GVAR(setVariablePublicArray) isEqualTo []) then {
[GVAR(setVariablePublicPFH)] call CBA_fnc_removePerFrameHandler;
GVAR(setVariablePublicPFH) = nil;
2015-02-12 12:23:38 +00:00
};
2015-09-19 21:18:07 +00:00
}, 0, []] call CBA_fnc_addPerFrameHandler;