Skip to content

Commit 9db07db

Browse files
Add function to create UUIDs (CBATeam#1459)
1 parent 4576509 commit 9db07db

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

addons/common/CfgFunctions.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class CfgFunctions {
134134
PATHTO_FNC(waitAndExecute);
135135
PATHTO_FNC(waitUntilAndExecute);
136136
PATHTO_FNC(compileFinal);
137+
PATHTO_FNC(createUUID);
137138
};
138139

139140
class Broken {

addons/common/fnc_createUUID.sqf

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "script_component.hpp"
2+
/* ----------------------------------------------------------------------------
3+
Function: CBA_fnc_createUUID
4+
5+
Description:
6+
Creates a version 4 UUID (universally unique identifier).
7+
8+
Parameters:
9+
None
10+
11+
Returns:
12+
UUID [String]
13+
14+
Example:
15+
(begin example)
16+
private _uuid = call CBA_fnc_createUUID;
17+
(end)
18+
19+
Author:
20+
BaerMitUmlaut
21+
--------------------------------------------------------------------------- */
22+
SCRIPT(createUUID);
23+
24+
private _hexDigits = [
25+
"0", "1", "2", "3", "4", "5", "6", "7",
26+
"8", "9", "a", "b", "c", "d", "e", "f"
27+
];
28+
private _versionByte = "4";
29+
private _variantByte = selectRandom ["8", "9", "a", "b"];
30+
31+
private _uuid = [];
32+
for "_i" from 0 to 29 do {
33+
_uuid pushBack selectRandom _hexDigits;
34+
};
35+
36+
_uuid insert [8, ["-"]];
37+
_uuid insert [13, ["-", _versionByte]];
38+
_uuid insert [17, ["-", _variantByte]];
39+
_uuid insert [22, ["-"]];
40+
_uuid joinString ""

0 commit comments

Comments
 (0)