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 ""