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

Add function to create UUIDs #1459

Merged
merged 1 commit into from
Jan 17, 2023
Merged
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
1 change: 1 addition & 0 deletions addons/common/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class CfgFunctions {
PATHTO_FNC(waitAndExecute);
PATHTO_FNC(waitUntilAndExecute);
PATHTO_FNC(compileFinal);
PATHTO_FNC(createUUID);
};

class Broken {
Expand Down
40 changes: 40 additions & 0 deletions addons/common/fnc_createUUID.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_createUUID

Description:
Creates a version 4 UUID (universally unique identifier).

Parameters:
None

Returns:
UUID [String]

Example:
(begin example)
private _uuid = call CBA_fnc_createUUID;
(end)

Author:
BaerMitUmlaut
--------------------------------------------------------------------------- */
SCRIPT(createUUID);

private _hexDigits = [
"0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "a", "b", "c", "d", "e", "f"
];
private _versionByte = "4";
private _variantByte = selectRandom ["8", "9", "a", "b"];

private _uuid = [];
for "_i" from 0 to 29 do {
_uuid pushBack selectRandom _hexDigits;
};

_uuid insert [8, ["-"]];
_uuid insert [13, ["-", _versionByte]];
_uuid insert [17, ["-", _variantByte]];
_uuid insert [22, ["-"]];
_uuid joinString ""