Skip to content

Commit

Permalink
Add function to create UUIDs (#1459)
Browse files Browse the repository at this point in the history
  • Loading branch information
BaerMitUmlaut committed Jan 17, 2023
1 parent 4576509 commit 9db07db
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/common/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,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 ""

0 comments on commit 9db07db

Please sign in to comment.