diff --git a/fxmanifest.lua b/fxmanifest.lua index 2380b61..14cb87a 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -3,7 +3,7 @@ game 'gta5' lua54 'yes' author 'The Order of the Sacred Framework' description 'A bridge made for the community to use as a base for their own projects. This bridge will allow a single format to work with nearly all commonly used systems while still offering expandability.' -version '0.0.8' +version '0.0.9' shared_scripts { 'settings/sharedConfig.lua', @@ -42,7 +42,6 @@ client_scripts { 'modules/progressbars/**/client.lua', 'modules/clothing/**/client.lua', 'modules/weather/**/client.lua', - 'modules/points/*.lua', 'modules/math/*.lua', 'init.lua', } diff --git a/init.lua b/init.lua index c3d820d..73d7c35 100644 --- a/init.lua +++ b/init.lua @@ -24,25 +24,10 @@ Bridge.Table = Table Bridge.Math = Math Bridge.Clothing = Clothing Bridge.Progressbar = Progressbar -Bridge.Helper = Helper +Bridge.Utility = Utility +Bridge.Prints = Prints +Bridge.Table = Table --- Fill the bridge tables with player data. -function FillBridgeTables() - PlayerLoaded = true - PlayerIdentifier = Framework.GetPlayerIdentifier() - PlayerJobName, PlayerJobLabel, PlayerJobGradeName, PlayerJobGradeLevel = Framework.GetPlayerJob() -end - --- Clean the bridge tables. -function ClearClientSideVariables() - PlayerLoaded = false - PlayerIdentifier = nil - PlayerJobName = nil - PlayerJobLabel = nil - PlayerJobGradeName = nil - PlayerJobGradeLevel = nil - StoredOldClothing = {} -end CreateThread(function() for k, v in pairs(Bridge) do @@ -85,4 +70,23 @@ exports('RegisterCompatibility', RegisterCompatibility) exports('Bridge', function() return Bridge -end) \ No newline at end of file +end) + +if IsDuplicityVersion() then return end + +function FillBridgeTables() + PlayerLoaded = true + PlayerIdentifier = Framework.GetPlayerIdentifier() + PlayerJobName, PlayerJobLabel, PlayerJobGradeName, PlayerJobGradeLevel = Framework.GetPlayerJob() +end + +-- Clean the bridge tables. +function ClearClientSideVariables() + PlayerLoaded = false + PlayerIdentifier = nil + PlayerJobName = nil + PlayerJobLabel = nil + PlayerJobGradeName = nil + PlayerJobGradeLevel = nil + StoredOldClothing = {} +end \ No newline at end of file diff --git a/modules/dispatch/cd_dispatch/client.lua b/modules/dispatch/cd_dispatch/client.lua index 720ef72..4547a3d 100644 --- a/modules/dispatch/cd_dispatch/client.lua +++ b/modules/dispatch/cd_dispatch/client.lua @@ -4,7 +4,7 @@ Dispatch = {} Dispatch.SendAlert = function(data) local playerData = exports['cd_dispatch']:GetPlayerInfo() - local randomID = Bridge.Helper.RandomString() + local randomID = Utility.CreateUniqueId(nil, 14, nil) TriggerServerEvent('cd_dispatch:AddNotification', { job_table = data.job, coords = data.coords or playerData.coords, diff --git a/modules/points/point_register.lua b/modules/points/point_register.lua deleted file mode 100644 index cd0fb19..0000000 --- a/modules/points/point_register.lua +++ /dev/null @@ -1,37 +0,0 @@ -Points = {} -local ActivePoints = {} - -Points.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 = Ids.CreateUniqueId(nil, 5, nil) - ActivePoints[pointID] = enterZone - return enterZone, pointID -end - --- Function to retrieve the enterZone using pointID -Points.GetPointById = function(pointID) - return ActivePoints[pointID] -end - -Points.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 diff --git a/modules/utilities/client/object_Placer.lua b/modules/utilities/client/object_Placer.lua index 56ba43b..28a3d1e 100644 --- a/modules/utilities/client/object_Placer.lua +++ b/modules/utilities/client/object_Placer.lua @@ -1,3 +1,5 @@ +Utility = Utility or {} + local activePlacementProp = nil lib.locale() diff --git a/modules/utilities/client/native_utility.lua b/modules/utilities/client/utility.lua similarity index 87% rename from modules/utilities/client/native_utility.lua rename to modules/utilities/client/utility.lua index d1fdb6e..be462ec 100644 --- a/modules/utilities/client/native_utility.lua +++ b/modules/utilities/client/utility.lua @@ -1,6 +1,7 @@ -Utility = {} +Utility = Utility or {} local blipIDs = {} local spawnedPeds = {} +local ActivePoints = {} lib.locale() Utility.CreateVehicle = function(model, coords, heading, networked) @@ -228,6 +229,42 @@ Utility.GetClosestPlayer = function(coords, distanceScope, includeMe) 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 diff --git a/modules/utilities/shared/prints.lua b/modules/utilities/shared/prints.lua new file mode 100644 index 0000000..96e78c7 --- /dev/null +++ b/modules/utilities/shared/prints.lua @@ -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 \ No newline at end of file diff --git a/modules/utilities/shared/uniqueids.lua b/modules/utilities/shared/uniqueids.lua new file mode 100644 index 0000000..f950b30 --- /dev/null +++ b/modules/utilities/shared/uniqueids.lua @@ -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 \ No newline at end of file