ACE3/addons/common/functions/fnc_setVariablePublic.sqf

57 lines
1.7 KiB
Plaintext
Raw Normal View History

2015-02-12 12:23:38 +00:00
/*
2015-09-19 21:18:07 +00:00
* Author: commy2 and joko // Jonas
* 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>
* 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];
// Exit if in SP
if (!isMultiplayer) exitWith {};
2015-02-12 12:23:38 +00:00
2015-09-19 21:18:07 +00:00
private ["_idName", "_syncTime"];
2015-02-12 12:23:38 +00:00
_idName = format ["ACE_setVariablePublic_%1", _varName];
2015-09-19 21:18:07 +00:00
if (_idName in GVAR(setVariableNames)) exitWith {};
2015-02-12 14:56:57 +00:00
_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];
GVAR(setVariablePublicArray) deleteAt (GVAR(setVariablePublicArray) find _x);
GVAR(setVariableNames) deleteAt (GVAR(setVariableNames) find _x);
2015-09-19 21:18:07 +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;