From 9db07db9a6f1e14e92f79814fb491c51e9e6066d Mon Sep 17 00:00:00 2001 From: BaerMitUmlaut Date: Tue, 17 Jan 2023 13:24:46 +0100 Subject: [PATCH] Add function to create UUIDs (#1459) --- addons/common/CfgFunctions.hpp | 1 + addons/common/fnc_createUUID.sqf | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 addons/common/fnc_createUUID.sqf diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index 118b7ed60..17478a755 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -134,6 +134,7 @@ class CfgFunctions { PATHTO_FNC(waitAndExecute); PATHTO_FNC(waitUntilAndExecute); PATHTO_FNC(compileFinal); + PATHTO_FNC(createUUID); }; class Broken { diff --git a/addons/common/fnc_createUUID.sqf b/addons/common/fnc_createUUID.sqf new file mode 100644 index 000000000..919ba9234 --- /dev/null +++ b/addons/common/fnc_createUUID.sqf @@ -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 ""