Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common - Synced Lists Functions #10764

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions addons/common/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ PREP(swayLoop);
PREP(switchAttachmentMode);
PREP(switchPersistentLaser);
PREP(switchToGroupSide);
PREP(syncedListGet);
PREP(syncedListPush);
PREP(throttledPublicVariable);
PREP(toBin);
PREP(toBitmask);
Expand Down
33 changes: 33 additions & 0 deletions addons/common/functions/fnc_syncedListGet.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "..\script_component.hpp"
/*
* Author: PabstMirror
* Pushes a element to a synced list (broken into buckets to avoid re-pushing the same data on each update)
*
* Arguments:
* 0: Namespace <OBJECT><NAMESPACE>
* 1: Var name <STRING>
* 2: Max Bucket Size <NUMBER> (default: 10)
*
* Return Value:
* None
*
* Example:
* [player, "var"] call ace_common_fnc_syncedListGet
*
* Public: No
*/

params ["_namespace", "_var", ["_bucketMax", 10, [0]]];

private _total = [];
private _index = 0;
while {
private _fullVar = format ["%1_%2", _var, _index];
private _bucket = _namespace getVariable [_fullVar, []];
_total append _bucket;
_bucket isNotEqualTo []
} do {
_index = _index + 1;
};

_total
34 changes: 34 additions & 0 deletions addons/common/functions/fnc_syncedListPush.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "..\script_component.hpp"
/*
* Author: PabstMirror
* Gets a synced list (broken into buckets to avoid re-pushing the same data on each update)
*
* Arguments:
* 0: Namespace <OBJECT><NAMESPACE>
* 1: Var name <STRING>
* 2: Element <ANY>
* 3: Max Bucket Size <NUMBER> (default: 10)
*
* Return Value:
* None
*
* Example:
* [player, "var", "x"] call ace_common_fnc_syncedListPush
*
* Public: No
*/
params ["_namespace", "_var", "_line", ["_bucketMax", 10, [0]]];

private _fullVar = "";
private _bucket = [];
private _index = 0;
while {
_fullVar = format ["%1_%2", _var, _index];
_bucket = _namespace getVariable [_fullVar, []];
(count _bucket) >= _bucketMax
} do {
_index = _index + 1;
};

_bucket pushBack _var;
_namespace setVariable [_fullVar, _bucket, true];