casing, RegisterModule adjustments, remove duplicate utilities table

This commit is contained in:
MrNewb committed 2025-01-10 16:36:20 -05:00
1 parent 515d4412b1
commit 733271562d
75 files changed
+1739 -14

No files matched your search

+109
View File
@@ -0,0 +1,109 @@
Utility = Utility or {}
local activePlacementProp = nil
lib.locale()
-- Object placer --
local placementText = {
locale('place_object'),
locale('place_object_place'),
locale('place_object_cancel'),
locale('place_object_scroll_up'),
locale('place_object_scroll_down')
}
local function finishPlacing()
Bridge.notify.HideHelpText()
if activePlacementProp == nil then return end
DeleteObject(activePlacementProp)
activePlacementProp = nil
end
Utility.PlaceObject = function(object, distance, snapToGround, allowedMats, offset)
if activePlacementProp then return end
if not object then Prints.Error('no_prop_defined') end
local propObject = type(object) == 'string' and joaat(object) or object
local heading = 0.0
local checkDist = distance or 10.0
Utility.LoadModel(propObject)
activePlacementProp = CreateObject(propObject, 1.0, 1.0, 1.0, false, true, true)
SetModelAsNoLongerNeeded(propObject)
SetEntityAlpha(activePlacementProp, 150, false)
SetEntityCollision(activePlacementProp, false, false)
SetEntityInvincible(activePlacementProp, true)
FreezeEntityPosition(activePlacementProp, true)
Bridge.notify.ShowHelpText(type(placementText) == 'table' and table.concat(placementText) or placementText, {
position = "left-center",
})
local outLine = false
while activePlacementProp do
--local hit, _, coords, _, materialHash = lib.raycast.fromCamera(1, 4)
--local hit, _, coords, _, materialHash = lib.raycast.fromCamera(1, 4, nil)
local hit, _, coords, _, materialHash = lib.raycast.fromCamera(1, 4)
if hit then
if offset then
coords += offset
end
SetEntityCoords(activePlacementProp, coords.x, coords.y, coords.z, false, false, false, false)
local distCheck = #(GetEntityCoords(cache.ped) - coords)
SetEntityHeading(activePlacementProp, heading)
if snapToGround then
PlaceObjectOnGroundProperly(activePlacementProp)
end
if outLine then
outLine = false
SetEntityDrawOutline(activePlacementProp, false)
end
if (allowedMats and not allowedMats[materialHash]) or distCheck >= checkDist then
if not outLine then
outLine = true
SetEntityDrawOutline(activePlacementProp, true)
end
end
if IsControlJustReleased(0, 38) then
if not outLine and (not allowedMats or allowedMats[materialHash]) and distCheck < checkDist then
finishPlacing()
return coords, heading
end
end
if IsControlJustReleased(0, 73) then
finishPlacing()
return nil, nil
end
if IsControlJustReleased(0, 14) then
heading = heading + 5
if heading > 360 then heading = 0.0 end
end
if IsControlJustReleased(0, 15) then
heading = heading - 5
if heading < 0 then
heading = 360.0
end
end
end
end
end
Utility.StopPlacing = function()
if not activePlacementProp then return end
finishPlacing()
end
-- This is derrived and slightly altered from its creator and licensed under GPL-3.0 license Author:Zoo, the original is located here https://github.com/Renewed-Scripts/Renewed-Lib/tree/main
+288
View File
@@ -0,0 +1,288 @@
Utility = Utility or {}
local blipIDs = {}
local spawnedPeds = {}
local ActivePoints = {}
lib.locale()
Utility.CreateVehicle = function(model, coords, heading, networked)
if networked == nil then networked = true end
Utility.LoadModel(model)
if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end
local vehicle = CreateVehicle(model, coords.x, coords.y, coords.z, heading, networked, false)
SetVehicleHasBeenOwnedByPlayer(vehicle, true)
SetVehicleNeedsToBeHotwired(vehicle, false)
SetModelAsNoLongerNeeded(model)
SetVehRadioStation(vehicle, "OFF")
return vehicle, { networkid = NetworkGetNetworkIdFromEntity(vehicle) or 0, coords = GetEntityCoords(vehicle), heading = GetEntityHeading(vehicle), }
end
Utility.StartBusySpinner = function(text)
AddTextEntry(text, text)
BeginTextCommandBusyString(text)
AddTextComponentSubstringPlayerName(text)
EndTextCommandBusyString(0)
end
Utility.StopBusySpinner = function()
if BusyspinnerIsOn() then BusyspinnerOff() end
end
Utility.CreateProp = function(model, coords, heading, networked)
if networked == nil then networked = true end
Utility.LoadModel(model)
if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end
local propEntity = CreateObject(model, coords.x, coords.y, coords.z, networked, false, false)
SetEntityHeading(propEntity, heading)
SetModelAsNoLongerNeeded(model)
return propEntity
end
Utility.CreateBlip = function(coords, sprite, color, scale, label, shortRange)
local blip = AddBlipForCoord(coords.x, coords.y, coords.z)
SetBlipSprite(blip, sprite or 8)
SetBlipColour(blip, color or 3)
SetBlipScale(blip, scale or 0.8)
SetBlipAsShortRange(blip, shortRange)
AddTextEntry(label, label)
BeginTextCommandSetBlipName(label)
EndTextCommandSetBlipName(blip)
table.insert(blipIDs, blip)
return blip
end
Utility.RemoveBlip = function(blip)
local success = false
for i, storedBlip in ipairs(blipIDs) do
if storedBlip == blip then
RemoveBlip(blip)
table.remove(blipIDs, i)
success = true
break
end
end
return success
end
Utility.LoadModel = function(model)
if type(model) ~= 'number' then model = joaat(model) end
if not IsModelValid(model) and not IsModelInCdimage(model) then return false end
RequestModel(model)
local count = 0
while not HasModelLoaded(model) and count < 30000 do
Wait(0)
count = count + 1
end
return HasModelLoaded(model)
end
Utility.CreatePed = function(model, coords, heading, networked, clothing)
if networked == nil then networked = true end
Utility.LoadModel(model)
if not HasModelLoaded(model) then return Prints.Error("Model Has Not Loaded") end
local spawnedEntity = CreatePed(0, model, coords.x, coords.y, coords.z, heading, networked, false)
if clothing then
for componentID, v in pairs(clothing) do
SetPedComponentVariation(spawnedEntity, componentID, v[1], v[2], 0)
end
end
FreezeEntityPosition(spawnedEntity, true)
SetEntityInvincible(spawnedEntity, true)
SetBlockingOfNonTemporaryEvents(spawnedEntity, true)
SetModelAsNoLongerNeeded(model)
table.insert(spawnedPeds, spawnedEntity)
return spawnedEntity
end
Utility.RemovePed = function(entity)
local success = false
DeleteEntity(entity)
for i, storedEntity in ipairs(spawnedPeds) do
if storedEntity == entity then
table.remove(spawnedPeds, i)
success = true
break
end
end
return success
end
Utility.NativeInputMenu = function(text, length)
local maxLength = Math.Clamp(length, 1, 50)
local menutText = text or 'enter text'
AddTextEntry(menutText, menutText)
DisplayOnscreenKeyboard(1, menutText, "", "", "", "", "", maxLength)
while(UpdateOnscreenKeyboard() == 0) do
DisableAllControlActions(0)
Wait(0)
end
if(GetOnscreenKeyboardResult()) then
local result = GetOnscreenKeyboardResult()
return result
end
return false
end
Utility.GetEntitySkinData = function(entity)
local skinData = {}
skinData.clothing = {}
for i = 0, 11 do
skinData.clothing[i] = {GetPedDrawableVariation(entity, i), GetPedTextureVariation(entity, i)}
end
return skinData
end
Utility.SetEntitySkinData = function(entity, skinData)
for i = 0, 11 do
SetPedComponentVariation(entity, i, skinData.clothing[i][1], skinData.clothing[i][2], 0)
end
return true
end
Utility.NativeAlert = function(data)
local message = data.message or 'No message provided'
local coords = data.coords or GetEntityCoords(cache.ped)
local job = data.job
local scale = data.scale or 0.8
local sprite = data.sprite or 1
TriggerServerEvent('community_bridge:server:alert', {message = message, coords = coords, job = job, scale = scale, sprite = sprite})
end
Utility.ReloadSkin = function()
local skinData = Utility.GetEntitySkinData(cache.ped)
Utility.SetEntitySkinData(cache.ped, skinData)
for _, props in pairs(GetGamePool("CObject")) do
if IsEntityAttachedToEntity(cache.ped, props) then
SetEntityAsMissionEntity(props, true, true)
DeleteObject(props)
DeleteEntity(props)
end
end
return true
end
Utility.RestoreAppearance = function(data)
return Utility.SetEntitySkinData(cache.ped, data)
end
Utility.HelpText = function(text, duration)
AddTextEntry(text, text)
BeginTextCommandDisplayHelp(text)
EndTextCommandDisplayHelp(0, false, true, duration or 5000)
end
Utility.NotifyText = function(text)
AddTextEntry(text, text)
SetNotificationTextEntry(text)
DrawNotification(false, true)
end
Utility.TeleportPlayer = function(coords, conditionFunction, afterTeleportFunction)
if conditionFunction ~= nil then
if not conditionFunction() then
return
end
end
DoScreenFadeOut(2500)
Wait(2500)
SetEntityCoords(cache.ped, coords.x, coords.y, coords.z, false, false, false, false)
if coords.w then
SetEntityHeading(cache.ped, coords.w)
end
FreezeEntityPosition(cache.ped, true)
local count = 0
while not HasCollisionLoadedAroundEntity(cache.ped) and count <= 30000 do
RequestCollisionAtCoord(coords.x, coords.y, coords.z)
Wait(0)
count = count + 1
end
FreezeEntityPosition(cache.ped, false)
DoScreenFadeIn(1000)
if afterTeleportFunction ~= nil then
afterTeleportFunction()
end
end
Utility.GetEntityHashFromModel = function(model)
if type(model) ~= 'number' then model = joaat(model) end
return model
end
Utility.GetClosestPlayer = function(coords, distanceScope, includeMe)
local players = GetActivePlayers()
local closestPlayer = 0
local selfPed = cache.ped
local selfCoords = coords or GetEntityCoords(cache.ped)
local closestDistance = distanceScope or 5
for _, player in ipairs(players) do
local playerPed = GetPlayerPed(player)
if includeMe or playerPed ~= selfPed then
local playerCoords = GetEntityCoords(playerPed)
local distance = #(selfCoords - playerCoords)
if closestDistance == -1 or distance < closestDistance then
closestPlayer = player
closestDistance = distance
end
end
end
return closestPlayer, closestDistance, GetPlayerServerId(closestPlayer)
end
-- register points
Utility.RegisterPoint = function(pointCoords, pointDistance, pointOnEnter, pointOnExit)
local enterZone = lib.points.new({
coords = pointCoords,
distance = pointDistance,
onEnter = function(self)
pointOnEnter(self)
end,
onExit = function(self)
pointOnExit(self)
end,
})
local pointID = Utility.CreateUniqueId(nil, 5, nil)
ActivePoints[pointID] = enterZone
return enterZone, pointID
end
-- Function to retrieve the enterZone using pointID
Utility.GetPointById = function(pointID)
return ActivePoints[pointID]
end
Utility.RemovePoint = function(pointID)
local point = ActivePoints[pointID]
if point then
--print("Removing point with ID " .. pointID)
point:remove() -- Call the remove method on the point (ensure this method stops all event listeners)
ActivePoints[pointID] = nil -- Remove from ActivePoints table
--print("Point removed successfully.")
return true
else
--print("Point with ID " .. pointID .. " not found.")
return false
end
end
AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then
for _, blip in pairs(blipIDs) do
if DoesBlipExist(blip.id) then
RemoveBlip(blip.id)
end
end
for _, ped in pairs(spawnedPeds) do
if DoesEntityExist(ped) then
DeleteEntity(ped)
end
end
end
end)
RegisterNetEvent('community_bridge:client:alert', function(data)
local blip = Utility.CreateBlip(data.coords, data.sprite, 3, data.scale, data.message, true)
SetTimeout(40000, function()
Utility.RemoveBlip(blip)
end)
end)
+38
View File
@@ -0,0 +1,38 @@
Utility = Utility or {}
function Utility.VersionChecker(repoPath)
local resource = repoPath:match("([^/]+)$")
if not resource then return Prints.Error('^1Invalid repository format. Expected format: "username/reponame"^0') end
local version = GetResourceMetadata(resource, "version", 0)
if not version then return Prints.Error(('^1Unable to determine current resource version for %s ^0'):format(resource)) end
version = version:match('%d+%.%d+%.%d+')
if not version then return Prints.Error(('^1Invalid version format for %s ^0'):format(resource)) end
local username, reponame = repoPath:match("([^/]+)/([^/]+)")
if not username or not reponame then return Prints.Error('^1Invalid repository format. Expected format: "username/reponame"^0') end
PerformHttpRequest(('https://api.github.com/repos/%s/%s/releases/latest'):format(username, reponame), function(status, response)
local failure = ('^1Unable locate github repo for resource %s ^0'):format(resource)
if status ~= 200 then return Prints.Error(failure) end
response = json.decode(response)
if response.prerelease then return Prints.Error(failure) end
local latest = response.tag_name:match('%d+%.%d+%.%d+')
if not latest then return Prints.Error(failure) end
if latest == version then return print(('^2 %s is on the latest version.^0'):format(resource)) end
local currentVersion, latestVersion = version:gsub('%D', ''), latest:gsub('%D', '')
if currentVersion < latestVersion then
return print(('^1An update is available for %s (current version: %s)\r\n - ^5Please download the latest version from the GitHub release page.^7\r\n%s'):format(resource, version, response.html_url))
end
end, 'GET')
end
AddEventHandler('onResourceStart', function(resourceName)
if GetCurrentResourceName() ~= resourceName then return end
Utility.VersionChecker("The-Order-Of-The-Sacred-Framework/community_bridge")
end)
+50
View File
@@ -0,0 +1,50 @@
Utility = Utility or {}
local WebhookURL = BridgeServerConfig.WebhookURL
local LogoForEmbed = BridgeServerConfig.WebhookImage
Utility.SendLog = function(src, message)
if not src or not message then return end
if BridgeServerConfig.LogSystem == "builtin" then
PerformHttpRequest(WebhookURL, function(err, text, headers) end, 'POST', json.encode(
{
username = "Community_Bridge's Logger",
avatar_url = 'https://cdn.discordapp.com/avatars/299410129982455808/31ce635662206e8bd0132c34ce9ce683?size=1024',
embeds = {
{
color = "15769093",
title = GetCurrentResourceName(),
url = 'https://discord.gg/wsPAK5mEPg',
--description = message,
thumbnail = { url = LogoForEmbed },
fields = {
{
name = '**Player ID**',
value = src,
inline = true,
},
{
name = '**Player Identifier**',
value = Framework.GetPlayerIdentifier(src),
inline = true,
},
{
name = 'Log Message',
value = "```"..message.."```",
inline = false,
},
},
timestamp = os.date('!%Y-%m-%dT%H:%M:%S'),
footer = {
text = "Community_Bridge | "..GetCurrentResourceName(),
icon_url = 'https://cdn.discordapp.com/avatars/299410129982455808/31ce635662206e8bd0132c34ce9ce683?size=1024',
},
}
}
}), { ['Content-Type']= 'application/json' })
elseif BridgeServerConfig.LogSystem == "qb" then
return TriggerEvent('qb-log:server:CreateLog', GetCurrentResourceName(), GetCurrentResourceName(), 'green', message)
elseif BridgeServerConfig.LogSystem == "ox" then
return exports.ox_lib:logger(src, GetCurrentResourceName(), message)
end
end
+70
View File
@@ -0,0 +1,70 @@
Utility = Utility or {}
local lootTables = {}
Utility.RegisterLootTable = function(name, items)
local repackedTable = {}
for k, v in pairs(items) do
table.insert(repackedTable, {
name = k,
min = v.min,
max = v.max,
chance = v.chance,
tier = v.tier,
item = v.item,
metadata = v.metadata
})
end
lootTables[name] = repackedTable
return lootTables[name]
end
Utility.GetLootTable = function(name)
assert(name, "No Name Passed For Loot Table")
return lootTables[name] or {}
end
Utility.GetRandomItem = function(name, tier, randomNumber)
assert(name, "No Name Passed For Loot Table")
if tier == nil then tier = 1 end
local lootTable = lootTables[name] or {}
math.randomseed(GetGameTimer())
local chance = randomNumber or math.random(1, 100)
for _, v in pairs(lootTable) do
if v.chance <= chance and tier == v.tier then
return { item = v.item, metadata = v.metadata, count = math.random(v.min, v.max), tier = v.tier, chance = v.chance}
end
end
end
Utility.GetRandomItems = function(name, tier, randomNumber)
assert(name, "No Name Passed For Loot Table")
if tier == nil then tier = 1 end
local lootTable = Utility.GetLootTable(name)
math.randomseed(GetGameTimer())
local chance = randomNumber or math.random(1, 100)
local items = {}
for _, v in pairs(lootTable) do
if v.chance <= chance and tier == v.tier then
table.insert(items,{item = v.item, metadata = v.metadata, count = math.random(v.min, v.max), tier = v.tier, chance = v.chance})
end
end
return items
end
Utility.GetRandomItemsWithLimit = function(name, tier, randomNumber)
assert(name, "No Name Passed For Loot Table")
if tier == nil then tier = 1 end
local lootTable = Utility.GetLootTable(name)
math.randomseed(GetGameTimer())
local chance = randomNumber or math.random(1, 100)
local items = {}
for k = #lootTable, 1, -1 do
local v = lootTable[k]
if chance <= v.chance and tier == v.tier then
table.insert(items, {v.item, v.metadata, math.random(v.min, v.max), v.tier, v.chance})
table.remove(lootTable, k)
end
end
return items
end
@@ -0,0 +1,6 @@
RegisterServerEvent("community_bridge:server:alert", function(data)
local playersByJob = Framework.GetPlayersByJob(data.job)
for _, src in pairs(playersByJob) do
TriggerClientEvent("community_bridge:client:alert", src, data)
end
end)
+145
View File
@@ -0,0 +1,145 @@
Callbacks = {}
cbData = {}
Callback = Callback or {}
local resource = GetCurrentResourceName() or 'unknown'
local clientToServerName = resource .. ':server:CS:TriggerCallback'
local clientToServerBackToClientName = resource .. ':client:CSC:TriggerCallback'
local serverToClientName = resource .. ':client:SC:TriggerCallback'
local serverToClientBackToServerName = resource .. ':server:SCS:TriggerCallback'
if not IsDuplicityVersion() then goto client end
-- -- -- -- -- -- -- -- -- --
-- ▄▀▀ ██▀ █▀▄ █ █ ██▀ █▀▄
-- ▄█▀ █▄▄ █▀▄ ▀▄▀ █▄▄ █▀▄
-- -- -- -- -- -- -- -- -- --
-- client to server rebound
function Callback.Register(name, callback, all)
Callback[name] = {
callback = callback,
toAll = all
}
end
RegisterNetEvent(clientToServerName, function(name, ...)
local src = source
local data = Callback[name]
if not data then return end
local func = data.callback
if not func then return end
local toAll = data.toAll and -1 or src
local cb = function(...)
TriggerClientEvent(clientToServerBackToClientName, toAll, name, ...)
end
func(src, cb, ...)
end)
-----------------------------
-- server to client rebound
function Callback.Trigger(name, src, func, ...)
if src == nil then src = -1 end
local p = promise.new()
cbData[name] = {cb = func, p = p}
if type(src) == 'table' then
for i, d in pairs(src) do
TriggerClientEvent(serverToClientName, tonumber(d), name, ...)
end
return Citizen.Await(p)
end
TriggerClientEvent(serverToClientName, tonumber(src), name, ...)
return Citizen.Await(p)
end
RegisterNetEvent(serverToClientBackToServerName, function(name, ...)
print('Rebound')
local data = cbData[name]
if not data then return end
local func = data.cb
if not func then return end
data.p:resolve(func(...) or true)
cbData[name] = nil
end)
-----------------------------
exports('RegisterCallback', Callback.Register)
exports('TriggerCallback', Callback.Trigger)
-- -- -- -- -- -- -- -- -- --
-- ▄▀▀ █ █ ██▀ █▄ █ ▀█▀
-- ▀▄▄ █▄▄ █ █▄▄ █ ▀█ █
-- -- -- -- -- -- -- -- -- --
if IsDuplicityVersion() then return end
::client::
cbRebounds = {}
function Callback.Register(name, callback, all)
Callback[name] = {
callback = callback,
}
end
function Callback.RegisterRebound(name, callback)
cbRebounds[name] = callback
end
-- client to server rebound
function Callback.Trigger(name, func, ...)
local p = promise.new()
TriggerServerEvent(clientToServerName, name, ...)
cbData[name] = {cb = func, p = p}
CreateThread(function()
Wait(5000)
if cbData[name] then
cbData[name].p:resolve()
cbData[name] = nil
end
end)
print('Triggered')
return Citizen.Await(p)
end
RegisterNetEvent(clientToServerBackToClientName, function(name, ...)
local clientRebound = cbRebounds[name]
if clientRebound then
clientRebound(...)
end
local data = cbData[name]
if not data then return end
local func = data.cb
if not func then return end
data.p:resolve(func(...) or true)
cbData[name] = nil
end)
-----------------------------
-- server to client rebound
RegisterNetEvent(serverToClientName, function(name, ...)
local data = Callback[name]
if not data then return end
local func = data.callback
if not func then return end
local cb = function(...)
TriggerServerEvent(serverToClientBackToServerName, name, ...)
end
func(cb, ...)
end)
-----------------------------
exports('RegisterCallback', Callback.Register)
exports('RegisterRebound', Callback.RegisterRebound)
exports('TriggerCallback', Callback.Trigger)
+24
View File
@@ -0,0 +1,24 @@
Prints = Prints or {}
local function printMessage(level, color, message)
if type(message) == 'table' then
message = json.encode(message)
end
print(color .. '[' .. level .. ']:', message)
end
Prints.Info = function(message)
printMessage('INFO', '^5', message)
end
Prints.Warn = function(message)
printMessage('WARN', '^3', message)
end
Prints.Error = function(message)
printMessage('ERROR', '^1', message)
end
Prints.Debug = function(message)
printMessage('DEBUG', '^2', message)
end
+108
View File
@@ -0,0 +1,108 @@
Table = {}
Table.CheckPopulated = function(tbl)
if #tbl == 0 then
for _, _ in pairs(tbl) do
return true
end
return false
end
return true
end
Table.DeepClone = function(tbl, out, omit)
if type(tbl) ~= "table" then return tbl end
local new = out or {}
omit = omit or {}
for key, data in pairs(tbl) do
if not omit[key] then
if type(data) == "table" then
new[key] = Table.DeepClone(data)
else
new[key] = data
end
end
end
return new
end
Table.TableContains = function(tbl, search, nested)
for _, v in pairs(tbl) do
if nested and type(v) == "table" then
return Table.TableContains(v, search)
elseif v == search then
return true, v
end
end
return false
end
Table.TableContainsKey = function(tbl, search)
for k, _ in pairs(tbl) do
if k == search then
return true, k
end
end
return false
end
Table.GetClosest = function(coords, tbl)
local closestPoint = nil
local dist = math.huge
for k, v in pairs(tbl) do
local c = v.coords
local d = c and #(coords - c)
if d < dist then
dist = d
closestPoint = v
end
end
return closestPoint
end
Table.FindFirstUnoccupiedSlot = function(tbl)
local occupiedSlots = {}
for _, v in pairs(tbl) do
occupiedSlots[v.slot] = true
end
for i = 1, BridgeServerConfig.MaxInventorySlots do
if not occupiedSlots[i] then
return i
end
end
return nil
end
Table.Append = function(tbl1, tbl2)
for _, v in pairs(tbl2) do
table.insert(tbl1, v)
end
return tbl1
end
Table.Split = function(tbl, size)
local new1 = {}
local new2 = {}
size = size or math.floor(#tbl / 2)
if size > #tbl then
assert(false, "Size is greater than the length of the table.")
end
for i = 1, size do
table.insert(new1, tbl[i])
end
for i = size + 1, #tbl do
table.insert(new2, tbl[i])
end
return new1, new2
end
Table.Shuffle = function(tbl)
for i = #tbl, 2, -1 do
local j = math.random(i)
tbl[i], tbl[j] = tbl[j], tbl[i]
end
return tbl
end
return Table
+25
View File
@@ -0,0 +1,25 @@
Utility = Utility or {}
-- for unique ids
Utility.CreateUniqueId = function(tbl, len, pattern) -- both optional
tbl = tbl or {} -- table to check uniqueness. Ids to check against must be the key to the tables value
len = len or 8
local id = ""
for i = 1, len do
local char = ""
if pattern then
char = pattern:sub(math.random(1, #pattern), math.random(1, #pattern))
else
char = math.random(1, 2) == 1 and string.char(math.random(65, 90)) or math.random(0, 9) -- CAP letter and number
end
id = id .. char
end
if tbl[id] then
return Utility.CreateUniqueId(tbl, len, pattern)
end
return id
end
Utility.RandomString = function()
return Utility.CreateUniqueId(nil, 14, nil)
end