From 718214d1359297f8739154f2a0bf6745706fa855 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Wed, 20 Aug 2025 16:59:04 -0400 Subject: [PATCH 01/62] This is busted, should be removed. Should be removed as not working for external resources. It will work in the bridge itself but could lead to bloat/misuse and we shouldn't be responsible. --- lib/generators/server/ItemsBuilder.lua | 210 ++++++++++++------------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/lib/generators/server/ItemsBuilder.lua b/lib/generators/server/ItemsBuilder.lua index 48bb998..3c8f647 100644 --- a/lib/generators/server/ItemsBuilder.lua +++ b/lib/generators/server/ItemsBuilder.lua @@ -1,117 +1,117 @@ -ItemsBuilder = ItemsBuilder or {} +-- ItemsBuilder = ItemsBuilder or {} -ItemsBuilder = {} +-- ItemsBuilder = {} ----This will generate the items in the formats of qb_core, qb_core_old and ox_inventory. It will then build a lua file in the generateditems folder of the community_bridge. ----@param invoking string ----@param itemsTable table -ItemsBuilder.Generate = function(invoking, outputPrefix, itemsTable, useQB) - if not itemsTable then return end - invoking = invoking or GetInvokingResource() or GetCurrentResourceName() or "community_bridge" +-- ---This will generate the items in the formats of qb_core, qb_core_old and ox_inventory. It will then build a lua file in the generateditems folder of the community_bridge. +-- ---@param invoking string +-- ---@param itemsTable table +-- ItemsBuilder.Generate = function(invoking, outputPrefix, itemsTable, useQB) +-- if not itemsTable then return end +-- invoking = invoking or GetInvokingResource() or GetCurrentResourceName() or "community_bridge" - local resourcePath = string.format("%s/%s/", GetResourcePath(invoking), outputPrefix or "generated_items") +-- local resourcePath = string.format("%s/%s/", GetResourcePath(invoking), outputPrefix or "generated_items") - -- remove any doubles slashes after initial double slash - -- resourcePath = resourcePath:gsub("//", "/") - -- check if directory exists - local folder = io.open(resourcePath, "r") - if not folder then - local createDirectoryCMD = string.format("if not exist \"%s\" mkdir \"%s\"", resourcePath, resourcePath) - local returned, err = io.popen(createDirectoryCMD) - if not returned then - print("🌮 Failed to create directory: ", err) - return - end - returned:close() - print("🌮 Created Directory: ", resourcePath) - else - folder:close() - end +-- -- remove any doubles slashes after initial double slash +-- -- resourcePath = resourcePath:gsub("//", "/") +-- -- check if directory exists +-- local folder = io.open(resourcePath, "r") +-- if not folder then +-- local createDirectoryCMD = string.format("if not exist \"%s\" mkdir \"%s\"", resourcePath, resourcePath) +-- local returned, err = io.popen(createDirectoryCMD) +-- if not returned then +-- print("🌮 Failed to create directory: ", err) +-- return +-- end +-- returned:close() +-- print("🌮 Created Directory: ", resourcePath) +-- else +-- folder:close() +-- end - local qbOld = {} - local qbNew = {} - local oxInventory = {} - if useQB then - for key, item in pairs(itemsTable) do - qbOld[key] = string.format( - "['%s'] = {name = '%s', label = '%s', weight = %s, type = 'item', image = '%s', unique = %s, useable = %s, shouldClose = %s, description = '%s'},", - key, key, item.label, item.weight, item.image or key .. 'png', item.unique, item.useable, item.shouldClose, item.description - ) - qbNew[key] = string.format( - "['%s'] = {['name'] = '%s', ['label'] = '%s', ['weight'] = %s, ['type'] = 'item',['image'] = '%s', ['unique'] = %s, ['useable'] = %s, ['shouldClose'] = %s, ['description'] = '%s'},", - key, key, item.label, item.weight, item.image or key .. 'png', item.unique, item.useable, item.shouldClose, item.description - ) - imagewithoutpng = item?.image and item.image:gsub(".png", "") - shouldRenderImage = imagewithoutpng and imagewithoutpng ~= key - oxInventory[key] = string.format( - [[ - ["%s"] = { - label = "%s", - description = "%s", - weight = %s, - stack = %s, - close = %s, - %s - }, ]], - key, item.label, item.description, item.weight, not item.unique, item.shouldClose, - shouldRenderImage and item.image and string.format([[client = { - image = '%s' - }]], item.image) or "" - ) - end +-- local qbOld = {} +-- local qbNew = {} +-- local oxInventory = {} +-- if useQB then +-- for key, item in pairs(itemsTable) do +-- qbOld[key] = string.format( +-- "['%s'] = {name = '%s', label = '%s', weight = %s, type = 'item', image = '%s', unique = %s, useable = %s, shouldClose = %s, description = '%s'},", +-- key, key, item.label, item.weight, item.image or key .. 'png', item.unique, item.useable, item.shouldClose, item.description +-- ) +-- qbNew[key] = string.format( +-- "['%s'] = {['name'] = '%s', ['label'] = '%s', ['weight'] = %s, ['type'] = 'item',['image'] = '%s', ['unique'] = %s, ['useable'] = %s, ['shouldClose'] = %s, ['description'] = '%s'},", +-- key, key, item.label, item.weight, item.image or key .. 'png', item.unique, item.useable, item.shouldClose, item.description +-- ) +-- imagewithoutpng = item?.image and item.image:gsub(".png", "") +-- shouldRenderImage = imagewithoutpng and imagewithoutpng ~= key +-- oxInventory[key] = string.format( +-- [[ +-- ["%s"] = { +-- label = "%s", +-- description = "%s", +-- weight = %s, +-- stack = %s, +-- close = %s, +-- %s +-- }, ]], +-- key, item.label, item.description, item.weight, not item.unique, item.shouldClose, +-- shouldRenderImage and item.image and string.format([[client = { +-- image = '%s' +-- }]], item.image) or "" +-- ) +-- end - else - for key, item in pairs(itemsTable) do - -- ['peanut_butter'] = {['name'] = 'peanut_butter',['label'] = 'Peanut Butter',['weight'] = 1000,['type'] = 'item',['image'] = 'peanut_butter.png',['unique'] = false,['useable'] = false,['shouldClose'] = true,['combinable'] = nil,['description'] = 'A cooking ingredient'}, +-- else +-- for key, item in pairs(itemsTable) do +-- -- ['peanut_butter'] = {['name'] = 'peanut_butter',['label'] = 'Peanut Butter',['weight'] = 1000,['type'] = 'item',['image'] = 'peanut_butter.png',['unique'] = false,['useable'] = false,['shouldClose'] = true,['combinable'] = nil,['description'] = 'A cooking ingredient'}, - qbOld[key] = string.format( - "['%s'] = {name = '%s', label = '%s', weight = %s, type = 'item', image = '%s', unique = %s, useable = %s, shouldClose = %s, description = '%s'},", - key, key, item.label, item.weight, item?.client?.image or key .. 'png', not item.stack, true, item.close, item.description - ) - qbNew[key] = string.format( - "['%s'] = {['name'] = '%s', ['label'] = '%s', ['weight'] = %s, ['type'] = 'item', ['image'] = '%s', ['unique'] = %s, ['useable'] = %s, ['shouldClose'] = %s, ['description'] = '%s'},", - key, key, item.label, item.weight, item?.client?.image or key .. 'png', not item.stack, true, item.close, item.description - ) - imagewithoutpng = item?.client?.image and item.client.image:gsub(".png", "") - shouldRenderImage = imagewithoutpng and imagewithoutpng ~= key - oxInventory[key] = string.format( - [[ - ["%s"] = { - label = "%s", - description = "%s", - weight = %s, - stack = %s, - close = %s, - %s - }, ]], - key, item.label, item.description, item.weight, item.stack, item.close, - shouldRenderImage and item?.client?.image and string.format( [[client = { - image = '%s' - }]], item.client.image) or "" - ) - end - end +-- qbOld[key] = string.format( +-- "['%s'] = {name = '%s', label = '%s', weight = %s, type = 'item', image = '%s', unique = %s, useable = %s, shouldClose = %s, description = '%s'},", +-- key, key, item.label, item.weight, item?.client?.image or key .. 'png', not item.stack, true, item.close, item.description +-- ) +-- qbNew[key] = string.format( +-- "['%s'] = {['name'] = '%s', ['label'] = '%s', ['weight'] = %s, ['type'] = 'item', ['image'] = '%s', ['unique'] = %s, ['useable'] = %s, ['shouldClose'] = %s, ['description'] = '%s'},", +-- key, key, item.label, item.weight, item?.client?.image or key .. 'png', not item.stack, true, item.close, item.description +-- ) +-- imagewithoutpng = item?.client?.image and item.client.image:gsub(".png", "") +-- shouldRenderImage = imagewithoutpng and imagewithoutpng ~= key +-- oxInventory[key] = string.format( +-- [[ +-- ["%s"] = { +-- label = "%s", +-- description = "%s", +-- weight = %s, +-- stack = %s, +-- close = %s, +-- %s +-- }, ]], +-- key, item.label, item.description, item.weight, item.stack, item.close, +-- shouldRenderImage and item?.client?.image and string.format( [[client = { +-- image = '%s' +-- }]], item.client.image) or "" +-- ) +-- end +-- end - local function write(fileName, content) - local filePath = resourcePath .. fileName - local file = io.open(filePath, "w") - if file then - for key, value in pairs(content) do - file:write(string.format("%s\n", value)) - end - file:close() - print("🌮 Items File Created: " .. filePath) - else - print("🌮 Something Broke for: " .. filePath) - end - end +-- local function write(fileName, content) +-- local filePath = resourcePath .. fileName +-- local file = io.open(filePath, "w") +-- if file then +-- for key, value in pairs(content) do +-- file:write(string.format("%s\n", value)) +-- end +-- file:close() +-- print("🌮 Items File Created: " .. filePath) +-- else +-- print("🌮 Something Broke for: " .. filePath) +-- end +-- end - write(invoking.."(".."qb_core_old).lua", qbOld) - write(invoking.."(".."qb_core_new).lua", qbNew) - write(invoking.."(".."ox_inventory).lua", oxInventory) -end +-- write(invoking.."(".."qb_core_old).lua", qbOld) +-- write(invoking.."(".."qb_core_new).lua", qbNew) +-- write(invoking.."(".."ox_inventory).lua", oxInventory) +-- end -exports('ItemsBuilder', ItemsBuilder) -return ItemsBuilder \ No newline at end of file +-- exports('ItemsBuilder', ItemsBuilder) +-- return ItemsBuilder \ No newline at end of file From 3289711297a3bf14a57a617ecda130bdc98d94b4 Mon Sep 17 00:00:00 2001 From: XenoS-ITA Date: Thu, 21 Aug 2025 00:34:00 +0200 Subject: [PATCH 02/62] refactor(fuel): more consistency, now SetFuel doesnt return and every SetFuel as type, that will be used only by ti_fuel --- modules/fuel/_default/client.lua | 20 +++++++++++--------- modules/fuel/bigDaddy-Fuel/client.lua | 18 ++++++++++-------- modules/fuel/cdn-fuel/client.lua | 20 +++++++++++--------- modules/fuel/esx-sna-fuel/client.lua | 18 ++++++++++-------- modules/fuel/lc_fuel/client.lua | 18 ++++++++++-------- modules/fuel/legacyfuel/client.lua | 18 ++++++++++-------- modules/fuel/okokGasStation/client.lua | 18 ++++++++++-------- modules/fuel/ox_fuel/client.lua | 21 +++++++++++---------- modules/fuel/ps-fuel/client.lua | 18 ++++++++++-------- modules/fuel/qb-fuel/client.lua | 18 ++++++++++-------- modules/fuel/qs-fuelstations/client.lua | 20 +++++++++++--------- modules/fuel/renewed-Fuel/client.lua | 18 ++++++++++-------- modules/fuel/ti_fuel/client.lua | 20 +++++++++++--------- modules/fuel/x-fuel/client.lua | 18 ++++++++++-------- 14 files changed, 145 insertions(+), 118 deletions(-) diff --git a/modules/fuel/_default/client.lua b/modules/fuel/_default/client.lua index 0e4e9c1..8430733 100644 --- a/modules/fuel/_default/client.lua +++ b/modules/fuel/_default/client.lua @@ -2,26 +2,28 @@ Fuel = Fuel or {} ----This will get the name of the Fuel being used (if a supported Fuel). +---Returns the name of the active fuel resource. +---If no supported resource is found, "default" will be returned. ---@return string Fuel.GetResourceName = function() return 'default' end ----This will get the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@return number fuel The fuel level of the vehicle. +---Returns the current fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@return number The vehicle fuel level. Fuel.GetFuel = function(vehicle) if not DoesEntityExist(vehicle) then return 0.0 end return GetVehicleFuelLevel(vehicle) end ----This will set the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@param fuel number The fuel level to set. +---Sets the fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@param fuel number The fuel level to assign. +---@param type? string The fuel type, used only in ti_fuel. (default: RON91) ---@return nil -Fuel.SetFuel = function(vehicle, fuel) +Fuel.SetFuel = function(vehicle, fuel, type) if not DoesEntityExist(vehicle) then return end - return SetVehicleFuelLevel(vehicle, fuel) + SetVehicleFuelLevel(vehicle, fuel) end return Fuel \ No newline at end of file diff --git a/modules/fuel/bigDaddy-Fuel/client.lua b/modules/fuel/bigDaddy-Fuel/client.lua index 941f529..56b1721 100644 --- a/modules/fuel/bigDaddy-Fuel/client.lua +++ b/modules/fuel/bigDaddy-Fuel/client.lua @@ -3,25 +3,27 @@ local resourceName = "BigDaddy-Fuel" if GetResourceState(resourceName) == 'missing' then return end Fuel = Fuel or {} ----This will get the name of the Fuel being used (if a supported Fuel). +---Returns the name of the active fuel resource. +---If no supported resource is found, "default" will be returned. ---@return string Fuel.GetResourceName = function() return resourceName end ----This will get the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@return number fuel The fuel level of the vehicle. +---Returns the current fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@return number The vehicle fuel level. Fuel.GetFuel = function(vehicle) if not DoesEntityExist(vehicle) then return 0.0 end return exports['BigDaddy-Fuel']:GetFuel(vehicle) end ----This will set the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@param fuel number The fuel level to set. +---Sets the fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@param fuel number The fuel level to assign. +---@param type? string The fuel type, used only in ti_fuel. (default: RON91) ---@return nil -Fuel.SetFuel = function(vehicle, fuel) +Fuel.SetFuel = function(vehicle, fuel, type) if not DoesEntityExist(vehicle) then return end exports['BigDaddy-Fuel']:SetFuel(vehicle, fuel) end diff --git a/modules/fuel/cdn-fuel/client.lua b/modules/fuel/cdn-fuel/client.lua index c94ead0..c4fd02f 100644 --- a/modules/fuel/cdn-fuel/client.lua +++ b/modules/fuel/cdn-fuel/client.lua @@ -3,27 +3,29 @@ local resourceName = "cdn-fuel" if GetResourceState(resourceName) == 'missing' then return end Fuel = Fuel or {} ----This will get the name of the Fuel being used (if a supported Fuel). +---Returns the name of the active fuel resource. +---If no supported resource is found, "default" will be returned. ---@return string Fuel.GetResourceName = function() return resourceName end ----This will get the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@return number fuel The fuel level of the vehicle. +---Returns the current fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@return number The vehicle fuel level. Fuel.GetFuel = function(vehicle) if not DoesEntityExist(vehicle) then return 0.0 end return exports['cdn-fuel']:GetFuel(vehicle) end ----This will set the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@param fuel number The fuel level to set. +---Sets the fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@param fuel number The fuel level to assign. +---@param type? string The fuel type, used only in ti_fuel. (default: RON91) ---@return nil -Fuel.SetFuel = function(vehicle, fuel) +Fuel.SetFuel = function(vehicle, fuel, type) if not DoesEntityExist(vehicle) then return end - return exports['cdn-fuel']:SetFuel(vehicle, fuel) + exports['cdn-fuel']:SetFuel(vehicle, fuel) end return Fuel \ No newline at end of file diff --git a/modules/fuel/esx-sna-fuel/client.lua b/modules/fuel/esx-sna-fuel/client.lua index 8205284..87eefe7 100644 --- a/modules/fuel/esx-sna-fuel/client.lua +++ b/modules/fuel/esx-sna-fuel/client.lua @@ -3,25 +3,27 @@ local resourceName = "esx-sna-fuel" if GetResourceState(resourceName) == 'missing' then return end Fuel = Fuel or {} ----This will get the name of the Fuel being used (if a supported Fuel). +---Returns the name of the active fuel resource. +---If no supported resource is found, "default" will be returned. ---@return string Fuel.GetResourceName = function() return resourceName end ----This will get the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@return number fuel The fuel level of the vehicle. +---Returns the current fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@return number The vehicle fuel level. Fuel.GetFuel = function(vehicle) if not DoesEntityExist(vehicle) then return 0.0 end return exports['esx-sna-fuel']:GetFuel(vehicle) end ----This will set the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@param fuel number The fuel level to set. +---Sets the fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@param fuel number The fuel level to assign. +---@param type? string The fuel type, used only in ti_fuel. (default: RON91) ---@return nil -Fuel.SetFuel = function(vehicle, fuel) +Fuel.SetFuel = function(vehicle, fuel, type) if not DoesEntityExist(vehicle) then return end exports['esx-sna-fuel']:SetFuel(vehicle, fuel) end diff --git a/modules/fuel/lc_fuel/client.lua b/modules/fuel/lc_fuel/client.lua index 21b03a3..7471143 100644 --- a/modules/fuel/lc_fuel/client.lua +++ b/modules/fuel/lc_fuel/client.lua @@ -3,27 +3,29 @@ local resourceName = "lc_fuel" if GetResourceState(resourceName) == 'missing' then return end Fuel = Fuel or {} ----This will get the name of the Fuel being used (if a supported Fuel). +---Returns the name of the active fuel resource. +---If no supported resource is found, "default" will be returned. ---@return string Fuel.GetResourceName = function() return resourceName end ----This will get the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@return number fuel The fuel level of the vehicle. +---Returns the current fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@return number The vehicle fuel level. Fuel.GetFuel = function(vehicle) if not DoesEntityExist(vehicle) then return 0.0 end return exports["lc_fuel"]:GetFuel(vehicle) end ----This will set the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@param fuel number The fuel level to set. +---Sets the fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@param fuel number The fuel level to assign. +---@param type? string The fuel type, used only in ti_fuel. (default: RON91) ---@return nil Fuel.SetFuel = function(vehicle, fuel, type) if not DoesEntityExist(vehicle) then return end - return exports["lc_fuel"]:SetFuel(vehicle, fuel) + exports["lc_fuel"]:SetFuel(vehicle, fuel) end return Fuel \ No newline at end of file diff --git a/modules/fuel/legacyfuel/client.lua b/modules/fuel/legacyfuel/client.lua index 273f17d..49a875c 100644 --- a/modules/fuel/legacyfuel/client.lua +++ b/modules/fuel/legacyfuel/client.lua @@ -4,27 +4,29 @@ if GetResourceState(resourceName) == 'missing' then return end if GetResourceState("qb-fuel") == 'started' then return end Fuel = Fuel or {} ----This will get the name of the Fuel being used (if a supported Fuel). +---Returns the name of the active fuel resource. +---If no supported resource is found, "default" will be returned. ---@return string Fuel.GetResourceName = function() return resourceName end ----This will get the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@return number fuel The fuel level of the vehicle. +---Returns the current fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@return number The vehicle fuel level. Fuel.GetFuel = function(vehicle) if not DoesEntityExist(vehicle) then return 0.0 end return exports['LegacyFuel']:GetFuel(vehicle) end ----This will set the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@param fuel number The fuel level to set. +---Sets the fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@param fuel number The fuel level to assign. +---@param type? string The fuel type, used only in ti_fuel. (default: RON91) ---@return nil Fuel.SetFuel = function(vehicle, fuel, type) if not DoesEntityExist(vehicle) then return end - return exports['LegacyFuel']:SetFuel(vehicle, fuel) + exports['LegacyFuel']:SetFuel(vehicle, fuel) end return Fuel \ No newline at end of file diff --git a/modules/fuel/okokGasStation/client.lua b/modules/fuel/okokGasStation/client.lua index 0069a12..f71a6c5 100644 --- a/modules/fuel/okokGasStation/client.lua +++ b/modules/fuel/okokGasStation/client.lua @@ -3,27 +3,29 @@ local resourceName = "okokGasStation" if GetResourceState(resourceName) == 'missing' then return end Fuel = Fuel or {} ----This will get the name of the Fuel being used (if a supported Fuel). +---Returns the name of the active fuel resource. +---If no supported resource is found, "default" will be returned. ---@return string Fuel.GetResourceName = function() return resourceName end ----This will get the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@return number fuel The fuel level of the vehicle. +---Returns the current fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@return number The vehicle fuel level. Fuel.GetFuel = function(vehicle) if not DoesEntityExist(vehicle) then return 0.0 end return exports['okokGasStation']:GetFuel(vehicle) end ----This will set the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@param fuel number The fuel level to set. +---Sets the fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@param fuel number The fuel level to assign. +---@param type? string The fuel type, used only in ti_fuel. (default: RON91) ---@return nil Fuel.SetFuel = function(vehicle, fuel, type) if not DoesEntityExist(vehicle) then return end - return exports['okokGasStation']:SetFuel(vehicle, fuel) + exports['okokGasStation']:SetFuel(vehicle, fuel) end return Fuel \ No newline at end of file diff --git a/modules/fuel/ox_fuel/client.lua b/modules/fuel/ox_fuel/client.lua index 7008bab..c643b95 100644 --- a/modules/fuel/ox_fuel/client.lua +++ b/modules/fuel/ox_fuel/client.lua @@ -3,29 +3,30 @@ local resourceName = "ox_fuel" if GetResourceState(resourceName) == 'missing' then return end Fuel = Fuel or {} ----This will get the name of the Fuel being used (if a supported Fuel). +---Returns the name of the active fuel resource. +---If no supported resource is found, "default" will be returned. ---@return string Fuel.GetResourceName = function() return resourceName end ----This will get the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@return number fuel The fuel level of the vehicle. +---Returns the current fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@return number The vehicle fuel level. Fuel.GetFuel = function(vehicle) if not DoesEntityExist(vehicle) then return 0.0 end return Entity(vehicle).state.fuel end ----This will set the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@param fuel number The fuel level to set. +---Sets the fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@param fuel number The fuel level to assign. +---@param type? string The fuel type, used only in ti_fuel. (default: RON91) ---@return nil Fuel.SetFuel = function(vehicle, fuel, type) if not DoesEntityExist(vehicle) then return end - local currentFuel = Entity(vehicle).state.fuel - Entity(vehicle).state.fuel = currentFuel and currentFuel + fuel or fuel - return Entity(vehicle).state.fuel + local state = Entity(vehicle).state + state.fuel = (state.fuel or 0) + fuel end return Fuel \ No newline at end of file diff --git a/modules/fuel/ps-fuel/client.lua b/modules/fuel/ps-fuel/client.lua index f083538..520a6b6 100644 --- a/modules/fuel/ps-fuel/client.lua +++ b/modules/fuel/ps-fuel/client.lua @@ -3,27 +3,29 @@ local resourceName = "ps-fuel" if GetResourceState(resourceName) == 'missing' then return end Fuel = Fuel or {} ----This will get the name of the Fuel being used (if a supported Fuel). +---Returns the name of the active fuel resource. +---If no supported resource is found, "default" will be returned. ---@return string Fuel.GetResourceName = function() return resourceName end ----This will get the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@return number fuel The fuel level of the vehicle. +---Returns the current fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@return number The vehicle fuel level. Fuel.GetFuel = function(vehicle) if not DoesEntityExist(vehicle) then return 0.0 end return exports["ps-fuel"]:GetFuel(vehicle) end ----This will set the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@param fuel number The fuel level to set. +---Sets the fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@param fuel number The fuel level to assign. +---@param type? string The fuel type, used only in ti_fuel. (default: RON91) ---@return nil Fuel.SetFuel = function(vehicle, fuel, type) if not DoesEntityExist(vehicle) then return end - return exports["ps-fuel"]:SetFuel(vehicle, fuel) + exports["ps-fuel"]:SetFuel(vehicle, fuel) end return Fuel \ No newline at end of file diff --git a/modules/fuel/qb-fuel/client.lua b/modules/fuel/qb-fuel/client.lua index 581e7e6..8c57932 100644 --- a/modules/fuel/qb-fuel/client.lua +++ b/modules/fuel/qb-fuel/client.lua @@ -3,27 +3,29 @@ local resourceName = "qb-fuel" if GetResourceState(resourceName) == 'missing' then return end Fuel = Fuel or {} ----This will get the name of the Fuel being used (if a supported Fuel). +---Returns the name of the active fuel resource. +---If no supported resource is found, "default" will be returned. ---@return string Fuel.GetResourceName = function() return resourceName end ----This will get the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@return number fuel The fuel level of the vehicle. +---Returns the current fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@return number The vehicle fuel level. Fuel.GetFuel = function(vehicle) if not DoesEntityExist(vehicle) then return 0.0 end return exports['qb-fuel']:GetFuel(vehicle) end ----This will set the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@param fuel number The fuel level to set. +---Sets the fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@param fuel number The fuel level to assign. +---@param type? string The fuel type, used only in ti_fuel. (default: RON91) ---@return nil Fuel.SetFuel = function(vehicle, fuel, type) if not DoesEntityExist(vehicle) then return end - return exports['qb-fuel']:SetFuel(vehicle, fuel) + exports['qb-fuel']:SetFuel(vehicle, fuel) end return Fuel \ No newline at end of file diff --git a/modules/fuel/qs-fuelstations/client.lua b/modules/fuel/qs-fuelstations/client.lua index ec4a91e..84e9e93 100644 --- a/modules/fuel/qs-fuelstations/client.lua +++ b/modules/fuel/qs-fuelstations/client.lua @@ -3,27 +3,29 @@ local resourceName = "qs-fuelstations" if GetResourceState(resourceName) == 'missing' then return end Fuel = Fuel or {} ----This will get the name of the Fuel being used (if a supported Fuel). +---Returns the name of the active fuel resource. +---If no supported resource is found, "default" will be returned. ---@return string Fuel.GetResourceName = function() return resourceName end ----This will get the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@return number fuel The fuel level of the vehicle. +---Returns the current fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@return number The vehicle fuel level. Fuel.GetFuel = function(vehicle) if not DoesEntityExist(vehicle) then return 0.0 end return exports['qs-fuelstations']:GetFuel(vehicle) end ----This will set the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@param fuel number The fuel level to set. +---Sets the fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@param fuel number The fuel level to assign. +---@param type? string The fuel type, used only in ti_fuel. (default: RON91) ---@return nil -Fuel.SetFuel = function(vehicle, fuel) +Fuel.SetFuel = function(vehicle, fuel, type) if not DoesEntityExist(vehicle) then return end - return exports['qs-fuelstations']:SetFuel(vehicle, fuel) + exports['qs-fuelstations']:SetFuel(vehicle, fuel) end return Fuel \ No newline at end of file diff --git a/modules/fuel/renewed-Fuel/client.lua b/modules/fuel/renewed-Fuel/client.lua index 0408a99..c5c0b90 100644 --- a/modules/fuel/renewed-Fuel/client.lua +++ b/modules/fuel/renewed-Fuel/client.lua @@ -3,27 +3,29 @@ local resourceName = "Renewed-Fuel" if GetResourceState(resourceName) == 'missing' then return end Fuel = Fuel or {} ----This will get the name of the Fuel being used (if a supported Fuel). +---Returns the name of the active fuel resource. +---If no supported resource is found, "default" will be returned. ---@return string Fuel.GetResourceName = function() return resourceName end ----This will get the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@return number fuel The fuel level of the vehicle. +---Returns the current fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@return number The vehicle fuel level. Fuel.GetFuel = function(vehicle) if not DoesEntityExist(vehicle) then return 0.0 end return exports['Renewed-Fuel']:GetFuel(vehicle) end ----This will set the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@param fuel number The fuel level to set. +---Sets the fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@param fuel number The fuel level to assign. +---@param type? string The fuel type, used only in ti_fuel. (default: RON91) ---@return nil Fuel.SetFuel = function(vehicle, fuel, type) if not DoesEntityExist(vehicle) then return end - return exports['Renewed-Fuel']:SetFuel(vehicle, fuel) + exports['Renewed-Fuel']:SetFuel(vehicle, fuel) end return Fuel \ No newline at end of file diff --git a/modules/fuel/ti_fuel/client.lua b/modules/fuel/ti_fuel/client.lua index 7c9e77d..005a078 100644 --- a/modules/fuel/ti_fuel/client.lua +++ b/modules/fuel/ti_fuel/client.lua @@ -3,28 +3,30 @@ local resourceName = "ti_fuel" if GetResourceState(resourceName) == 'missing' then return end Fuel = Fuel or {} ----This will get the name of the Fuel being used (if a supported Fuel). +---Returns the name of the active fuel resource. +---If no supported resource is found, "default" will be returned. ---@return string Fuel.GetResourceName = function() return resourceName end ----This will get the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@return number fuel The fuel level of the vehicle. +---Returns the current fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@return number The vehicle fuel level. Fuel.GetFuel = function(vehicle) if not DoesEntityExist(vehicle) then return 0.0 end local level, _ = exports["ti_fuel"]:getFuel(vehicle) return level end ----This will set the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@param fuel number The fuel level to set. +---Sets the fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@param fuel number The fuel level to assign. +---@param type? string The fuel type, used only in ti_fuel. (default: RON91) ---@return nil -Fuel.SetFuel = function(vehicle, fuel) +Fuel.SetFuel = function(vehicle, fuel, type) if not DoesEntityExist(vehicle) then return end - return exports['ti_fuel']:setFuel(vehicle, fuel, "RON91") + exports['ti_fuel']:setFuel(vehicle, fuel, type or "RON91") end return Fuel \ No newline at end of file diff --git a/modules/fuel/x-fuel/client.lua b/modules/fuel/x-fuel/client.lua index fc2d054..712c5de 100644 --- a/modules/fuel/x-fuel/client.lua +++ b/modules/fuel/x-fuel/client.lua @@ -3,26 +3,28 @@ local resourceName = "x-fuel" if GetResourceState(resourceName) == 'missing' then return end Fuel = Fuel or {} ----This will get the name of the Fuel being used (if a supported Fuel). +---Returns the name of the active fuel resource. +---If no supported resource is found, "default" will be returned. ---@return string Fuel.GetResourceName = function() return resourceName end ----This will get the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@return number fuel The fuel level of the vehicle. +---Returns the current fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@return number The vehicle fuel level. Fuel.GetFuel = function(vehicle) if not DoesEntityExist(vehicle) then return 0.0 end local level, _ = exports["x-fuel"]:getFuel(vehicle) return level end ----This will set the fuel level of the vehicle. ----@param vehicle number The vehicle entity ID. ----@param fuel number The fuel level to set. +---Sets the fuel level of a vehicle. +---@param vehicle number The vehicle entity handle. +---@param fuel number The fuel level to assign. +---@param type? string The fuel type, used only in ti_fuel. (default: RON91) ---@return nil -Fuel.SetFuel = function(vehicle, fuel) +Fuel.SetFuel = function(vehicle, fuel, type) if not DoesEntityExist(vehicle) then return end return exports['x-fuel']:SetFuel(vehicle, fuel) end From 9e810d4b247009db594e65a22c374231d54e0341 Mon Sep 17 00:00:00 2001 From: XenoS-ITA Date: Thu, 21 Aug 2025 01:23:58 +0200 Subject: [PATCH 03/62] refactor(vehicleKey): enhance key management functions with assertions, improved documentation and remove vehicle keys where they was missing --- .../F_RealCarKeysSystem/client/client.lua | 28 +++++++++++++++-- .../MrNewbVehicleKeys/client/client.lua | 24 +++++++++++++-- .../Renewed-Vehiclekeys/client/client.lua | 24 +++++++++++++-- modules/vehicleKey/_default/client/client.lua | 19 ++++++------ .../vehicleKey/cd_garage/client/client.lua | 18 +++++++++-- modules/vehicleKey/jacksam/client.lua | 28 ++++++++++++++--- .../mk_vehiclekeys/client/client.lua | 21 ++++++++++--- .../vehicleKey/okokGarage/client/client.lua | 26 ++++++++++++++-- .../qb-vehiclekeys/client/client.lua | 24 +++++++++++++-- .../qbx_vehiclekeys/client/client.lua | 27 +++++++++++++++-- .../qs-vehiclekeys/client/client.lua | 30 +++++++++++++++---- .../vehicleKey/t1ger_keys/client/client.lua | 22 +++++++++++--- .../wasabi_carlock/client/client.lua | 24 +++++++++++++-- 13 files changed, 271 insertions(+), 44 deletions(-) diff --git a/modules/vehicleKey/F_RealCarKeysSystem/client/client.lua b/modules/vehicleKey/F_RealCarKeysSystem/client/client.lua index 249c770..9426293 100644 --- a/modules/vehicleKey/F_RealCarKeysSystem/client/client.lua +++ b/modules/vehicleKey/F_RealCarKeysSystem/client/client.lua @@ -1,15 +1,39 @@ ---@diagnostic disable: duplicate-set-field local resourceName = "F_RealCarKeysSystem" if GetResourceState(resourceName) == 'missing' then return end + VehicleKey = VehicleKey or {} +---Gives the player (self) the keys of the specified vehicle. +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.GiveKeys = function(vehicle, plate) - if not plate then return false end + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + TriggerServerEvent('F_RealCarKeysSystem:generateVehicleKeys', plate) end +-- TODO: Test, documentation of the script is missing + +---Removes the keys of the specified vehicle from the player (self). +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - return true + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + + TriggerServerEvent('F_RealCarKeysSystem:removeVehicleKeysByPlate', plate) end return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/MrNewbVehicleKeys/client/client.lua b/modules/vehicleKey/MrNewbVehicleKeys/client/client.lua index a05405f..bfd4a99 100644 --- a/modules/vehicleKey/MrNewbVehicleKeys/client/client.lua +++ b/modules/vehicleKey/MrNewbVehicleKeys/client/client.lua @@ -4,13 +4,33 @@ if GetResourceState(resourceName) == 'missing' then return end VehicleKey = VehicleKey or {} +---Gives the player (self) the keys of the specified vehicle. +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.GiveKeys = function(vehicle, plate) - if not plate then return false end + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + return exports.MrNewbVehicleKeys:GiveKeysByPlate(plate) end +---Removes the keys of the specified vehicle from the player (self). +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - if not plate then return false end + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + return exports.MrNewbVehicleKeys:RemoveKeysByPlate(plate) end diff --git a/modules/vehicleKey/Renewed-Vehiclekeys/client/client.lua b/modules/vehicleKey/Renewed-Vehiclekeys/client/client.lua index 62e4da7..69653bc 100644 --- a/modules/vehicleKey/Renewed-Vehiclekeys/client/client.lua +++ b/modules/vehicleKey/Renewed-Vehiclekeys/client/client.lua @@ -4,13 +4,33 @@ if GetResourceState(resourceName) == 'missing' then return end VehicleKey = VehicleKey or {} +---Gives the player (self) the keys of the specified vehicle. +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.GiveKeys = function(vehicle, plate) - if not plate then return false end + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + return exports['Renewed-Vehiclekeys']:addKey(plate) end +---Removes the keys of the specified vehicle from the player (self). +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - if not plate then return false end + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + return exports['Renewed-Vehiclekeys']:removeKey(plate) end diff --git a/modules/vehicleKey/_default/client/client.lua b/modules/vehicleKey/_default/client/client.lua index adb02d3..6d66938 100644 --- a/modules/vehicleKey/_default/client/client.lua +++ b/modules/vehicleKey/_default/client/client.lua @@ -1,19 +1,20 @@ ---@diagnostic disable: duplicate-set-field VehicleKey = VehicleKey or {} ----This will give keys to the specifed vehicle/plate. ----@param vehicle number The vehicle entity ID. ----@param plate string The plate of the vehicle. +---Gives the player (self) the keys of the specified vehicle. +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.GiveKeys = function(vehicle, plate) - return true, Prints.Error("There Is No Vehicle Key System Installed") + Prints.Info("There is no compatible vehicle key resource.") end ----This will remove keys from the specifed vehicle/plate. ----@param vehicle number The vehicle entity ID. ----@param plate string The plate of the vehicle. ----@return boolean | nil +---Removes the keys of the specified vehicle from the player (self). +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - return true, Prints.Error("There Is No Vehicle Key System Installed") + Prints.Info("There is no compatible vehicle key resource.") end return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/cd_garage/client/client.lua b/modules/vehicleKey/cd_garage/client/client.lua index 9ab85d1..d45dc23 100644 --- a/modules/vehicleKey/cd_garage/client/client.lua +++ b/modules/vehicleKey/cd_garage/client/client.lua @@ -4,13 +4,27 @@ if GetResourceState(resourceName) == 'missing' then return end VehicleKey = VehicleKey or {} +---Gives the player (self) the keys of the specified vehicle. +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.GiveKeys = function(vehicle, plate) - if not plate then return false end + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + TriggerEvent('cd_garage:AddKeys', plate) end +---Removes the keys of the specified vehicle from the player (self). +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - return true + Prints.Info("cd_garage doesnt support removing keys.") end return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/jacksam/client.lua b/modules/vehicleKey/jacksam/client.lua index 0da5d3e..d47b413 100644 --- a/modules/vehicleKey/jacksam/client.lua +++ b/modules/vehicleKey/jacksam/client.lua @@ -4,14 +4,34 @@ if GetResourceState(resourceName) == 'missing' then return end VehicleKey = VehicleKey or {} +---Gives the player (self) the keys of the specified vehicle. +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.GiveKeys = function(vehicle, plate) - if not plate then return false end - return TriggerServerEvent("vehicles_keys:selfGiveVehicleKeys", plate) + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + + TriggerServerEvent("vehicles_keys:selfGiveVehicleKeys", plate) end +---Removes the keys of the specified vehicle from the player (self). +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - if not plate then return false end - return TriggerServerEvent("vehicles_keys:selfRemoveKeys", plate) + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + + TriggerServerEvent("vehicles_keys:selfRemoveKeys", plate) end return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/mk_vehiclekeys/client/client.lua b/modules/vehicleKey/mk_vehiclekeys/client/client.lua index 0c7d643..cf2c004 100644 --- a/modules/vehicleKey/mk_vehiclekeys/client/client.lua +++ b/modules/vehicleKey/mk_vehiclekeys/client/client.lua @@ -1,16 +1,29 @@ ---@diagnostic disable: duplicate-set-field local resourceName = "mk_vehiclekeys" if GetResourceState(resourceName) == 'missing' then return end + VehicleKey = VehicleKey or {} +---Gives the player (self) the keys of the specified vehicle. +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.GiveKeys = function(vehicle, plate) - if not vehicle and not DoesEntityExist(vehicle) then return false end - return exports["mk_vehiclekeys"]:AddKey(vehicle) + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + exports["mk_vehiclekeys"]:AddKey(vehicle) end +---Removes the keys of the specified vehicle from the player (self). +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - if not vehicle and not DoesEntityExist(vehicle) then return false end - return exports["mk_vehiclekeys"]:RemoveKey(vehicle) + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + exports["mk_vehiclekeys"]:RemoveKey(vehicle) end return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/okokGarage/client/client.lua b/modules/vehicleKey/okokGarage/client/client.lua index 705c2f0..fee3fa4 100644 --- a/modules/vehicleKey/okokGarage/client/client.lua +++ b/modules/vehicleKey/okokGarage/client/client.lua @@ -4,13 +4,35 @@ if GetResourceState(resourceName) == 'missing' then return end VehicleKey = VehicleKey or {} +---Gives the player (self) the keys of the specified vehicle. +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.GiveKeys = function(vehicle, plate) - if not plate then return false end + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + TriggerServerEvent('okokGarage:GiveKeys', plate) end +---Removes the keys of the specified vehicle from the player (self). +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - return true + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + + local source = GetPlayerServerId(PlayerId()) + TriggerServerEvent("okokGarage:RemoveKeys", plate, source) end return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/qb-vehiclekeys/client/client.lua b/modules/vehicleKey/qb-vehiclekeys/client/client.lua index 861c8d8..bc01002 100644 --- a/modules/vehicleKey/qb-vehiclekeys/client/client.lua +++ b/modules/vehicleKey/qb-vehiclekeys/client/client.lua @@ -4,13 +4,33 @@ if GetResourceState(resourceName) == 'missing' then return end VehicleKey = VehicleKey or {} +---Gives the player (self) the keys of the specified vehicle. +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.GiveKeys = function(vehicle, plate) - if not plate then return false end + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + TriggerServerEvent("qb-vehiclekeys:server:AcquireVehicleKeys", plate) end +---Removes the keys of the specified vehicle from the player (self). +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - if not plate then return false end + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + TriggerEvent("qb-vehiclekeys:client:RemoveKeys", plate) end diff --git a/modules/vehicleKey/qbx_vehiclekeys/client/client.lua b/modules/vehicleKey/qbx_vehiclekeys/client/client.lua index 0502ac1..69c4ac9 100644 --- a/modules/vehicleKey/qbx_vehiclekeys/client/client.lua +++ b/modules/vehicleKey/qbx_vehiclekeys/client/client.lua @@ -4,13 +4,34 @@ if GetResourceState(resourceName) == 'missing' then return end VehicleKey = VehicleKey or {} +---Gives the player (self) the keys of the specified vehicle. +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.GiveKeys = function(vehicle, plate) - if not plate then return false end - TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate) + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + + TriggerServerEvent("qb-vehiclekeys:server:AcquireVehicleKeys", plate) end +---Removes the keys of the specified vehicle from the player (self). +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - return true + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + + TriggerEvent("qb-vehiclekeys:client:RemoveKeys", plate) end return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/qs-vehiclekeys/client/client.lua b/modules/vehicleKey/qs-vehiclekeys/client/client.lua index 2280713..06bdfdd 100644 --- a/modules/vehicleKey/qs-vehiclekeys/client/client.lua +++ b/modules/vehicleKey/qs-vehiclekeys/client/client.lua @@ -4,18 +4,36 @@ if GetResourceState(resourceName) == 'missing' then return end VehicleKey = VehicleKey or {} +---Gives the player (self) the keys of the specified vehicle. +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.GiveKeys = function(vehicle, plate) - if not vehicle then return false end + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + local model = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle)) - local verifiedPlate = GetVehicleNumberPlateText(vehicle) - return exports['qs-vehiclekeys']:GiveKeys(verifiedPlate, model, true) + return exports['qs-vehiclekeys']:GiveKeys(plate, model, true) end +---Removes the keys of the specified vehicle from the player (self). +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - if not vehicle then return false end + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + local model = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle)) - local verifiedPlate = GetVehicleNumberPlateText(vehicle) - return exports['qs-vehiclekeys']:RemoveKeys(verifiedPlate, model) + return exports['qs-vehiclekeys']:RemoveKeys(plate, model) end return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/t1ger_keys/client/client.lua b/modules/vehicleKey/t1ger_keys/client/client.lua index a040a7a..e996071 100644 --- a/modules/vehicleKey/t1ger_keys/client/client.lua +++ b/modules/vehicleKey/t1ger_keys/client/client.lua @@ -4,14 +4,28 @@ if GetResourceState(resourceName) == 'missing' then return end VehicleKey = VehicleKey or {} +---Gives the player (self) the keys of the specified vehicle. +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.GiveKeys = function(vehicle, plate) - if not DoesEntityExist(vehicle) then return false end - local vehicle_display_name = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle)) - return exports['t1ger_keys']:GiveTemporaryKeys(plate, vehicle_display_name, 'some_keys') + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + + local model = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle)) + return exports['t1ger_keys']:GiveTemporaryKeys(plate, model, '') end +---Removes the keys of the specified vehicle from the player (self). +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - + Prints.Info("t1ger_keys doesnt support removing keys.") end return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/wasabi_carlock/client/client.lua b/modules/vehicleKey/wasabi_carlock/client/client.lua index bde20f5..328699d 100644 --- a/modules/vehicleKey/wasabi_carlock/client/client.lua +++ b/modules/vehicleKey/wasabi_carlock/client/client.lua @@ -4,13 +4,33 @@ if GetResourceState(resourceName) == 'missing' then return end VehicleKey = VehicleKey or {} +---Gives the player (self) the keys of the specified vehicle. +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.GiveKeys = function(vehicle, plate) - if not plate and vehicle then plate = GetVehicleNumberPlateText(vehicle) end + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + exports.wasabi_carlock:GiveKey(plate) end +---Removes the keys of the specified vehicle from the player (self). +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - if not plate and vehicle then plate = GetVehicleNumberPlateText(vehicle) end + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + if not plate then + plate = GetVehicleNumberPlateText(vehicle) + end + exports.wasabi_carlock:RemoveKey(plate) end From 783c15ad9c053ae7f85f9a28f608bedb5a16f816 Mon Sep 17 00:00:00 2001 From: XenoS-ITA Date: Thu, 21 Aug 2025 01:24:27 +0200 Subject: [PATCH 04/62] refactor(vehicleKey): remove obsolete client.lua file for mono_carkeys --- .../vehicleKey/mono_carkeys/client/client.lua | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 modules/vehicleKey/mono_carkeys/client/client.lua diff --git a/modules/vehicleKey/mono_carkeys/client/client.lua b/modules/vehicleKey/mono_carkeys/client/client.lua deleted file mode 100644 index 7ee881a..0000000 --- a/modules/vehicleKey/mono_carkeys/client/client.lua +++ /dev/null @@ -1,16 +0,0 @@ ----@diagnostic disable: duplicate-set-field -local resourceName = "mono_carkeys" -if GetResourceState(resourceName) == 'missing' then return end - -VehicleKey = VehicleKey or {} -VehicleKey.GiveKeys = function(vehicle, plate) - if not plate then return false end - TriggerServerEvent('mono_carkeys:CreateKey', plate) -end - -VehicleKey.RemoveKeys = function(vehicle, plate) - if not plate then return false end - TriggerServerEvent('mono_carkeys:DeleteKey', 1, plate) -end - -return VehicleKey \ No newline at end of file From a289e6f1d2e82dbb3f7b55de298f89d9dffec22b Mon Sep 17 00:00:00 2001 From: XenoS-ITA Date: Thu, 21 Aug 2025 01:24:41 +0200 Subject: [PATCH 05/62] refactor(vehicleKey): add client.lua for mVehicle --- modules/vehicleKey/mVehicle/client/client.lua | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 modules/vehicleKey/mVehicle/client/client.lua diff --git a/modules/vehicleKey/mVehicle/client/client.lua b/modules/vehicleKey/mVehicle/client/client.lua new file mode 100644 index 0000000..5216aac --- /dev/null +++ b/modules/vehicleKey/mVehicle/client/client.lua @@ -0,0 +1,26 @@ +---@diagnostic disable: duplicate-set-field +local resourceName = "mVehicle" +if GetResourceState(resourceName) == 'missing' then return end + +VehicleKey = VehicleKey or {} + +---Gives the player (self) the keys of the specified vehicle. +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil +VehicleKey.GiveKeys = function(vehicle, plate) + assert(vehicle, "vehicle is nil") + assert(DoesEntityExist(vehicle), "vehicle does not exist") + + exports.mVehicle:AddTemporalVehicleClient(vehicle) +end + +---Removes the keys of the specified vehicle from the player (self). +---@param vehicle number The vehicle entity handle. +---@param plate? string The plate of the vehicle. +---@return nil +VehicleKey.RemoveKeys = function(vehicle, plate) + Prints.Info("mVehicle doesnt support removing keys.") +end + +return VehicleKey \ No newline at end of file From de52a3e8e1a8a18d2b310611e2a8e07c8a539ee4 Mon Sep 17 00:00:00 2001 From: XenoS-ITA Date: Thu, 21 Aug 2025 01:25:40 +0200 Subject: [PATCH 06/62] refactor(attributions): remove dirk_lib from attributions --- Attributions.md | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/Attributions.md b/Attributions.md index a902bc1..bad4521 100644 --- a/Attributions.md +++ b/Attributions.md @@ -27,27 +27,6 @@ --- -### dirk\_lib - -**Purpose:** Vehicle fuel and vehicle key bridging systems -**Repository:** [dirk\_lib](https://github.com/DirkDigglerz/dirk_lib) - -
-Implementation Details - -**Code we use:** - -* Client-side vehicle fuel management -* Vehicle key bridging functionality - -**Modifications made:** - -* None - code used as-is with full credit to original author - -
- ---- - ### ox\_lib **Purpose:** External compatibility and architectural inspiration From c17b4e1fe6767c0781968c726710bf12ce4082d4 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Wed, 20 Aug 2025 19:38:47 -0400 Subject: [PATCH 07/62] Update client.lua --- modules/skills/_default/client.lua | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/modules/skills/_default/client.lua b/modules/skills/_default/client.lua index c2e723b..7d3cd9e 100644 --- a/modules/skills/_default/client.lua +++ b/modules/skills/_default/client.lua @@ -7,6 +7,47 @@ Skills.GetResourceName = function() return "community_bridge" end +XP_CACHE = {} + +-- Calculate XP required for a level using RuneScape algorithm (with caching) +Skills.GetXPForLevel = function(level) + if not level or level < 1 then return 0 end + if level == 1 then return 0 end -- Level 1 requires 0 XP + + -- Check cache first + if XP_CACHE[level] then + return XP_CACHE[level] + end + + -- Calculate and cache + local xp = 0 + for n = 1, level - 1 do + xp = xp + math.floor(n + 300 * (2 ^ (n / 7))) + end + local result = math.floor(xp / 4) + XP_CACHE[level] = result + + return result +end + +-- Create a skill (for initialization) +Skills.Create = function(name, maxLevel, baseXP) + if not name then return end + Skills.All[name] = { name = name, maxLevel = maxLevel or 99, baseXP = baseXP or 50 } + return Skills.All[name] +end + +Skills.GetScaledXP = function(baseXP, playerLevel) + return math.floor(baseXP * (1 + playerLevel * 0.05)) +end + +-- Get XP required to complete the current level +Skills.GetXPRequiredForLevel = function(level) + if not level or level < 1 then return 0 end + if level == 1 then return 83 end -- Level 1 to 2 requires 83 XP + return Skills.GetXPForLevel(level) +end + ---This will get the skill level of the passed skill name. (returns 1 if not found) ---@param skillName string ---@return number @@ -17,6 +58,17 @@ Skills.GetSkillLevel = function(skillName) return plyrSkills[skillName].level or 1 end +---This will get the skill xp of the passed skill name. (returns 1 if not found) +---@param skillName string +---@return number +Skills.GetXP = function(skillName) + if not skillName then return 0 end + local plyrSkills = Framework.GetPlayerMetaData("community_bridge_skills") + if not plyrSkills or not plyrSkills[skillName] then return 1 end + return plyrSkills[skillName].currentXP or 1 +end + + -- RegisterCommand("getfishingLevel", function(source, args) -- local level = Skills.GetSkillLevel("fishing") -- print("Client Fishing Level issssssssss " .. level) From b06d2fb49ee835faa01eea28f09d33ecdd97ec3e Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Wed, 20 Aug 2025 22:23:07 -0500 Subject: [PATCH 08/62] Discarded entityactions and updated target Discarded entityactions: was not used and bloat. Need a new system that handled networked entities static vs dynamic (non-moving non networked vs moving networked) updated target to improve performance on canInteract. It seems that the target systems spam this function. Using a state and checking every second instead of allowing spamming Added ClientEntity.ChangeModel --- lib/entities/client/client_entity.lua | 65 ++------- lib/entities/client/client_entity_actions.lua | 136 ------------------ lib/entities/server/server_entity.lua | 1 - lib/init.lua | 1 - modules/target/_default/client.lua | 39 ++++- modules/target/ox_target/client.lua | 7 + modules/target/qb-target/client.lua | 7 + modules/target/sleepless_interact/client.lua | 7 + 8 files changed, 73 insertions(+), 190 deletions(-) delete mode 100644 lib/entities/client/client_entity_actions.lua diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index 0b2c8c1..85a3fab 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -1,7 +1,6 @@ Utility = Utility or Require("lib/utility/client/utility.lua") Ids = Ids or Require("lib/utility/shared/ids.lua") Point = Point or Require("lib/points/client/points.lua") -ClientEntityActions = ClientEntityActions or Require("lib/entities/client/client_entity_actions_ext.lua") -- Added local Entities = {} -- Stores entity data received from server ClientEntity = {} -- Renamed from BaseEntity @@ -86,8 +85,6 @@ end -- Depricated use ClientEntity.CreateBulk instead ClientEntity.RegisterBulk = ClientEntity.CreateBulk - - --- Unregisters an entity and removes it from the world if spawned. -- @param id string|number The ID of the entity to unregister. function ClientEntity.Destroy(id) @@ -100,7 +97,6 @@ function ClientEntity.Destroy(id) end ClientEntity.Unregister = ClientEntity.Destroy - --- Updates the data for a registered entity. -- @param id string|number The ID of the entity to update. -- @param data table The data fields to update. @@ -165,10 +161,6 @@ function ClientEntity.GetAll() return Entities end -function ClientEntity.RegisterAction(name, func) - ClientEntityActions.RegisterAction(name, func) -end - function ClientEntity.OnCreate(_type, func) ClientEntity.OnCreates = ClientEntity.OnCreates or {} if not ClientEntity.OnCreates[_type] then @@ -203,11 +195,22 @@ function ClientEntity.UpdateCoords(id, coords) end entityData.coords = coords Point.UpdateCoords(id, coords) - if entityData.spawned and DoesEntityExist(entityData.spawned) then - SetEntityCoords(entityData.spawned, coords.x, coords.y, coords.z, false, false, false, true) - end + if not entityData.spawned or not DoesEntityExist(entityData.spawned) then return end + SetEntityCoords(entityData.spawned, coords.x, coords.y, coords.z, false, false, false, true) end +function ClientEntity.ChangeModel(id, model) + local entityData = Entities[id] + if not entityData then return print(string.format("[ClientEntity] ChangeModel: Entity %s does not exist", id)) end + + entityData.model = model + if not entityData.spawned or not DoesEntityExist(entityData.spawned) then return end + + RemoveEntity(entityData) + SpawnEntity(entityData) +end + + -- Network Event Handlers RegisterNetEvent("community_bridge:client:CreateEntity", function(entityData) ClientEntity.Create(entityData) @@ -225,46 +228,6 @@ RegisterNetEvent("community_bridge:client:UpdateEntity", function(id, data) ClientEntity.Update(id, data) end) --- New handler for entity actions -RegisterNetEvent("community_bridge:client:TriggerEntityAction", function(entityId, actionName, ...) - local entityData = Entities[entityId] - -- Check if entity exists locally (it doesn't need to be spawned to queue actions) - if entityData then - if actionName == "Stop" then - ClientEntityActions.StopAction(entityId) - elseif actionName == "Skip" then - ClientEntityActions.SkipAction(entityId) - else - print(string.format("[ClientEntity] Triggering action '%s' for entity %s", actionName, entityId)) - local currentAction = ClientEntityActions.ActionQueue[entityId] and ClientEntityActions.ActionQueue[entityId][1] - ClientEntityActions.QueueAction(entityData, actionName, ...) - end - -- else - -- Optional: Log if action received but entity doesn't exist locally at all - -- print(string.format("[ClientEntity] Received action '%s' for non-existent entity %s.", actionName, entityId)) - end -end) - -RegisterNetEvent("community_bridge:client:TriggerEntityActions", function(entityId, actions, endPosition) - local entityData = Entities[entityId] - if entityData then - for _, actionData in pairs(actions) do - local actionName = actionData.name - local actionParams = actionData.params - if actionName == "Stop" then - ClientEntityActions.StopAction(entityId) - elseif actionName == "Skip" then - ClientEntityActions.SkipAction(entityId) - else - local currentAction = ClientEntityActions.ActionQueue[entityId] and ClientEntityActions.ActionQueue[entityId][1] - ClientEntityActions.QueueAction(entityData, actionName, table.unpack(actionParams)) - end - end - else - print(string.format("[ClientEntity] Received actions for non-existent entity %s.", entityId)) - end -end) - -- Resource Stop Cleanup AddEventHandler('onResourceStop', function(resourceName) if resourceName == GetCurrentResourceName() then diff --git a/lib/entities/client/client_entity_actions.lua b/lib/entities/client/client_entity_actions.lua deleted file mode 100644 index 31b66b3..0000000 --- a/lib/entities/client/client_entity_actions.lua +++ /dev/null @@ -1,136 +0,0 @@ - - -ClientEntityActions = {} -ClientEntityActions.ActionThreads = {} -- Store running action threads { [entityId] = thread } -ClientEntityActions.ActionQueue = {} -- Stores pending actions { [entityId] = {{name="ActionName", args={...}}, ...} } -ClientEntityActions.IsActionRunning = {} -- Tracks if an action is currently running { [entityId] = boolean } -ClientEntityActions.RegisteredActions = {} -- New: Registry for action implementations { [actionName] = function(entityData, ...) } --- Forward declaration - - ---- Processes the next action in the queue for a given entity. --- @param entityId string|number The ID of the entity. -function ClientEntityActions.ProcessNextAction(entityId) - if ClientEntityActions.IsActionRunning [entityId] then return end -- Already running something - local queue = ClientEntityActions.ActionQueue[entityId] - if not queue or #queue == 0 then return end -- Queue is empty - - local nextAction = table.remove(queue, 1) -- Dequeue (FIFO) - local entityData = ClientEntity.Get(entityId) -- Assumes ClientEntity is accessible - -- Check if entity is still valid and spawned before starting next action - if not entityData or not entityData.spawned or not DoesEntityExist(entityData.spawned) then - -- Entity despawned while idle, clear queue and do nothing - ClientEntityActions.ActionQueue[entityId] = nil - return - end - - -- Look up the action in the registry - local actionFunc = ClientEntityActions.RegisteredActions [nextAction.name] - if actionFunc then - -- print(string.format("[ClientEntityActions] Starting action '%s' for entity %s", nextAction.name, entityId)) - ClientEntityActions.IsActionRunning [entityId] = true - -- Call the registered function - ClientEntityActions.ActionQueue[entityId] = actionFunc(entityData, table.unpack(nextAction.args)) - if not ClientEntityActions.ActionQueue[entityId] then - -- If the action function doesn't return a queue, set it to nil - ClientEntityActions.IsActionRunning[entityId] = false - ClientEntityActions.ProcessNextAction(entityId) -- Try next action if this one failed immediately - end - else - print(string.format("[ClientEntityActions] Unknown action '%s' dequeued for entity %s", nextAction.name, entityId)) - -- Skip unknown action and try the next one immediately - ClientEntityActions.ActionQueue[entityId] = ClientEntityActions.ProcessNextAction(entityId) - end -end ---- Registers a custom action implementation. --- The action function should handle its own logic, including threading if needed, --- and MUST call ClientEntityActions.ProcessNextAction(entityData.id) when it completes or fails, --- after setting ClientEntityActions.IsActionRunning [entityData.id] = false. --- @param actionName string The name used to trigger this action. --- @param actionFunc function The function to execute. Signature: function(entityData, ...) -function ClientEntityActions.RegisterAction(actionName, actionFunc) - if ClientEntityActions.RegisteredActions [actionName] then - print(string.format("[ClientEntityActions] WARNING: Overwriting registered action '%s'", actionName)) - end - assert(type(actionName) == "string", "actionName must be a string") - ClientEntityActions.RegisteredActions[actionName] = actionFunc - -- print(string.format("[ClientEntityActions] Registered action: %s", actionName)) -end - ---- Queues an action for an entity. Starts processing if idle. --- @param entityData table The entity data. --- @param actionName string The name of the action. --- @param ... any Arguments for the action. -function ClientEntityActions.QueueAction(entityData, actionName, ...) - local entityId = entityData.id - if not ClientEntityActions.ActionQueue[entityId] then - ClientEntityActions.ActionQueue[entityId] = {} - end - - local actionArgs = {...} - table.insert(ClientEntityActions.ActionQueue[entityId], { name = actionName, args = actionArgs }) - -- print(string.format("[ClientEntityActions] Queued action '%s' for entity %s. Queue size: %d", actionName, entityId, #ClientEntityActions.ActionQueue[entityId])) - - -- If the entity isn't currently doing anything, start processing immediately - if not ClientEntityActions.IsActionRunning [entityId] then - ClientEntityActions.ProcessNextAction(entityId) - end -end ---- Stops the current action and clears the queue for a specific entity. --- @param entityId string|number The ID of the entity. -function ClientEntityActions.StopAction(entityId) - -- print(string.format("[ClientEntityActions] Stopping all actions for entity %s", entityId)) - ClientEntityActions.ActionQueue[entityId] = nil -- Clear the queue - ClientEntityActions.IsActionRunning [entityId] = false -- Mark as not running (this will stop loops in threads) - - -- Stop current task/thread if applicable - if ClientEntityActions.ActionThreads[entityId] then - -- Lua threads stop themselves based on ClientEntityActions.IsActionRunning flag - ClientEntityActions.ActionThreads[entityId] = nil - end - - -- Specific task clearing for peds - local entityData = ClientEntity.Get(entityId) - if entityData and entityData.spawned and DoesEntityExist(entityData.spawned) then - if IsEntityAPed(entityData.spawned) then - ClearPedTasksImmediately(entityData.spawned) -- Use Immediately for forceful stop - end - -- Other entity types might need different stop logic - end -end ---- Skips the current action and starts the next one in the queue, if any. --- @param entityId string|number The ID of the entity. -function ClientEntityActions.SkipAction(entityId) - if not ClientEntityActions.IsActionRunning [entityId] then - -- print(string.format("[ClientEntityActions] SkipAction called for %s, but no action running.", entityId)) - return -- Nothing to skip - end - -- print(string.format("[ClientEntityActions] Skipping current action for entity %s", entityId)) - - ClientEntityActions.IsActionRunning [entityId] = false -- Mark as not running (this will stop loops in threads) - - -- Stop current task/thread if applicable - if ClientEntityActions.ActionThreads[entityId] then - ClientEntityActions.ActionThreads[entityId] = nil - end - - local entityData = ClientEntity.Get(entityId) - if entityData and entityData.spawned and DoesEntityExist(entityData.spawned) then - if IsEntityAPed(entityData.spawned) then - ClearPedTasksImmediately(entityData.spawned) - end - end - - -- Immediately try to process the next action - ClientEntityActions.ProcessNextAction(entityId) -end --- Add server-callable functions for Stop and Skip -function ClientEntityActions.Stop(entityData) - ClientEntityActions.StopAction(entityData.id) -end - -function ClientEntityActions.Skip(entityData) - ClientEntityActions.SkipAction(entityData.id) -end - -return ClientEntityActions diff --git a/lib/entities/server/server_entity.lua b/lib/entities/server/server_entity.lua index e6784a8..9d00fc4 100644 --- a/lib/entities/server/server_entity.lua +++ b/lib/entities/server/server_entity.lua @@ -29,7 +29,6 @@ end function ServerEntity.Create(id, entityType, model, coords, rotation, meta) local self = ServerEntity.New(id, entityType, model, coords, rotation, meta) if not self then - -- print("Failed to create entity with ID: " .. tostring(id)) return nil end TriggerClientEvent("community_bridge:client:CreateEntity", -1, self) diff --git a/lib/init.lua b/lib/init.lua index 23f448f..b97a442 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -76,7 +76,6 @@ cLib.Point = Point or Require("lib/points/client/pointsv2.lua") cLib.Particle = Particle or Require("lib/particles/client/particles.lua") cLib.Cache = Cache or Require("lib/cache/client/cache.lua") cLib.ClientEntity = ClientEntity or Require("lib/entities/client/client_entity.lua") -cLib.ClientEntityActions = ClientEntityActions or Require("lib/entities/client/client_entity_actions.lua") cLib.ClientStateBag = ClientStateBag or Require("lib/statebags/client/client.lua") cLib.Marker = Marker or Require("lib/markers/client/markers.lua") cLib.Anim = Anim or Require("lib/anim/client/client.lua") diff --git a/modules/target/_default/client.lua b/modules/target/_default/client.lua index 25a3478..33416e7 100644 --- a/modules/target/_default/client.lua +++ b/modules/target/_default/client.lua @@ -1,9 +1,40 @@ ---@diagnostic disable: duplicate-set-field Target = Target or {} +Ids = Ids or Require("lib/utility/shared/ids.lua") local function warnUser() print("Currently Only Targeting Is Supported By Community Bridge, You Are Using A Resource That Requires The Target Module To Be Used.") end +local InteractIds = {} + +Target.GetCanInteract = function(id) + return InteractIds[id] +end + +Target.CreateCanInteract = function(cb) + if not cb then return end + local id = Ids.CreateUniqueId(InteractIds) + InteractIds[id] = { + id = id, + ableToInteract = -1, + onInteract = cb + } + return id +end + +Target.CanInteract = function(id, ...) + local interactData = InteractIds[id] + if not interactData then return true end + if interactData.ableToInteract == -1 then + local cb = interactData.onInteract + local canInteractStatus = cb(...) + interactData.ableToInteract = canInteractStatus and 1 or 0 + SetTimeout(1000, function() + interactData.ableToInteract = -1 + end) + end + return interactData.ableToInteract > 0 +end Target.FixOptions = function(options) for k, v in pairs(options) do @@ -15,6 +46,13 @@ Target.FixOptions = function(options) return action(entityOrData) end options[k].onSelect = select + local optionsCanInteract = v.canInteract + if optionsCanInteract then + local id = Target.CreateCanInteract(optionsCanInteract) + v.canInteract = function(...) + return Target.CanInteract(id, ...) + end + end end return options end @@ -78,7 +116,6 @@ Target.AddLocalEntity = function(entities, _options) end end - Target.AddModel = function(models, options) warnUser() end diff --git a/modules/target/ox_target/client.lua b/modules/target/ox_target/client.lua index 28551ed..129af5b 100644 --- a/modules/target/ox_target/client.lua +++ b/modules/target/ox_target/client.lua @@ -40,6 +40,13 @@ Target.FixOptions = function(options) end v.groups = v.job or v.groups + local optionsCanInteract = v.canInteract + if optionsCanInteract then + local id = Target.CreateCanInteract(optionsCanInteract) + v.canInteract = function(...) + return Target.CanInteract(id, ...) + end + end -- print(json.encode(v)) end return options diff --git a/modules/target/qb-target/client.lua b/modules/target/qb-target/client.lua index ddc1a6a..46288b2 100644 --- a/modules/target/qb-target/client.lua +++ b/modules/target/qb-target/client.lua @@ -40,6 +40,13 @@ Target.FixOptions = function(options) options[k].action = select options[k].job = v.job or v.groups options[k].jobType = v.jobType + local optionsCanInteract = v.canInteract + if optionsCanInteract then + local id = Target.CreateCanInteract(optionsCanInteract) + v.canInteract = function(...) + return Target.CanInteract(id, ...) + end + end end return options end diff --git a/modules/target/sleepless_interact/client.lua b/modules/target/sleepless_interact/client.lua index 95e6375..c9909da 100644 --- a/modules/target/sleepless_interact/client.lua +++ b/modules/target/sleepless_interact/client.lua @@ -29,6 +29,13 @@ Target.FixOptions = function(options) end options[k].onSelect = select options[k].groups = v.job or v.groups + local optionsCanInteract = v.canInteract + if optionsCanInteract then + local id = Target.CreateCanInteract(optionsCanInteract) + v.canInteract = function(...) + return Target.CanInteract(id, ...) + end + end end return options end From b896b940016c6e2f37109a5fc6b141545f1f695d Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Wed, 20 Aug 2025 23:38:22 -0400 Subject: [PATCH 09/62] sync --- lib/batch/shared/test-extension.lua | 23 -- lib/dui/client/dui.lua | 329 ------------------------- lib/generators/server/ItemsBuilder.lua | 117 --------- 3 files changed, 469 deletions(-) delete mode 100644 lib/batch/shared/test-extension.lua delete mode 100644 lib/dui/client/dui.lua delete mode 100644 lib/generators/server/ItemsBuilder.lua diff --git a/lib/batch/shared/test-extension.lua b/lib/batch/shared/test-extension.lua deleted file mode 100644 index 81e4017..0000000 --- a/lib/batch/shared/test-extension.lua +++ /dev/null @@ -1,23 +0,0 @@ --- Test file for FiveM Community Bridge Extension --- Try the following to test extension features: - --- 1. Type "CommunityBridge." (with the dot) and you should see auto-completion --- CommunityBridge. - --- 2. Type "AddEventHandler" and see parameter hints --- AddEventHandler( - --- 3. Hover over these function names to see documentation: --- GetPlayerData, SetPlayerData, TriggerEvent, RegisterNetEvent - --- 4. Try these snippets (type the word and press Tab): --- event --- thread --- command --- cbget --- cbset - --- 5. Test signature help - start typing a function call: --- CommunityBridge.GetPlayerData( - -print("Extension test file loaded") diff --git a/lib/dui/client/dui.lua b/lib/dui/client/dui.lua deleted file mode 100644 index 1b9fd68..0000000 --- a/lib/dui/client/dui.lua +++ /dev/null @@ -1,329 +0,0 @@ --- -- DUI (Direct User Interface) Manager for FiveM --- -- Basic table-based implementation with full mouse support - --- ---@class DUI --- DUI = {} - --- -- Constants --- local DEFAULT_WIDTH = 1280 --- local DEFAULT_HEIGHT = 720 - --- -- Store active DUI instances --- local activeInstances = {} --- local instanceCounter = 0 - --- -- Mouse tracking state --- local mouseState = { --- tracking = false, --- activeId = nil, --- lastX = 0, --- lastY = 0, --- isPressed = false, --- currentButton = nil --- } - --- -- Mouse button constants --- local MOUSE_BUTTONS = { --- LEFT = "left", --- MIDDLE = "middle", --- RIGHT = "right" --- } - --- ---@class DUIInstance --- ---@field id number Unique identifier for this DUI instance --- ---@field url string URL loaded in the DUI --- ---@field width number Width of the DUI --- ---@field height number Height of the DUI --- ---@field handle number DUI browser handle --- ---@field txd string Texture dictionary name --- ---@field txn string Texture name --- ---@field active boolean Whether the DUI is active --- ---@field trackMouse boolean Whether mouse tracking is enabled for this instance --- ---@field mouseScale table Scale factors for mouse coordinates - --- -- Create a new DUI instance --- ---@param url string URL to load --- ---@param width? number Width of the DUI (default: 1280) --- ---@param height? number Height of the DUI (default: 720) --- ---@return number|nil id The DUI instance ID if successful, nil if failed --- function DUI.Create(url, width, height) --- if not url or type(url) ~= "string" then --- return print("DUI.Create: URL is required and must be a string") --- end - --- width = width or DEFAULT_WIDTH --- height = height or DEFAULT_HEIGHT --- instanceCounter = instanceCounter + 1 - --- local id = instanceCounter --- local handle = CreateDui(url, width, height) - --- if not handle then --- return print("DUI.Create: Failed to create DUI instance") --- end - --- local instance = { --- id = id, --- url = url, --- width = width, --- height = height, --- handle = handle, --- txd = "dui_" .. id, --- txn = "texture_" .. id, --- active = true, --- trackMouse = false, --- mouseScale = { --- x = 1.0, --- y = 1.0 --- } --- } - --- -- Create runtime texture --- local duiHandle = GetDuiHandle(handle) --- CreateRuntimeTextureFromDuiHandle(CreateRuntimeTxd(instance.txd), instance.txn, duiHandle) - --- activeInstances[id] = instance --- return id --- end - --- -- Destroy a DUI instance --- ---@param id number DUI instance ID --- ---@return boolean success Whether the operation was successful --- function DUI.Destroy(id) --- local instance = activeInstances[id] --- if not instance then return false end - --- if instance.handle then --- DestroyDui(instance.handle) --- end - --- activeInstances[id] = nil --- return true --- end - --- -- Set URL for a DUI instance --- ---@param id number DUI instance ID --- ---@param url string New URL to load --- ---@return boolean success Whether the operation was successful --- function DUI.SetURL(id, url) --- local instance = activeInstances[id] --- if not instance then return false end - --- SetDuiUrl(instance.handle, url) --- instance.url = url --- return true --- end - --- -- Send a message to the DUI --- ---@param id number DUI instance ID --- ---@param message table Message to send (will be JSON encoded) --- ---@return boolean success Whether the operation was successful --- function DUI.SendMessage(id, message) --- local instance = activeInstances[id] --- if not instance then return false end - --- SendDuiMessage(instance.handle, json.encode(message)) --- return true --- end - --- -- Mouse interaction functions - --- -- Move mouse cursor on DUI --- ---@param id number DUI instance ID --- ---@param x number X coordinate --- ---@param y number Y coordinate --- ---@return boolean success Whether the operation was successful --- function DUI.MoveMouse(id, x, y) --- local instance = activeInstances[id] --- if not instance then return false end - --- SendDuiMouseMove(instance.handle, x, y) --- return true --- end - --- -- Simulate mouse button press --- ---@param id number DUI instance ID --- ---@param button "left"|"middle"|"right" Mouse button to simulate --- ---@return boolean success Whether the operation was successful --- function DUI.MouseDown(id, button) --- local instance = activeInstances[id] --- if not instance then return false end - --- if not MOUSE_BUTTONS[button:upper()] then --- return print("DUI.MouseDown: Invalid button. Must be 'left', 'middle', or 'right'") --- end - --- -- Update mouse state --- if instance.trackMouse then --- mouseState.isPressed = true --- mouseState.currentButton = button --- end - --- SendDuiMouseDown(instance.handle, button) --- return true --- end - --- -- Simulate mouse button release --- ---@param id number DUI instance ID --- ---@param button "left"|"middle"|"right" Mouse button to simulate --- ---@return boolean success Whether the operation was successful --- function DUI.MouseUp(id, button) --- local instance = activeInstances[id] --- if not instance then return false end - --- if not MOUSE_BUTTONS[button:upper()] then --- return print("DUI.MouseUp: Invalid button. Must be 'left', 'middle', or 'right'") --- end - --- -- Update mouse state --- if instance.trackMouse then --- mouseState.isPressed = false --- mouseState.currentButton = nil --- end - --- SendDuiMouseUp(instance.handle, button) --- return true --- end - --- -- Simulate mouse wheel movement --- ---@param id number DUI instance ID --- ---@param deltaY number Vertical scroll amount --- ---@param deltaX number Horizontal scroll amount --- ---@return boolean success Whether the operation was successful --- function DUI.MouseWheel(id, deltaY, deltaX) --- local instance = activeInstances[id] --- if not instance then return false end - --- SendDuiMouseWheel(instance.handle, deltaY, deltaX) --- return true --- end - --- -- Click helper function (combines MoveMouse, MouseDown, and MouseUp) --- ---@param id number DUI instance ID --- ---@param x number X coordinate --- ---@param y number Y coordinate --- ---@param button? "left"|"middle"|"right" Mouse button to click (default: "left") --- ---@return boolean success Whether the operation was successful --- function DUI.Click(id, x, y, button) --- button = button or "left" - --- if not DUI.MoveMouse(id, x, y) then return false end --- if not DUI.MouseDown(id, button) then return false end - --- -- Small delay to simulate real click --- Citizen.Wait(50) - --- return DUI.MouseUp(id, button) --- end - --- -- Enable or disable mouse tracking for a DUI instance --- ---@param id number DUI instance ID --- ---@param enabled boolean Whether to enable mouse tracking --- ---@param scaleX? number Scale factor for X coordinates (default: 1.0) --- ---@param scaleY? number Scale factor for Y coordinates (default: 1.0) --- ---@return boolean success Whether the operation was successful --- function DUI.TrackMouse(id, enabled, scaleX, scaleY) --- local instance = activeInstances[id] --- if not instance then return false end - --- instance.trackMouse = enabled --- instance.mouseScale.x = scaleX or 1.0 --- instance.mouseScale.y = scaleY or 1.0 - --- if enabled then --- mouseState.tracking = true --- mouseState.activeId = id --- elseif mouseState.activeId == id then --- mouseState.tracking = false --- mouseState.activeId = nil --- end - --- return true --- end - --- -- Update mouse coordinates from screen position --- ---@param screenX number Screen X coordinate --- ---@param screenY number Screen Y coordinate --- ---@return boolean updated Whether coordinates were updated --- local function UpdateMousePosition(screenX, screenY) --- if not mouseState.tracking or not mouseState.activeId then return false end - --- local instance = activeInstances[mouseState.activeId] --- if not instance or not instance.trackMouse then return false end - --- -- Scale coordinates based on DUI dimensions and scale factors --- local scaledX = screenX * instance.mouseScale.x --- local scaledY = screenY * instance.mouseScale.y - --- -- Only update if position changed --- if scaledX ~= mouseState.lastX or scaledY ~= mouseState.lastY then --- mouseState.lastX = scaledX --- mouseState.lastY = scaledY --- DUI.MoveMouse(mouseState.activeId, scaledX, scaledY) --- return true --- end - --- return false --- end - --- -- Mouse tracking thread --- Citizen.CreateThread(function() --- while true do --- if mouseState.tracking and mouseState.activeId then --- local instance = activeInstances[mouseState.activeId] --- if instance and instance.trackMouse then --- -- Get current cursor position --- local screenX, screenY = GetNuiCursorPosition() --- UpdateMousePosition(screenX, screenY) - --- -- Handle held mouse buttons --- if mouseState.isPressed and mouseState.currentButton then --- -- Keep the button pressed state --- SendDuiMouseDown(instance.handle, mouseState.currentButton) --- end --- end --- end --- Citizen.Wait(0) --- end --- end) - --- -- Utility functions - --- -- Get textures for a DUI instance --- ---@param id number DUI instance ID --- ---@return string|nil txd, string|nil txn Texture dictionary and name, or nil if instance not found --- function DUI.GetTextures(id) --- local instance = activeInstances[id] --- if not instance then return nil, nil end - --- return instance.txd, instance.txn --- end - --- -- Check if a DUI instance exists --- ---@param id number DUI instance ID --- ---@return boolean exists Whether the instance exists and is active --- function DUI.Exists(id) --- local instance = activeInstances[id] --- return instance ~= nil and instance.active --- end - --- -- Get all active DUI instances --- ---@return table instances Table of active DUI instances --- function DUI.GetActiveInstances() --- return activeInstances --- end - --- -- Cleanup all DUI instances --- function DUI.CleanupAll() --- for id in pairs(activeInstances) do --- DUI.Destroy(id) --- end --- end - --- -- Automatic cleanup on resource stop --- AddEventHandler('onResourceStop', function(resourceName) --- if GetCurrentResourceName() ~= resourceName then return end --- DUI.CleanupAll() --- end) - --- return DUI diff --git a/lib/generators/server/ItemsBuilder.lua b/lib/generators/server/ItemsBuilder.lua deleted file mode 100644 index 3c8f647..0000000 --- a/lib/generators/server/ItemsBuilder.lua +++ /dev/null @@ -1,117 +0,0 @@ --- ItemsBuilder = ItemsBuilder or {} - --- ItemsBuilder = {} - --- ---This will generate the items in the formats of qb_core, qb_core_old and ox_inventory. It will then build a lua file in the generateditems folder of the community_bridge. --- ---@param invoking string --- ---@param itemsTable table --- ItemsBuilder.Generate = function(invoking, outputPrefix, itemsTable, useQB) --- if not itemsTable then return end --- invoking = invoking or GetInvokingResource() or GetCurrentResourceName() or "community_bridge" - --- local resourcePath = string.format("%s/%s/", GetResourcePath(invoking), outputPrefix or "generated_items") - --- -- remove any doubles slashes after initial double slash --- -- resourcePath = resourcePath:gsub("//", "/") --- -- check if directory exists --- local folder = io.open(resourcePath, "r") --- if not folder then --- local createDirectoryCMD = string.format("if not exist \"%s\" mkdir \"%s\"", resourcePath, resourcePath) --- local returned, err = io.popen(createDirectoryCMD) --- if not returned then --- print("🌮 Failed to create directory: ", err) --- return --- end --- returned:close() --- print("🌮 Created Directory: ", resourcePath) --- else --- folder:close() --- end - --- local qbOld = {} --- local qbNew = {} --- local oxInventory = {} --- if useQB then --- for key, item in pairs(itemsTable) do --- qbOld[key] = string.format( --- "['%s'] = {name = '%s', label = '%s', weight = %s, type = 'item', image = '%s', unique = %s, useable = %s, shouldClose = %s, description = '%s'},", --- key, key, item.label, item.weight, item.image or key .. 'png', item.unique, item.useable, item.shouldClose, item.description --- ) --- qbNew[key] = string.format( --- "['%s'] = {['name'] = '%s', ['label'] = '%s', ['weight'] = %s, ['type'] = 'item',['image'] = '%s', ['unique'] = %s, ['useable'] = %s, ['shouldClose'] = %s, ['description'] = '%s'},", --- key, key, item.label, item.weight, item.image or key .. 'png', item.unique, item.useable, item.shouldClose, item.description --- ) --- imagewithoutpng = item?.image and item.image:gsub(".png", "") --- shouldRenderImage = imagewithoutpng and imagewithoutpng ~= key --- oxInventory[key] = string.format( --- [[ --- ["%s"] = { --- label = "%s", --- description = "%s", --- weight = %s, --- stack = %s, --- close = %s, --- %s --- }, ]], --- key, item.label, item.description, item.weight, not item.unique, item.shouldClose, --- shouldRenderImage and item.image and string.format([[client = { --- image = '%s' --- }]], item.image) or "" --- ) --- end - --- else --- for key, item in pairs(itemsTable) do --- -- ['peanut_butter'] = {['name'] = 'peanut_butter',['label'] = 'Peanut Butter',['weight'] = 1000,['type'] = 'item',['image'] = 'peanut_butter.png',['unique'] = false,['useable'] = false,['shouldClose'] = true,['combinable'] = nil,['description'] = 'A cooking ingredient'}, - --- qbOld[key] = string.format( --- "['%s'] = {name = '%s', label = '%s', weight = %s, type = 'item', image = '%s', unique = %s, useable = %s, shouldClose = %s, description = '%s'},", --- key, key, item.label, item.weight, item?.client?.image or key .. 'png', not item.stack, true, item.close, item.description --- ) --- qbNew[key] = string.format( --- "['%s'] = {['name'] = '%s', ['label'] = '%s', ['weight'] = %s, ['type'] = 'item', ['image'] = '%s', ['unique'] = %s, ['useable'] = %s, ['shouldClose'] = %s, ['description'] = '%s'},", --- key, key, item.label, item.weight, item?.client?.image or key .. 'png', not item.stack, true, item.close, item.description --- ) --- imagewithoutpng = item?.client?.image and item.client.image:gsub(".png", "") --- shouldRenderImage = imagewithoutpng and imagewithoutpng ~= key --- oxInventory[key] = string.format( --- [[ --- ["%s"] = { --- label = "%s", --- description = "%s", --- weight = %s, --- stack = %s, --- close = %s, --- %s --- }, ]], --- key, item.label, item.description, item.weight, item.stack, item.close, --- shouldRenderImage and item?.client?.image and string.format( [[client = { --- image = '%s' --- }]], item.client.image) or "" --- ) --- end --- end - --- local function write(fileName, content) --- local filePath = resourcePath .. fileName --- local file = io.open(filePath, "w") --- if file then --- for key, value in pairs(content) do --- file:write(string.format("%s\n", value)) --- end --- file:close() --- print("🌮 Items File Created: " .. filePath) --- else --- print("🌮 Something Broke for: " .. filePath) --- end --- end - - - --- write(invoking.."(".."qb_core_old).lua", qbOld) --- write(invoking.."(".."qb_core_new).lua", qbNew) --- write(invoking.."(".."ox_inventory).lua", oxInventory) --- end - --- exports('ItemsBuilder', ItemsBuilder) --- return ItemsBuilder \ No newline at end of file From f900bc5ce13657d69d314f06a42f16cd54a89887 Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Wed, 20 Aug 2025 23:49:22 -0500 Subject: [PATCH 10/62] Clean up --- .../shared/callback.lua} | 0 lib/generators/server/lootTables.lua | 74 ---- lib/init.lua | 4 +- lib/points/client/points.lua | 255 -------------- lib/statebags/client/client.lua | 48 --- lib/statebags/server/server.lua | 0 lib/utility/shared/math.lua | 54 +++ lib/utility/shared/perlin.lua | 110 ------ lib/utility/shared/rebound_entities.lua | 324 ------------------ .../shared/rebound_entitiy_actions.lua | 45 --- modules/math/computation.lua | 70 ---- 11 files changed, 56 insertions(+), 928 deletions(-) rename lib/{utility/shared/callbacks.lua => callback/shared/callback.lua} (100%) delete mode 100644 lib/generators/server/lootTables.lua delete mode 100644 lib/points/client/points.lua delete mode 100644 lib/statebags/client/client.lua delete mode 100644 lib/statebags/server/server.lua delete mode 100644 lib/utility/shared/perlin.lua delete mode 100644 lib/utility/shared/rebound_entities.lua delete mode 100644 lib/utility/shared/rebound_entitiy_actions.lua delete mode 100644 modules/math/computation.lua diff --git a/lib/utility/shared/callbacks.lua b/lib/callback/shared/callback.lua similarity index 100% rename from lib/utility/shared/callbacks.lua rename to lib/callback/shared/callback.lua diff --git a/lib/generators/server/lootTables.lua b/lib/generators/server/lootTables.lua deleted file mode 100644 index 9adc49d..0000000 --- a/lib/generators/server/lootTables.lua +++ /dev/null @@ -1,74 +0,0 @@ -LootTable = LootTable or {} - -local lootTables = {} - -LootTable.Register = 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 - -LootTable.Get = function(name) - assert(name, "No Name Passed For Loot Table") - return lootTables[name] or {} -end - -LootTable.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 - -LootTable.GetRandomItems = function(name, tier, randomNumber) - assert(name, "No Name Passed For Loot Table") - if tier == nil then tier = 1 end - local lootTable = LootTable.Get(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 - -LootTable.GetRandomItemsWithLimit = function(name, tier, randomNumber) - assert(name, "No Name Passed For Loot Table") - if tier == nil then tier = 1 end - local lootTable = LootTable.Get(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 --- - -exports('LootTable', LootTable) -return LootTable \ No newline at end of file diff --git a/lib/init.lua b/lib/init.lua index b97a442..ed37f5d 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -39,10 +39,10 @@ end cLib = { Require = Require, - Callback = Callback or Require("lib/utility/shared/callbacks.lua"), + Callback = Callback or Require("lib/callback/shared/callback.lua"), Ids = Ids or Require("lib/utility/shared/ids.lua"), ReboundEntities = ReboundEntities or Require("lib/utility/shared/rebound_entities.lua"), - Tables = Tables or Require("lib/utility/shared/tables.lua"), + Tables = Table or Require("lib/utility/shared/tables.lua"), Prints = Prints or Require("lib/utility/shared/prints.lua"), Math = Math or Require("lib/utility/shared/math.lua"), LA = LA or Require("lib/utility/shared/la.lua"), diff --git a/lib/points/client/points.lua b/lib/points/client/points.lua deleted file mode 100644 index 569d29c..0000000 --- a/lib/points/client/points.lua +++ /dev/null @@ -1,255 +0,0 @@ --- -- Grid-based point system --- Point = {} --- local ActivePoints = {} --- local GridCells = {} --- local LoopStarted = false --- local insidePoints = {} --- local data = {} -- 👈 Move this outside the function - --- -- Grid configuration --- local GRID_SIZE = 500.0 -- Size of each grid cell --- local CELL_BUFFER = 1 -- Number of adjacent cells to check - --- -- Consider adding these optimizations --- local ADAPTIVE_WAIT = false -- Adjust wait time based on player speed - --- ---This is an internal function, do not call this externally --- function Point.GetCellKey(coords) --- local cellX = math.floor(coords.x / GRID_SIZE) --- local cellY = math.floor(coords.y / GRID_SIZE) --- return cellX .. ":" .. cellY --- end - --- ---This is an internal function, do not call this externally --- function Point.RegisterInGrid(point) --- local cellKey = Point.GetCellKey(point.coords) - --- -- Initialize cell if it doesn't exist --- GridCells[cellKey] = GridCells[cellKey] or { --- points = {}, --- count = 0 --- } - --- -- Add point to cell --- GridCells[cellKey].points[point.id] = point --- GridCells[cellKey].count = GridCells[cellKey].count + 1 - --- -- Store cell reference in point --- point.cellKey = cellKey --- end - --- ---This is an internal function, do not call this externally --- function Point.UpdateInGrid(point, oldCellKey) --- -- Remove from old cell if cell key changed --- if oldCellKey and oldCellKey ~= point.cellKey then --- if GridCells[oldCellKey] and GridCells[oldCellKey].points[point.id] then --- GridCells[oldCellKey].points[point.id] = nil --- GridCells[oldCellKey].count = GridCells[oldCellKey].count - 1 - --- -- Clean up empty cells --- if GridCells[oldCellKey].count <= 0 then --- GridCells[oldCellKey] = nil --- end --- end - --- -- Add to new cell --- Point.RegisterInGrid(point) --- end --- end - --- ---Gets nearby cells based on the coords --- ---@param coords table --- ---@return table --- function Point.GetNearbyCells(coords) --- local cellX = math.floor(coords.x / GRID_SIZE) --- local cellY = math.floor(coords.y / GRID_SIZE) --- local nearbyCells = {} - --- -- Get current and adjacent cells --- for x = cellX - CELL_BUFFER, cellX + CELL_BUFFER do --- for y = cellY - CELL_BUFFER, cellY + CELL_BUFFER do --- local key = x .. ":" .. y --- if GridCells[key] then --- table.insert(nearbyCells, key) --- end --- end --- end - --- return nearbyCells --- end - --- ---Returns all points in the same cell as the given point --- ---This will require you to pass the point object --- ---@param point table --- ---@return table --- function Point.CheckPointsInSameCell(point) --- local cellKey = point.cellKey --- if not GridCells[cellKey] then return {} end - --- local nearbyPoints = {} --- for id, otherPoint in pairs(GridCells[cellKey].points) do --- if id ~= point.id then --- local distance = #(point.coords - otherPoint.coords) --- if distance < (point.distance + otherPoint.distance) then --- nearbyPoints[id] = otherPoint --- end --- end --- end - --- return nearbyPoints --- end - --- ---Internal function that starts the loop. Do not call this function directly. --- function Point.StartLoop() --- if LoopStarted then return false end --- LoopStarted = true --- -- Remove the "local data = {}" line from here --- CreateThread(function() --- while LoopStarted do --- local playerPed = PlayerPedId() --- while playerPed == -1 do --- Wait(100) --- playerPed = PlayerPedId() --- end --- local playerCoords = GetEntityCoords(playerPed) --- local targetsExist = false --- local playerCellKey = Point.GetCellKey(playerCoords) --- local nearbyCells = Point.GetNearbyCells(playerCoords) - --- local playerSpeed = GetEntitySpeed(playerPed) --- local maxWeight = 1000 --- local waitTime = ADAPTIVE_WAIT and math.max(maxWeight/10, maxWeight - playerSpeed * maxWeight/10) or maxWeight --- -- Process only points in nearby cells --- for _, cellKey in ipairs(nearbyCells) do --- if GridCells[cellKey] then --- for id, point in pairs(GridCells[cellKey].points) do --- targetsExist = true - --- -- Update entity position if needed --- local oldCellKey = point.cellKey --- if point.isEntity then --- point.coords = GetEntityCoords(point.target) --- point.cellKey = Point.GetCellKey(point.coords) --- Point.UpdateInGrid(point, oldCellKey) --- end --- local coords = point.coords and vector3(point.coords.x, point.coords.y, point.coords.z) or vector3(0, 0, 0) --- local distance = #(playerCoords - coords) --- --local distance = #(playerCoords - point.coords) - --- -- Check if player entered/exited the point --- if distance < point.distance then --- if not point.inside then --- point.inside = true --- data[point.id] = data[point.id] or point.args or {} --- data[point.id] = point.onEnter(point, data[point.id]) --- insidePoints[point.id] = point --- end --- -- Modified main loop exit handler --- elseif point.inside then --- point.inside = false --- data[point.id] = data[point.id] or point.args or {} --- local result = point.onExit(point, data[point.id]) --- data[point.id] = result ~= nil and result or data[point.id] -- ← Use consistent fallback --- point.args = data[point.id] -- ← Update point.args to match data[point.id] --- insidePoints[point.id] = nil --- end - --- -- if point.onNearby then --- -- point.onNearby(GridCells[cellKey]?.points, waitTime) --- -- end --- end --- end --- end - --- for id, insidepoint in pairs(insidePoints) do --- local pos = insidepoint.coords and vector3(insidepoint.coords.x, insidepoint.coords.y, insidepoint.coords.z) or vector3(0, 0, 0) --- local dist = #(playerCoords - pos) --- if dist > insidepoint.distance then --- insidepoint.inside = false --- data[insidepoint.id] = data[insidepoint.id] or insidepoint.args or {} --- local result = insidepoint.onExit(insidepoint, data[insidepoint.id]) --- data[insidepoint.id] = result ~= nil and result or data[insidepoint.id] --- insidepoint.args = data[insidepoint.id] -- ← Keep data in sync --- insidePoints[insidepoint.id] = nil --- end --- end --- Wait(waitTime) -- Faster updates when moving quickly --- end --- end) --- return true --- end - --- ---Create a point based on a vector or entityID --- ---@param id string --- ---@param target number || vector3 --- ---@param distance number --- ---@param _onEnter function --- ---@param _onExit function --- ---@param _onNearby function --- ---@param data self --- ---@return table --- function Point.Register(id, target, distance, args, _onEnter, _onExit, _onNearby) --- local isEntity = type(target) == "number" --- local coords = isEntity and GetEntityCoords(target) or target - --- local self = {} --- self.id = id --- self.target = target -- Store entity ID or Vector3 --- self.isEntity = isEntity --- self.coords = coords --- self.distance = distance --- self.onEnter = _onEnter or function() end --- self.onExit = _onExit or function() end --- self.onNearby = _onNearby or function() end --- self.inside = false -- Track if player is inside --- self.args = args or {} - --- ActivePoints[id] = self --- Point.RegisterInGrid(self) --- Point.StartLoop() --- return self --- end - --- ---Remove an exsisting point by its id --- ---@param id string --- function Point.Remove(id) --- local point = ActivePoints[id] --- if point then --- local cellKey = point.cellKey --- if GridCells[cellKey] and GridCells[cellKey].points[id] then --- GridCells[cellKey].points[id] = nil --- GridCells[cellKey].count = GridCells[cellKey].count - 1 - --- if GridCells[cellKey].count <= 0 then --- GridCells[cellKey] = nil --- end --- end - --- ActivePoints[id] = nil --- end --- end - --- ---Returnes a point by its id --- ---@param id string --- ---@return table --- function Point.Get(id) --- return ActivePoints[id] --- end - --- function Point.UpdateCoords(id, coords) --- local point = ActivePoints[id] --- if point then --- point.coords = coords --- local oldCellKey = point.cellKey --- point.cellKey = Point.GetCellKey(coords) --- Point.UpdateInGrid(point, oldCellKey) --- end --- end - --- ---Returns all points --- ---@return table --- function Point.GetAll() --- return ActivePoints --- end - --- return Point \ No newline at end of file diff --git a/lib/statebags/client/client.lua b/lib/statebags/client/client.lua deleted file mode 100644 index 2c2c364..0000000 --- a/lib/statebags/client/client.lua +++ /dev/null @@ -1,48 +0,0 @@ -ClientStateBag = {} - ----Gets an entity from a statebag name ----@param entityId string The entity ID or statebag name ----@return number|nil entity The entity handle or nil if not found -local function getStateBagEntity(entityId) - local _entity = GetEntityFromStateBagName(entityId) - return _entity -end - -local function getPlayerFromStateBagName(stateBagName) - return getPlayerFromStateBagName(stateBagName) -end - ----Adds a handler for entity statebag changes ----@param keyName string The statebag key to watch for changes ----@param entityId string|nil The specific entity ID to watch, or nil for all entities ----@param callback function The callback function to handle changes (function(entityId, key, value, lastValue, replicated)) ----@return number handler The handler ID -function ClientStateBag.AddEntityChangeHandler(keyName, entityId, callback) - return AddStateBagChangeHandler(keyName, entityId or nil, function(bagName, key, value, lastValue, replicated) - local entity = getStateBagEntity(bagName) - if not DoesEntityExist(entity) then return end - if entity then - return callback(entity, key, value, lastValue, replicated) - end - end) -end - ----Adds a handler for player statebag changes ----@param keyName string The statebag key to watch for changes ----@param filter boolean|nil If true, only watch for changes from the current player ----@param callback function The callback function to handle changes (function(playerId, key, value, lastValue, replicated)) ----@return number handler The handler ID -function ClientStateBag.AddPlayerChangeHandler(keyName, filter, callback) - return AddStateBagChangeHandler(keyName, filter and ("player:%s"):format(GetPlayerServerId(PlayerId())) or nil, - function(bagName, key, value, lastValue, replicated) - local actualPlayerId = getPlayerFromStateBagName(bagName) - if DoesEntityExist(actualPlayerId) and (actualPlayerId ~= PlayerPedId()) then -- you cant have a statebag value if you are not the player - return false - end - if actualPlayerId and actualPlayerId ~= 0 then - return callback(tonumber(actualPlayerId), key, value, lastValue, replicated) - end - end) -end - -return ClientStateBag diff --git a/lib/statebags/server/server.lua b/lib/statebags/server/server.lua deleted file mode 100644 index e69de29..0000000 diff --git a/lib/utility/shared/math.lua b/lib/utility/shared/math.lua index 30717ce..499d8c4 100644 --- a/lib/utility/shared/math.lua +++ b/lib/utility/shared/math.lua @@ -1,5 +1,59 @@ Math = Math or {} + + +---@class Math +------@field public name string @add name field to class Car, you'll see it in code completion +Math = {} + + +--- Rounds a number to the nearest whole number. +---@param value number: The value to round. +---@return number: The rounded value. +function Math.Round(value) + return math.floor(value + 0.5) +end + +function Math.Truncate(value, decimals) + local mul = decimals and (10 ^ decimals) or 1 + if value < 0 then + return math.ceil(value * mul) / mul + else + return math.floor(value * mul) / mul + end +end + +--- Warps the number around from max to min and vice versa. +---@param value number: The value to wrap. +---@param min number: The minimum value. +---@param max number: The maximum value. +---@return number: The wrapped value. +function Math.Wrap(value, min, max) + local range = max - min + return (value - min) % range + min +end + +--- Gets an interpolated value between two numbers. +---@see https://en.wikipedia.org/wiki/Smoothstep +---@param value number The interpolation value. +---@param min number : The minimum value. +---@param max number : The maximum value. +---@return number The interpolated value. +function Math.Smooth(value, min, max) + value = Math.Clamp((value - min) / (max - min), 0, 1) + return value * value * (3 - 2 * value) +end + +--- Maps a value from one range to another. +---@param value number The value to map. +---@param inMin number The minimum value for the provided value. +---@param inMax number The maximum value for the provided value. +---@param outMin number The minimum value for the output. +---@param outMax number The maximum value for the output. +function Math.Map(value, inMin, inMax, outMin, outMax) + return (value - inMin) / (inMax - inMin) * (outMax - outMin) + outMin +end + function Math.Clamp(value, min, max) return math.min(math.max(value, min), max) end diff --git a/lib/utility/shared/perlin.lua b/lib/utility/shared/perlin.lua deleted file mode 100644 index 36ff967..0000000 --- a/lib/utility/shared/perlin.lua +++ /dev/null @@ -1,110 +0,0 @@ -local Perlin = {} - --- Permutation table for random gradients -local perm = {} -local grad3 = { - {1,1,0}, {-1,1,0}, {1,-1,0}, {-1,-1,0}, - {1,0,1}, {-1,0,1}, {1,0,-1}, {-1,0,-1}, - {0,1,1}, {0,-1,1}, {0,1,-1}, {0,-1,-1} -} - --- Initialize permutation table -local function ShufflePermutation() - local p = {} - for i = 0, 255 do - p[i] = i - end - for i = 255, 1, -1 do - local j = math.random(i + 1) - 1 - p[i], p[j] = p[j], p[i] - end - for i = 0, 255 do - perm[i] = p[i] - perm[i + 256] = p[i] -- Repeat for wrapping - end -end - -ShufflePermutation() -- Randomize on load - --- Dot product helper -local function Dot(g, x, y, z) - return g[1] * x + g[2] * y + (z and g[3] * z or 0) -end - --- Fade function (smootherstep) -local function Fade(t) - return t * t * t * (t * (t * 6 - 15) + 10) -end - --- Linear interpolation -local function Lerp(a, b, t) - return a + (b - a) * t -end - --- **Perlin Noise 1D** -function Perlin.Noise1D(x) - local X = math.floor(x) & 255 - x = x - math.floor(x) - local u = Fade(x) - - local a = perm[X] - local b = perm[X + 1] - - return Lerp(a, b, u) * (2 / 255) - 1 -end - --- **Perlin Noise 2D** -function Perlin.Noise2D(x, y) - local X = math.floor(x) & 255 - local Y = math.floor(y) & 255 - x, y = x - math.floor(x), y - math.floor(y) - - local u, v = Fade(x), Fade(y) - - local aa = perm[X] + Y - local ab = perm[X] + Y + 1 - local ba = perm[X + 1] + Y - local bb = perm[X + 1] + Y + 1 - - return Lerp( - Lerp(Dot(grad3[perm[aa] % 12 + 1], x, y), Dot(grad3[perm[ba] % 12 + 1], x - 1, y), u), - Lerp(Dot(grad3[perm[ab] % 12 + 1], x, y - 1), Dot(grad3[perm[bb] % 12 + 1], x - 1, y - 1), u), - v - ) -end - --- **Perlin Noise 3D** -function Perlin.Noise3D(x, y, z) - local X = math.floor(x) & 255 - local Y = math.floor(y) & 255 - local Z = math.floor(z) & 255 - x, y, z = x - math.floor(x), y - math.floor(y), z - math.floor(z) - - local u, v, w = Fade(x), Fade(y), Fade(z) - - local aaa = perm[X] + Y + Z - local aba = perm[X] + Y + Z + 1 - local aab = perm[X] + Y + 1 + Z - local abb = perm[X] + Y + 1 + Z + 1 - local baa = perm[X + 1] + Y + Z - local bba = perm[X + 1] + Y + Z + 1 - local bab = perm[X + 1] + Y + 1 + Z - local bbb = perm[X + 1] + Y + 1 + Z + 1 - - return Lerp( - Lerp( - Lerp(Dot(grad3[perm[aaa] % 12 + 1], x, y, z), Dot(grad3[perm[baa] % 12 + 1], x - 1, y, z), u), - Lerp(Dot(grad3[perm[aab] % 12 + 1], x, y - 1, z), Dot(grad3[perm[bab] % 12 + 1], x - 1, y - 1, z), u), - v - ), - Lerp( - Lerp(Dot(grad3[perm[aba] % 12 + 1], x, y, z - 1), Dot(grad3[perm[bba] % 12 + 1], x - 1, y, z - 1), u), - Lerp(Dot(grad3[perm[abb] % 12 + 1], x, y - 1, z - 1), Dot(grad3[perm[bbb] % 12 + 1], x - 1, y - 1, z - 1), u), - v - ), - w - ) -end - -exports('Perlin', Perlin) -return Perlin diff --git a/lib/utility/shared/rebound_entities.lua b/lib/utility/shared/rebound_entities.lua deleted file mode 100644 index 2ab3ee7..0000000 --- a/lib/utility/shared/rebound_entities.lua +++ /dev/null @@ -1,324 +0,0 @@ -local Entities = {} -local isServer = IsDuplicityVersion() -local registeredFunctions = {} -ReboundEntities = {} - -function ReboundEntities.AddFunction(func) - assert(func, "Func is nil") - table.insert(registeredFunctions, func) - return #registeredFunctions -end - -function ReboundEntities.RemoveFunction(id) - assert(id and registeredFunctions[id], "Invalid ID") - registeredFunctions[id] = false -end - -function FireFunctions(...) - for _, func in pairs(registeredFunctions) do - func(...) - end -end - -function ReboundEntities.Register(entityData) - assert(entityData and entityData.position, "Invalid entity data") - entityData.id = entityData.id or Ids.CreateUniqueId(Entities) - entityData.isServer = isServer - setmetatable(entityData, { __tostring = function() return entityData.id end }) - Entities[entityData.id] = entityData - FireFunctions(entityData) - return entityData -end - -local function Unregister(id) - Entities[id] = nil -end - -function ReboundEntities.GetSyncData(entityData, key) - return entityData[key] -end - -function ReboundEntities.GetAll() - return Entities -end - -function ReboundEntities.GetById(id) - return Entities[tostring(id)] -end - -function ReboundEntities.GetByModel(model) - local entities = {} - for _, entity in pairs(Entities) do - if entity.model == model then - table.insert(entities, entity) - end - end - return entities -end - -function ReboundEntities.GetClosest(pos) - local closest, closestDist = nil, 9999 - for _, entity in pairs(Entities) do - local dist = #(pos - entity.position) - if dist < closestDist then - closest, closestDist = entity, dist - end - end - return closest -end - -function ReboundEntities.GetWithinRadius(pos, radius) - local entities = {} - for _, entity in pairs(Entities) do - if #(pos - entity.position) < radius then - table.insert(entities, entity) - end - end - return entities -end - -function ReboundEntities.SetOnSyncKeyChange(entityData, cb) - local data = ReboundEntities.GetById(entityData.id or entityData) - assert(data, "Entity not found") - data.onSyncKeyChange = cb -end - -exports('ReboundEntities', ReboundEntities) - -if not isServer then goto client end - -function ReboundEntities.Create(entityData, src) - local entity = ReboundEntities.Register(entityData) - assert(entity and entity.position, "Invalid entity data") - entity.rotation = entity.rotation or vector3(0, 0, entityData.heading or 0) - TriggerClientEvent(GetCurrentResourceName() .. ":client:CreateReboundEntity", src or -1, entity) - return entity -end - - -function ReboundEntities.SetCheckRestricted(entityData, cb) - assert(type(cb) == "function", "Check restricted is not a function") - entityData.restricted = cb -end - - -function ReboundEntities.CheckRestricted(src, entityData) - return entityData.restricted and entityData.restricted(tonumber(src), entityData) or false -end - -function ReboundEntities.Refresh(src) - TriggerClientEvent(GetCurrentResourceName() .. ":client:CreateReboundEntities", tonumber(src), ReboundEntities.GetAccessibleList(src)) -end - -function ReboundEntities.Delete(id) - Unregister(id) - TriggerClientEvent(GetCurrentResourceName() .. ":client:DeleteReboundEntity", -1, id) -end - -function ReboundEntities.DeleteMultiple(entityDatas) - local ids = {} - for _, data in pairs(entityDatas) do - Unregister(data.id) - table.insert(ids, data.id) - end - TriggerClientEvent(GetCurrentResourceName() .. ":client:DeleteReboundEntities", -1, ids) -end - -function ReboundEntities.CreateMultiple(entityDatas, src, restricted) - local _entityDatas = {} - for _, data in pairs(entityDatas) do - local entity = ReboundEntities.Register(data) - assert(entity and entity.position, "Invalid entity data") - entity.rotation = entity.rotation or vector3(0, 0, 0) - if restricted then ReboundEntities.SetCheckRestricted(entity, restricted) end - if not ReboundEntities.CheckRestricted(src, entity) then - _entityDatas[entity.id] = entity - end - end - TriggerClientEvent(GetCurrentResourceName() .. ":client:CreateReboundEntities", src or -1, _entityDatas) - return _entityDatas -end - -function ReboundEntities.SetSyncData(entityData, key, value) - entityData[key] = value - if entityData.onSyncKeyChange then - entityData.onSyncKeyChange(entityData, key, value) - end - TriggerClientEvent(GetCurrentResourceName() .. ":client:SetReboundSyncData", -1, entityData.id, key, value) -end - -function ReboundEntities.GetAccessibleList(src) - local list = {} - for _, data in pairs(ReboundEntities.GetAll()) do - if not ReboundEntities.CheckRestricted(src, data) then - list[data.id] = data - end - end - return list -end - -RegisterNetEvent("playerJoining", function() - ReboundEntities.Refresh(source) -end) - -AddEventHandler('onResourceStart', function(resource) - if resource ~= GetCurrentResourceName() then return end - Wait(1000) - for _, src in pairs(GetPlayers()) do - ReboundEntities.Refresh(src) - end -end) - -::client:: -if isServer then return ReboundEntities end - -function ReboundEntities.LoadModel(model) - assert(model, "Model is nil") - model = type(model) == "number" and model or GetHashKey(model) -- Corrected to GetHashKey - RequestModel(model) - for i = 1, 100 do - if HasModelLoaded(model) then return model end - Wait(100) - end - error(string.format("Failed to load model %s", model)) -end - -function ReboundEntities.Spawn(entityData) - local model = entityData.model - local position = entityData.position - assert(position, "Position is nil") - local rotation = entityData.rotation or vector3(0, 0, 0) - local entity = model and CreateObject(ReboundEntities.LoadModel(model), position.x, position.y, position.z, false, false, false) - if entity then SetEntityRotation(entity, rotation.x, rotation.y, rotation.z) end - if entityData.onSpawn then entity = entityData.onSpawn(entityData, entity) or entity end - return entity, true -end - -function ReboundEntities.SetOnSpawn(id, cb) - local entity = ReboundEntities.GetById(tostring(id)) - assert(entity, "Entity not found") - entity.onSpawn = cb - return true -end - -function ReboundEntities.Despawn(entityData) - local entity = entityData.entity - if entityData.onDespawn then entityData.onDespawn(entityData, entity) end - if entity and DoesEntityExist(entity) then DeleteEntity(entity) end - return nil, nil -end - -function ReboundEntities.SetOnDespawn(id, cb) - local entity = ReboundEntities.GetById(tostring(id)) - assert(entity, "Entity not found") - entity.onDespawn = cb - return true -end - -local spawnLoopRunning = false - -function ReboundEntities.SpawnLoop(distanceToCheck, waitTime) - if spawnLoopRunning then return end - spawnLoopRunning = true - distanceToCheck = distanceToCheck or 50 - waitTime = waitTime or 2500 - CreateThread(function() - while spawnLoopRunning do - for _, entity in pairs(Entities) do - local pos = GetEntityCoords(PlayerPedId()) - local position = vector3(entity.position.x, entity.position.y, entity.position.z) - local dist = #(pos - position) - if dist <= distanceToCheck and not entity.entity then - entity.entity, entity.inRange = ReboundEntities.Spawn(entity) - elseif dist > distanceToCheck and entity.entity then - entity.entity, entity.inRange = ReboundEntities.Despawn(entity) - end - end - Wait(waitTime) - end - end) -end - -function ReboundEntities.GetByEntity(entity) - for _, data in pairs(Entities) do - if data.entity == entity then return data end - end -end - -function ReboundEntities.CreateClient(entityData) - local entity = ReboundEntities.Register(entityData) - if entity then ReboundEntities.SpawnLoop() end - return entity -end - -function ReboundEntities.DeleteClient(id) - local entityData = ReboundEntities.GetById(tostring(id)) - assert(not entityData.isServer, "Cannot delete server entity from client") - if entityData.entity then ReboundEntities.Despawn(entityData) end - Unregister(id) - return true -end - -function ReboundEntities.CreateMultipleClient(entityDatas) - local _entityDatas = {} - for _, data in pairs(entityDatas) do - local entityData = ReboundEntities.CreateClient(data) - _entityDatas[entityData.id] = entityData - end - return _entityDatas -end - -function ReboundEntities.DeleteMultipleClient(ids) - for _, id in pairs(ids) do - ReboundEntities.DeleteClient(id) - end -end - -local function DeleteFromServer(id) - local entityData = ReboundEntities.GetById(tostring(id)) - if entityData then - entityData.isServer = nil - ReboundEntities.DeleteClient(id) - end -end - -local function DeleteMultipleFromServer(ids) - for _, id in pairs(ids) do - DeleteFromServer(id) - end -end - -RegisterNetEvent(GetCurrentResourceName() .. ":client:CreateReboundEntity", function(entityData) - ReboundEntities.CreateClient(entityData) -end) - -RegisterNetEvent(GetCurrentResourceName() .. ":client:DeleteReboundEntity", function(id) - DeleteFromServer(id) -end) - -RegisterNetEvent(GetCurrentResourceName() .. ":client:CreateReboundEntities", function(entityDatas) - ReboundEntities.CreateMultipleClient(entityDatas) -end) - -RegisterNetEvent(GetCurrentResourceName() .. ":client:DeleteReboundEntities", function(ids) - ReboundEntities.DeleteMultipleClient(ids) -end) - -RegisterNetEvent(GetCurrentResourceName() .. ":client:SetReboundSyncData", function(id, key, value) - local entityData = ReboundEntities.GetById(id) - if not entityData then return end - entityData[key] = value - if entityData.onSyncKeyChange then - entityData.onSyncKeyChange(entityData, key, value) - end -end) - -AddEventHandler('onResourceStop', function(resource) - if resource ~= GetCurrentResourceName() then return end - spawnLoopRunning = false - for _, entity in pairs(Entities) do - if entity.entity then DeleteEntity(tonumber(entity.entity)) end - end -end) - -return ReboundEntities diff --git a/lib/utility/shared/rebound_entitiy_actions.lua b/lib/utility/shared/rebound_entitiy_actions.lua deleted file mode 100644 index 78bee35..0000000 --- a/lib/utility/shared/rebound_entitiy_actions.lua +++ /dev/null @@ -1,45 +0,0 @@ -local ReboundEntities = ReboundEntities or Require("lib/utility/shared/rebound_entities.lua") -- Fixed path -local Action = Action or Require("lib/entities/shared/actions.lua") -- Fixed path and name -local LA = LA or Require("lib/utility/shared/la.lua") -- Fixed path - -REA = {} - -if not IsDuplicityVersion() then goto client end - - - -if IsDuplicityVersion() then return end -::client:: - -local ActionsInProgress = {} - - -Action.Create("LerpToPosition", function(reboundId, start, position, duration, shouldRepeat, overrideStartTime) - local re = ReboundEntities.GetById(reboundId) -- Use GetById - assert(re, "Rebound entity not found") - local entity = re and re.entity - if not entity or not DoesEntityExist(entity) then return end -- Check existence - local startTime = GetGameTimer() - local endTime = overrideStartTime or startTime + duration - ActionsInProgress[reboundId] = {reboundId, start, position, duration, shouldRepeat, startTime} - local t = 0 - CreateThread(function() - while shouldRepeat or t < 1 do - -- Check if entity still exists - if not re.entity or not DoesEntityExist(re.entity) then - ActionsInProgress[reboundId] = nil - break - end - entity = re.entity -- Update entity handle in case it changed (unlikely but safe) - t = (GetGameTimer() - startTime) / duration - local lerpPosition = LA.LerpVector(start, position, t) - SetEntityCoordsNoOffset(entity, lerpPosition.x, lerpPosition.y, lerpPosition.z, false, false, false) -- Use NoOffset - Wait(0) - end - -- Set final position if not repeating - if not shouldRepeat and re.entity and DoesEntityExist(re.entity) then - SetEntityCoordsNoOffset(re.entity, position.x, position.y, position.z, false, false, false) - end - ActionsInProgress[reboundId] = nil -- Clear when done - end) -end) diff --git a/modules/math/computation.lua b/modules/math/computation.lua deleted file mode 100644 index f007806..0000000 --- a/modules/math/computation.lua +++ /dev/null @@ -1,70 +0,0 @@ - ----@class Math -------@field public name string @add name field to class Car, you'll see it in code completion -Math = {} - ---- If the value is less than the minimum, it will return the minimum. ---- If the value is greater than the maximum, it will return the maximum. ---- Otherwise, it will return the value. ----@param value number: The value to clamp. ----@param min number: The minimum value. ----@param max number: The maximum value. ----@return number: The clamped value. -function Math.Clamp(value, min, max) - if value < min then - return min - elseif value > max then - return max - else - return value - end -end - ---- Rounds a number to the nearest whole number. ----@param value number: The value to round. ----@return number: The rounded value. -function Math.Round(value) - return math.floor(value + 0.5) -end - -function Math.Truncate(value, decimals) - local mul = decimals and (10 ^ decimals) or 1 - if value < 0 then - return math.ceil(value * mul) / mul - else - return math.floor(value * mul) / mul - end -end - ---- Warps the number around from max to min and vice versa. ----@param value number: The value to wrap. ----@param min number: The minimum value. ----@param max number: The maximum value. ----@return number: The wrapped value. -function Math.Wrap(value, min, max) - local range = max - min - return (value - min) % range + min -end - ---- Gets an interpolated value between two numbers. ----@see https://en.wikipedia.org/wiki/Smoothstep ----@param value number The interpolation value. ----@param min number : The minimum value. ----@param max number : The maximum value. ----@return number The interpolated value. -function Math.Smooth(value, min, max) - value = Math.Clamp((value - min) / (max - min), 0, 1) - return value * value * (3 - 2 * value) -end - ---- Maps a value from one range to another. ----@param value number The value to map. ----@param inMin number The minimum value for the provided value. ----@param inMax number The maximum value for the provided value. ----@param outMin number The minimum value for the output. ----@param outMax number The maximum value for the output. -function Math.Map(value, inMin, inMax, outMin, outMax) - return (value - inMin) / (inMax - inMin) * (outMax - outMin) + outMin -end - -return Math \ No newline at end of file From cba3ba1d98b817371f27766d05f7d823ef4592f0 Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Wed, 20 Aug 2025 23:51:03 -0500 Subject: [PATCH 11/62] forgot to save init file --- lib/init.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/init.lua b/lib/init.lua index ed37f5d..ac11ae4 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -46,7 +46,6 @@ cLib = { Prints = Prints or Require("lib/utility/shared/prints.lua"), Math = Math or Require("lib/utility/shared/math.lua"), LA = LA or Require("lib/utility/shared/la.lua"), - Perlin = Perlin or Require("lib/utility/shared/perlin.lua"), -- Zones = Poly or Require("lib/zones/shared/zones.lua"), -- Action = Action or Require("lib/entities/shared/actions.lua"), } @@ -60,7 +59,6 @@ cLib.Logs = Logs or Require("lib/logs/server/logs.lua") cLib.ItemsBuilder = ItemsBuilder or Require("lib/generators/server/ItemsBuilder.lua") cLib.LootTables = LootTables or Require("lib/generators/server/lootTables.lua") cLib.Cache = Cache or Require("lib/cache/shared/cache.lua") -cLib.ServerEntity = ServerEntity or Require("lib/entities/server/server_entity.lua") cLib.Marker = Marker or Require("lib/markers/server/server.lua") cLib.Particle = Particle or Require("lib/particles/server/particles.lua") cLib.Shell = Shells or Require("lib/shells/server/shells.lua") @@ -80,7 +78,6 @@ cLib.ClientStateBag = ClientStateBag or Require("lib/statebags/client/client.lua cLib.Marker = Marker or Require("lib/markers/client/markers.lua") cLib.Anim = Anim or Require("lib/anim/client/client.lua") cLib.Cutscene = Cutscene or Require("lib/cutscenes/client/cutscene.lua") ---cLib.DUI = DUI or Require("lib/dui/client/dui.lua") cLib.Particle = Particle or Require("lib/particles/client/particles.lua") return cLib From d0d72bdba57d03da9b6fe6d3ccadf68abf3fbae8 Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Thu, 21 Aug 2025 00:09:54 -0500 Subject: [PATCH 12/62] here we go again --- lib/init.lua | 8 ++------ lib/points/client/{pointsv2.lua => points.lua} | 0 lib/utility/client/utility.lua | 2 +- modules/clothing/_default/client.lua | 2 +- modules/clothing/_default/server.lua | 2 +- 5 files changed, 5 insertions(+), 9 deletions(-) rename lib/points/client/{pointsv2.lua => points.lua} (100%) diff --git a/lib/init.lua b/lib/init.lua index ac11ae4..b95fee8 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -41,11 +41,10 @@ cLib = { Require = Require, Callback = Callback or Require("lib/callback/shared/callback.lua"), Ids = Ids or Require("lib/utility/shared/ids.lua"), - ReboundEntities = ReboundEntities or Require("lib/utility/shared/rebound_entities.lua"), Tables = Table or Require("lib/utility/shared/tables.lua"), Prints = Prints or Require("lib/utility/shared/prints.lua"), Math = Math or Require("lib/utility/shared/math.lua"), - LA = LA or Require("lib/utility/shared/la.lua"), + LA = LA or Require("lib/utility/shared/la.lua") -- Zones = Poly or Require("lib/zones/shared/zones.lua"), -- Action = Action or Require("lib/entities/shared/actions.lua"), } @@ -56,8 +55,6 @@ if not IsDuplicityVersion() then goto client end cLib.SQL = SQL or Require("lib/sql/server/sqlHandler.lua") cLib.Logs = Logs or Require("lib/logs/server/logs.lua") -cLib.ItemsBuilder = ItemsBuilder or Require("lib/generators/server/ItemsBuilder.lua") -cLib.LootTables = LootTables or Require("lib/generators/server/lootTables.lua") cLib.Cache = Cache or Require("lib/cache/shared/cache.lua") cLib.Marker = Marker or Require("lib/markers/server/server.lua") cLib.Particle = Particle or Require("lib/particles/server/particles.lua") @@ -70,11 +67,10 @@ cLib.Placeable = Placeable or Require("lib/placers/client/object_placer.lua") cLib.Utility = Utility or Require("lib/utility/client/utility.lua") cLib.PlaceableObject = ObjectPlacer or Require("lib/placers/client/placeable_object.lua") cLib.Raycast = Raycast or Require("lib/raycast/client/raycast.lua") -cLib.Point = Point or Require("lib/points/client/pointsv2.lua") +cLib.Point = Point or Require("lib/points/client/points.lua") cLib.Particle = Particle or Require("lib/particles/client/particles.lua") cLib.Cache = Cache or Require("lib/cache/client/cache.lua") cLib.ClientEntity = ClientEntity or Require("lib/entities/client/client_entity.lua") -cLib.ClientStateBag = ClientStateBag or Require("lib/statebags/client/client.lua") cLib.Marker = Marker or Require("lib/markers/client/markers.lua") cLib.Anim = Anim or Require("lib/anim/client/client.lua") cLib.Cutscene = Cutscene or Require("lib/cutscenes/client/cutscene.lua") diff --git a/lib/points/client/pointsv2.lua b/lib/points/client/points.lua similarity index 100% rename from lib/points/client/pointsv2.lua rename to lib/points/client/points.lua diff --git a/lib/utility/client/utility.lua b/lib/utility/client/utility.lua index 050a058..0ebcf95 100644 --- a/lib/utility/client/utility.lua +++ b/lib/utility/client/utility.lua @@ -3,7 +3,7 @@ local blipIDs = {} local spawnedPeds = {} Locales = Locales or Require('modules/locales/shared.lua') -Point = Point or Require('lib/points/client/pointsv2.lua') +Point = Point or Require('lib/points/client/points.lua') ---Get the hash of a model (string or number) ---@param model string|number diff --git a/modules/clothing/_default/client.lua b/modules/clothing/_default/client.lua index abd882c..47f0380 100644 --- a/modules/clothing/_default/client.lua +++ b/modules/clothing/_default/client.lua @@ -2,7 +2,7 @@ Clothing = Clothing or {} ClothingBackup = {} -Callback = Callback or Require("lib/utility/shared/callbacks.lua") +Callback = Callback or Require("lib/callback/shared/callback.lua") Ultility = Utility or Require('lib/utility/client/utility.lua') Cache = Cache or Require('lib/cache/shared/cache.lua') diff --git a/modules/clothing/_default/server.lua b/modules/clothing/_default/server.lua index c6c2d0e..312df50 100644 --- a/modules/clothing/_default/server.lua +++ b/modules/clothing/_default/server.lua @@ -1,7 +1,7 @@ ---@diagnostic disable: duplicate-set-field Clothing = Clothing or {} Clothing.LastAppearance = Clothing.LastAppearance or {} -Callback = Callback or Require("lib/utility/shared/callbacks.lua") +Callback = Callback or Require("lib/callback/shared/callback.lua") function Clothing.IsMale(src) local ped = GetPlayerPed(src) From a1181c2758142207c5dd14dfe410a2fdc4fea229 Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Thu, 21 Aug 2025 02:27:38 -0500 Subject: [PATCH 13/62] distance compatibility --- modules/target/qb-target/client.lua | 36 ++++++++++++++++++----------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/modules/target/qb-target/client.lua b/modules/target/qb-target/client.lua index 46288b2..6fd49d2 100644 --- a/modules/target/qb-target/client.lua +++ b/modules/target/qb-target/client.lua @@ -17,6 +17,16 @@ local targetZones = {} Target = Target or {} local qb_target = exports['qb-target'] +function GetLargestDistance(data) + local largestDistance = -1 + for _, v in pairs(data) do + if v.distance and v.distance > largestDistance then + largestDistance = v.distance + end + end + return largestDistance ~= -1 and largestDistance or 2.0 +end + ---This is an internal function that is used to fix the options passed to fit alternative target systems, for example qb-ox or ox-qb etc. ---@param options table @@ -63,7 +73,7 @@ Target.AddGlobalPlayer = function(options) options = Target.FixOptions(options) qb_target:AddGlobalPlayer({ options = options, - distance = options.distance or 1.5 + distance = GetLargestDistance(options) }) end @@ -74,11 +84,11 @@ end ---This will add target options to all specified models. This is useful for when you want to add target options to all models of a specific type. ---@param options table -Target.AddGlobalPed = function(options) +Target.AddGlobalPed = function(options, distance) options = Target.FixOptions(options) qb_target:AddGlobalPed({ options = options, - distance = options.distance or 1.5 + distance = GetLargestDistance(options) }) end @@ -90,11 +100,11 @@ end ---This will add taget options to all vehicles. ---@param options table -Target.AddGlobalVehicle = function(options) +Target.AddGlobalVehicle = function(options, distance) options = Target.FixOptions(options) qb_target:AddGlobalVehicle({ options = options, - distance = options.distance or 1.5 + distance = GetLargestDistance(options) }) end @@ -126,11 +136,11 @@ end ---This will generate targets on non networked entites with the passed options. ---@param entities number | table ---@param options table -Target.AddLocalEntity = function(entities, options) +Target.AddLocalEntity = function(entities, options, distance) options = Target.FixOptions(options) qb_target:AddTargetEntity(entities, { options = options, - distance = options.distance or 1.5 + distance = GetLargestDistance(options) }) end @@ -144,11 +154,11 @@ end ---This will add target options to all specified models. This is useful for when you want to add target options to all models of a specific type. ---@param models number | table ---@param options table -Target.AddModel = function(models, options) +Target.AddModel = function(models, options, distance) options = Target.FixOptions(options) qb_target:AddTargetModel(models, { options = options, - distance = options.distance or 1.5, + distance = GetLargestDistance(options), }) end @@ -164,7 +174,7 @@ end ---@param size table ---@param heading number ---@param options table -Target.AddBoxZone = function(name, coords, size, heading, options, debug) +Target.AddBoxZone = function(name, coords, size, heading, options, debug, distance) options = Target.FixOptions(options) if not next(options) then return end qb_target:AddBoxZone(name, coords, size.x, size.y, { @@ -175,7 +185,7 @@ Target.AddBoxZone = function(name, coords, size, heading, options, debug) maxZ = coords.z + (size.z * 0.5), }, { options = options, - distance = options.distance or 1.5, + distance = GetLargestDistance(options), }) table.insert(targetZones, { name = name, creator = GetInvokingResource() }) end @@ -185,14 +195,14 @@ end ---@param coords table ---@param radius number ---@param options table -Target.AddSphereZone = function(name, coords, radius, options, debug) +Target.AddSphereZone = function(name, coords, radius, options, debug, distance) options = Target.FixOptions(options) qb_target:AddCircleZone(name, coords, radius, { name = name, debugPoly = targetDebug or debug, }, { options = options, - distance = options.distance or 1.5, + distance = GetLargestDistance(options), }) table.insert(targetZones, { name = name, creator = GetInvokingResource() }) end From f2fad0cb5bc3b725044215791702cbba2e309b77 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Thu, 21 Aug 2025 05:37:44 -0400 Subject: [PATCH 14/62] Update server.lua --- modules/doorlock/ox_doorlock/server.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/doorlock/ox_doorlock/server.lua b/modules/doorlock/ox_doorlock/server.lua index 739751d..b7f8461 100644 --- a/modules/doorlock/ox_doorlock/server.lua +++ b/modules/doorlock/ox_doorlock/server.lua @@ -4,10 +4,13 @@ if GetResourceState('ox_doorlock') == 'missing' then return end Doorlock = Doorlock or {} ---This will toggle the lock status of the door. ----@param doorID string +---@param doorID string|number ---@param toggle boolean ---@return boolean Doorlock.ToggleDoorLock = function(doorID, toggle) + if type(doorID) == 'string' then + doorID = tonumber(doorID) + end local state = toggle if state then exports.ox_doorlock:setDoorState(doorID, 1) From 4e313c40cb4cca2199cf806d0fb1cb44bb62c1b4 Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Fri, 22 Aug 2025 03:27:03 -0500 Subject: [PATCH 15/62] Update to utility for blip added .CreateBlipRadius which makes a circular blip with some radius in meters --- lib/utility/client/utility.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/utility/client/utility.lua b/lib/utility/client/utility.lua index 0ebcf95..45476b0 100644 --- a/lib/utility/client/utility.lua +++ b/lib/utility/client/utility.lua @@ -131,6 +131,19 @@ function Utility.CreateBlip(coords, sprite, color, scale, label, shortRange, dis return blip end +function Utility.CreateBlipRadius(coords, radius, color, alpha, label, shortRange, displayType) + local blip = AddBlipForRadius(coords.x, coords.y, coords.z, radius) + SetBlipColour(blip, color or 3) + SetBlipAlpha(blip, alpha or 255) + SetBlipDisplay(blip, displayType or 2) + SetBlipAsShortRange(blip, shortRange) + AddTextEntry(label, label) + BeginTextCommandSetBlipName(label) + EndTextCommandSetBlipName(blip) + blipIDs[tostring(blip)] = blip + return blip +end + ---Create a blip on the provided entity ---@param entity number ---@param sprite number From 2da3fed196cab6acb258c27b223c94c6820ca16c Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Fri, 22 Aug 2025 03:33:42 -0500 Subject: [PATCH 16/62] following convention for blips switched to follow naming convention for others --- lib/utility/client/utility.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utility/client/utility.lua b/lib/utility/client/utility.lua index 45476b0..762d26f 100644 --- a/lib/utility/client/utility.lua +++ b/lib/utility/client/utility.lua @@ -131,7 +131,7 @@ function Utility.CreateBlip(coords, sprite, color, scale, label, shortRange, dis return blip end -function Utility.CreateBlipRadius(coords, radius, color, alpha, label, shortRange, displayType) +function Utility.CreateRadiusBlip(coords, radius, color, alpha, label, shortRange, displayType) local blip = AddBlipForRadius(coords.x, coords.y, coords.z, radius) SetBlipColour(blip, color or 3) SetBlipAlpha(blip, alpha or 255) From 48cba10ad2dab3ccc03000ac24fb3f29f6a7f113 Mon Sep 17 00:00:00 2001 From: solaire-fivem Date: Fri, 22 Aug 2025 22:08:41 +0100 Subject: [PATCH 17/62] fix minor typo, 'platerData' to 'playerData' --- modules/framework/qbx_core/client.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/framework/qbx_core/client.lua b/modules/framework/qbx_core/client.lua index 88cac76..7ba21b9 100644 --- a/modules/framework/qbx_core/client.lua +++ b/modules/framework/qbx_core/client.lua @@ -168,8 +168,8 @@ end ---This will get a players dead status. ---@return boolean Framework.GetIsPlayerDead = function() - local platerData = Framework.GetPlayerData() - return platerData.metadata["isdead"] or platerData.metadata["inlaststand"] + local playerData = Framework.GetPlayerData() + return playerData.metadata["isdead"] or playerData.metadata["inlaststand"] end RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() From fcd279b30aa903aee3343aa060410d167558651a Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Fri, 22 Aug 2025 16:49:17 -0500 Subject: [PATCH 18/62] Zones compatibility Createzone, remove zone, cleanup on resource stop, cleanup on invoked resource stop, --- examples/zones.lua | 53 +++++++++++++ fxmanifest.lua | 1 + init.lua | 3 +- modules/menu/ox_lib/client.lua | 2 + modules/zones/oxlib/client.lua | 122 ++++++++++++++++++++++++++++++ modules/zones/polyzone/client.lua | 116 ++++++++++++++++++++++++++++ 6 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 examples/zones.lua create mode 100644 modules/zones/oxlib/client.lua create mode 100644 modules/zones/polyzone/client.lua diff --git a/examples/zones.lua b/examples/zones.lua new file mode 100644 index 0000000..d3f676a --- /dev/null +++ b/examples/zones.lua @@ -0,0 +1,53 @@ +Bridge = Bridge or exports['community_bridge']:Bridge() + +RegisterCommand('testboxzone', function(source, args, rawCommand) + local playerPos = GetEntityCoords(PlayerPedId()) + Bridge.Zones.Create("box", { + coords = vector3(playerPos.x, playerPos.y, playerPos.z), + size = vector3(2, 2, 6), + heading = 90, + debug = true, + onEnter = function(data) + print("Entered Zone: " .. data.id) + end, + onExit = function(data) + print("Exited Zone:") + end + }) +end, false) + +RegisterCommand('testpolyzone', function(source, args, rawCommand) + local playerPos = GetEntityCoords(PlayerPedId()) + Bridge.Zones.Create("poly", { + points = { + vector3(playerPos.x - 1, playerPos.y - 1, playerPos.z), + vector3(playerPos.x + 1, playerPos.y - 1, playerPos.z), + vector3(playerPos.x + 1, playerPos.y + 1, playerPos.z), + vector3(playerPos.x - 1, playerPos.y + 1, playerPos.z) + }, + size = vector3(1, 1, 1), + heading = 90, + debug = true, + onEnter = function(data) + print("Entered Zone: " .. data.id) + end, + onExit = function(data) + print("Exited Zone:") + end + }) +end, false) + +RegisterCommand('testspherezone', function(source, args, rawCommand) + local playerPos = GetEntityCoords(PlayerPedId()) + Bridge.Zones.Create("sphere", { + coords = vector3(playerPos.x, playerPos.y, playerPos.z), + radius = 2.0, + debug = true, + onEnter = function(data) + print("Entered Zone: " .. data.id) + end, + onExit = function(data) + print("Exited Zone:") + end + }) +end, false) diff --git a/fxmanifest.lua b/fxmanifest.lua index 8fa380e..361d07c 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -61,6 +61,7 @@ client_scripts { 'modules/housing/**/client.lua', 'modules/skills/**/client.lua', 'modules/bossmenu/**/client.lua', + 'modules/zones/**/client.lua', 'init.lua', -- 'unit_tests/*.lua', } diff --git a/init.lua b/init.lua index f4b020b..0d6bc0d 100644 --- a/init.lua +++ b/init.lua @@ -106,4 +106,5 @@ Bridge.RegisterModule("Weather", Weather) Bridge.RegisterModule("Target", Target) Bridge.RegisterModule("Menu", Menu) -Bridge.RegisterModule("Dialogue", Dialogue) \ No newline at end of file +Bridge.RegisterModule("Dialogue", Dialogue) +Bridge.RegisterModule("Zones", cZones) \ No newline at end of file diff --git a/modules/menu/ox_lib/client.lua b/modules/menu/ox_lib/client.lua index 6b65140..710dac0 100644 --- a/modules/menu/ox_lib/client.lua +++ b/modules/menu/ox_lib/client.lua @@ -3,6 +3,8 @@ local configValue = BridgeClientConfig.MenuSystem if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end Menus = Menus or {} +lib = lib or Require("init.lua", "ox_lib") + ---Converts a QB menu to an Ox menu. ---@param id string The menu ID. ---@param menu table The QB menu data. diff --git a/modules/zones/oxlib/client.lua b/modules/zones/oxlib/client.lua new file mode 100644 index 0000000..26f67ca --- /dev/null +++ b/modules/zones/oxlib/client.lua @@ -0,0 +1,122 @@ +---@diagnostic disable: duplicate-set-field +local resourceName = "ox_lib" +if GetResourceState(resourceName) == 'missing' then return end +lib = lib or Require("init.lua", "ox_lib") +Ids = Ids or Require('lib/utility/shared/ids.lua') + +cZones = {} --conflict with ox +cZones.All = {} +function cZones.Create(type, data) + assert(type, "Requires zone type ('box', 'sphere', or 'poly')") + assert(data, "Requires data table") + data.id = Ids.CreateUniqueId(cZones.All) + data.invoking = GetInvokingResource() or "unknown" + + local onEnter = data.onEnter or data.OnEnter + local onExit = data.onExit or data.OnExit + local zone = nil + if type == "box" then + assert(data.coords, "Requires .coords as vector3 in data") + local width = data.size?.x or data.length or 1.0 + local height = data.size?.y or data.width or 1.0 + local z = data.size?.z or data.height or 1.0 + zone = lib.zones.box({ + coords = data.coords, + size = vec3(width, height, z), + rotation = data.heading or data.rotation or 0.0, + debug = data.debug or false, + onEnter = function(point) + if onEnter then + onEnter(data) + end + end, + onExit = function(point) + if onExit then + onExit(data) + end + end, + }) + data.zone = zone + print("Created Zone: " .. data.id, json.encode(cZones.All)) + cZones.All[data.id] = data + return data.id + elseif type == "sphere" then + assert(data.coords, "Requires .coords as vector3 in data") + data.radius = data.radius or data.size?.x or 1 + lib.zones.sphere(data) + local zone = lib.zones.sphere({ + coords = data.coords, + radius = data.radius, + debug = data.debug or false, + onEnter = function(point) + data.zone = data.zone or point + if onEnter then + onEnter(data) + end + end, + onExit = function(point) + data.zone = data.zone or point + if onExit then + onExit(data) + end + end, + }) + data.zone = zone + cZones.All[data.id] = data + return data.id + elseif type == "poly" then + assert(data.points, "Requires an array of vector2 in .points") + assert(#data.points > 2, "Requires at least three points in .points") + local zSize = data.minZ or data.size?.z or data.height or data.thickness or 2 + + local polyZone = lib.zones.poly({ + points = data.points, + thickness = zSize, + debug = data.debug or false, + onEnter = function(point) + data.zone = data.zone or point + if onEnter then + onEnter(data) + end + end, + onExit = function(point) + data.zone = data.zone or point + if onExit then + onExit(data) + end + end, + }) + data.zone = polyZone + cZones.All[data.id] = data + return data.id + end + return nil +end + +function cZones.Destroy(id) + if not id then return false end + local zone = cZones.All[id].zone + if not zone then return false end + zone:remove() + cZones.All[id] = nil + return true +end + +function cZones.DestroyByResource(resource) + if not resource then return false end + for id, zone in pairs(cZones.All or {}) do + if zone.invoking == resource then + zone.zone:remove() + end + end + return true +end + +function cZones.Get(id) + if not id then return nil end + return cZones.All[id] +end + +RegisterNetEvent("onResourceStop", function(resource) + cZones.DestroyByResource(resource) +end) diff --git a/modules/zones/polyzone/client.lua b/modules/zones/polyzone/client.lua new file mode 100644 index 0000000..7d9fa42 --- /dev/null +++ b/modules/zones/polyzone/client.lua @@ -0,0 +1,116 @@ +---@diagnostic disable: duplicate-set-field + +local resourceName = "PolyZone" +if GetResourceState(resourceName) == 'missing' or GetResourceState('ox_lib') ~= 'missing' then return end + +Require("client.lua", resourceName) +Require("BoxZone.lua", resourceName) +Require("EntityZone.lua", resourceName) +Require("CircleZone.lua", resourceName) +Require("ComboZone.lua", resourceName) +Ids = Ids or Require('lib/utility/shared/ids.lua') +cZones = { + All = {} +} +--- Create a zone of the specified type. +--- Supported types: "box", "sphere", "poly" +---@param type ZoneType +---@param data ZoneData +---@return string|nil id Returns the generated zone id on success, or nil on failure +function cZones.Create(type, data) + assert(type, "Requires zone type ('box', 'sphere', or 'poly')") + assert(data, "Requires data table") + data.id = Ids.CreateUniqueId(cZones.All) + data.invoking = GetInvokingResource() or "unknown" + local zone = nil + if type == "box" then + assert(data.coords, "Requires .coords as vector3 in data") + local width = data.size.x or data.length or 1.0 + local height = data.size.y or data.width or 1.0 + local z = data.size?.z or data.height or 1.0 + data.size = vec3(width, height, z) + data.heading = data.heading or data.rotation + data.rotation = data.heading + zone = BoxZone:Create(data.coords, width, height, { + name = data.id, + debugPoly = data.debug, + minZ = data.coords.z - 0.5, + maxZ = data.coords.z + z - 0.5, + heading = data.heading or data.rotation + }) + elseif type == "sphere" then + assert(data.coords, "Requires .coords as vector3 in data") + data.radius = data.radius or data.size?.x or 1 + zone = CircleZone:Create(data.coords, data.radius, { + name = data.id, + debugPoly = data.debug, + }) + elseif type == "poly" then + assert(data.points, "Requires an array of vector2 in .points") + assert(#data.points > 2, "Requires at least three points in .points") + local zSize = data.minZ or data.size?.z or data.height or data.thickness or 2 + local firstPoint = data.points[1] + local firstZ = firstPoint.z + zone = PolyZone:Create(data.points, { + name = data.id, + debugPoly = data.debug, + minZ = firstZ - 0.5, + maxZ = firstZ and (firstZ + zSize - 0.5) or nil, + }) + end + if not zone then return end + data.zone = zone + zone:onPlayerInOut(function(isInside, _) + if isInside then + if data.onEnter or data.OnEnter then + (data.onEnter or data.OnEnter)(data) + end + else + if data.onExit or data.OnExit then + (data.onExit or data.OnExit)(data) + end + end + end) + + cZones.All[data.id] = data + return data.id +end + +--- Destroy a zone by id. +---@param id string +---@return boolean success True if destroyed, false otherwise +function cZones.Destroy(id) + if not id then return false end + local zone = cZones.All[id].zone + if not zone then return false end + zone:destroy() + cZones.All[id] = nil + return true +end + +--- Destroy all zones created by a specific resource. +---@param resource string Name of the invoking resource +---@return boolean success True if operation completed (no guarantee zones existed) +function cZones.DestroyByResource(resource) + if not resource then return false end + for id, zone in pairs(cZones.All) do + if zone.invoking == resource then + zone.zone:destroy() + end + end + return true +end + +--- Retrieve zone data by id. +---@param id string +---@return ZoneData|nil +function cZones.Get(id) + if not id then return nil end + return cZones.All[id] +end + +--- Event handler: clean up zones when a resource stops. +---@param resource string +RegisterNetEvent("onResourceStop", function(resource) + cZones.DestroyByResource(resource) +end) From 8c309e248ea446b1e707803193d4f427dc9cc3a1 Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Sat, 23 Aug 2025 22:53:49 -0500 Subject: [PATCH 19/62] Added behaviors and documentation to oxlibs zones Will provide file in example when more features are implimented --- examples/behaviorTemplate.lua | 20 +++ fxmanifest.lua | 5 +- lib/entities/client/behaviors.lua | 61 ++++++++ lib/entities/client/behaviors/init.lua | 20 +++ lib/entities/client/behaviors/particles.lua | 56 +++++++ lib/entities/client/behaviors/targets.lua | 54 +++++++ lib/entities/client/client_entity.lua | 162 +++++++++++++------- lib/particles/client/particles.lua | 116 ++++++-------- lib/points/client/points.lua | 9 +- modules/target/qb-target/client.lua | 10 +- modules/zones/oxlib/client.lua | 39 +++++ 11 files changed, 418 insertions(+), 134 deletions(-) create mode 100644 examples/behaviorTemplate.lua create mode 100644 lib/entities/client/behaviors.lua create mode 100644 lib/entities/client/behaviors/init.lua create mode 100644 lib/entities/client/behaviors/particles.lua create mode 100644 lib/entities/client/behaviors/targets.lua diff --git a/examples/behaviorTemplate.lua b/examples/behaviorTemplate.lua new file mode 100644 index 0000000..383eb5f --- /dev/null +++ b/examples/behaviorTemplate.lua @@ -0,0 +1,20 @@ +-- -- Make sure to include filename in the init (prefix of the .lua)Utility = Utility or Require("lib/utility/client/utility.lua") +-- local ParticlesBehaviors = { +-- tag = "isTemplate", +-- default = { +-- } + +-- } + +-- function ParticlesBehaviors.OnSpawn(entityData) +-- end + + +-- function ParticlesBehaviors.OnRemove(entityData) +-- end + +-- function ParticlesBehaviors.OnUpdate(entityData) + +-- end + +-- return ParticlesBehaviors diff --git a/fxmanifest.lua b/fxmanifest.lua index 361d07c..5e430ad 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -73,9 +73,8 @@ files { 'web/dist/assets/*.css', 'web/dist/assets/*.js', 'locales/*.json', - 'lib/**/client/*.lua', - 'lib/**/shared/*.lua', - 'lib/**/server/*.lua', + 'lib/**/**/*.lua', + 'lib/**/**/**/*.lua', 'modules/**', 'settings/*.lua', 'lib/init.lua', diff --git a/lib/entities/client/behaviors.lua b/lib/entities/client/behaviors.lua new file mode 100644 index 0000000..8641d03 --- /dev/null +++ b/lib/entities/client/behaviors.lua @@ -0,0 +1,61 @@ +Behaviors = { + All = {}, + isSetup = false, +} + +function Behaviors.Setup() + if Behaviors.isSetup then return end + Behaviors.isSetup = true + local behaviors = Require("lib/entities/client/behaviors/init.lua") + for _, behavior in ipairs(behaviors) do + Behaviors.Create(behavior.tag, behavior) + end +end + +function Behaviors.Create(behaviorId, behavior) + if not behaviorId or not behavior then return end + if Behaviors.All[behaviorId] then + print(string.format("[ClientEntity] Behavior %s already exists", behaviorId)) + return + end + Behaviors.All[behaviorId] = behavior +end + +function Behaviors.Get(behaviorId) + return Behaviors.All[behaviorId] +end + +function Behaviors.Remove(behaviorId) + if not Behaviors.All[behaviorId] then return end + Behaviors.All[behaviorId] = nil + return true +end + +function Behaviors.Trigger(actionName, clientEntityData, ...) + if not clientEntityData or not actionName then return end + for tag, behavior in pairs(Behaviors.All) do + local hasBehaviorArgs = Behaviors.Has(tag, clientEntityData) -- this is everything that's contained inside the object's individual tag + if hasBehaviorArgs and behavior[actionName] then + behavior[actionName](clientEntityData, hasBehaviorArgs, ...) + end + end +end + +function Behaviors.Inherit(behaviorId, clientEntityData, defaultData) + if not Behaviors.All[behaviorId] then + print(string.format("[ClientEntity] Behavior %s does not exist", behaviorId)) + return false + end + if not clientEntityData or not clientEntityData.id then + print("[ClientEntity] Invalid client entity data provided for inheritance") + return false + end + clientEntityData[behaviorId] = defaultData or {} -- Mark the entity as having this behavior + return true +end + +function Behaviors.Has(behaviorId, clientEntityData) + return clientEntityData and clientEntityData[behaviorId] +end + +return Behaviors \ No newline at end of file diff --git a/lib/entities/client/behaviors/init.lua b/lib/entities/client/behaviors/init.lua new file mode 100644 index 0000000..8c70fff --- /dev/null +++ b/lib/entities/client/behaviors/init.lua @@ -0,0 +1,20 @@ +local fileList = { + "particles", + "targets", +} + +local path = "lib/entities/client/behaviors/" + +local function loadAllResources() + local modules = {} + for _, fileName in ipairs(fileList) do + local filePath = path .. fileName .. ".lua" + local required = Require(filePath) + if required then + table.insert(modules, required) + end + end + return modules +end + +return loadAllResources() \ No newline at end of file diff --git a/lib/entities/client/behaviors/particles.lua b/lib/entities/client/behaviors/particles.lua new file mode 100644 index 0000000..418569b --- /dev/null +++ b/lib/entities/client/behaviors/particles.lua @@ -0,0 +1,56 @@ +Utility = Utility or Require("lib/utility/client/utility.lua") +local ParticlesBehaviors = { + tag = "particles", + default = { + dict = "cut_exile3", + ptfx = "cs_ex3_wheel_spin", + offset = vector3(0, 0, 0), + rotation = vector3(0, 0, 0), + size = 1.0, + color = vector3(255, 255, 255), + loopLength = 5000, + } + +} + +function ParticlesBehaviors.OnSpawn(entityData) + if not entityData.particles then return end + if entityData.particles.dict then -- single particle + entityData.particles = {entityData.particles} + end + + for _, particleData in ipairs(entityData.particles) do + local position = vector3(entityData.coords.x, entityData.coords.y, entityData.coords.z) + local rotation = vector3(entityData.rotation.x, entityData.rotation.y, entityData.rotation.z) + position = position + (particleData.offset?.xyz or vector3(0, 0, 0)) + rotation = rotation + (particleData.rotation?.xyz or vector3(0, 0, 0)) + particleData.playing = Particle.Play( + particleData.dict or ParticlesBehaviors.default.dict, + particleData.ptfx or ParticlesBehaviors.default.ptfx, + position, + rotation, + particleData.size or ParticlesBehaviors.default.size, + particleData.color or ParticlesBehaviors.default.color, + particleData.looped, + particleData.loopLength or ParticlesBehaviors.default.loopLength + ) + end +end + + +function ParticlesBehaviors.OnRemove(entityData) + if not entityData.particles then return end + for _, particleData in ipairs(entityData.particles) do + if particleData.playing then + Particle.Stop(particleData.playing) + particleData.playing = nil + end + end +end + +-- function ParticlesBehaviors.OnUpdate(entityData) +-- if not entityData.particles then return end + +-- end + +return ParticlesBehaviors diff --git a/lib/entities/client/behaviors/targets.lua b/lib/entities/client/behaviors/targets.lua new file mode 100644 index 0000000..81135c2 --- /dev/null +++ b/lib/entities/client/behaviors/targets.lua @@ -0,0 +1,54 @@ + +local Targets = { + tag = "targets", + default = { + label = "Default Target Label", + distance = 2, + } +} + + +function Targets.OnSpawn(entityData) + if not entityData.spawned or not entityData.target then return end + if entityData.targets?.label then + entityData.newTargets = {entityData.targets} + else + entityData.newTargets = entityData.targets or {} + end + for k, v in pairs(entityData.newTargets) do + local onSelect = v.onSelect + if onSelect then + v.onSelect = function(entity) + onSelect(entityData, entity) + end + end + end + Target.AddLocalEntity(entityData.spawned, entityData.newTargets) + entityData.oldTargets = entityData.newTargets +end + +function Targets.OnRemove(entityData) + if not entityData.spawned or not entityData.newTargets then return end + Target.RemoveLocalEntity(entityData.spawned) +end + +function Targets.OnUpdate(entityData) + if not entityData.spawned or not entityData.newTargets then return end + for i, target in ipairs(entityData.oldTargets) do + local newTarget = entityData.targets.label + if newTarget then + entityData.newTargets = {entityData.targets} + end + newTarget = entityData.newTargets[i] + if newTarget + and target.label ~= newTarget.label + or target.distance ~= newTarget.distance + or target.description ~= newTarget.description + then + Targets.OnRemove(entityData) + Targets.OnSpawn(entityData) + end + end +end + +return Targets \ No newline at end of file diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index 85a3fab..7892405 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -1,12 +1,17 @@ Utility = Utility or Require("lib/utility/client/utility.lua") Ids = Ids or Require("lib/utility/shared/ids.lua") Point = Point or Require("lib/points/client/points.lua") - +Behaviors = Behaviors or Require("lib/entities/client/behaviors.lua") local Entities = {} -- Stores entity data received from server ClientEntity = {} -- Renamed from BaseEntity +ClientEntity.Behaviors = Behaviors + + + + +-------------------- local function SpawnEntity(entityData) - entityData = entityData and entityData.args if entityData.spawned and DoesEntityExist(entityData.spawned) then return end -- Already spawned local loaded, model = Utility.LoadModel(entityData.model) if not loaded then @@ -39,13 +44,15 @@ local function SpawnEntity(entityData) if entityData.OnSpawn then pcall(function (...) return entityData.OnSpawn(entityData) - end) + end) end + Behaviors.Trigger("OnSpawn", entityData) end local function RemoveEntity(entityData) entityData = entityData and entityData.args or entityData if not entityData then return end + Behaviors.Trigger("OnRemove", entityData) if entityData.OnRemove then pcall(function (...) return entityData.OnRemove(entityData) @@ -59,13 +66,48 @@ local function RemoveEntity(entityData) end end +local function UpdateEntity(_entityData) + local entityData = ClientEntity.Get(_entityData.id) + if not entityData then return end + if entityData.oldCoords and entityData.oldCoords ~= entityData.coords then + local dist = #(entityData.coords.xyz - entityData.oldCoords.xyz) + if dist > 0.1 then + ClientEntity.UpdateCoords(entityData.id, entityData.coords) + end + entityData.oldCoords = entityData.coords + end + + if not entityData.oldRotation or entityData.oldRotation ~= entityData.rotation then + if entityData.spawned and DoesEntityExist(entityData.spawned) then + if entityData.entityType == 'object' then + SetEntityRotation(entityData.spawned, entityData.rotation.x, entityData.rotation.y, entityData.rotation.z, 2, true) + else -- Ped/Vehicle heading + SetEntityHeading(entityData.spawned, type(entityData.rotation) == 'number' and entityData.rotation or entityData.rotation.z) + end + end + entityData.oldRotation = entityData.rotation + end + if entityData.OnUpdate then + pcall(function (...) + return entityData.OnUpdate(entityData) + end) + end + Behaviors.Trigger("OnUpdate", entityData) +end + --- Registers an entity received from the server and sets up proximity spawning. -- @param entityData table Data received from the server via 'community_bridge:client:CreateEntity' function ClientEntity.Create(entityData) entityData.id = entityData.id or Ids.CreateUniqueId(Entities) - if Entities[entityData.id] then return Entities[entityData.id] end -- Already registered - Entities[entityData.id] = entityData - return Point.Register(entityData.id, entityData.coords, entityData.spawnDistance or 50.0, entityData, SpawnEntity, RemoveEntity, function() end) + if Entities[entityData.id] then return Entities[entityData.id] end + entityData.rotation = entityData.rotation or vector3(0.0, 0.0, entityData.heading or 0.0) + entityData.oldCoords = entityData.oldCoords or vector3(0.0, 0.0, 0.0) + entityData.oldRotation = entityData.rotation + + local entityPoint = Point.Register(entityData.id, entityData.coords, entityData.spawnDistance or 50.0, entityData, SpawnEntity, RemoveEntity, UpdateEntity) + Entities[entityData.id] = entityPoint + Behaviors.Trigger("OnCreate", entityPoint) + return entityPoint end --Depricated use ClientEntity.Create instead @@ -97,61 +139,68 @@ function ClientEntity.Destroy(id) end ClientEntity.Unregister = ClientEntity.Destroy + + +function ClientEntity.Set(id, key, value) + local entityData = ClientEntity.Get(id) + if not entityData then return print(string.format("[ClientEntity] SetKey: Entity %s does not exist", id)) end + entityData[key] = value +end + --- Updates the data for a registered entity. -- @param id string|number The ID of the entity to update. -- @param data table The data fields to update. -function ClientEntity.Update(id, data) - local entityData = Entities[id] - -- print(string.format("[ClientEntity] Updating entity %s", id)) - if not entityData then return end +-- function ClientEntity.Update(id, data) +-- local entityData = ClientEntity.Get(id) +-- if not entityData then return end - local needsPointUpdate = false - for key, value in pairs(data) do - if key == 'coords' and #(entityData.coords - value) > 0.1 then - needsPointUpdate = true - end - if key == 'spawnDistance' and entityData.spawnDistance ~= value then - needsPointUpdate = true - end - entityData[key] = value - end +-- local needsPointUpdate = false +-- for key, value in pairs(data) do +-- if key == 'coords' and #(entityData.coords - value) > 0.1 then +-- needsPointUpdate = true +-- end +-- if key == 'spawnDistance' and entityData.spawnDistance ~= value then +-- needsPointUpdate = true +-- end +-- entityData[key] = value +-- end - -- If entity is currently spawned, apply updates - if entityData.spawned and DoesEntityExist(entityData.spawned) then - if data.coords then - SetEntityCoords(entityData.spawned, entityData.coords.x, entityData.coords.y, entityData.coords.z, false, false, false, true) - end - if data.rotation then - if entityData.entityType == 'object' then - SetEntityRotation(entityData.spawned, entityData.rotation.x, entityData.rotation.y, entityData.rotation.z, 2, true) - else -- Ped/Vehicle heading - SetEntityHeading(entityData.spawned, type(entityData.rotation) == 'number' and entityData.rotation or entityData.rotation.z) - end - end - if data.freeze ~= nil then - FreezeEntityPosition(entityData.spawned, data.freeze) - end - -- Add other updatable properties as needed - end +-- -- If entity is currently spawned, apply updates +-- if entityData.spawned and DoesEntityExist(entityData.spawned) then +-- if data.coords then +-- SetEntityCoords(entityData.spawned, entityData.coords.x, entityData.coords.y, entityData.coords.z, false, false, false, true) +-- end +-- if data.rotation then +-- if entityData.entityType == 'object' then +-- SetEntityRotation(entityData.spawned, entityData.rotation.x, entityData.rotation.y, entityData.rotation.z, 2, true) +-- else -- Ped/Vehicle heading +-- SetEntityHeading(entityData.spawned, type(entityData.rotation) == 'number' and entityData.rotation or entityData.rotation.z) +-- end +-- end +-- if data.freeze ~= nil then +-- FreezeEntityPosition(entityData.spawned, data.freeze) +-- end +-- -- Add other updatable properties as needed +-- end - -- Update Point registration if coords or distance changed - if needsPointUpdate then - Point.Remove(id) - Point.Register( - entityData.id, - entityData.coords, - entityData.spawnDistance or 50.0, - SpawnEntity, - RemoveEntity, - nil, - entityData - ) - end +-- -- Update Point registration if coords or distance changed +-- if needsPointUpdate then +-- Point.Remove(id) +-- Point.Register( +-- entityData.id, +-- entityData.coords, +-- entityData.spawnDistance or 50.0, +-- entityData, +-- SpawnEntity, +-- RemoveEntity, +-- OnUpdateEntity +-- ) +-- end - if entityData.OnUpdate and type(entityData.OnUpdate) == 'function' then - entityData.OnUpdate(entityData, data) - end -end +-- if entityData.OnUpdate and type(entityData.OnUpdate) == 'function' then +-- entityData.OnUpdate(entityData, data) +-- end +-- end function ClientEntity.Get(id) return Entities[id] @@ -228,6 +277,11 @@ RegisterNetEvent("community_bridge:client:UpdateEntity", function(id, data) ClientEntity.Update(id, data) end) +AddEventHandler('onResourceStart', function(resourceName) + if resourceName ~= GetCurrentResourceName() then return end + Behaviors.Setup() +end) + -- Resource Stop Cleanup AddEventHandler('onResourceStop', function(resourceName) if resourceName == GetCurrentResourceName() then diff --git a/lib/particles/client/particles.lua b/lib/particles/client/particles.lua index d425163..a5be4dc 100644 --- a/lib/particles/client/particles.lua +++ b/lib/particles/client/particles.lua @@ -1,7 +1,7 @@ Particles = {} Particle = {} ---@diagnostic disable: duplicate-set-field -local Ids = Ids or Require("lib/utility/shared/ids.lua") +Ids = Ids or Require("lib/utility/shared/ids.lua") local point = Require("lib/points/client/points.lua") ---Loads a ptfx asset into memory. @@ -28,21 +28,58 @@ end --- @param looped boolean --- @param loopLength number|nil --- @return number|nil ptfxHandle -- The handle of the particle effect, or nil if it failed to create. -function Particle.Play(dict, ptfx, pos, rot, scale, color, looped, loopLength) +function Particle.Play(dict, ptfx, pos, rot, scale, color, looped, removeAfter) LoadPtfxAsset(dict) UseParticleFxAssetNextCall(dict) SetParticleFxNonLoopedColour(color.x, color.y, color.z) local particle = nil + removeAfter = removeAfter or 5000 if looped then particle = StartParticleFxLoopedAtCoord(ptfx, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, scale, false, false, false, false) - CreateThread(function() - if loopLength then - Wait(loopLength) - Particle.Remove(particle) + local strParticle = tostring(particle) + Particles[strParticle] = particle + Wait(10) + if particle == 0 or not DoesParticleFxLoopedExist(particle) then + particle = StartParticleFxNonLoopedAtCoord(ptfx, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, scale, false, false, false, false) + if not particle and particle == 0 then + print(string.format("[Particle] Failed to start particle fx: %s from dict: %s", ptfx, dict)) + return nil end - end) - else - particle = StartParticleFxNonLoopedAtCoord(ptfx, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, scale, false, false, false, false) + local strParticle = tostring(particle) + Particles[strParticle] = particle + CreateThread(function() + while Particles[strParticle] do + Wait(removeAfter) + if not Particles[strParticle] then break end + RemoveParticleFx(particle, false) + particle = StartParticleFxNonLoopedAtCoord(ptfx, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, scale, false, false, false, false) + Particles[strParticle] = particle + end + end) + return strParticle + else + if not removeAfter or removeAfter <= 0 then return particle end + CreateThread(function() + while Particles[strParticle] do + Wait(removeAfter) + if not Particles[strParticle] then break end + StopParticleFxLooped(particle, false) + UseParticleFxAssetNextCall(dict) + LoadPtfxAsset(dict) + particle = StartParticleFxLoopedAtCoord(ptfx, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, scale, false, false, false, false) + Particles[strParticle] = particle + end + end) + return strParticle + end + else + particle = StartParticleFxLoopedAtCoord(ptfx, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, scale, false, false, false, false) + Wait(10) + if not DoesParticleFxLoopedExist(particle) then + particle = StartParticleFxNonLoopedAtCoord(ptfx, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, scale, false, false, false, false) + end + Wait(removeAfter) + Particle.Stop(particle) end return particle @@ -53,66 +90,7 @@ function Particle.Stop(particle) StopParticleFxLooped(particle, false) RemoveParticleFx(particle, false) RemoveNamedPtfxAsset(particle) -end - -function Particle.Create(data) - assert(data, "Particle data is nil") - assert(data.dict, "Invalid particle data. Must contain string dict.") - assert(data.ptfx, "Invalid particle data. Must contain string ptfx.") - - local _id = data.id or Ids.CreateUniqueId(Particles) - data = { - id = _id, - dict = data.dict, - ptfx = data.ptfx, - position = data.position or vector3(0.0, 0.0, 0.0), - rotation = data.rotation or vector3(0, 0, 0), - size = data.size or 1.0, - color = data.color or vector3(255, 255, 255), - looped = data.looped or false, - loopLength = data.loopLength or nil, - spawned = false, - } - Particles[_id] = data - - point.Register( -- checking if players in range - _id, - data.position, - data.drawDistance or 50.0, - data, - function(_) - if not Particles[_id] then return point.Remove(_id) end - local particleData = Particles[_id] - if particleData.spawned then return end - particleData.spawned = Particle.Play( - particleData.dict, - particleData.ptfx, - particleData.position, - particleData.rotation, - particleData.size, - particleData.color, - particleData.looped, - particleData.loopLength - ) - end, - function(markerData) - if not Particles[_id] then return end - local particleData = Particles[_id] - if not particleData.spawned then return end - Particle.Stop(particleData.spawned) - particleData.spawned = nil - end - ) - return _id -end - -function Particle.Remove(id) - if not id then return end - local particle = Particles[id] - if not particle then return end - Particle.Stop(particle.spawned) - Particles[id] = nil - point.Remove(id) + Particles[tostring(particle)] = nil end diff --git a/lib/points/client/points.lua b/lib/points/client/points.lua index cbd9319..97e7ceb 100644 --- a/lib/points/client/points.lua +++ b/lib/points/client/points.lua @@ -75,6 +75,9 @@ function Point.StartLoop() point.args = point?.onExit(point, point.args) or point.args end end + if point.inside and point.onUpdate then + point.onUpdate(point, point.args) + end end end Wait(1000) @@ -82,11 +85,11 @@ function Point.StartLoop() end) end -function Point.Register(id, target, distance, args, _onEnter, _onExit) +function Point.Register(id, target, distance, args, _onEnter, _onExit, _onUpdate) local isEntity = type(target) == "number" local coords = isEntity and GetEntityCoords(target) or target Grid.Generate() - local self = {} + local self = args or {} self.id = id self.target = target -- Store entity ID or Vector3 self.isEntity = isEntity @@ -94,8 +97,8 @@ function Point.Register(id, target, distance, args, _onEnter, _onExit) self.distance = distance self.onEnter = _onEnter or function() end self.onExit = _onExit or function() end + self.onUpdate = _onUpdate or function() end self.inside = false -- Track if player is inside - self.args = args or {} local grid = Grid.GetCellByCoords(coords) grid[id] = self Point.All[id] = self diff --git a/modules/target/qb-target/client.lua b/modules/target/qb-target/client.lua index 6fd49d2..c1a4b63 100644 --- a/modules/target/qb-target/client.lua +++ b/modules/target/qb-target/client.lua @@ -84,7 +84,7 @@ end ---This will add target options to all specified models. This is useful for when you want to add target options to all models of a specific type. ---@param options table -Target.AddGlobalPed = function(options, distance) +Target.AddGlobalPed = function(options) options = Target.FixOptions(options) qb_target:AddGlobalPed({ options = options, @@ -100,7 +100,7 @@ end ---This will add taget options to all vehicles. ---@param options table -Target.AddGlobalVehicle = function(options, distance) +Target.AddGlobalVehicle = function(options) options = Target.FixOptions(options) qb_target:AddGlobalVehicle({ options = options, @@ -136,7 +136,7 @@ end ---This will generate targets on non networked entites with the passed options. ---@param entities number | table ---@param options table -Target.AddLocalEntity = function(entities, options, distance) +Target.AddLocalEntity = function(entities, options) options = Target.FixOptions(options) qb_target:AddTargetEntity(entities, { options = options, @@ -174,7 +174,7 @@ end ---@param size table ---@param heading number ---@param options table -Target.AddBoxZone = function(name, coords, size, heading, options, debug, distance) +Target.AddBoxZone = function(name, coords, size, heading, options, debug) options = Target.FixOptions(options) if not next(options) then return end qb_target:AddBoxZone(name, coords, size.x, size.y, { @@ -195,7 +195,7 @@ end ---@param coords table ---@param radius number ---@param options table -Target.AddSphereZone = function(name, coords, radius, options, debug, distance) +Target.AddSphereZone = function(name, coords, radius, options, debug) options = Target.FixOptions(options) qb_target:AddCircleZone(name, coords, radius, { name = name, diff --git a/modules/zones/oxlib/client.lua b/modules/zones/oxlib/client.lua index 26f67ca..f181615 100644 --- a/modules/zones/oxlib/client.lua +++ b/modules/zones/oxlib/client.lua @@ -1,3 +1,25 @@ +--- ox_lib compatibility wrapper for zone creation and management. +--- Provides a small API around lib.zones (box, sphere, poly) to create/destroy +--- and lookup zones with automatic id generation and resource ownership. +--- +--- Example: +--- local id = cZones.Create("box", { coords = vec3(0,0,0), size = vec3(2,2,2), onEnter = function(z) ... end }) +--- cZones.Destroy(id) +--- +---@module cZones +---@class ZoneData +---@field id string Unique id for the zone (generated) +---@field invoking string Resource that created the zone +---@field coords vector3? Center coordinates (box/sphere) +---@field points vector2[]? Array of points for poly zones +---@field radius number? Radius for sphere zones +---@field size table? Size table or vec3 for box zones +---@field zone any Internal zone handle returned by lib.zones +---@field debug boolean? Debug flag passed to lib.zones +---@field onEnter fun(data:ZoneData)? Callback invoked on enter (receives ZoneData) +---@field onExit fun(data:ZoneData)? Callback invoked on exit (receives ZoneData) +---@alias ZoneType "box"|"sphere"|"poly" + ---@diagnostic disable: duplicate-set-field local resourceName = "ox_lib" if GetResourceState(resourceName) == 'missing' then return end @@ -6,6 +28,12 @@ Ids = Ids or Require('lib/utility/shared/ids.lua') cZones = {} --conflict with ox cZones.All = {} + +--- Create a zone of the specified type. +--- Supported types: "box", "sphere", "poly" +---@param type ZoneType +---@param data ZoneData +---@return string|nil id Returns the generated zone id on success, or nil on failure function cZones.Create(type, data) assert(type, "Requires zone type ('box', 'sphere', or 'poly')") assert(data, "Requires data table") @@ -93,6 +121,9 @@ function cZones.Create(type, data) return nil end +--- Destroy a zone by id. +---@param id string +---@return boolean success True if destroyed, false otherwise function cZones.Destroy(id) if not id then return false end local zone = cZones.All[id].zone @@ -102,6 +133,9 @@ function cZones.Destroy(id) return true end +--- Destroy all zones created by a specific resource. +---@param resource string Name of the invoking resource +---@return boolean success True if operation completed (no guarantee zones existed) function cZones.DestroyByResource(resource) if not resource then return false end for id, zone in pairs(cZones.All or {}) do @@ -112,11 +146,16 @@ function cZones.DestroyByResource(resource) return true end +--- Retrieve zone data by id. +---@param id string +---@return ZoneData|nil function cZones.Get(id) if not id then return nil end return cZones.All[id] end +--- Event handler: clean up zones when a resource stops. +--- This is registered to the "onResourceStop" event and delegates to DestroyByResource. RegisterNetEvent("onResourceStop", function(resource) cZones.DestroyByResource(resource) end) From 7693648c32029f7f43491901a51824e85d8741a6 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Sun, 24 Aug 2025 17:32:16 -0400 Subject: [PATCH 20/62] yeeeeet --- modules/dialogue/_default/client/client.lua | 60 --------------------- 1 file changed, 60 deletions(-) diff --git a/modules/dialogue/_default/client/client.lua b/modules/dialogue/_default/client/client.lua index 4768371..0e6b130 100644 --- a/modules/dialogue/_default/client/client.lua +++ b/modules/dialogue/_default/client/client.lua @@ -94,64 +94,4 @@ RegisterNuiCallback("dialogue:SelectOption", function(data) promis(data.id) end) --- Debug command -if BridgeSharedConfig.DebugLevel >= 1 then - -- RegisterCommand("dialogue", function() - -- local pos = GetOffsetFromEntityInWorldCoords(PlayerPedId(), 0, 2.0, 0) - -- local timeout = 500 - -- local model = `a_f_y_hipster_01` - -- RequestModel(model) - -- while not HasModelLoaded(model) do - -- Wait(0) - -- timeout = timeout - 1 - -- if timeout == 0 then - -- print("Failed to load model") - -- return - -- end - -- end - -- local ped = CreatePed(0, model, pos.x, pos.y, pos.z, 0.0, false, false) - - -- local characterData = { - -- entity = ped, - -- offset = vector3(0, 0, 0), - -- rotationOffset = vector3(0, 0, 0) - -- } - -- Wait(750) - -- Dialogue.Open("Akmed", "Hello how are you doing my friend?", characterData, { - -- { - -- label = "Trade with me", - -- id = 'something', - -- }, - -- { - -- label = "Goodbye", - -- id = 'someotherthing', - -- }, - -- }, - -- function(selectedId) - -- if selectedId == 'something' then - -- Dialogue.Open( "Akmed" , "Thank you for wanting to purchase me lucky charms", characterData, { - -- { - -- label = "Fuck off", - -- id = 'something', - -- }, - -- { - -- label = "Goodbye", - -- id = 'someotherthing', - -- }, - -- }, - -- function(selectedId) - -- DeleteEntity(ped) - -- if selectedId == "something" then - -- print("You hate lucky charms") - -- else - -- print("Thanks for keeping it civil") - -- end - -- end) - -- else - -- DeleteEntity(ped) - -- end - -- end) - -- end) -end - return Dialogue \ No newline at end of file From 5b6641fc6074db538e5284b5ffc7d9d2a14b8756 Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Sun, 24 Aug 2025 20:02:47 -0500 Subject: [PATCH 21/62] silly me woopsies --- lib/entities/client/client_entity.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index 7892405..6e17102 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -70,9 +70,16 @@ local function UpdateEntity(_entityData) local entityData = ClientEntity.Get(_entityData.id) if not entityData then return end if entityData.oldCoords and entityData.oldCoords ~= entityData.coords then - local dist = #(entityData.coords.xyz - entityData.oldCoords.xyz) + local coords = vector3(entityData.coords.x, entityData.coords.y, entityData.coords.z) + local dist = #(coords.xyz - entityData.oldCoords.xyz) if dist > 0.1 then - ClientEntity.UpdateCoords(entityData.id, entityData.coords) + -- ClientEntity.UpdateCoords(entityData.id, entityData.coords) + if entityData.OnMove then + pcall(function (...) + return entityData.OnMove(entityData) + end) + end + Behaviors.Trigger("OnMove", entityData, entityData.oldCoords, entityData.coords) end entityData.oldCoords = entityData.coords end @@ -145,6 +152,7 @@ function ClientEntity.Set(id, key, value) local entityData = ClientEntity.Get(id) if not entityData then return print(string.format("[ClientEntity] SetKey: Entity %s does not exist", id)) end entityData[key] = value + -- TriggerServerEvent("community_bridge:server:UpdateEntity", id, {[key] = value}) end --- Updates the data for a registered entity. From e06e04a2c6941d4263d0c992bf7ecbe93ad90ecf Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Wed, 27 Aug 2025 05:47:44 -0500 Subject: [PATCH 22/62] hope this works --- lib/entities/client/behaviors.lua | 61 ------------------- lib/entities/client/behaviors/init.lua | 20 ------- lib/entities/client/client_entity.lua | 13 +++- lib/entities/server/server_entity.lua | 13 ++++ lib/entities/shared/behaviors.lua | 73 +++++++++++++++++++++++ modules/inventory/ox_inventory/server.lua | 60 +++++++++++++------ 6 files changed, 138 insertions(+), 102 deletions(-) delete mode 100644 lib/entities/client/behaviors.lua delete mode 100644 lib/entities/client/behaviors/init.lua create mode 100644 lib/entities/shared/behaviors.lua diff --git a/lib/entities/client/behaviors.lua b/lib/entities/client/behaviors.lua deleted file mode 100644 index 8641d03..0000000 --- a/lib/entities/client/behaviors.lua +++ /dev/null @@ -1,61 +0,0 @@ -Behaviors = { - All = {}, - isSetup = false, -} - -function Behaviors.Setup() - if Behaviors.isSetup then return end - Behaviors.isSetup = true - local behaviors = Require("lib/entities/client/behaviors/init.lua") - for _, behavior in ipairs(behaviors) do - Behaviors.Create(behavior.tag, behavior) - end -end - -function Behaviors.Create(behaviorId, behavior) - if not behaviorId or not behavior then return end - if Behaviors.All[behaviorId] then - print(string.format("[ClientEntity] Behavior %s already exists", behaviorId)) - return - end - Behaviors.All[behaviorId] = behavior -end - -function Behaviors.Get(behaviorId) - return Behaviors.All[behaviorId] -end - -function Behaviors.Remove(behaviorId) - if not Behaviors.All[behaviorId] then return end - Behaviors.All[behaviorId] = nil - return true -end - -function Behaviors.Trigger(actionName, clientEntityData, ...) - if not clientEntityData or not actionName then return end - for tag, behavior in pairs(Behaviors.All) do - local hasBehaviorArgs = Behaviors.Has(tag, clientEntityData) -- this is everything that's contained inside the object's individual tag - if hasBehaviorArgs and behavior[actionName] then - behavior[actionName](clientEntityData, hasBehaviorArgs, ...) - end - end -end - -function Behaviors.Inherit(behaviorId, clientEntityData, defaultData) - if not Behaviors.All[behaviorId] then - print(string.format("[ClientEntity] Behavior %s does not exist", behaviorId)) - return false - end - if not clientEntityData or not clientEntityData.id then - print("[ClientEntity] Invalid client entity data provided for inheritance") - return false - end - clientEntityData[behaviorId] = defaultData or {} -- Mark the entity as having this behavior - return true -end - -function Behaviors.Has(behaviorId, clientEntityData) - return clientEntityData and clientEntityData[behaviorId] -end - -return Behaviors \ No newline at end of file diff --git a/lib/entities/client/behaviors/init.lua b/lib/entities/client/behaviors/init.lua deleted file mode 100644 index 8c70fff..0000000 --- a/lib/entities/client/behaviors/init.lua +++ /dev/null @@ -1,20 +0,0 @@ -local fileList = { - "particles", - "targets", -} - -local path = "lib/entities/client/behaviors/" - -local function loadAllResources() - local modules = {} - for _, fileName in ipairs(fileList) do - local filePath = path .. fileName .. ".lua" - local required = Require(filePath) - if required then - table.insert(modules, required) - end - end - return modules -end - -return loadAllResources() \ No newline at end of file diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index 6e17102..22fa91b 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -282,12 +282,21 @@ RegisterNetEvent("community_bridge:client:DeleteEntity", function(id) end) RegisterNetEvent("community_bridge:client:UpdateEntity", function(id, data) - ClientEntity.Update(id, data) + for k, v in pairs(data) do + ClientEntity.Set(id, k, v) + end +end) + +local Loaded = false +AddEventHandler('community_bridge:Client:OnPlayerLoaded', function(resourceName) + if Loaded then return end + Loaded = true end) AddEventHandler('onResourceStart', function(resourceName) if resourceName ~= GetCurrentResourceName() then return end - Behaviors.Setup() + if Loaded then return end + Loaded = true end) -- Resource Stop Cleanup diff --git a/lib/entities/server/server_entity.lua b/lib/entities/server/server_entity.lua index 9d00fc4..487a809 100644 --- a/lib/entities/server/server_entity.lua +++ b/lib/entities/server/server_entity.lua @@ -117,6 +117,19 @@ function ServerEntity.Remove(id) Entities[id] = nil end +--- Updates data for a server-side entity and notifies clients. +-- @param id string|number The ID of the entity to update. +-- @param data table The data fields to update. +function ServerEntity.Set(id, data) + local entity = Entities[id] + if not entity then return false end + for key, value in pairs(data) do + entity[key] = value + end + TriggerClientEvent("community_bridge:client:UpdateEntity", -1, id, data) + return true +end + -- Clean up entities associated with a stopped resource AddEventHandler('onResourceStop', function(resourceName) local toDelete = {} diff --git a/lib/entities/shared/behaviors.lua b/lib/entities/shared/behaviors.lua new file mode 100644 index 0000000..f152c8e --- /dev/null +++ b/lib/entities/shared/behaviors.lua @@ -0,0 +1,73 @@ +Behaviors = { + All = {}, + isSetup = false, + invoked = {} +} + + +function Behaviors.Create(behaviorId, behavior) + if not behaviorId or not behavior then return end + if Behaviors.All[behaviorId] then return print(string.format("[ClientEntity] Behavior %s already exists", behaviorId)) end + local invoking = GetInvokingResource() or "community_bridge" + Behaviors.All[behaviorId] = behavior + Behaviors.invoked[invoking] = Behaviors.invoked[invoking] or {} + table.insert(Behaviors.invoked[invoking], behaviorId) +end + +function Behaviors.Get(behaviorId) + return Behaviors.All[behaviorId] +end + +function Behaviors.Remove(behaviorId) + if not Behaviors.All[behaviorId] then return end + Behaviors.All[behaviorId] = nil + return true +end + +function Behaviors.Trigger(actionName, clientEntityData, ...) + if not clientEntityData or not actionName then return end + for property, behavior in pairs(Behaviors.All) do + local hasBehaviorArgs = Behaviors.Has(property, clientEntityData) -- this is everything that's contained inside the object's individual property + if hasBehaviorArgs and behavior[actionName] then + local success, result = pcall(behavior[actionName], clientEntityData, hasBehaviorArgs, ...) + if not success then + print(string.format("[ClientEntity] Behavior %s failed: %s", property, result)) + end + end + end +end + +function Behaviors.Inherit(behaviorId, clientEntityData, defaultData) + if not Behaviors.All[behaviorId] then + print(string.format("[ClientEntity] Behavior %s does not exist", behaviorId)) + return false + end + if not clientEntityData or not clientEntityData.id then + print("[ClientEntity] Invalid client entity data provided for inheritance") + return false + end + clientEntityData[behaviorId] = defaultData or {} -- Mark the entity as having this behavior + return true +end + +function Behaviors.Has(behaviorId, clientEntityData) + return clientEntityData and clientEntityData[behaviorId] +end + +function Behaviors.Cleanup(resourceName) + if not resourceName or not Behaviors.invoked[resourceName] then return end + for _, behaviorId in ipairs(Behaviors.invoked[resourceName]) do + Behaviors.Remove(behaviorId) + end + Behaviors.invoked[resourceName] = nil +end + +AddEventHandler("onResourceStop", function(resourceName) + Behaviors.Cleanup(resourceName) + if resourceName ~= GetCurrentResourceName() then return end + for behaviorId, _ in pairs(Behaviors.All) do + Behaviors.Remove(behaviorId) + end +end) + +return Behaviors \ No newline at end of file diff --git a/modules/inventory/ox_inventory/server.lua b/modules/inventory/ox_inventory/server.lua index f4702b4..10730e0 100644 --- a/modules/inventory/ox_inventory/server.lua +++ b/modules/inventory/ox_inventory/server.lua @@ -131,17 +131,16 @@ Inventory.OpenStash = function(src, _type, id) end ---This will register a stash ----@param id number|string +---@param id string ---@param label string ---@param slots number ---@param weight number ---@param owner string ---@param groups table ---@param coords table ----@return boolean ----@return string|number +---@return string Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) - if Inventory.Stashes[id] then return true, id end + if Inventory.Stashes[id] then return id end Inventory.Stashes[id] = { id = id, label = label, @@ -151,8 +150,8 @@ Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coor groups = groups, coords = coords } - ox_inventory:RegisterStash(id, label, slots, weight, owner, groups) - return true, id + ox_inventory:RegisterStash(id, label, slots, weight, owner, groups, coords) + return id end ---This will return a boolean if the player has the item. @@ -194,24 +193,47 @@ end -- This will open the specified shop for the src passed. ---@param src number ----@param shopTitle string -Inventory.OpenShop = function(src, shopTitle) - TriggerClientEvent('ox_inventory:openInventory', src, 'shop', {type = shopTitle}) +---@param id string +Inventory.OpenShop = function(src, id) + local title = registeredShops[id]?.title or id + TriggerClientEvent('ox_inventory:openInventory', src, 'shop', {type = title}) end -- This will register a shop, if it already exists it will return true. ----@param shopTitle string ----@param shopInventory table ----@param shopCoords table ----@param shopGroups table -Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGroups) - if registeredShops[shopTitle] then return true end - registeredShops[shopTitle] = true - ox_inventory:RegisterShop(shopTitle, { name = shopTitle, inventory = shopInventory, groups = shopGroups, }) - --return Inventory.OpenShop(src, shopTitle) - return true +---@param title string +---@param items table +---@param coords table +---@param groups table +Inventory.RegisterShop = function(title, items, coords, groups) + return Inventory.CreateShop({id = title, name = title, items = items, coords = coords, groups = groups}) end +--- Creates a new shop if it doesn't already exist. +--- +--- @class ShopData +--- @field id string|nil -- Unique identifier for the shop (optional, falls back to title) +--- @field name string -- Display name of the shop +--- @field items table -- Table of items available in the shop +--- @field coords table|nil -- Optional coordinates for the shop location +--- @field groups table|nil -- Optional groups allowed to access the shop +--- +--- @param data ShopData -- Table containing shop properties +--- @return string|boolean -- Returns the shop ID if the shop was created, false if it already exists +Inventory.CreateShop = function(data) + assert(data, "CreateShop: data is required") + local id = data.id or data.name + if registeredShops[id] then return id end + assert(data.name, "CreateShop: name is required") + assert(data.items and type(data.items) == "table", "CreateShop: items table is required") + registeredShops[id] = { + name = data.name, + items = data.items, + coords = data.coords, + groups = data.groups + } + ox_inventory:RegisterShop(id, data) + return id +end ---UNUSED: ---This will return generic item data from the specified inventory, with the items total count. From 495b24e53fd7aedc273274683b350b49a8a9cb37 Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Wed, 27 Aug 2025 06:13:02 -0500 Subject: [PATCH 23/62] fixed last mess --- lib/entities/client/behaviors/particles.lua | 56 ---------- lib/entities/client/behaviors/targets.lua | 54 ---------- lib/entities/client/client_entity.lua | 19 +++- lib/entities/server/server_entity.lua | 112 +++++++------------- lib/entities/shared/actions.lua | 49 --------- lib/init.lua | 1 + 6 files changed, 55 insertions(+), 236 deletions(-) delete mode 100644 lib/entities/client/behaviors/particles.lua delete mode 100644 lib/entities/client/behaviors/targets.lua delete mode 100644 lib/entities/shared/actions.lua diff --git a/lib/entities/client/behaviors/particles.lua b/lib/entities/client/behaviors/particles.lua deleted file mode 100644 index 418569b..0000000 --- a/lib/entities/client/behaviors/particles.lua +++ /dev/null @@ -1,56 +0,0 @@ -Utility = Utility or Require("lib/utility/client/utility.lua") -local ParticlesBehaviors = { - tag = "particles", - default = { - dict = "cut_exile3", - ptfx = "cs_ex3_wheel_spin", - offset = vector3(0, 0, 0), - rotation = vector3(0, 0, 0), - size = 1.0, - color = vector3(255, 255, 255), - loopLength = 5000, - } - -} - -function ParticlesBehaviors.OnSpawn(entityData) - if not entityData.particles then return end - if entityData.particles.dict then -- single particle - entityData.particles = {entityData.particles} - end - - for _, particleData in ipairs(entityData.particles) do - local position = vector3(entityData.coords.x, entityData.coords.y, entityData.coords.z) - local rotation = vector3(entityData.rotation.x, entityData.rotation.y, entityData.rotation.z) - position = position + (particleData.offset?.xyz or vector3(0, 0, 0)) - rotation = rotation + (particleData.rotation?.xyz or vector3(0, 0, 0)) - particleData.playing = Particle.Play( - particleData.dict or ParticlesBehaviors.default.dict, - particleData.ptfx or ParticlesBehaviors.default.ptfx, - position, - rotation, - particleData.size or ParticlesBehaviors.default.size, - particleData.color or ParticlesBehaviors.default.color, - particleData.looped, - particleData.loopLength or ParticlesBehaviors.default.loopLength - ) - end -end - - -function ParticlesBehaviors.OnRemove(entityData) - if not entityData.particles then return end - for _, particleData in ipairs(entityData.particles) do - if particleData.playing then - Particle.Stop(particleData.playing) - particleData.playing = nil - end - end -end - --- function ParticlesBehaviors.OnUpdate(entityData) --- if not entityData.particles then return end - --- end - -return ParticlesBehaviors diff --git a/lib/entities/client/behaviors/targets.lua b/lib/entities/client/behaviors/targets.lua deleted file mode 100644 index 81135c2..0000000 --- a/lib/entities/client/behaviors/targets.lua +++ /dev/null @@ -1,54 +0,0 @@ - -local Targets = { - tag = "targets", - default = { - label = "Default Target Label", - distance = 2, - } -} - - -function Targets.OnSpawn(entityData) - if not entityData.spawned or not entityData.target then return end - if entityData.targets?.label then - entityData.newTargets = {entityData.targets} - else - entityData.newTargets = entityData.targets or {} - end - for k, v in pairs(entityData.newTargets) do - local onSelect = v.onSelect - if onSelect then - v.onSelect = function(entity) - onSelect(entityData, entity) - end - end - end - Target.AddLocalEntity(entityData.spawned, entityData.newTargets) - entityData.oldTargets = entityData.newTargets -end - -function Targets.OnRemove(entityData) - if not entityData.spawned or not entityData.newTargets then return end - Target.RemoveLocalEntity(entityData.spawned) -end - -function Targets.OnUpdate(entityData) - if not entityData.spawned or not entityData.newTargets then return end - for i, target in ipairs(entityData.oldTargets) do - local newTarget = entityData.targets.label - if newTarget then - entityData.newTargets = {entityData.targets} - end - newTarget = entityData.newTargets[i] - if newTarget - and target.label ~= newTarget.label - or target.distance ~= newTarget.distance - or target.description ~= newTarget.description - then - Targets.OnRemove(entityData) - Targets.OnSpawn(entityData) - end - end -end - -return Targets \ No newline at end of file diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index 22fa91b..0c3f8a5 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -1,9 +1,11 @@ Utility = Utility or Require("lib/utility/client/utility.lua") Ids = Ids or Require("lib/utility/shared/ids.lua") Point = Point or Require("lib/points/client/points.lua") -Behaviors = Behaviors or Require("lib/entities/client/behaviors.lua") +Behaviors = Behaviors or Require("lib/entities/shared/behaviors.lua") local Entities = {} -- Stores entity data received from server -ClientEntity = {} -- Renamed from BaseEntity +ClientEntity = { + Invoked = {} +} -- Renamed from BaseEntity ClientEntity.Behaviors = Behaviors @@ -113,6 +115,9 @@ function ClientEntity.Create(entityData) local entityPoint = Point.Register(entityData.id, entityData.coords, entityData.spawnDistance or 50.0, entityData, SpawnEntity, RemoveEntity, UpdateEntity) Entities[entityData.id] = entityPoint + entityData.invoked = GetInvokingResource() or "community_bridge" + ClientEntity.Invoked[entityData.invoked] = ClientEntity.Invoked[entityData.invoked] or {} + ClientEntity.Invoked[entityData.invoked][entityData.id] = entityData Behaviors.Trigger("OnCreate", entityPoint) return entityPoint end @@ -146,7 +151,9 @@ function ClientEntity.Destroy(id) end ClientEntity.Unregister = ClientEntity.Destroy - +function ClientEntity.RegisterBehavior(id, behavior) + Behaviors.Create(id, behavior) +end function ClientEntity.Set(id, key, value) local entityData = ClientEntity.Get(id) @@ -307,6 +314,12 @@ AddEventHandler('onResourceStop', function(resourceName) RemoveEntity(entityData) -- Clean up spawned game entity end Entities = {} -- Clear local cache + else + for id, entityData in pairs(ClientEntity.Invoked[resourceName] or {}) do + Point.Remove(id) -- Clean up point registration + RemoveEntity(entityData) -- Clean up spawned game entity + Entities[id] = nil + end end end) diff --git a/lib/entities/server/server_entity.lua b/lib/entities/server/server_entity.lua index 487a809..28d0ccb 100644 --- a/lib/entities/server/server_entity.lua +++ b/lib/entities/server/server_entity.lua @@ -1,7 +1,10 @@ Ids = Ids or Require("lib/utility/shared/ids.lua") +Behaviors = Behaviors or Require("lib/entities/shared/behaviors.lua") local Entities = {} ServerEntity = {} -- Renamed from EntityRelay +ServerEntity.Behaviors = Behaviors +local Invoked = {} --- Creates a server-side representation of an entity and notifies clients. -- @param entityType string 'object', 'ped', or 'vehicle' @@ -10,27 +13,28 @@ ServerEntity = {} -- Renamed from EntityRelay -- @param rotation vector3|number Heading for peds/vehicles, rotation for objects -- @param meta table Optional additional data -- @return table The created entity data -function ServerEntity.New(id, entityType, model, coords, rotation, meta) - local self = meta or {} +function ServerEntity.New(id, entityType, model, coords, rotation, args) + assert(entityType, "EntityType is required") + assert(model, "Model is required for entity creation") + assert(coords, "Coords are required for entity creation") + local self = args or {} self.id = id or Ids.CreateUniqueId(Entities) self.entityType = entityType self.model = model self.coords = coords - self.rotation = rotation or (entityType == 'object' and vector3(0.0, 0.0, 0.0) or 0.0) -- Default rotation or heading - self.resource = GetInvokingResource() + self.rotation = rotation or vector3(0.0, 0.0, 0.0) + local invoking = GetInvokingResource() or "community_bridge" + self.invoking = invoking + Invoked[invoking] = Invoked[invoking] or {} + table.insert(Invoked[invoking], self) - assert(self.id, "ID Failed to generate") - assert(self.entityType, "EntityType is required") - assert(self.model, "Model is required for entity creation") - assert(self.coords, "Coords are required for entity creation") ServerEntity.Add(self) return self end -function ServerEntity.Create(id, entityType, model, coords, rotation, meta) - local self = ServerEntity.New(id, entityType, model, coords, rotation, meta) - if not self then - return nil - end +function ServerEntity.Create(data) + local self = ServerEntity.New(data.id, data.entityType, data.model, data.coords, data.rotation or vector3(0.0, 0.0, data.heading or 0.0), data) + if not self then return nil end + Behaviors.Trigger("OnCreate", self) TriggerClientEvent("community_bridge:client:CreateEntity", -1, self) return self end @@ -39,15 +43,9 @@ function ServerEntity.CreateBulk(entities) local createdEntities = {} for _, entityData in pairs(entities) do local id = entityData.id or Ids.CreateUniqueId(Entities) - local entity = ServerEntity.New( - id, - entityData.entityType, - entityData.model, - entityData.coords, - entityData.rotation, - entityData.meta - ) + local entity = ServerEntity.New(id, entityData.entityType, entityData.model, entityData.coords, entityData.rotation, entityData) createdEntities[id] = entity + Behaviors.Trigger("OnCreate", entity) end TriggerClientEvent("community_bridge:client:CreateEntities", -1, createdEntities) return createdEntities @@ -55,54 +53,19 @@ end --- Deletes a server-side entity representation and notifies clients. -- @param id string|number The ID of the entity to delete. -function ServerEntity.Delete(id) - if Entities[id] then - ServerEntity.Remove(id) - TriggerClientEvent("community_bridge:client:DeleteEntity", -1, id) - end +function ServerEntity.Destroy(id) + if not Entities[id] then return end + ServerEntity.Remove(id) + TriggerClientEvent("community_bridge:client:DeleteEntity", -1, id) end +ServerEntity.Delete = ServerEntity.Destroy ---- Updates data for a server-side entity and notifies clients. --- @param id string|number The ID of the entity to update. --- @param data table The data fields to update. -function ServerEntity.Update(id, data) - local entity = Entities[id] - -- print("Updating entity: ", id, entity) - if not entity then return false end - - for key, value in pairs(data) do - entity[key] = value +function ServerEntity.DestroyBulk(entityDatas) + for _, entityData in pairs(entityDatas) do + ServerEntity.Remove(entityData.id) end - TriggerClientEvent("community_bridge:client:UpdateEntity", -1, id, data) - return true -end - ---- Triggers a specific action on the client-side entity. --- Clients will only execute the action if the entity is currently spawned for them. --- @param entityId string|number The ID of the entity. --- @param actionName string The name of the action to trigger (must match a function in ClientEntityActions). --- @param ... any Additional arguments for the action function. -function ServerEntity.TriggerAction(entityId, actionName, endPosition, ...) - -- print("Triggering action: ", entityId, actionName, ...) - local entity = Entities[entityId] - if not entity then - print(string.format("[ServerEntity] Attempted to trigger action '%s' on non-existent entity %s", actionName, entityId)) - return - end - TriggerClientEvent("community_bridge:client:TriggerEntityAction", -1, entityId, actionName, endPosition, ...) -end - -function ServerEntity.TriggerActions(entityId, actions, endPosition) - local entity = Entities[entityId] - if not entity then - print(string.format("[ServerEntity] Attempted to trigger actions on non-existent entity %s", entityId)) - return - end - TriggerClientEvent("community_bridge:client:TriggerEntityActions", -1, entityId, actions, endPosition) -end - -function ServerEntity.GetAll() - return Entities + print("[ServerEntity] DestroyBulk: Removed", #entityDatas, "entities") + TriggerClientEvent("community_bridge:client:DeleteBulk", -1, entityDatas) end function ServerEntity.Get(id) @@ -130,18 +93,19 @@ function ServerEntity.Set(id, data) return true end + -- Clean up entities associated with a stopped resource AddEventHandler('onResourceStop', function(resourceName) - local toDelete = {} - for id, entity in pairs(Entities) do - if entity.resource == resourceName then - table.insert(toDelete, id) - end - end - for _, id in pairs(toDelete) do - ServerEntity.Delete(id) + if Invoked[resourceName] then + ServerEntity.DestroyBulk(Invoked[resourceName]) + Invoked[resourceName] = nil end end) +AddEventHandler('community_bridge:Server:OnPlayerLoaded', function(source) + print("Player loaded:", source) + TriggerClientEvent("community_bridge:client:CreateEntities", source, Entities) +end) + return ServerEntity diff --git a/lib/entities/shared/actions.lua b/lib/entities/shared/actions.lua deleted file mode 100644 index 1725820..0000000 --- a/lib/entities/shared/actions.lua +++ /dev/null @@ -1,49 +0,0 @@ -local Actions = {} -Action = {} - - -if not IsDuplicityVersion() then goto client end - -function Action.Fire(id, players, ...) - local action = Actions[id] - if not action then return end - if type(players) == "table" then - for _, player in ipairs(players) do - TriggerClientEvent(GetCurrentResourceName() .. "client:Action", tonumber(player), id, ...) - end - return - end - TriggerClientEvent(GetCurrentResourceName() .. "client:Action", tonumber(players or -1), id, ...) -end - -if IsDuplicityVersion() then return Actions end -::client:: - -function Action.Create(id, action) - assert(type(id) == "string", "id must be a string") - assert(type(action) == "function", "action must be a function") - Actions[id] = action -end - -function Action.Remove(id) - Actions[id] = nil -end - -function Action.Get(id) - return Actions[id] -end - -function Action.GetAll() - return Actions -end - -RegisterNetEvent(GetCurrentResourceName() .. "client:Action", function(id, ...) - local action = Actions[id] - if not action then return end - action(...) -end) - -exports("Action", Action) -return Action - - diff --git a/lib/init.lua b/lib/init.lua index b95fee8..e8676e0 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -59,6 +59,7 @@ cLib.Cache = Cache or Require("lib/cache/shared/cache.lua") cLib.Marker = Marker or Require("lib/markers/server/server.lua") cLib.Particle = Particle or Require("lib/particles/server/particles.lua") cLib.Shell = Shells or Require("lib/shells/server/shells.lua") +cLib.ServerEntity = ServerEntity or Require("lib/entities/server/server_entity.lua") if IsDuplicityVersion() then return cLib end ::client:: From 996339f0bc951eddaf773f485e6bd83dc8969174 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Thu, 28 Aug 2025 12:47:40 -0400 Subject: [PATCH 24/62] Update init.lua --- init.lua | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/init.lua b/init.lua index 0d6bc0d..52bd867 100644 --- a/init.lua +++ b/init.lua @@ -20,31 +20,24 @@ function Bridge.RegisterModule(moduleName, moduleTable) if BridgeSharedConfig.DebugLevel ~= 0 then print("^2 Registering module:", moduleName, "^0") end + -- remove __ENV as its not present in luajit at all from what ive read. Good find guys :P Bridge[moduleName] = wrappedModule - _ENV[moduleName] = wrappedModule -- Add to the ENV table the modules so is more easy and safe to call from inside - _ENV.Bridge = Bridge -- Add the bridge too to the _ENV exports(moduleName, function() return wrappedModule end) - --trigger update object event TriggerEvent("Bridge:Refresh", moduleName, wrappedModule) end exports("RegisterModule", Bridge.RegisterModule) ---TODO: Create a way to overide functions or create a new functions for module - function Bridge.RegisterModuleFunction(moduleName, functionName, func) assert(moduleName and functionName and func, string.format("Bridge.RegisterModuleFunction(%s, %s, %s) - Invalid arguments", moduleName, functionName, func)) Bridge[moduleName] = Bridge[moduleName] or {} Bridge[moduleName][functionName] = func - --trigger update object event TriggerEvent("Bridge:Refresh", moduleName, Bridge[moduleName]) end - ---Bridge Bridge.RegisterModule("Framework", Framework) Bridge.RegisterModule("BossMenu", BossMenu) Bridge.RegisterModule("Inventory", Inventory) @@ -58,24 +51,9 @@ Bridge.RegisterModule("Dispatch", Dispatch) Bridge.RegisterModule("Shops", Shops) Bridge.RegisterModule("Housing", Housing) Bridge.RegisterModule("Version", Version) - ---lib --- Bridge.RegisterModule("Tables", cLib.Tables) --- Bridge.RegisterModule("Math", cLib.Math) --- Bridge.RegisterModule("Prints", cLib.Prints) --- Bridge.RegisterModule("Callback", cLib.Callback) - --- --new Bridge.RegisterModule("Require", Require) --- Bridge.RegisterModule("Ids", cLib.Ids) --- Bridge.RegisterModule("ReboundEntities", cLib.ReboundEntities) --- Bridge.RegisterModule("LA", cLib.LA) --- Bridge.RegisterModule("Perlin", cLib.Perlin) --- Bridge.RegisterModule("Actions", cLib.Actions) --- Bridge.RegisterModule("Cache", cLib.Cache) Bridge.RegisterModule("Skills", Skills) - for k, v in pairs(cLib) do if v then Bridge.RegisterModule(k, v) @@ -86,18 +64,13 @@ exports('Bridge', function() return Bridge end) --- ▄▀▀ ██▀ █▀▄ █ █ ██▀ █▀▄ --- ▄█▀ █▄▄ █▀▄ ▀▄▀ █▄▄ █▀▄ if not IsDuplicityVersion() then goto client end Bridge.RegisterModule('Version', Version) Bridge.RegisterModule('Banking', Banking) --- ▄▀▀ █ █ ██▀ █▄ █ ▀█▀ --- ▀▄▄ █▄▄ █ █▄▄ █ ▀█ █ if IsDuplicityVersion() then return end ::client:: - Bridge.RegisterModule("Fuel", Fuel) Bridge.RegisterModule("Input", Input) Bridge.RegisterModule("ProgressBar", ProgressBar) From ac9f0ae77775ce44af258eca49ea3138e88cf9ea Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Fri, 29 Aug 2025 23:47:52 -0400 Subject: [PATCH 25/62] Restore legacy shop logic Reverts shop registration to pre-commit #e06e04a behavior, removing the CreateShop function and restoring RegisterShop. This fixes breaking changes affecting multiple resources and inventories without any deprecation path. --- modules/inventory/ox_inventory/server.lua | 45 ++++++----------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/modules/inventory/ox_inventory/server.lua b/modules/inventory/ox_inventory/server.lua index 10730e0..71750be 100644 --- a/modules/inventory/ox_inventory/server.lua +++ b/modules/inventory/ox_inventory/server.lua @@ -199,40 +199,19 @@ Inventory.OpenShop = function(src, id) TriggerClientEvent('ox_inventory:openInventory', src, 'shop', {type = title}) end --- This will register a shop, if it already exists it will return true. ----@param title string ----@param items table ----@param coords table ----@param groups table -Inventory.RegisterShop = function(title, items, coords, groups) - return Inventory.CreateShop({id = title, name = title, items = items, coords = coords, groups = groups}) -end +-- restores shops to before commit #e06e04a (no depreication path followed, breaking change and not present on all inventories so undoing it. (also breaking multiple resources)) ---- Creates a new shop if it doesn't already exist. ---- ---- @class ShopData ---- @field id string|nil -- Unique identifier for the shop (optional, falls back to title) ---- @field name string -- Display name of the shop ---- @field items table -- Table of items available in the shop ---- @field coords table|nil -- Optional coordinates for the shop location ---- @field groups table|nil -- Optional groups allowed to access the shop ---- ---- @param data ShopData -- Table containing shop properties ---- @return string|boolean -- Returns the shop ID if the shop was created, false if it already exists -Inventory.CreateShop = function(data) - assert(data, "CreateShop: data is required") - local id = data.id or data.name - if registeredShops[id] then return id end - assert(data.name, "CreateShop: name is required") - assert(data.items and type(data.items) == "table", "CreateShop: items table is required") - registeredShops[id] = { - name = data.name, - items = data.items, - coords = data.coords, - groups = data.groups - } - ox_inventory:RegisterShop(id, data) - return id +-- This will register a shop, if it already exists it will return true. +---@param shopTitle string +---@param shopInventory table +---@param shopCoords table +---@param shopGroups table +Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGroups) + if registeredShops[shopTitle] then return true end + registeredShops[shopTitle] = true + ox_inventory:RegisterShop(shopTitle, { name = shopTitle, inventory = shopInventory, groups = shopGroups, }) + --return Inventory.OpenShop(src, shopTitle) + return true end ---UNUSED: From 9062e5b2a807b8bb78310aead8043e5b1e7902d9 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Fri, 29 Aug 2025 23:49:59 -0400 Subject: [PATCH 26/62] Restore shop opening logic to pre-e06e04a behavior Reverts breaking changes from commit #e06e04a by restoring the previous shop opening logic. This fixes compatibility issues with multiple resources that were affected by the change. --- modules/inventory/ox_inventory/server.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/inventory/ox_inventory/server.lua b/modules/inventory/ox_inventory/server.lua index 71750be..eb3afd0 100644 --- a/modules/inventory/ox_inventory/server.lua +++ b/modules/inventory/ox_inventory/server.lua @@ -191,16 +191,15 @@ Inventory.GetImagePath = function(item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" end +-- restores shops to before commit #e06e04a (no depreication path followed, breaking change and not present on all inventories so undoing it. (also breaking multiple resources)) -- This will open the specified shop for the src passed. ---@param src number ----@param id string -Inventory.OpenShop = function(src, id) - local title = registeredShops[id]?.title or id - TriggerClientEvent('ox_inventory:openInventory', src, 'shop', {type = title}) +---@param shopTitle string +Inventory.OpenShop = function(src, shopTitle) + TriggerClientEvent('ox_inventory:openInventory', src, 'shop', {type = shopTitle}) end -- restores shops to before commit #e06e04a (no depreication path followed, breaking change and not present on all inventories so undoing it. (also breaking multiple resources)) - -- This will register a shop, if it already exists it will return true. ---@param shopTitle string ---@param shopInventory table From a435a4a75c4b0de31b8239ce43c8b3f6f01011dd Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Fri, 29 Aug 2025 23:53:44 -0400 Subject: [PATCH 27/62] Restore stash registration return values Reverts stash registration to return a boolean and id, undoing a breaking change from commit #e06e04a. This restores compatibility with multiple resources and inventories that rely on the previous behavior. Also returning a success status on registration has many uses. --- modules/inventory/ox_inventory/server.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/inventory/ox_inventory/server.lua b/modules/inventory/ox_inventory/server.lua index eb3afd0..66aeaaa 100644 --- a/modules/inventory/ox_inventory/server.lua +++ b/modules/inventory/ox_inventory/server.lua @@ -130,17 +130,19 @@ Inventory.OpenStash = function(src, _type, id) ox_inventory:forceOpenInventory(src, _type, id) end +-- restores stashes to before commit #e06e04a (no depreication path followed, breaking change and not present on all inventories so undoing it. (also breaking multiple resources)) ---This will register a stash ----@param id string +---@param id number|string ---@param label string ---@param slots number ---@param weight number ---@param owner string ---@param groups table ---@param coords table ----@return string +---@return boolean +---@return string|number Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coords) - if Inventory.Stashes[id] then return id end + if Inventory.Stashes[id] then return true, id end Inventory.Stashes[id] = { id = id, label = label, @@ -151,7 +153,7 @@ Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coor coords = coords } ox_inventory:RegisterStash(id, label, slots, weight, owner, groups, coords) - return id + return true, id end ---This will return a boolean if the player has the item. From 26bd9e1cadec49993541b8a44e2f6dd0a1695125 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Sat, 30 Aug 2025 03:43:01 -0400 Subject: [PATCH 28/62] Update server_entity.lua --- lib/entities/server/server_entity.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/entities/server/server_entity.lua b/lib/entities/server/server_entity.lua index 28d0ccb..b2a37e8 100644 --- a/lib/entities/server/server_entity.lua +++ b/lib/entities/server/server_entity.lua @@ -103,7 +103,7 @@ AddEventHandler('onResourceStop', function(resourceName) end) AddEventHandler('community_bridge:Server:OnPlayerLoaded', function(source) - print("Player loaded:", source) + -- print("Player loaded:", source) TriggerClientEvent("community_bridge:client:CreateEntities", source, Entities) end) From f2ff03734e334b3705a6934b350a6e39e4e730fd Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Sat, 30 Aug 2025 19:12:56 -0500 Subject: [PATCH 29/62] prep for behaviors readded behaviors --- lib/entities/client/client_entity.lua | 2 +- lib/entities/server/server_entity.lua | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index 0c3f8a5..187c253 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -323,4 +323,4 @@ AddEventHandler('onResourceStop', function(resourceName) end end) -return ClientEntity +return ClientEntity \ No newline at end of file diff --git a/lib/entities/server/server_entity.lua b/lib/entities/server/server_entity.lua index b2a37e8..d47a56e 100644 --- a/lib/entities/server/server_entity.lua +++ b/lib/entities/server/server_entity.lua @@ -93,6 +93,9 @@ function ServerEntity.Set(id, data) return true end +function ServerEntity.RegisterBehavior(id, behavior) + Behaviors.Create(id, behavior) +end -- Clean up entities associated with a stopped resource AddEventHandler('onResourceStop', function(resourceName) @@ -108,4 +111,4 @@ AddEventHandler('community_bridge:Server:OnPlayerLoaded', function(source) end) -return ServerEntity +return ServerEntity \ No newline at end of file From b0f5cd85a97b2de9060e79b06c084d74981ff884 Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Sun, 31 Aug 2025 03:23:09 -0500 Subject: [PATCH 30/62] Add dialogue example script Introduces a Lua script demonstrating a simple NPC dialogue interaction using Bridge.Dialogue. The script spawns a ped, opens a dialogue menu, and handles user selections with follow-up actions. --- examples/dialogue.lua | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 examples/dialogue.lua diff --git a/examples/dialogue.lua b/examples/dialogue.lua new file mode 100644 index 0000000..53582e9 --- /dev/null +++ b/examples/dialogue.lua @@ -0,0 +1,60 @@ +Bridge = Bridge or exports['community_bridge']:Bridge() +RegisterCommand("dialogue", function() + local pos = GetOffsetFromEntityInWorldCoords(PlayerPedId(), 0, 2.0, 0) + local timeout = 500 + local model = `a_f_y_hipster_01` + RequestModel(model) + while not HasModelLoaded(model) do + Wait(0) + timeout = timeout - 1 + if timeout == 0 then + print("Failed to load model") + return + end + end + local ped = CreatePed(0, model, pos.x, pos.y, pos.z, 0.0, false, false) + SetEntityHeading(ped, 50.0) + local characterData = { + entity = ped, + offset = vector3(0, 0, 0), + rotationOffset = vector3(0, 0, 0) + } + Bridge.Dialogue.Open("Akmed", "Hello how are you doing my friend?", ped, { + { + label = "Trade with me", + id = 'something', + }, + { + label = "Goodbye", + id = 'someotherthing', + }, + }, + function(selectedId) + if selectedId == 'something' then + Dialogue.Open( "Akmed" , "Thank you for wanting to purchase me lucky charms", characterData, { + { + label = "Fuck off", + id = 'something', + }, + { + label = "Goodbye", + id = 'someotherthing', + }, + }, + function(selectedId) + DeleteEntity(ped) + if selectedId == "something" then + print("You hate lucky charms") + else + print("Thanks for keeping it civil") + end + end) + else + DeleteEntity(ped) + end + end) +end) + + + + From f5017792e3249918d9280b6d28dc3ee468ff6bd2 Mon Sep 17 00:00:00 2001 From: solaire-fivem Date: Sun, 31 Aug 2025 18:41:12 +0100 Subject: [PATCH 31/62] es_extended framework code cleanup --- modules/framework/es_extended/client.lua | 123 +++++----- modules/framework/es_extended/server.lua | 275 +++++++++++------------ 2 files changed, 196 insertions(+), 202 deletions(-) diff --git a/modules/framework/es_extended/client.lua b/modules/framework/es_extended/client.lua index 38a2125..21b22a5 100644 --- a/modules/framework/es_extended/client.lua +++ b/modules/framework/es_extended/client.lua @@ -1,13 +1,14 @@ ---@diagnostic disable: duplicate-set-field if GetResourceState('es_extended') ~= 'started' then return end -ESX = exports["es_extended"]:getSharedObject() +ESX = exports.es_extended:getSharedObject() Callback = Callback or Require("lib/utility/shared/callbacks.lua") Framework = Framework or {} local cachedItemList = nil --- This is an internal function, its here to attempt to emulate qbs shared items mainly. + +--- @description This is an internal function, its here to attempt to emulate qbs shared items mainly Framework.ItemList = function() if cachedItemList then return cachedItemList end local items = Callback.Trigger('community_bridge:Callback:GetFrameworkItems', false) @@ -15,98 +16,99 @@ Framework.ItemList = function() return cachedItemList end ----This will get the name of the framework being used (if a supported framework). ----@return string +--- @description This will get the name of the framework being used (if a supported framework). +--- @return string Framework.GetFrameworkName = function() return 'es_extended' end ----This will return true if the player is loaded, false otherwise. ----This could be useful in scripts that rely on player loaded events and offer a debug mode to hit this function. ----@return boolean +--- @description This will return true if the player is loaded, false otherwise. +--- This could be useful in scripts that rely on player loaded events and offer a debug mode to hit this function +--- @return boolean Framework.GetIsPlayerLoaded = function() return ESX.IsPlayerLoaded() end ----This will return a table of the player data, this will be in the framework format. ----This is mainly for internal bridge use and should be avoided. ----@return table +--- @description This will return a table of the player data, this will be in the framework format +--- This is mainly for internal bridge use and should be avoided. +--- @return table Framework.GetPlayerData = function() return ESX.GetPlayerData() end ----This will return a table of all the jobs in the framework. ----@return table +--- @description This will return a table of all the jobs in the framework. +--- @return table Framework.GetFrameworkJobs = function() local jobs = Callback.Trigger('community_bridge:Callback:GetFrameworkJobs', false) return jobs end ----This will return the players birth date ----@return string +--- @description This will return the players birth date +--- @return string Framework.GetPlayerDob = function() local playerData = Framework.GetPlayerData() local dob = playerData.dateofbirth return dob end ----This will return the players metadata for the specified metadata key. ----@param metadata table | string +--- @description This will return the players metadata for the specified metadata key. +--- @param metadata table | string ---@return table | string | number | boolean Framework.GetPlayerMetaData = function(metadata) return Framework.GetPlayerData().metadata[metadata] end ----This will send a notification to the player. ----@param message string ----@param type string ----@param time number ----@return nil +--- @description This will send a notification to the player. +--- @param message string +--- @param type string +--- @param time number +--- @return nil Framework.Notify = function(message, type, time) return ESX.ShowNotification(message, type, time) end ----Will Display the help text message on the screen ----@param message string ----@param _ unknown ----@return nil +--- @description This will display the help text message on the screen +--- @param message string +--- @param _ unknown +--- @return nil Framework.ShowHelpText = function(message, _) - return exports['esx_textui']:TextUI(message, "info") + return exports.esx_textui:TextUI(message, "info") end ----This will hide the help text message on the screen ----@return nil +--- @description This will hide the help text message on the screen +--- @return nil Framework.HideHelpText = function() - return exports['esx_textui']:HideUI() + return exports.esx_textui:HideUI() end ----This will get the players identifier (citizenid) etc. +--- @description This will get the players identifier (citizenid) etc. ---@return string Framework.GetPlayerIdentifier = function() local playerData = Framework.GetPlayerData() return playerData.identifier end ----This will get the players name (first and last). ----@return string ----@return string +--- @description This will get the players name (first and last). +--- @return string +--- @return string Framework.GetPlayerName = function() local playerData = Framework.GetPlayerData() return playerData.firstName, playerData.lastName end ----Depricated : This will return the players job name, job label, job grade label and job grade level ----@return string ----@return string ----@return string ----@return string +--- @deprecated This will return the players job name, job label, job grade label and job grade level +--- @return string returns job name +--- @return string returns job label +--- @return string returns job grade label +--- @return string returns job grade level Framework.GetPlayerJob = function() local playerData = Framework.GetPlayerData() return playerData.job.name, playerData.job.label, playerData.job.grade_label, playerData.job.grade end ----This will return the players job name, job label, job grade label job grade level, boss status, and duty status in a table ----@return table +--- @description This will return the players job name, job label, job grade label job grade level, +--- boss status, and duty status in a table +--- @return table Framework.GetPlayerJobData = function() local playerData = Framework.GetPlayerData() local jobData = playerData.job @@ -122,34 +124,33 @@ Framework.GetPlayerJobData = function() } end ----This will return if the player has the specified item in their inventory. ----@param item string ----@return boolean +--- @description This will return if the player has the specified item in their inventory +--- @param item string +--- @return boolean Framework.HasItem = function(item) local hasItem = ESX.SearchInventory(item, true) return hasItem > 0 and true or false end ----This will return the item count for the specified item in the players inventory. ----@param item string ----@return number +--- @description This will return the item count for the specified item in the players inventory +--- @param item string +--- @return number Framework.GetItemCount = function(item) local inventory = Framework.GetPlayerInventory() if not inventory then return 0 end return inventory[item].count or 0 end ----This will return a table of the players inventory ----@return table +--- @description This will return a table of the players inventory +--- @return table Framework.GetPlayerInventory = function() local playerData = Framework.GetPlayerData() return playerData.inventory end ----This will return the players money by type, I recommend not useing this as its the client and not secure or to be trusted. ----Use case is for a ui or a menu I guess. ----@param _type string ----@return number +--- @description This will return the players money by type, I recommend not using this as its the client and not secure or to be trusted +--- @param _type string +--- @return number Framework.GetAccountBalance = function(_type) local player = Framework.GetPlayerData() if not player then return 0 end @@ -163,19 +164,19 @@ Framework.GetAccountBalance = function(_type) return 0 end ----This will return the vehicle properties for the specified vehicle. ----@param vehicle number ----@return table +--- @description This will return the vehicle properties for the specified vehicle +--- @param vehicle number +--- @return table Framework.GetVehicleProperties = function(vehicle) if not vehicle or not DoesEntityExist(vehicle) then return {} end local vehicleProps = ESX.Game.GetVehicleProperties(vehicle) return vehicleProps or {} end ----This will set the vehicle properties for the specified vehicle. ----@param vehicle number ----@param properties table ----@return boolean +--- @description This will set the vehicle properties for the specified vehicle +--- @param vehicle number +--- @param properties table +--- @return boolean Framework.SetVehicleProperties = function(vehicle, properties) if not vehicle or not DoesEntityExist(vehicle) then return false end if not properties then return false end @@ -203,8 +204,8 @@ Framework.SetVehicleProperties = function(vehicle, properties) return true, ESX.Game.SetVehicleProperties(vehicle, properties) end ----This will get a players dead status. ----@return boolean +--- @description This will get a players dead status +--- @return boolean Framework.GetIsPlayerDead = function() local playerData = Framework.GetPlayerData() return playerData.dead diff --git a/modules/framework/es_extended/server.lua b/modules/framework/es_extended/server.lua index d0adad1..6daf30f 100644 --- a/modules/framework/es_extended/server.lua +++ b/modules/framework/es_extended/server.lua @@ -4,19 +4,19 @@ if GetResourceState('es_extended') ~= 'started' then return end Prints = Prints or Require("lib/utility/shared/prints.lua") Callback = Callback or Require("lib/utility/shared/callbacks.lua") -ESX = exports["es_extended"]:getSharedObject() +ESX = exports.es_extended:getSharedObject() Framework = Framework or {} local cachedItemList = nil ----This will return the name of the framework in use. ----@return string +--- @description This will return the name of the framework in use +--- @return string Framework.GetFrameworkName = function() return 'es_extended' end --- This is an internal function, its here to attempt to emulate qbs shared items mainly. +--- @description This is an internal function, its here to attempt to emulate qbs shared items mainly Framework.ItemList = function() if cachedItemList then return cachedItemList end local items = ESX.Items @@ -40,9 +40,9 @@ Framework.ItemList = function() return cachedItemList end ----This will return if the player is an admin in the framework. ----@param src any ----@return boolean +--- @description This will return if the player is an admin in the framework +--- @param src any +--- @return boolean Framework.GetIsFrameworkAdmin = function(src) if not src then return false end local xPlayer = Framework.GetPlayer(src) @@ -52,8 +52,8 @@ Framework.GetIsFrameworkAdmin = function(src) return false end ----This will get the players birth date ----@return string|nil +--- @description This will get the players birth date +--- @return string|nil Framework.GetPlayerDob = function(src) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end @@ -61,43 +61,40 @@ Framework.GetPlayerDob = function(src) return dob end ---- Returns the player data of the specified source in the framework defualt format. ----@param src any ----@return table | nil +--- @description Returns the player data of the specified source in the framework defualt format +--- @param src any +--- @return table | nil Framework.GetPlayer = function(src) local xPlayer = ESX.GetPlayerFromId(src) if not xPlayer then return end return xPlayer end --- Framework.GetPlayerIdentifier(src) --- Returns the citizen ID of the player. ----@param src number ----@return string | nil +--- @description Returns the citizen ID of the player. +--- @param src number +--- @return string | nil returns the citizen ID of the player if it exists Framework.GetPlayerIdentifier = function(src) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end return xPlayer.getIdentifier() end ----This will return the jobs registered in the framework in a table. ----Format of the table is: ----{name = jobName, label = jobLabel, grade = {name = gradeName, level = gradeLevel}} ----@return table +--- @description This will return the jobs registered in the framework in a table. +--- @return table in the format "{name = jobName, label = jobLabel, grade = {name = gradeName, level = gradeLevel}}" Framework.GetFrameworkJobs = function() return ESX.GetJobs() end --- Framework.GetPlayerName(src) --- Returns the first and last name of the player. ----@return string|nil, string|nil + +--- @description This will return the first and last name of the player. +--- @return string|nil, string|nil returns the first and last name of the player Framework.GetPlayerName = function(src) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end return xPlayer.variables.firstName, xPlayer.variables.lastName end ----This will return a table of all logged in players ----@return table +--- @description This will return a table of all logged in players +--- @return table Framework.GetPlayers = function() local players = ESX.GetExtendedPlayers() local playerList = {} @@ -107,12 +104,11 @@ Framework.GetPlayers = function() return playerList end ----Returns a table of items matching the specified name and if passed metadata from the player's inventory. ----returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot} ----@param src number ----@param item string ----@param _ table ----@return table|nil +--- @description This will return a table of items matching the specified name and if passed metadata from the player's inventory +--- @param src number +--- @param item string +--- @param _ table +--- @return table|nil returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot} Framework.GetItem = function(src, item, _) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end @@ -131,32 +127,29 @@ Framework.GetItem = function(src, item, _) return repackedTable end ----This will return the count of the item in the players inventory, if not found will return 0. ----if metadata is passed it will find the matching items count (esx_core does not feature metadata items). ----@param src number ----@param item string ----@param _ table ----@return number +--- @param src number +--- @param item string +--- @param _ table +--- @return number returns the count of the item in the players inventory, if not found will return 0. +--- If metadata is passed it will find the matching items count (esx_core does not feature metadata items) Framework.GetItemCount = function(src, item, _) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end return xPlayer.getInventoryItem(item).count end ----This will return a boolean if the player has the item. ----@param src number ----@param item string ----@return boolean +--- @description This will return true if the player has the item, false otherwise +--- @param src number +--- @param item string +--- @return boolean returns true if the player has the item, false otherwise. Framework.HasItem = function(src, item) local getCount = Framework.GetItemCount(src, item, nil) return getCount > 0 end --- Framework.GetPlayerInventory(src) --- Returns the entire inventory of the player as a table. --- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot} ----@param src number ----@return table | nil +--- @description This will return the player's inventory as a table +--- @param src number +--- @return table | nil returns the player's inventory as a table in format: {name = v.name, count = v.amount, metadata = v.info, slot = v.slot} Framework.GetPlayerInventory = function(src) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end @@ -175,9 +168,11 @@ Framework.GetPlayerInventory = function(src) return repackedTable end --- Framework.SetMetadata(src, metadata, value) --- Adds the specified metadata key and number value to the player's data. ----@return boolean|nil +--- @description Adds the specified metadata key and number value to the player's data. +--- @param src number +--- @param metadata string +--- @param value any +--- @return boolean|nil returns true if the metadata was set successfully, otherwise it returns nil Framework.SetPlayerMetadata = function(src, metadata, value) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end @@ -186,39 +181,44 @@ Framework.SetPlayerMetadata = function(src, metadata, value) end -- Framework.GetMetadata(src, metadata) --- Gets the specified metadata key to the player's data. ----@param src number ----@param metadata string ----@return any|nil +--- @description Gets the specified metadata key to the player's data. +--- @param src number +--- @param metadata string +--- @return any|nil Framework.GetPlayerMetadata = function(src, metadata) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end return xPlayer.getMeta(metadata) or false end --- defualt esx Available tables are --- identifier, accounts, group, inventory, job, job_grade, loadout, --- metadata, position, firstname, lastname, dateofbirth, sex, height, --- skin, status, is_dead, id, disabled, last_property, created_at, last_seen, --- phone_number, pincode +--- @description This will return the specified status column of the player. +--- @param src number +--- @param column string +--- @return string|nil Framework.GetStatus = function(src, column) + --[[ + defualt esx Available tables are: + identifier, accounts, group, inventory, job, job_grade, loadout, metadata, position, + firstname, lastname, dateofbirth, sex, height, skin, status, is_dead, id, disabled, + last_property, created_at, last_seen, phone_number, pincode + ]] local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end return xPlayer.get(column) or nil end ----This will return a boolean if the player is dead or in last stand. ----@param src number ----@return boolean|nil +--- @description This will return a boolean if the player is dead or in last stand +--- @param src number +--- @return boolean|nil Framework.GetIsPlayerDead = function(src) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end return xPlayer.get("is_dead") or false end ----This will revive a player, if the player is dead or in last stand. ----@param src number ----@return boolean +--- @description This will revive a player, if the player is dead or in last stand +--- @param src number +--- @return boolean Framework.RevivePlayer = function(src) src = tonumber(src) if not src then return false end @@ -226,11 +226,10 @@ Framework.RevivePlayer = function(src) return true end --- Framework.AddThirst(src, value) --- Adds the specified value from the player's thirst level. ----@param src number ----@param value number ----@return number | nil +--- @description Adds the specified value from the player's thirst level +--- @param src number +--- @param value number +--- @return number | nil Framework.AddThirst = function(src, value) local clampIT = Math.Clamp(value, 0, 200000) local levelForEsx = clampIT * 2000 @@ -238,11 +237,10 @@ Framework.AddThirst = function(src, value) return levelForEsx end --- Framework.AddHunger(src, value) --- Adds the specified value from the player's hunger level. ----@param src number ----@param value number ----@return number | nil +--- @description Adds the specified value from the player's hunger level +--- @param src number +--- @param value number +--- @return number | nil Framework.AddHunger = function(src, value) local clampIT = Math.Clamp(value, 0, 200000) local levelForEsx = clampIT * 2000 @@ -250,36 +248,34 @@ Framework.AddHunger = function(src, value) return levelForEsx end ----This will get the hunger of a player ----@param src number ----@return number | nil +--- @description This will get the hunger of a player +--- @param src number +--- @return number | nil Framework.GetHunger = function(src) local status = Framework.GetStatus(src, "status") if not status then return 0 end return status.hunger end ----This will get the thirst of a player ----@param src any ----@return number | nil +--- @description This will get the thirst of a player +--- @param src any +--- @return number | nil Framework.GetThirst = function(src) local status = Framework.GetStatus(src, "status") if not status then return 0 end return status.thirst end --- Framework.GetPlayerPhone(src) --- Returns the phone number of the player. ----@param src number ----@return string | nil +--- @description This will get the phone number of a player +--- @param src number +--- @return string | nil return the phone number of the player Framework.GetPlayerPhone = function(src) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end return xPlayer.get("phone_number") end - ----Depricated: Returns the job name, label, grade name, and grade level of the player. +---@deprecated This will return the job name, label, grade name, and grade level of the player. ---@param src number ---@return string | nil ---@return string | nil @@ -292,9 +288,10 @@ Framework.GetPlayerJob = function(src) return job.name, job.label, job.grade_label, job.grade end ----This will return the players job name, job label, job grade label job grade level, boss status, and duty status in a table ----@param src number ----@return table | nil +--- @description This will return the players job name, job label, job grade label job grade level, +--- boss status, and duty status in a table +--- @param src number +--- @return table | nil Framework.GetPlayerJobData = function(src) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end @@ -311,9 +308,9 @@ Framework.GetPlayerJobData = function(src) } end ----Returns the players duty status. ----@param src number ----@return boolean +--- @description This will return the players duty status, true if on duty false otherwise +--- @param src number +--- @return boolean return the players duty status Framework.GetPlayerDuty = function(src) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return false end @@ -322,10 +319,10 @@ Framework.GetPlayerDuty = function(src) return true end ----This will toggle a players duty status ----@param src number ----@param status boolean ----@return boolean +--- @description This will toggle a players duty status +--- @param src number +--- @param status boolean +--- @return boolean Framework.SetPlayerDuty = function(src, status) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return false end @@ -335,18 +332,18 @@ Framework.SetPlayerDuty = function(src, status) return true end ----This will get a table of player sources that have the specified job name. ----@param job string ----@return table +--- @description This will get a table of player sources that have the specified job name +--- @param job string +--- @return table Framework.GetPlayersByJob = function(job) return Framework.GetPlayerSourcesByJob(job) or {} end --- Sets the player's job to the specified name and grade. ----@param src number ----@param name string ----@param grade string ----@return nil +--- @description This will set the player's job to the specified name and grade +--- @param src number +--- @param name string +--- @param grade string +--- @return nil Framework.SetPlayerJob = function(src, name, grade) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end @@ -358,11 +355,11 @@ Framework.SetPlayerJob = function(src, name, grade) return true end ----This will add money based on the type of account (money/bank) ----@param src number ----@param _type string ----@param amount number ----@return boolean | nil +--- @description This will add money based on the type of account (money/bank) +--- @param src number +--- @param _type string +--- @param amount number +--- @return boolean | nil Framework.AddAccountBalance = function(src, _type, amount) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end @@ -371,11 +368,11 @@ Framework.AddAccountBalance = function(src, _type, amount) return true end ----This will remove money based on the type of account (money/bank) ----@param src number ----@param _type string ----@param amount number ----@return boolean | nil +--- @description This will remove money based on the type of account (money/bank) +--- @param src number +--- @param _type string +--- @param amount number +--- @return boolean | nil Framework.RemoveAccountBalance = function(src, _type, amount) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end @@ -384,10 +381,10 @@ Framework.RemoveAccountBalance = function(src, _type, amount) return true end ----This will remove money based on the type of account (money/bank) ----@param src number ----@param _type string ----@return string | nil +--- @description This will get the account balance based on the type of account (money/bank) +--- @param src number +--- @param _type string +--- @return string | nil Framework.GetAccountBalance = function(src, _type) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end @@ -395,14 +392,13 @@ Framework.GetAccountBalance = function(src, _type) return xPlayer.getAccount(_type).money end --- Framework.AddItem(src, item, amount, slot, metadata) --- Adds the specified item to the player's inventory. ----@param src number ----@param item string ----@param amount number ----@param slot number ----@param metadata table ----@return boolean | nil +--- @description Adds the specified item to the player's inventory +--- @param src number +--- @param item string +--- @param amount number +--- @param slot number +--- @param metadata table +--- @return boolean | nil Framework.AddItem = function(src, item, amount, slot, metadata) local xPlayer = Framework.GetPlayer(src) if not xPlayer then return end @@ -410,13 +406,12 @@ Framework.AddItem = function(src, item, amount, slot, metadata) return true end --- Framework.RemoveItem(src, item, amount, slot, metadata) --- Removes the specified item from the player's inventory. ----@param src number ----@param item string ----@param amount number ----@param slot number ----@param metadata table +--- @description Removes the specified item from the player's inventory +--- @param src number +--- @param item string +--- @param amount number +--- @param slot number +--- @param metadata table ---@return boolean | nil Framework.RemoveItem = function(src, item, amount, slot, metadata) local xPlayer = Framework.GetPlayer(src) @@ -425,9 +420,9 @@ Framework.RemoveItem = function(src, item, amount, slot, metadata) return true end ----This will get all owned vehicles for the player ----@param src number ----@return table +--- @description This will get all owned vehicles for the player +--- @param src number +--- @return table Framework.GetOwnedVehicles = function(src) local citizenId = Framework.GetPlayerIdentifier(src) local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM owned_vehicles WHERE owner = '" .. citizenId .. "'") @@ -441,11 +436,9 @@ Framework.GetOwnedVehicles = function(src) return vehicles end - --- Framework.RegisterUsableItem(item, cb) --- Registers a usable item with a callback function. ----@param itemName string ----@param cb function +--- @description Registers a usable item with a callback function +--- @param itemName string +--- @param cb function Framework.RegisterUsableItem = function(itemName, cb) local func = function(src, item, itemData) itemData = itemData or item From c399fbaca456381e446d9e26d4c568a52b795db2 Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Sun, 31 Aug 2025 20:50:46 -0500 Subject: [PATCH 32/62] Refactor behavior and entity invocation handling Standardizes the use of the 'invoked' property for entities and behaviors, ensuring behaviors are scoped per invoking resource. Updates behavior registration, retrieval, removal, and cleanup logic to support resource-specific behavior tables, improving modularity and preventing cross-resource conflicts. --- lib/entities/client/client_entity.lua | 4 +-- lib/entities/server/server_entity.lua | 2 +- lib/entities/shared/behaviors.lua | 37 +++++++++++++++------------ 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index 187c253..3544dbb 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -112,10 +112,10 @@ function ClientEntity.Create(entityData) entityData.rotation = entityData.rotation or vector3(0.0, 0.0, entityData.heading or 0.0) entityData.oldCoords = entityData.oldCoords or vector3(0.0, 0.0, 0.0) entityData.oldRotation = entityData.rotation - + entityData.invoked = entityData.invoked or GetInvokingResource() or "community_bridge" local entityPoint = Point.Register(entityData.id, entityData.coords, entityData.spawnDistance or 50.0, entityData, SpawnEntity, RemoveEntity, UpdateEntity) Entities[entityData.id] = entityPoint - entityData.invoked = GetInvokingResource() or "community_bridge" + ClientEntity.Invoked[entityData.invoked] = ClientEntity.Invoked[entityData.invoked] or {} ClientEntity.Invoked[entityData.invoked][entityData.id] = entityData Behaviors.Trigger("OnCreate", entityPoint) diff --git a/lib/entities/server/server_entity.lua b/lib/entities/server/server_entity.lua index d47a56e..c9950c0 100644 --- a/lib/entities/server/server_entity.lua +++ b/lib/entities/server/server_entity.lua @@ -24,7 +24,7 @@ function ServerEntity.New(id, entityType, model, coords, rotation, args) self.coords = coords self.rotation = rotation or vector3(0.0, 0.0, 0.0) local invoking = GetInvokingResource() or "community_bridge" - self.invoking = invoking + self.invoked = invoking Invoked[invoking] = Invoked[invoking] or {} table.insert(Invoked[invoking], self) diff --git a/lib/entities/shared/behaviors.lua b/lib/entities/shared/behaviors.lua index f152c8e..65f56a0 100644 --- a/lib/entities/shared/behaviors.lua +++ b/lib/entities/shared/behaviors.lua @@ -4,29 +4,31 @@ Behaviors = { invoked = {} } - function Behaviors.Create(behaviorId, behavior) if not behaviorId or not behavior then return end - if Behaviors.All[behaviorId] then return print(string.format("[ClientEntity] Behavior %s already exists", behaviorId)) end + Behaviors.All = Behaviors.All or {} local invoking = GetInvokingResource() or "community_bridge" - Behaviors.All[behaviorId] = behavior - Behaviors.invoked[invoking] = Behaviors.invoked[invoking] or {} - table.insert(Behaviors.invoked[invoking], behaviorId) + Behaviors.All[invoking] = Behaviors.All[invoking] or {} + Behaviors.All[invoking][behaviorId] = behavior end function Behaviors.Get(behaviorId) - return Behaviors.All[behaviorId] + local invoking = GetInvokingResource() or "community_bridge" + return Behaviors.All[invoking] and Behaviors.All[invoking][behaviorId] end function Behaviors.Remove(behaviorId) - if not Behaviors.All[behaviorId] then return end - Behaviors.All[behaviorId] = nil + local invoking = GetInvokingResource() or "community_bridge" + if not Behaviors.All[invoking] or not Behaviors.All[invoking][behaviorId] then return end + Behaviors.All[invoking][behaviorId] = nil return true end function Behaviors.Trigger(actionName, clientEntityData, ...) if not clientEntityData or not actionName then return end - for property, behavior in pairs(Behaviors.All) do + + local invoking = clientEntityData.invoked or GetInvokingResource() or "community_bridge" + for property, behavior in pairs(Behaviors.All[invoking] or {}) do local hasBehaviorArgs = Behaviors.Has(property, clientEntityData) -- this is everything that's contained inside the object's individual property if hasBehaviorArgs and behavior[actionName] then local success, result = pcall(behavior[actionName], clientEntityData, hasBehaviorArgs, ...) @@ -38,7 +40,8 @@ function Behaviors.Trigger(actionName, clientEntityData, ...) end function Behaviors.Inherit(behaviorId, clientEntityData, defaultData) - if not Behaviors.All[behaviorId] then + local invoking = GetInvokingResource() or "community_bridge" + if not Behaviors.All[invoking] or not Behaviors.All[invoking][behaviorId] then print(string.format("[ClientEntity] Behavior %s does not exist", behaviorId)) return false end @@ -55,19 +58,21 @@ function Behaviors.Has(behaviorId, clientEntityData) end function Behaviors.Cleanup(resourceName) - if not resourceName or not Behaviors.invoked[resourceName] then return end - for _, behaviorId in ipairs(Behaviors.invoked[resourceName]) do + if not resourceName or not Behaviors.All[resourceName] then return end + for _, behaviorId in ipairs(Behaviors.All[resourceName]) do Behaviors.Remove(behaviorId) end - Behaviors.invoked[resourceName] = nil + Behaviors.All[resourceName] = nil end AddEventHandler("onResourceStop", function(resourceName) Behaviors.Cleanup(resourceName) if resourceName ~= GetCurrentResourceName() then return end - for behaviorId, _ in pairs(Behaviors.All) do - Behaviors.Remove(behaviorId) + for invoking, behaviors in pairs(Behaviors.All) do + for behaviorId, _ in pairs(behaviors) do + Behaviors.Remove(behaviorId) + end end end) -return Behaviors \ No newline at end of file +return Behaviors From 9fdb41e9f65737060a0779f86336561753bc48a0 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Sun, 31 Aug 2025 19:17:01 -0400 Subject: [PATCH 33/62] Add job count management on player events Introduces event handlers to update job counts when players load, change jobs, or unload across multiple framework modules. Ensures job count tracking stays accurate by adding or removing counts based on player actions. (would like to update this to have some client event tables?) --- modules/framework/_default/server.lua | 10 ++++++++++ modules/framework/es_extended/server.lua | 3 +++ modules/framework/qb-core/server.lua | 3 +++ modules/framework/qbx_core/server.lua | 3 +++ 4 files changed, 19 insertions(+) diff --git a/modules/framework/_default/server.lua b/modules/framework/_default/server.lua index 0cedf7c..5dcdf95 100644 --- a/modules/framework/_default/server.lua +++ b/modules/framework/_default/server.lua @@ -53,4 +53,14 @@ Framework.RemoveJobCount = function(src, jobName) return true, #jobsRegisteredTable[jobName] end +AddEventHandler('community_bridge:Server:OnPlayerJobChange', function(src, newJobName) + local previousJob = Framework.SearchJobCountBySource(src) + if previousJob then Framework.RemoveJobCount(src, previousJob) end + if newJobName then Framework.AddJobCount(src, newJobName) end +end) + +AddEventHandler('community_bridge:Server:OnPlayerUnload', function(src) + Framework.RemoveJobCount(src) +end) + return Framework \ No newline at end of file diff --git a/modules/framework/es_extended/server.lua b/modules/framework/es_extended/server.lua index 6daf30f..40e809b 100644 --- a/modules/framework/es_extended/server.lua +++ b/modules/framework/es_extended/server.lua @@ -452,6 +452,9 @@ end RegisterNetEvent("esx:playerLoaded", function(src) src = src or source TriggerEvent("community_bridge:Server:OnPlayerLoaded", src) + local jobData = Framework.GetPlayerJobData(src) + if not jobData then return end + Framework.AddJobCount(src, jobData.jobName) end) RegisterNetEvent("esx:playerLogout", function(src) diff --git a/modules/framework/qb-core/server.lua b/modules/framework/qb-core/server.lua index 6b8049f..1ba3d10 100644 --- a/modules/framework/qb-core/server.lua +++ b/modules/framework/qb-core/server.lua @@ -557,6 +557,9 @@ end RegisterNetEvent("QBCore:Server:OnPlayerLoaded", function(src) src = src or source TriggerEvent("community_bridge:Server:OnPlayerLoaded", src) + local jobData = Framework.GetPlayerJobData(src) + if not jobData then return end + Framework.AddJobCount(src, jobData.jobName) end) RegisterNetEvent("QBCore:Server:OnPlayerUnload", function(src) diff --git a/modules/framework/qbx_core/server.lua b/modules/framework/qbx_core/server.lua index 47a1ce2..de994dd 100644 --- a/modules/framework/qbx_core/server.lua +++ b/modules/framework/qbx_core/server.lua @@ -467,6 +467,9 @@ end RegisterNetEvent("QBCore:Server:OnPlayerLoaded", function(src) src = src or source TriggerEvent("community_bridge:Server:OnPlayerLoaded", src) + local jobData = Framework.GetPlayerJobData(src) + if not jobData then return end + Framework.AddJobCount(src, jobData.jobName) end) RegisterNetEvent("QBCore:Server:OnPlayerUnload", function(src) From 014dba1012d57e61f0b2ecf16f7be0bfd2269972 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Sun, 31 Aug 2025 22:49:12 -0400 Subject: [PATCH 34/62] Add job count tracking to framework Introduces job count tracking and retrieval functions to both client and server modules. The server now maintains and updates a global state of job counts, synchronizing changes to clients. Refactors job registration logic for accuracy and consistency, and adds utility functions for total job counts and player source retrieval. This usage with the state may be a problem on initial start for highly populated servers as 200 players load in for example... --- modules/framework/_default/client.lua | 27 +++++++++++ modules/framework/_default/server.lua | 68 ++++++++++++++++++++++----- 2 files changed, 82 insertions(+), 13 deletions(-) diff --git a/modules/framework/_default/client.lua b/modules/framework/_default/client.lua index 5d895be..2bcb7c6 100644 --- a/modules/framework/_default/client.lua +++ b/modules/framework/_default/client.lua @@ -1,3 +1,30 @@ +---@diagnostic disable: duplicate-set-field Framework = Framework or {} +local currentJobCounts = GlobalState.jobcounts or {} + +AddStateBagChangeHandler('jobcounts', 'global', function(bagName, key, value) + if not value then currentJobCounts = {} return end + currentJobCounts = value +end) + +---This is an internal function that will be used to retrieve job counts later. +---@param jobName string +---@return number +Framework.GetJobCount = function(jobName) + if not currentJobCounts[jobName] then return 0 end + return currentJobCounts[jobName] +end + +---This will allow passing a table of job names and returning a sum of the total count. +---@param tbl any +---@return number +Framework.GetJobCountTotal = function(tbl) + local total = 0 + for _, jobName in pairs(tbl) do + total = total + Framework.GetJobCount(jobName) + end + return total +end + return Framework \ No newline at end of file diff --git a/modules/framework/_default/server.lua b/modules/framework/_default/server.lua index 5dcdf95..40161ff 100644 --- a/modules/framework/_default/server.lua +++ b/modules/framework/_default/server.lua @@ -1,13 +1,33 @@ +---@diagnostic disable: duplicate-set-field Framework = Framework or {} local jobsRegisteredTable = {} local invertedJobsRegisteredTable = {} +local globalState = GlobalState + +globalState.jobcounts = {} ---This is an internal function that will be used to retrieve job counts later. ---@param jobName string ---@return number Framework.GetJobCount = function(jobName) - return #jobsRegisteredTable[jobName] or 0 + if not jobsRegisteredTable[jobName] then return 0 end + local count = 0 + for _ in pairs(jobsRegisteredTable[jobName]) do + count = count + 1 + end + return count +end + +---This will allow passing a table of job names and returning a sum of the total count. +---@param tbl any +---@return number +Framework.GetJobCountTotal = function(tbl) + local total = 0 + for _, jobName in pairs(tbl) do + total = total + Framework.GetJobCount(jobName) + end + return total end ---This will return a list of player sources for a given job. @@ -15,7 +35,11 @@ end ---@return table Framework.GetPlayerSourcesByJob = function(jobName) if not jobsRegisteredTable[jobName] then return {} end - return jobsRegisteredTable[jobName] + local sources = {} + for src in pairs(jobsRegisteredTable[jobName]) do + table.insert(sources, src) + end + return sources end ---This will update the cached tables for job counts. @@ -23,18 +47,25 @@ end ---@param src number ---@param jobName string Framework.AddJobCount = function(src, jobName) + if not src or not jobName then return false end if not jobsRegisteredTable[jobName] then jobsRegisteredTable[jobName] = {} end if jobsRegisteredTable[jobName][src] then return false end + jobsRegisteredTable[jobName][src] = true invertedJobsRegisteredTable[src] = jobName - return true, #jobsRegisteredTable[jobName] + + local newJobCounts = {} + for job, _ in pairs(jobsRegisteredTable) do + newJobCounts[job] = Framework.GetJobCount(job) + end + globalState.jobcounts = newJobCounts + + return true end ---This will return the job name for a given source. ----This is an internal function that will be used to retrieve job names in situations where player data is unavailable. ---@param src number Framework.SearchJobCountBySource = function(src) - if not invertedJobsRegisteredTable[src] then return nil end return invertedJobsRegisteredTable[src] end @@ -42,19 +73,30 @@ end ---@param src number ---@param jobName string | nil Framework.RemoveJobCount = function(src, jobName) - if not jobName then - jobName = Framework.SearchJobCountBySource(src) - end + if not src then return false end + + if not jobName then jobName = invertedJobsRegisteredTable[src] end if not jobName then return false end - if not jobsRegisteredTable[jobName] then return false end - if not jobsRegisteredTable[jobName][src] then return false end + invertedJobsRegisteredTable[src] = nil - jobsRegisteredTable[jobName][src] = nil - return true, #jobsRegisteredTable[jobName] + if jobsRegisteredTable[jobName] then + jobsRegisteredTable[jobName][src] = nil + end + + local newJobCounts = {} + for job, _ in pairs(jobsRegisteredTable) do + local count = Framework.GetJobCount(job) + if count > 0 then + newJobCounts[job] = count + end + end + globalState.jobcounts = newJobCounts + + return true end AddEventHandler('community_bridge:Server:OnPlayerJobChange', function(src, newJobName) - local previousJob = Framework.SearchJobCountBySource(src) + local previousJob = invertedJobsRegisteredTable[src] if previousJob then Framework.RemoveJobCount(src, previousJob) end if newJobName then Framework.AddJobCount(src, newJobName) end end) From 7f14eef82bf5ccecfbb228c906334778b905d3fc Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Mon, 1 Sep 2025 02:29:15 -0400 Subject: [PATCH 35/62] Refactor logging system and centralize config Reworked the logging system to use a unified handler approach supporting built-in, qb, ox_lib, and Fivemerr log systems. Deprecated Logs.Send and Logs.Notify in favor of Logs.CreateLog. Centralized all logging configuration options in serverConfig.lua for easier management and extensibility. --- lib/logs/server/logs.lua | 158 ++++++++++++++------------------------ settings/serverConfig.lua | 7 +- 2 files changed, 62 insertions(+), 103 deletions(-) diff --git a/lib/logs/server/logs.lua b/lib/logs/server/logs.lua index 5fc0cec..650778a 100644 --- a/lib/logs/server/logs.lua +++ b/lib/logs/server/logs.lua @@ -1,115 +1,71 @@ Logs = Logs or {} +local BridgeServerConfig = BridgeServerConfig or Require("settings/serverConfig.lua") -local WebhookURL = "" -- Add webhook URL here if using built-in logging system -local LogoForEmbed = "https://cdn.discordapp.com/avatars/299410129982455808/31ce635662206e8bd0132c34ce9ce683?size=1024" -local LogSystem = "built-in" -- Default log system, can be "built-in", "qb", or "ox_lib" +local logHandlers = { + fivemerr = function(logData) + local fivemerrData = { + level = "info", + message = tostring(logData), + resource = GetInvokingResource() or GetCurrentResourceName(), + } + PerformHttpRequest("https://api.fivemerr.com/v1/logs", function(code, text, headers) + if code ~= 200 then + print(("Failed to send log to Fivemerr API (HTTP %d): Please verify your API key is correct and the service is available."):format(code)) + else + print("Log successfully sent to Fivemerr") + end + end, 'POST', json.encode(fivemerrData), { + ['Content-Type'] = 'application/json', + ['Authorization'] = BridgeServerConfig.FivemerrApiKey + }) + end, ----This will send a log to the configured webhook or log system. ----@param src number ----@param message string ----@return nil -Logs.Send = function(src, message) - if not src or not message then return end - local logType = LogSystem or "built-in" - if logType == "built-in" then - PerformHttpRequest(WebhookURL, function(err, text, headers) end, 'POST', json.encode( - { + qb = function(message) + TriggerEvent('qb-log:server:CreateLog', GetCurrentResourceName(), GetInvokingResource(), 'green', message, false) + end, + + ox_lib = function(message) + lib.logger(GetInvokingResource(), GetCurrentResourceName(), message) + end, + + ["built-in"] = function(message) + PerformHttpRequest(BridgeServerConfig.WebhookURL, function(err, text, headers) end, 'POST', json.encode({ username = "Community_Bridge's Logger", avatar_url = 'https://avatars.githubusercontent.com/u/192999457?s=400&u=da632e8f64c85def390cfd1a73c3b664d6882b38&v=4', - embeds = { - { - color = "15769093", - title = GetCurrentResourceName(), - url = 'https://discord.gg/Gm6rYEXUsn', - 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 | ", - icon_url = 'https://avatars.githubusercontent.com/u/192999457?s=400&u=da632e8f64c85def390cfd1a73c3b664d6882b38&v=4', - }, - } - } - }), { ['Content-Type']= 'application/json' }) - elseif logType == "qb" then - return TriggerEvent('qb-log:server:CreateLog', GetCurrentResourceName(), GetCurrentResourceName(), 'green', message) - elseif logType == "ox_lib" then - return lib.logger(src, GetCurrentResourceName(), message) + embeds = { { + color = "15769093", + title = GetInvokingResource(), + thumbnail = { url = BridgeServerConfig.EmbedLogo }, + fields = { + { + name = 'Log Message', + value = "```" .. message .. "```", + inline = false, + } + }, + timestamp = os.date('!%Y-%m-%dT%H:%M:%S'), + } } + }), { ['Content-Type'] = 'application/json' }) end +} + +---@deprecated Use Logs.CreateLog instead (deprecated 9/1/25) +Logs.Send = function(src, message) + print("^1Deprecated^0 function 'Logs.Send' called. Please use 'Logs.CreateLog' instead.") + Logs.CreateLog(message) end -local embeds = {} +---@deprecated Use Logs.CreateLog instead (deprecated 9/1/25) Logs.Notify = function(src, url, image, message) - if not src or not message then return end - local logType = LogSystem or "built-in" - if logType == "built-in" then - embeds[url] = embeds[url] or {} - local embed = embeds[url].embed or {} - local firstName, lastName = Framework.GetPlayerName(src) - - table.insert(embed, { - color = "15769093", - title = GetInvokingResource(), - -- url = 'https://discord.gg/Gm6rYEXUsn', - 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 | ", - icon_url = 'https://avatars.githubusercontent.com/u/192999457?s=400&u=da632e8f64c85def390cfd1a73c3b664d6882b38&v=4', - }, - }) - embeds[url].embed = embed - if embeds[url].inProgress then return end - embeds[url].inProgress = true - SetTimeout(5000, function() - PerformHttpRequest(url, function(err, text, headers) end, 'POST', json.encode({ - username = string.format("%s %s", firstName, lastName), - avatar_url = image or 'https://avatars.githubusercontent.com/u/192999457?s=400&u=da632e8f64c85def390cfd1a73c3b664d6882b38&v=4', - embeds = embeds[url].embed - }), { ['Content-Type']= 'application/json' }) - embeds[url].inProgress = false - end) - elseif logType == "qb" then - return TriggerEvent('qb-log:server:CreateLog', GetCurrentResourceName(), GetCurrentResourceName(), 'green', message) - elseif logType == "ox_lib" then - return lib.logger(src, GetCurrentResourceName(), message) - end + print("^1Deprecated^0 function 'Logs.Notify' called. Please use 'Logs.CreateLog' instead.") + Logs.CreateLog(message) end +Logs.CreateLog = function(logData) + local handler = logHandlers[BridgeServerConfig.LogSystem] + if handler then handler(logData) end +end exports('Logs', Logs) -return Logs +return Logs \ No newline at end of file diff --git a/settings/serverConfig.lua b/settings/serverConfig.lua index 742dd26..ebde8e6 100644 --- a/settings/serverConfig.lua +++ b/settings/serverConfig.lua @@ -1,4 +1,7 @@ BridgeServerConfig = {} BridgeServerConfig.MaxInventorySlots = 50 - -return BridgeServerConfig +BridgeServerConfig.LogSystem = "built-in" -- can be "none", "built-in", "qb", "fivemerr" or "ox_lib" +BridgeServerConfig.WebhookURL = "" -- Add webhook URL here if using built-in logging system +BridgeServerConfig.FivemerrApiKey = "" -- Add Fivemerr API key here if using fiveMerr +BridgeServerConfig.EmbedLogo = "https://cdn.discordapp.com/avatars/299410129982455808/31ce635662206e8bd0132c34ce9ce683?size=1024" +return BridgeServerConfig \ No newline at end of file From e9fa5a2891274b9d176186595392077da0de6203 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Mon, 1 Sep 2025 02:31:14 -0400 Subject: [PATCH 36/62] Fix type annotation for job count function Updated the type annotation for the 'tbl' parameter in Framework.GetJobCountTotal from 'any' to 'table' for improved clarity and correctness. --- modules/framework/_default/client.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/framework/_default/client.lua b/modules/framework/_default/client.lua index 2bcb7c6..0f6cbb0 100644 --- a/modules/framework/_default/client.lua +++ b/modules/framework/_default/client.lua @@ -17,7 +17,7 @@ Framework.GetJobCount = function(jobName) end ---This will allow passing a table of job names and returning a sum of the total count. ----@param tbl any +---@param tbl table ---@return number Framework.GetJobCountTotal = function(tbl) local total = 0 From 63d2f675f6046e6ba95aa641624495f460601388 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Mon, 1 Sep 2025 03:33:29 -0400 Subject: [PATCH 37/62] Buffer and batch Discord log messages Introduces a queue and timer to batch log messages before sending them to Discord, reducing the number of HTTP requests. Refactors the built-in log handler to use the new queuing system and improves code consistency. Looks gross but works. --- lib/logs/server/logs.lua | 86 +++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 27 deletions(-) diff --git a/lib/logs/server/logs.lua b/lib/logs/server/logs.lua index 650778a..2d1a086 100644 --- a/lib/logs/server/logs.lua +++ b/lib/logs/server/logs.lua @@ -1,19 +1,67 @@ Logs = Logs or {} -local BridgeServerConfig = BridgeServerConfig or Require("settings/serverConfig.lua") +local BridgeServerConfig = BridgeServerConfig or Require('settings/serverConfig.lua') + + +local pendingLogs = {} +local sendTimer = nil + +local function sendBufferedLogsToDiscord() + if #pendingLogs == 0 then + sendTimer = nil + return + end + + local embeds = {} + for _, log in ipairs(pendingLogs) do + table.insert(embeds, { + color = '15769093', + title = log.resource, + thumbnail = { url = BridgeServerConfig.EmbedLogo }, + fields = { + { + name = 'Log Message', + value = '```' .. log.message .. '```', + inline = false, + } + }, + timestamp = log.timestamp, + }) + end + + PerformHttpRequest(BridgeServerConfig.WebhookURL, function(err, text, headers) end, 'POST', json.encode({ + username = 'Community_Bridge Logger', + avatar_url = 'https://avatars.githubusercontent.com/u/192999457?s=400&u=da632e8f64c85def390cfd1a73c3b664d6882b38&v=4', + embeds = embeds + }), { ['Content-Type'] = 'application/json' }) + + pendingLogs = {} + sendTimer = nil +end + +local function queueLogForDiscord(message) + table.insert(pendingLogs, { + message = tostring(message), + resource = GetInvokingResource() or GetCurrentResourceName(), + timestamp = os.date('!%Y-%m-%dT%H:%M:%S') + }) + + if not sendTimer then + sendTimer = true + SetTimeout(3000, sendBufferedLogsToDiscord) + end +end local logHandlers = { fivemerr = function(logData) local fivemerrData = { - level = "info", + level = 'info', message = tostring(logData), resource = GetInvokingResource() or GetCurrentResourceName(), } - PerformHttpRequest("https://api.fivemerr.com/v1/logs", function(code, text, headers) + PerformHttpRequest('https://api.fivemerr.com/v1/logs', function(code, text, headers) if code ~= 200 then - print(("Failed to send log to Fivemerr API (HTTP %d): Please verify your API key is correct and the service is available."):format(code)) - else - print("Log successfully sent to Fivemerr") + print(('Failed to send log to Fivemerr API (HTTP %d): Please verify your API key is correct and the service is available.'):format(code)) end end, 'POST', json.encode(fivemerrData), { ['Content-Type'] = 'application/json', @@ -29,36 +77,20 @@ local logHandlers = { lib.logger(GetInvokingResource(), GetCurrentResourceName(), message) end, - ["built-in"] = function(message) - PerformHttpRequest(BridgeServerConfig.WebhookURL, function(err, text, headers) end, 'POST', json.encode({ - username = "Community_Bridge's Logger", - avatar_url = 'https://avatars.githubusercontent.com/u/192999457?s=400&u=da632e8f64c85def390cfd1a73c3b664d6882b38&v=4', - embeds = { { - color = "15769093", - title = GetInvokingResource(), - thumbnail = { url = BridgeServerConfig.EmbedLogo }, - fields = { - { - name = 'Log Message', - value = "```" .. message .. "```", - inline = false, - } - }, - timestamp = os.date('!%Y-%m-%dT%H:%M:%S'), - } } - }), { ['Content-Type'] = 'application/json' }) + ['built-in'] = function(message) + queueLogForDiscord(message) end } ---@deprecated Use Logs.CreateLog instead (deprecated 9/1/25) Logs.Send = function(src, message) - print("^1Deprecated^0 function 'Logs.Send' called. Please use 'Logs.CreateLog' instead.") + print('^1Deprecated^0 function Logs.Send called. Please use Logs.CreateLog instead.') Logs.CreateLog(message) end ---@deprecated Use Logs.CreateLog instead (deprecated 9/1/25) Logs.Notify = function(src, url, image, message) - print("^1Deprecated^0 function 'Logs.Notify' called. Please use 'Logs.CreateLog' instead.") + print('^1Deprecated^0 function Logs.Notify called. Please use Logs.CreateLog instead.') Logs.CreateLog(message) end @@ -68,4 +100,4 @@ Logs.CreateLog = function(logData) end exports('Logs', Logs) -return Logs \ No newline at end of file +return Logs From 71cd1e067664ab7e6a2a72225040ec85b1f7d871 Mon Sep 17 00:00:00 2001 From: solaire-fivem Date: Mon, 1 Sep 2025 14:22:03 +0100 Subject: [PATCH 38/62] Fix issue with GetThirst and GetHunger not working in ESX --- modules/framework/es_extended/server.lua | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/modules/framework/es_extended/server.lua b/modules/framework/es_extended/server.lua index 6daf30f..8371e3f 100644 --- a/modules/framework/es_extended/server.lua +++ b/modules/framework/es_extended/server.lua @@ -248,22 +248,32 @@ Framework.AddHunger = function(src, value) return levelForEsx end ---- @description This will get the hunger of a player +--- @description This will get the hunger of a player (ESX we get the percent of the status) --- @param src number --- @return number | nil Framework.GetHunger = function(src) local status = Framework.GetStatus(src, "status") - if not status then return 0 end - return status.hunger + if not status then return nil end + + for _, entry in ipairs(status) do + if entry.name == "hunger" then + return entry.percent + end + end end ---- @description This will get the thirst of a player +--- @description This will get the thirst of a player (ESX we get the percent of the status) --- @param src any --- @return number | nil Framework.GetThirst = function(src) local status = Framework.GetStatus(src, "status") - if not status then return 0 end - return status.thirst + if not status then return nil end + + for _, entry in ipairs(status) do + if entry.name == "thirst" then + return entry.percent + end + end end --- @description This will get the phone number of a player From 9c61f7967d9029c78dc7f9379aa40f331fcf0311 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Mon, 1 Sep 2025 17:05:34 -0400 Subject: [PATCH 39/62] Update callback module import paths Changed all references from 'lib/utility/shared/callbacks.lua' to 'lib/callback/shared/callback.lua' in client and server files for framework, inventory, and phone modules to reflect new file structure or module location. Commit#f900bc5 did not adjust these, correcting. --- modules/framework/es_extended/client.lua | 2 +- modules/framework/es_extended/server.lua | 2 +- modules/inventory/core_inventory/client.lua | 2 +- modules/inventory/core_inventory/server.lua | 2 +- modules/phone/okokPhone/client.lua | 2 +- modules/phone/okokPhone/server.lua | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/framework/es_extended/client.lua b/modules/framework/es_extended/client.lua index 21b22a5..a37df82 100644 --- a/modules/framework/es_extended/client.lua +++ b/modules/framework/es_extended/client.lua @@ -2,7 +2,7 @@ if GetResourceState('es_extended') ~= 'started' then return end ESX = exports.es_extended:getSharedObject() -Callback = Callback or Require("lib/utility/shared/callbacks.lua") +Callback = Callback or Require("lib/callback/shared/callback.lua") Framework = Framework or {} diff --git a/modules/framework/es_extended/server.lua b/modules/framework/es_extended/server.lua index 6daf30f..dbcbcc0 100644 --- a/modules/framework/es_extended/server.lua +++ b/modules/framework/es_extended/server.lua @@ -2,7 +2,7 @@ if GetResourceState('es_extended') ~= 'started' then return end Prints = Prints or Require("lib/utility/shared/prints.lua") -Callback = Callback or Require("lib/utility/shared/callbacks.lua") +Callback = Callback or Require("lib/callback/shared/callback.lua") ESX = exports.es_extended:getSharedObject() diff --git a/modules/inventory/core_inventory/client.lua b/modules/inventory/core_inventory/client.lua index 214f728..da9124d 100644 --- a/modules/inventory/core_inventory/client.lua +++ b/modules/inventory/core_inventory/client.lua @@ -1,7 +1,7 @@ ---@diagnostic disable: duplicate-set-field if GetResourceState('core_inventory') ~= 'started' then return end local core = exports.core_inventory -Callback = Callback or Require("lib/utility/shared/callbacks.lua") +Callback = Callback or Require("lib/callback/shared/callback.lua") Inventory = Inventory or {} diff --git a/modules/inventory/core_inventory/server.lua b/modules/inventory/core_inventory/server.lua index b3d7032..e2a4771 100644 --- a/modules/inventory/core_inventory/server.lua +++ b/modules/inventory/core_inventory/server.lua @@ -3,7 +3,7 @@ if GetResourceState('core_inventory') ~= 'started' then return end Inventory = Inventory or {} Inventory.Stashes = Inventory.Stashes or {} -Callback = Callback or Require("lib/utility/shared/callbacks.lua") +Callback = Callback or Require("lib/callback/shared/callback.lua") local core = exports.core_inventory ---This will add an item, and return true or false based on success diff --git a/modules/phone/okokPhone/client.lua b/modules/phone/okokPhone/client.lua index 90b8c0a..e4231ea 100644 --- a/modules/phone/okokPhone/client.lua +++ b/modules/phone/okokPhone/client.lua @@ -2,7 +2,7 @@ local resourceName = "okokPhone" if GetResourceState(resourceName) == 'missing' then return end Phone = Phone or {} -Callback = Callback or Require("lib/utility/shared/callbacks.lua") +Callback = Callback or Require("lib/callback/shared/callback.lua") ---This will get the name of the Phone system being being used. ---@return string diff --git a/modules/phone/okokPhone/server.lua b/modules/phone/okokPhone/server.lua index 03b4e07..ce59722 100644 --- a/modules/phone/okokPhone/server.lua +++ b/modules/phone/okokPhone/server.lua @@ -17,7 +17,7 @@ local resourceName = "okokPhone" if GetResourceState(resourceName) == 'missing' then return end Phone = Phone or {} -Callback = Callback or Require("lib/utility/shared/callbacks.lua") +Callback = Callback or Require("lib/callback/shared/callback.lua") ---This will get the name of the Phone system being being used. ---@return string From 8346130b004a1e275b088c6452f5f53ac5acddd8 Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Wed, 3 Sep 2025 00:28:17 -0500 Subject: [PATCH 40/62] Add modular entity behaviors and update entity logic Introduces modular behaviors for entities, including anim, attach, clothing, follow, particles, scenarios, shop, stash, targets, and weapon, each in their own files. Updates client_entity.lua and behaviors.lua to support dynamic behavior registration, initialization, and triggering. Refactors entity update logic to improve movement handling and behavior invocation. --- lib/entities/client/client_entity.lua | 24 +++--- lib/entities/shared/behaviors.lua | 35 ++++++++- lib/entities/shared/behaviors/anim.lua | 62 ++++++++++++++++ lib/entities/shared/behaviors/attach.lua | 50 +++++++++++++ lib/entities/shared/behaviors/clothing.lua | 82 +++++++++++++++++++++ lib/entities/shared/behaviors/follow.lua | 75 +++++++++++++++++++ lib/entities/shared/behaviors/particles.lua | 80 ++++++++++++++++++++ lib/entities/shared/behaviors/scenarios.lua | 64 ++++++++++++++++ lib/entities/shared/behaviors/shop.lua | 58 +++++++++++++++ lib/entities/shared/behaviors/stash.lua | 59 +++++++++++++++ lib/entities/shared/behaviors/targets.lua | 61 +++++++++++++++ lib/entities/shared/behaviors/weapon.lua | 54 ++++++++++++++ 12 files changed, 693 insertions(+), 11 deletions(-) create mode 100644 lib/entities/shared/behaviors/anim.lua create mode 100644 lib/entities/shared/behaviors/attach.lua create mode 100644 lib/entities/shared/behaviors/clothing.lua create mode 100644 lib/entities/shared/behaviors/follow.lua create mode 100644 lib/entities/shared/behaviors/particles.lua create mode 100644 lib/entities/shared/behaviors/scenarios.lua create mode 100644 lib/entities/shared/behaviors/shop.lua create mode 100644 lib/entities/shared/behaviors/stash.lua create mode 100644 lib/entities/shared/behaviors/targets.lua create mode 100644 lib/entities/shared/behaviors/weapon.lua diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index 3544dbb..cc32930 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -71,10 +71,21 @@ end local function UpdateEntity(_entityData) local entityData = ClientEntity.Get(_entityData.id) if not entityData then return end + if entityData.OnUpdate then + pcall(function (...) + return entityData.OnUpdate(entityData) + end) + end + Behaviors.Trigger("OnUpdate", entityData) if entityData.oldCoords and entityData.oldCoords ~= entityData.coords then local coords = vector3(entityData.coords.x, entityData.coords.y, entityData.coords.z) + entityData.oldCoords = vector3(entityData.oldCoords.x, entityData.oldCoords.y, entityData.oldCoords.z) local dist = #(coords.xyz - entityData.oldCoords.xyz) - if dist > 0.1 then + if dist > 0.05 then + if entityData.spawned then + print("Moving entity:", entityData.id) + SetEntityCoords(entityData.spawned, coords.x, coords.y, coords.z, false, false, false, true) + end -- ClientEntity.UpdateCoords(entityData.id, entityData.coords) if entityData.OnMove then pcall(function (...) @@ -96,12 +107,7 @@ local function UpdateEntity(_entityData) end entityData.oldRotation = entityData.rotation end - if entityData.OnUpdate then - pcall(function (...) - return entityData.OnUpdate(entityData) - end) - end - Behaviors.Trigger("OnUpdate", entityData) + end --- Registers an entity received from the server and sets up proximity spawning. @@ -258,9 +264,7 @@ function ClientEntity.UpdateCoords(id, coords) return end entityData.coords = coords - Point.UpdateCoords(id, coords) - if not entityData.spawned or not DoesEntityExist(entityData.spawned) then return end - SetEntityCoords(entityData.spawned, coords.x, coords.y, coords.z, false, false, false, true) + Point.UpdateCoords(id, coords) end function ClientEntity.ChangeModel(id, model) diff --git a/lib/entities/shared/behaviors.lua b/lib/entities/shared/behaviors.lua index 65f56a0..e30b3d2 100644 --- a/lib/entities/shared/behaviors.lua +++ b/lib/entities/shared/behaviors.lua @@ -4,6 +4,27 @@ Behaviors = { invoked = {} } +Behaviors.init = { + "anim", + "attach", + 'clothing', + 'follow', + 'particles', + 'scenarios', + 'shop', + 'stash', + 'targets', + 'weapon' +} + +function Behaviors.Init() + if Behaviors.isSetup then return end + Behaviors.isSetup = true + for k, v in pairs(Behaviors.init) do + Require(string.format("lib/entities/shared/behaviors/%s.lua", v)) + end +end + function Behaviors.Create(behaviorId, behavior) if not behaviorId or not behavior then return end Behaviors.All = Behaviors.All or {} @@ -26,7 +47,6 @@ end function Behaviors.Trigger(actionName, clientEntityData, ...) if not clientEntityData or not actionName then return end - local invoking = clientEntityData.invoked or GetInvokingResource() or "community_bridge" for property, behavior in pairs(Behaviors.All[invoking] or {}) do local hasBehaviorArgs = Behaviors.Has(property, clientEntityData) -- this is everything that's contained inside the object's individual property @@ -37,6 +57,15 @@ function Behaviors.Trigger(actionName, clientEntityData, ...) end end end + for property, behavior in pairs(Behaviors.All['community_bridge'] or {}) do + local hasBehaviorArgs = Behaviors.Has(property, clientEntityData) -- this is everything that's contained inside the object's individual property + if hasBehaviorArgs and behavior[actionName] and not Behaviors.All[invoking]?[actionName] then + local success, result = pcall(behavior[actionName], clientEntityData, hasBehaviorArgs, ...) + if not success then + print(string.format("[ClientEntity] Behavior %s failed: %s", property, result)) + end + end + end end function Behaviors.Inherit(behaviorId, clientEntityData, defaultData) @@ -75,4 +104,8 @@ AddEventHandler("onResourceStop", function(resourceName) end end) +AddEventHandler("onResourceStart", function(resourceName) + Behaviors.Init() +end) + return Behaviors diff --git a/lib/entities/shared/behaviors/anim.lua b/lib/entities/shared/behaviors/anim.lua new file mode 100644 index 0000000..ef8574e --- /dev/null +++ b/lib/entities/shared/behaviors/anim.lua @@ -0,0 +1,62 @@ +if IsDuplicityVersion() then return end +local Animation = { + property = "anim", + default = { + flags = 49, + duration = -1 + } +} +-- Anim.Play(id, entity, animDict, animName, blendIn, blendOut, duration, flag, playbackRate, onComplete) +function Animation.Play(entityData) + if entityData.entityType ~= "ped" then return end + local entity = entityData.spawned + if not entity then return end + local dict = entityData.anim?.dict + local name = entityData.anim?.name + local onComplete = entityData.anim?.onComplete and function() entityData.anim.onComplete(entityData) end + if not dict or not name then return end + local flags = entityData.anim.flags or Animation.default.flags + local duration = entityData.anim.duration or Animation.default.duration + entityData.anim.id = Bridge.Anim.Play(nil, entity, dict, name, 8.0, -8.0, duration, flags, 0.0, onComplete) + Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) + entityData.oldAnim = entityData.anim + Bridge.ClientEntity.Set(entityData.id, "oldAnim", entityData.oldAnim) + -- SetTimeout(1000, function() + -- if entityData.anim then + -- entityData.anim.disable = false + -- Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) + -- end + -- end) +end + +function Animation.OnSpawn(entityData) + print("Spawning animation for entity:", entityData.id) + if not entityData.spawned or not entityData.anim then return end + Animation.Play(entityData) + entityData.anim.disable = false + TaskSetBlockingOfNonTemporaryEvents(entityData.spawned, true) + SetBlockingOfNonTemporaryEvents(entityData.spawned, true) + Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) +end + +function Animation.OnRemove(entityData) + if not entityData.spawned or not entityData.anim then return end + entityData.oldAnim = nil + entityData.anim.disable = true + Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) + Bridge.ClientEntity.Set(entityData.id, "oldAnim", entityData.oldAnim) +end + +function Animation.OnUpdate(entityData) + if not entityData.spawned or not entityData.anim then return end + if entityData.anim.disable then return end + if not IsEntityPlayingAnim(entityData.spawned, entityData.anim.dict, entityData.anim.name, 3) then + Bridge.Anim.Stop(entityData.anim?.id) + ClearPedTasksImmediately(entityData.spawned) + Wait(100) + Animation.Play(entityData) + end +end + +Bridge.ClientEntity.RegisterBehavior("anim", Animation) +return Animation \ No newline at end of file diff --git a/lib/entities/shared/behaviors/attach.lua b/lib/entities/shared/behaviors/attach.lua new file mode 100644 index 0000000..291de33 --- /dev/null +++ b/lib/entities/shared/behaviors/attach.lua @@ -0,0 +1,50 @@ +if IsDuplicityVersion() then return end +local Attach = { + property = "attach", + default = { + bone = 0, + offset = vector3(0.0, 0.0, 0.0), + rotation = vector3(0.0, 0.0, 0.0) + } +} + + +function Attach.OnSpawn(entityData) + if not entityData.spawned or not entityData.attach then return end + local entity = entityData.spawned + local targetEntity = entityData.attach.target + if type(targetEntity) == "string" then + targetEntity = Bridge.ClientEntity.Get(targetEntity)?.spawned or targetEntity + else + local player = GetPlayerFromServerId(targetEntity) + if player and player ~= -1 then + targetEntity = GetPlayerPed(player) + end + end + targetEntity = tonumber(targetEntity) + if not targetEntity then return end + local bone = entityData.attach.bone or Attach.default.bone + local offset = entityData.attach.offset or Attach.default.offset + local rotation = entityData.attach.rotation or Attach.default.rotation + AttachEntityToEntity(entity, targetEntity, GetPedBoneIndex(targetEntity, bone), offset.x, offset.y, offset.z, rotation.x, rotation.y, rotation.z, true, true, false, true, 1, true) + Bridge.ClientEntity.Set(entityData.id, "attach", entityData.attach) +end + +function Attach.Detach(entityData) + if not entityData.spawned or not IsEntityAttached(entityData.spawned) then return end + DetachEntity(entityData.spawned, true, true) + Bridge.ClientEntity.Set(entityData.id, "attach", entityData.attach) +end + +function Attach.OnUpdate(entityData) + if not entityData.spawned then return end + if entityData.attach.disable then + return Attach.Detach(entityData) + end + local entity = entityData.spawned + if IsEntityAttached(entity) then return end + Attach.OnSpawn(entityData) +end + +Bridge.ClientEntity.RegisterBehavior("attach", Attach) +return Attach \ No newline at end of file diff --git a/lib/entities/shared/behaviors/clothing.lua b/lib/entities/shared/behaviors/clothing.lua new file mode 100644 index 0000000..1b3f605 --- /dev/null +++ b/lib/entities/shared/behaviors/clothing.lua @@ -0,0 +1,82 @@ +if IsDuplicityVersion() then return end +local Clothing = { + property = "clothing", + default = { + components = {}, + props = {} + } +} + +function Clothing.ChangeClothes(entityData) + if entityData.entityType ~= "ped" then return end + local entity = entityData.spawned + if not entity or not DoesEntityExist(entity) then return end + local clothing = entityData.clothing.target + if clothing then + if type(clothing) == "number" then + local player = GetPlayerFromServerId(clothing) + if player and player ~= -1 then + clothing = Bridge.Clothing.GetAppearance(GetPlayerPed(player)) + end + elseif type(clothing) == "string" then + local targetEntityData = Bridge.ClientEntity.Get(clothing) + if targetEntityData then + clothing = Bridge.Clothing.GetAppearance(targetEntityData.spawned) + end + end + else + clothing = entityData.clothing + end + + Bridge.Clothing.SetAppearance(entity, clothing) + Bridge.ClientEntity.Set(entityData.id, "clothing", clothing) + entityData.oldClothing = clothing + Bridge.ClientEntity.Set(entityData.id, "oldClothing", clothing) + +end + + +function Clothing.OnSpawn(entityData) + if not entityData.spawned or not entityData.clothing then return end + Clothing.ChangeClothes(entityData) + entityData.clothing.updating = false +end + +function Clothing.OnRemove(entityData) + if not entityData.spawned or not entityData.clothing then return end + entityData.oldClothing = nil + entityData.clothing.updating = true +end + +function Clothing.OnUpdate(entityData) + if not entityData.spawned or not entityData.clothing then return end + if entityData.clothing.updating then return end + entityData.clothing.updating = true + if not entityData.oldClothing then + Clothing.ChangeClothes(entityData) + return + end + for componentId, component in pairs(entityData.clothing.components or {}) do + local oldComponent = entityData.oldClothing.components and entityData.oldClothing.components[componentId] + if not oldComponent or oldComponent.drawable ~= component.drawable or oldComponent.texture ~= component.texture then + Clothing.ChangeClothes(entityData) + return + end + end + for propId, prop in pairs(entityData.clothing.props or {}) do + local oldProp = entityData.oldClothing.props and entityData.oldClothing.props[propId] + if not oldProp or oldProp.drawable ~= prop.drawable or oldProp.texture ~= prop.texture then + Clothing.ChangeClothes(entityData) + return + end + end + SetTimeout(1000, function() + if entityData.clothing then + entityData.clothing.updating = false + Bridge.ClientEntity.Set(entityData.id, "clothing", entityData.clothing) + end + end) +end + +Bridge.ClientEntity.RegisterBehavior("clothing", Clothing) +return Clothing \ No newline at end of file diff --git a/lib/entities/shared/behaviors/follow.lua b/lib/entities/shared/behaviors/follow.lua new file mode 100644 index 0000000..b5361a9 --- /dev/null +++ b/lib/entities/shared/behaviors/follow.lua @@ -0,0 +1,75 @@ +if IsDuplicityVersion() then return end +local Follow = { + All = {}, + property = "follow", + default = { + speed = 1.0, + distance = 2.0 + } +} + +function Follow.PedWalkToPos(entityData) + if not entityData?.follow?.target or entityData?.entityType ~= "ped" then return end + local entity = entityData.spawned + local targetCoords = entityData.follow.target + if not targetCoords then return end + if type(targetCoords) == "number" then + local player = GetPlayerFromServerId(targetCoords) + if player and player ~= -1 then + targetCoords = GetEntityCoords(GetPlayerPed(player)) + else + targetCoords = GetEntityCoords(targetCoords) + end + elseif type(targetCoords) == "string" then + local targetEntityData = Bridge.ClientEntity.Get(targetCoords) + if targetEntityData then + targetCoords = GetEntityCoords(targetEntityData.spawned) + end + end + local entityPos = GetEntityCoords(entity) + local distance = #(targetCoords - entityPos) + if distance > (entityData.follow.distance or Follow.default.distance) then + if entityData.anim then + entityData.anim.disable = true + Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) + end + if entityData.scenarios then + entityData.scenarios.disable = true + Bridge.ClientEntity.Set(entityData.id, "scenarios", entityData.scenarios) + end + local speed = entityData.follow.speed or Follow.default.speed + local heading = GetHeadingFromVector_2d(targetCoords.x - entityPos.x, targetCoords.y - entityPos.y) + TaskGoStraightToCoord(entity, targetCoords.x, targetCoords.y, targetCoords.z, speed, -1, heading, 0.0) + entityData.coords = GetEntityCoords(entity) + entityData.follow.walking = true + Bridge.ClientEntity.Set(entityData.id, "coords", entityData.coords) + Bridge.ClientEntity.Set(entityData.id, "follow", entityData.follow) + if entityData.follow.OnExit then entityData.follow.OnExit(entityData) end + return false + end + if not entityData.follow.walking then return end + entityData.follow.walking = false + Bridge.ClientEntity.Set(entityData.id, "follow", entityData.follow) + if entityData.anim then + entityData.anim.disable = false + Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) + end + if entityData.scenarios then + entityData.scenarios.disable = false + Bridge.ClientEntity.Set(entityData.id, "scenarios", entityData.scenarios) + end + ClearPedTasks(entity) + if entityData.follow.OnEnter then entityData.follow.OnEnter(entityData) end + return true +end + + +function Follow.OnUpdate(entityData) + assert(entityData?.id, "Entity ID is required") + local entity = entityData.spawned + if not entity or not DoesEntityExist(entity) then return end + return Follow.PedWalkToPos(entityData) +end + +Bridge.ClientEntity.RegisterBehavior("follow", Follow) +return Follow \ No newline at end of file diff --git a/lib/entities/shared/behaviors/particles.lua b/lib/entities/shared/behaviors/particles.lua new file mode 100644 index 0000000..fecc6b7 --- /dev/null +++ b/lib/entities/shared/behaviors/particles.lua @@ -0,0 +1,80 @@ +if IsDuplicityVersion() then return end +Utility = Utility or Bridge.Utility +local ParticlesBehaviors = { + property = "particles", + default = { + dict = "cut_exile3", + ptfx = "cs_ex3_wheel_spin", + offset = vector3(0, 0, 0), + rotation = vector3(0, 0, 0), + size = 1.0, + color = vector3(255, 255, 255), + loopLength = 5000, + } + +} + +function ParticlesBehaviors.Start(entityData) + for _, particleData in ipairs(entityData.particles) do + local position = vector3(entityData.coords.x, entityData.coords.y, entityData.coords.z) + local rotation = vector3(entityData.rotation.x, entityData.rotation.y, entityData.rotation.z) + position = position + (particleData.offset?.xyz or vector3(0, 0, 0)) + rotation = rotation + (particleData.rotation?.xyz or vector3(0, 0, 0)) + particleData.playing = Bridge.Particle.Play( + particleData.dict or ParticlesBehaviors.default.dict, + particleData.ptfx or ParticlesBehaviors.default.ptfx, + position, + rotation, + particleData.size or ParticlesBehaviors.default.size, + particleData.color or ParticlesBehaviors.default.color, + particleData.looped, + particleData.loopLength or ParticlesBehaviors.default.loopLength + ) + end +end + +function ParticlesBehaviors.OnSpawn(entityData) + if not entityData.particles then return end + if entityData.particles.dict then -- single particle + entityData.particles = {entityData.particles} + end + ParticlesBehaviors.Start(entityData) +end + + +function ParticlesBehaviors.OnRemove(entityData) + if not entityData.particles then return end + for _, particleData in ipairs(entityData.particles) do + if particleData.playing then + Bridge.Particle.Stop(particleData.playing) + particleData.playing = nil + end + end +end + +function ParticlesBehaviors.OnMove(entityData) + if not entityData.particles then return end + for _, particleData in ipairs(entityData.particles) do + if particleData.playing then + Particle.Stop(particleData.playing) + particleData.playing = nil + local position = vector3(entityData.coords.x, entityData.coords.y, entityData.coords.z) + local rotation = vector3(entityData.rotation.x, entityData.rotation.y, entityData.rotation.z) + position = position + (particleData.offset?.xyz or vector3(0, 0, 0)) + rotation = rotation + (particleData.rotation?.xyz or vector3(0, 0, 0)) + particleData.playing = Bridge.Particle.Play( + particleData.dict or ParticlesBehaviors.default.dict, + particleData.ptfx or ParticlesBehaviors.default.ptfx, + position, + rotation, + particleData.size or ParticlesBehaviors.default.size, + particleData.color or ParticlesBehaviors.default.color, + particleData.looped, + particleData.loopLength or ParticlesBehaviors.default.loopLength + ) + end + end +end + +Bridge.ClientEntity.RegisterBehavior("particles", ParticlesBehaviors) +return ParticlesBehaviors \ No newline at end of file diff --git a/lib/entities/shared/behaviors/scenarios.lua b/lib/entities/shared/behaviors/scenarios.lua new file mode 100644 index 0000000..20efb69 --- /dev/null +++ b/lib/entities/shared/behaviors/scenarios.lua @@ -0,0 +1,64 @@ + +if IsDuplicityVersion() then return end +local Scenarios = { + property = "scenarios", + default = { + introClip = true, + duration = -1 + } +} +-- scenarios.Play(id, entity, scenariosDict, scenariosName, blendIn, blendOut, duration, flag, playbackRate, onComplete) +function Scenarios.Play(entityData) + if entityData.entityType ~= "ped" then return end + local entity = entityData.spawned + if not entity then return end + local name = entityData.scenarios?.name + if not name then return end + local duration = entityData.scenarios?.duration or Scenarios.default.duration + local introClip = entityData.scenarios?.introClip or Scenarios.default.introClip + TaskStartScenarioInPlace(entity, name, duration, introClip) + if duration < 0 then return end + SetTimeout(duration, function() + if not entityData.scenarios then return end + ClearPedTasks(entity) + if not entityData.scenarios.onComplete then return end + entityData.scenarios.disabled = true + Bridge.ClientEntity.Set(entityData.id, "scenarios", entityData.scenarios) + entityData.scenarios.onComplete(entityData) + end) + +end + +function Scenarios.OnSpawn(entityData) + if not entityData.spawned or not entityData.scenarios then return end + Scenarios.Play(entityData) +end + +function Scenarios.OnRemove(entityData) + if not entityData.spawned or not entityData.scenarios then return end + ClearPedTasks(entityData.spawned) +end + +function Scenarios.OnUpdate(entityData) + if not entityData.spawned or not entityData.scenarios then return end + if entityData.scenarios.disable then return end + if IsPedUsingScenario(entityData.spawned, entityData.scenarios.name) then return end + local entities = GetGamePool('CObject') + for _, obj in ipairs(entities or {}) do + obj = tonumber(obj) + local entityCoords = GetEntityCoords(obj) + local coords = vector3(entityData.coords.x, entityData.coords.y, entityData.coords.z) + if entityCoords then + local distance = #(entityCoords - coords) + if distance < 2.0 then + SetEntityAsMissionEntity(obj, false, false) + DeleteObject(obj) + break + end + end + end + Scenarios.Play(entityData) +end + +Bridge.ClientEntity.RegisterBehavior("scenarios", Scenarios) +return Scenarios \ No newline at end of file diff --git a/lib/entities/shared/behaviors/shop.lua b/lib/entities/shared/behaviors/shop.lua new file mode 100644 index 0000000..048e786 --- /dev/null +++ b/lib/entities/shared/behaviors/shop.lua @@ -0,0 +1,58 @@ +local Shop = { + property = "shop", + default = { + label = "Default Shop Label", + items = { + {item = "water", price = 10} + }, + target = { + label = "Open Shop", + icon = "fa-solid fa-box" + } + } +} + +function Shop.OnCreate(entityData) + local shop = entityData.shop + if not shop then return end + if IsDuplicityVersion() then + local label = shop.label or Shop.default.label + local items = shop.items or Shop.default.items + local coords = entityData.coords + local groups = shop.groups + Bridge.Inventory.RegisterShop(label, items, nil, groups) + return + end + entityData.targets = entityData.targets or {} + print(json.encode(entityData.targets)) + table.insert(entityData.targets, + { + label = shop.target.label or "Shop", + icon = shop.target.icon or "fa-solid fa-box", + onSelect = function() + TriggerServerEvent("community_bridge:server:OpenShop", entityData.id) + end + } + ) +end + +if not IsDuplicityVersion() then return Bridge.ClientEntity.RegisterBehavior("shop", Shop) end + +RegisterNetEvent("community_bridge:server:OpenShop", function(id) + local src = source + if not src then return end + local entityData = Bridge.ServerEntity.Get(id) + if not entityData or not entityData.shop then + return print(string.format("[Shop] OpenShop: Entity %s does not exist or has no shop", id)) + end + local coords = entityData.coords + if not coords then return end + local distance = #(GetEntityCoords(GetPlayerPed(src)) - coords) + if distance > 3.0 then + return print(string.format("[Shop] OpenShop: Player %s is too far from entity %s", src, id)) + end + Bridge.Inventory.OpenShop(src, id) +end) + + +return Shop \ No newline at end of file diff --git a/lib/entities/shared/behaviors/stash.lua b/lib/entities/shared/behaviors/stash.lua new file mode 100644 index 0000000..c006a11 --- /dev/null +++ b/lib/entities/shared/behaviors/stash.lua @@ -0,0 +1,59 @@ +local Stash = { + property = "stash", + default = { + label = "default_stash_label", + slots = 20, + maxWeight = 100000, + target = { + label = "Open Stash", + icon = "fa-solid fa-box", + } + } +} + +function Stash.OnCreate(entityData) + if not entityData.stash then return end + if IsDuplicityVersion() then + local label = entityData.stash.label or Stash.default.label + local slots = entityData.stash.slots or Stash.default.slots + local weight = entityData.stash.maxWeight or Stash.default.maxWeight + local owner = entityData.stash.owner + local groups = entityData.stash.groups + Bridge.Inventory.RegisterStash(entityData.id, label, slots, weight, owner, groups) + else + entityData.targets = entityData.targets or {} + entityData.targets['stash'] = { + label = entityData.stash.target.label or Stash.default.target.label, + icon = entityData.stash.target.icon or Stash.default.target.icon, + canInteract = function(_) + local entData = Bridge.ClientEntity.Get(entityData.id) + return not entData.stash.disable + end, + onSelect = function() + TriggerServerEvent("community_bridge:server:OpenStash", entityData.id) + end + } + + Bridge.ClientEntity.Set(entityData.id, 'targets', entityData.targets) + end +end + +if not IsDuplicityVersion() then return Bridge.ClientEntity.RegisterBehavior("stash", Stash) end + +RegisterNetEvent("community_bridge:server:OpenStash", function(id) + local src = source + if not src then return end + local entityData = Bridge.ServerEntity.Get(id) + if not entityData or not entityData.stash then + return print(string.format("[Stash] OpenStash: Entity %s does not exist or has no stash", id)) + end + local coords = vector3(entityData.coords.x, entityData.coords.y, entityData.coords.z) + if not coords then return end + local distance = #(GetEntityCoords(GetPlayerPed(src)) - coords) + if distance > 3.0 then + return print(string.format("[Stash] OpenStash: Player %s is too far from entity %s", src, id)) + end + Bridge.Inventory.OpenStash(src, "stash", id) +end) + +Bridge.ServerEntity.RegisterBehavior("stash", Stash) \ No newline at end of file diff --git a/lib/entities/shared/behaviors/targets.lua b/lib/entities/shared/behaviors/targets.lua new file mode 100644 index 0000000..cb15ac3 --- /dev/null +++ b/lib/entities/shared/behaviors/targets.lua @@ -0,0 +1,61 @@ +if IsDuplicityVersion() then return end +local Targets = { + property = "targets", + default = { + label = "Default Target Label", + distance = 2, + } +} + +function Targets.OnSpawn(entityData) + if not entityData.spawned or not entityData.targets then return end + if entityData.targets?.label then + local temp = entityData.targets + entityData.targets = {temp} + end + local numberedTargets = {} + for k, v in pairs(entityData.targets) do + local onSelect = v.onSelect + if onSelect then + v.onSelect = function(entity) + onSelect(entityData, entity) + end + end + table.insert(numberedTargets, v) + end + table.sort(numberedTargets, function(a, b) return (a.label < b.label) end) + Bridge.Target.AddLocalEntity(entityData.spawned, numberedTargets) + entityData.oldTargets = entityData.targets + Bridge.ClientEntity.Set(entityData.id, "oldTargets", entityData.oldTargets) +end + +function Targets.OnRemove(entityData) + if not entityData.spawned or not entityData.oldTargets then return end + Bridge.Target.RemoveLocalEntity(entityData.spawned) +end + +function Targets.OnUpdate(entityData) + if not entityData.spawned or not entityData.oldTargets then return end + local doesntMatch = false + for k, v in pairs(entityData.targets) do + if not entityData.oldTargets or not entityData.oldTargets[k] then + doesntMatch = true + break + end + local old = entityData.oldTargets[k] + if old.label ~= v.label + or old.distance ~= v.distance + or old.description ~= v.description + then + doesntMatch = true + break + end + end + if doesntMatch then + Targets.OnRemove(entityData) + Wait(100) + Targets.OnSpawn(entityData) + end +end +Bridge.ClientEntity.RegisterBehavior("targets", Targets) +return Targets \ No newline at end of file diff --git a/lib/entities/shared/behaviors/weapon.lua b/lib/entities/shared/behaviors/weapon.lua new file mode 100644 index 0000000..d055ccd --- /dev/null +++ b/lib/entities/shared/behaviors/weapon.lua @@ -0,0 +1,54 @@ +if IsDuplicityVersion() then return end +local Weapon = { + property = "weapon", + default = { + name = "WEAPON_UNARMED", + ammo = 0 + } +} + +function Weapon.GiveWeapon(entityData) + if entityData.entityType ~= "ped" then return end + local entity = entityData.spawned + + if not entity or not DoesEntityExist(entity) then return end + if entityData.weapon?.name then + local ammo = entityData.weapon.ammo or 0 + local hash = GetHashKey(entityData.weapon.name) + GiveWeaponToPed(entity, hash, ammo, false, true) + TaskSwapWeapon(entity, true) + end + entityData.oldWeapon = entityData.weapon + Bridge.ClientEntity.Set(entityData.id, "oldWeapon", entityData.oldWeapon) +end + +function Weapon.OnSpawn(entityData) + if not entityData.spawned or not entityData.weapon then return end + Weapon.GiveWeapon(entityData) + entityData.weapon.updating = false +end + +function Weapon.OnRemove(entityData) + if not entityData.spawned or not entityData.weapon then return end + entityData.oldWeapon = nil + entityData.weapon.updating = true +end + +function Weapon.OnUpdate(entityData) + if not entityData.spawned or not entityData.weapon then return end + if entityData.weapon.updating then return end + entityData.weapon.updating = true + if not entityData.oldWeapon or entityData.oldWeapon.name ~= entityData.weapon.name then + Weapon.GiveWeapon(entityData) + end + SetTimeout(1000, function() + if entityData.weapon then + entityData.weapon.updating = false + Bridge.ClientEntity.Set(entityData.id, "weapon", entityData.weapon) + end + end) + Bridge.ClientEntity.Set(entityData.id, "weapon", entityData.weapon) +end + +Bridge.ClientEntity.RegisterBehavior("weapon", Weapon) +return Weapon \ No newline at end of file From dd08f058c35457eb9b10aaacf7018df2749193a4 Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Wed, 3 Sep 2025 01:04:04 -0500 Subject: [PATCH 41/62] Refactor client entity management functions Added freeze position handling in UpdateEntity and ensured OnDestroy behavior is triggered on entity destruction. Removed unused and commented-out Update function, and improved code clarity in Set and Destroy methods. --- lib/entities/client/client_entity.lua | 70 +++++---------------------- 1 file changed, 11 insertions(+), 59 deletions(-) diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index cc32930..a4faabc 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -107,7 +107,10 @@ local function UpdateEntity(_entityData) end entityData.oldRotation = entityData.rotation end - + + if entityData.freeze ~= nil and entityData.spawned and IsEntityPositionFrozen(entityData.spawned) then + FreezeEntityPosition(entityData.spawned, entityData.freeze) + end end --- Registers an entity received from the server and sets up proximity spawning. @@ -150,9 +153,9 @@ ClientEntity.RegisterBulk = ClientEntity.CreateBulk function ClientEntity.Destroy(id) local entityData = Entities[id] if not entityData then return end - + Behaviors.Trigger("OnDestroy", entityData) Point.Remove(id) - RemoveEntity(entityData) + RemoveEntity(entityData) Entities[id] = nil end ClientEntity.Unregister = ClientEntity.Destroy @@ -161,68 +164,17 @@ function ClientEntity.RegisterBehavior(id, behavior) Behaviors.Create(id, behavior) end +--- Sets a key-value pair for a client entity. +---@param id any +---@param key any +---@param value any +---@return nil function ClientEntity.Set(id, key, value) local entityData = ClientEntity.Get(id) if not entityData then return print(string.format("[ClientEntity] SetKey: Entity %s does not exist", id)) end entityData[key] = value - -- TriggerServerEvent("community_bridge:server:UpdateEntity", id, {[key] = value}) end ---- Updates the data for a registered entity. --- @param id string|number The ID of the entity to update. --- @param data table The data fields to update. --- function ClientEntity.Update(id, data) --- local entityData = ClientEntity.Get(id) --- if not entityData then return end - --- local needsPointUpdate = false --- for key, value in pairs(data) do --- if key == 'coords' and #(entityData.coords - value) > 0.1 then --- needsPointUpdate = true --- end --- if key == 'spawnDistance' and entityData.spawnDistance ~= value then --- needsPointUpdate = true --- end --- entityData[key] = value --- end - --- -- If entity is currently spawned, apply updates --- if entityData.spawned and DoesEntityExist(entityData.spawned) then --- if data.coords then --- SetEntityCoords(entityData.spawned, entityData.coords.x, entityData.coords.y, entityData.coords.z, false, false, false, true) --- end --- if data.rotation then --- if entityData.entityType == 'object' then --- SetEntityRotation(entityData.spawned, entityData.rotation.x, entityData.rotation.y, entityData.rotation.z, 2, true) --- else -- Ped/Vehicle heading --- SetEntityHeading(entityData.spawned, type(entityData.rotation) == 'number' and entityData.rotation or entityData.rotation.z) --- end --- end --- if data.freeze ~= nil then --- FreezeEntityPosition(entityData.spawned, data.freeze) --- end --- -- Add other updatable properties as needed --- end - --- -- Update Point registration if coords or distance changed --- if needsPointUpdate then --- Point.Remove(id) --- Point.Register( --- entityData.id, --- entityData.coords, --- entityData.spawnDistance or 50.0, --- entityData, --- SpawnEntity, --- RemoveEntity, --- OnUpdateEntity --- ) --- end - --- if entityData.OnUpdate and type(entityData.OnUpdate) == 'function' then --- entityData.OnUpdate(entityData, data) --- end --- end - function ClientEntity.Get(id) return Entities[id] end From cb9dbdf61057e09189e7339308d2c0728644c42d Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Wed, 3 Sep 2025 01:23:01 -0500 Subject: [PATCH 42/62] Adjust entity movement threshold and follow behavior Increased the movement threshold for entity updates from 0.05 to 1.0 to reduce unnecessary position updates. Modified follow behavior to offset the entity's coordinates by -1 on the Z axis when updating, possibly to account for ground level or animation adjustments. --- lib/entities/client/client_entity.lua | 5 +---- lib/entities/shared/behaviors/follow.lua | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index a4faabc..443baec 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -8,9 +8,6 @@ ClientEntity = { } -- Renamed from BaseEntity ClientEntity.Behaviors = Behaviors - - - -------------------- local function SpawnEntity(entityData) @@ -81,7 +78,7 @@ local function UpdateEntity(_entityData) local coords = vector3(entityData.coords.x, entityData.coords.y, entityData.coords.z) entityData.oldCoords = vector3(entityData.oldCoords.x, entityData.oldCoords.y, entityData.oldCoords.z) local dist = #(coords.xyz - entityData.oldCoords.xyz) - if dist > 0.05 then + if dist > 1.0 then if entityData.spawned then print("Moving entity:", entityData.id) SetEntityCoords(entityData.spawned, coords.x, coords.y, coords.z, false, false, false, true) diff --git a/lib/entities/shared/behaviors/follow.lua b/lib/entities/shared/behaviors/follow.lua index b5361a9..9a4c2c4 100644 --- a/lib/entities/shared/behaviors/follow.lua +++ b/lib/entities/shared/behaviors/follow.lua @@ -42,7 +42,7 @@ function Follow.PedWalkToPos(entityData) TaskGoStraightToCoord(entity, targetCoords.x, targetCoords.y, targetCoords.z, speed, -1, heading, 0.0) entityData.coords = GetEntityCoords(entity) entityData.follow.walking = true - Bridge.ClientEntity.Set(entityData.id, "coords", entityData.coords) + Bridge.ClientEntity.Set(entityData.id, "coords", entityData.coords - vector3(0,0,1)) Bridge.ClientEntity.Set(entityData.id, "follow", entityData.follow) if entityData.follow.OnExit then entityData.follow.OnExit(entityData) end return false From dff4622a943852590a2a8107c0afc2e5a02cb5d0 Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Wed, 3 Sep 2025 04:06:31 -0500 Subject: [PATCH 43/62] Refactor entity behavior to use Bridge.Entity Replaces all usage of Bridge.ClientEntity and Bridge.ServerEntity with Bridge.Entity across shared behavior modules. Updates initialization in lib/init.lua to use cLib.Entity and marks cLib.ClientEntity and cLib.ServerEntity as deprecated for consistency and future maintainability. --- lib/entities/shared/behaviors/anim.lua | 14 +++++++------- lib/entities/shared/behaviors/attach.lua | 10 ++++++---- lib/entities/shared/behaviors/clothing.lua | 10 +++++----- lib/entities/shared/behaviors/follow.lua | 18 +++++++++--------- lib/entities/shared/behaviors/particles.lua | 2 +- lib/entities/shared/behaviors/scenarios.lua | 4 ++-- lib/entities/shared/behaviors/shop.lua | 4 ++-- lib/entities/shared/behaviors/stash.lua | 10 +++++----- lib/entities/shared/behaviors/targets.lua | 4 ++-- lib/entities/shared/behaviors/weapon.lua | 8 ++++---- lib/init.lua | 11 +++++++++-- 11 files changed, 52 insertions(+), 43 deletions(-) diff --git a/lib/entities/shared/behaviors/anim.lua b/lib/entities/shared/behaviors/anim.lua index ef8574e..ee6e40a 100644 --- a/lib/entities/shared/behaviors/anim.lua +++ b/lib/entities/shared/behaviors/anim.lua @@ -18,13 +18,13 @@ function Animation.Play(entityData) local flags = entityData.anim.flags or Animation.default.flags local duration = entityData.anim.duration or Animation.default.duration entityData.anim.id = Bridge.Anim.Play(nil, entity, dict, name, 8.0, -8.0, duration, flags, 0.0, onComplete) - Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) + Bridge.Entity.Set(entityData.id, "anim", entityData.anim) entityData.oldAnim = entityData.anim - Bridge.ClientEntity.Set(entityData.id, "oldAnim", entityData.oldAnim) + Bridge.Entity.Set(entityData.id, "oldAnim", entityData.oldAnim) -- SetTimeout(1000, function() -- if entityData.anim then -- entityData.anim.disable = false - -- Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) + -- Bridge.Entity.Set(entityData.id, "anim", entityData.anim) -- end -- end) end @@ -36,15 +36,15 @@ function Animation.OnSpawn(entityData) entityData.anim.disable = false TaskSetBlockingOfNonTemporaryEvents(entityData.spawned, true) SetBlockingOfNonTemporaryEvents(entityData.spawned, true) - Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) + Bridge.Entity.Set(entityData.id, "anim", entityData.anim) end function Animation.OnRemove(entityData) if not entityData.spawned or not entityData.anim then return end entityData.oldAnim = nil entityData.anim.disable = true - Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) - Bridge.ClientEntity.Set(entityData.id, "oldAnim", entityData.oldAnim) + Bridge.Entity.Set(entityData.id, "anim", entityData.anim) + Bridge.Entity.Set(entityData.id, "oldAnim", entityData.oldAnim) end function Animation.OnUpdate(entityData) @@ -58,5 +58,5 @@ function Animation.OnUpdate(entityData) end end -Bridge.ClientEntity.RegisterBehavior("anim", Animation) +Bridge.Entity.RegisterBehavior("anim", Animation) return Animation \ No newline at end of file diff --git a/lib/entities/shared/behaviors/attach.lua b/lib/entities/shared/behaviors/attach.lua index 291de33..8b3f66f 100644 --- a/lib/entities/shared/behaviors/attach.lua +++ b/lib/entities/shared/behaviors/attach.lua @@ -14,7 +14,7 @@ function Attach.OnSpawn(entityData) local entity = entityData.spawned local targetEntity = entityData.attach.target if type(targetEntity) == "string" then - targetEntity = Bridge.ClientEntity.Get(targetEntity)?.spawned or targetEntity + targetEntity = Bridge.Entity.Get(targetEntity)?.spawned or targetEntity else local player = GetPlayerFromServerId(targetEntity) if player and player ~= -1 then @@ -27,13 +27,13 @@ function Attach.OnSpawn(entityData) local offset = entityData.attach.offset or Attach.default.offset local rotation = entityData.attach.rotation or Attach.default.rotation AttachEntityToEntity(entity, targetEntity, GetPedBoneIndex(targetEntity, bone), offset.x, offset.y, offset.z, rotation.x, rotation.y, rotation.z, true, true, false, true, 1, true) - Bridge.ClientEntity.Set(entityData.id, "attach", entityData.attach) + Bridge.Entity.Set(entityData.id, "attach", entityData.attach) end function Attach.Detach(entityData) if not entityData.spawned or not IsEntityAttached(entityData.spawned) then return end DetachEntity(entityData.spawned, true, true) - Bridge.ClientEntity.Set(entityData.id, "attach", entityData.attach) + Bridge.Entity.Set(entityData.id, "attach", entityData.attach) end function Attach.OnUpdate(entityData) @@ -42,9 +42,11 @@ function Attach.OnUpdate(entityData) return Attach.Detach(entityData) end local entity = entityData.spawned + local coords = GetEntityCoords(entity) + Bridge.Entity.Set(entityData.id, "coords", vector3(coords.x, coords.y, coords.z)) if IsEntityAttached(entity) then return end Attach.OnSpawn(entityData) end -Bridge.ClientEntity.RegisterBehavior("attach", Attach) +Bridge.Entity.RegisterBehavior("attach", Attach) return Attach \ No newline at end of file diff --git a/lib/entities/shared/behaviors/clothing.lua b/lib/entities/shared/behaviors/clothing.lua index 1b3f605..4ae11db 100644 --- a/lib/entities/shared/behaviors/clothing.lua +++ b/lib/entities/shared/behaviors/clothing.lua @@ -19,7 +19,7 @@ function Clothing.ChangeClothes(entityData) clothing = Bridge.Clothing.GetAppearance(GetPlayerPed(player)) end elseif type(clothing) == "string" then - local targetEntityData = Bridge.ClientEntity.Get(clothing) + local targetEntityData = Bridge.Entity.Get(clothing) if targetEntityData then clothing = Bridge.Clothing.GetAppearance(targetEntityData.spawned) end @@ -29,9 +29,9 @@ function Clothing.ChangeClothes(entityData) end Bridge.Clothing.SetAppearance(entity, clothing) - Bridge.ClientEntity.Set(entityData.id, "clothing", clothing) + Bridge.Entity.Set(entityData.id, "clothing", clothing) entityData.oldClothing = clothing - Bridge.ClientEntity.Set(entityData.id, "oldClothing", clothing) + Bridge.Entity.Set(entityData.id, "oldClothing", clothing) end @@ -73,10 +73,10 @@ function Clothing.OnUpdate(entityData) SetTimeout(1000, function() if entityData.clothing then entityData.clothing.updating = false - Bridge.ClientEntity.Set(entityData.id, "clothing", entityData.clothing) + Bridge.Entity.Set(entityData.id, "clothing", entityData.clothing) end end) end -Bridge.ClientEntity.RegisterBehavior("clothing", Clothing) +Bridge.Entity.RegisterBehavior("clothing", Clothing) return Clothing \ No newline at end of file diff --git a/lib/entities/shared/behaviors/follow.lua b/lib/entities/shared/behaviors/follow.lua index 9a4c2c4..addefb3 100644 --- a/lib/entities/shared/behaviors/follow.lua +++ b/lib/entities/shared/behaviors/follow.lua @@ -21,7 +21,7 @@ function Follow.PedWalkToPos(entityData) targetCoords = GetEntityCoords(targetCoords) end elseif type(targetCoords) == "string" then - local targetEntityData = Bridge.ClientEntity.Get(targetCoords) + local targetEntityData = Bridge.Entity.Get(targetCoords) if targetEntityData then targetCoords = GetEntityCoords(targetEntityData.spawned) end @@ -31,32 +31,32 @@ function Follow.PedWalkToPos(entityData) if distance > (entityData.follow.distance or Follow.default.distance) then if entityData.anim then entityData.anim.disable = true - Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) + Bridge.Entity.Set(entityData.id, "anim", entityData.anim) end if entityData.scenarios then entityData.scenarios.disable = true - Bridge.ClientEntity.Set(entityData.id, "scenarios", entityData.scenarios) + Bridge.Entity.Set(entityData.id, "scenarios", entityData.scenarios) end local speed = entityData.follow.speed or Follow.default.speed local heading = GetHeadingFromVector_2d(targetCoords.x - entityPos.x, targetCoords.y - entityPos.y) TaskGoStraightToCoord(entity, targetCoords.x, targetCoords.y, targetCoords.z, speed, -1, heading, 0.0) entityData.coords = GetEntityCoords(entity) entityData.follow.walking = true - Bridge.ClientEntity.Set(entityData.id, "coords", entityData.coords - vector3(0,0,1)) - Bridge.ClientEntity.Set(entityData.id, "follow", entityData.follow) + Bridge.Entity.Set(entityData.id, "coords", entityData.coords - vector3(0,0,1)) + Bridge.Entity.Set(entityData.id, "follow", entityData.follow) if entityData.follow.OnExit then entityData.follow.OnExit(entityData) end return false end if not entityData.follow.walking then return end entityData.follow.walking = false - Bridge.ClientEntity.Set(entityData.id, "follow", entityData.follow) + Bridge.Entity.Set(entityData.id, "follow", entityData.follow) if entityData.anim then entityData.anim.disable = false - Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) + Bridge.Entity.Set(entityData.id, "anim", entityData.anim) end if entityData.scenarios then entityData.scenarios.disable = false - Bridge.ClientEntity.Set(entityData.id, "scenarios", entityData.scenarios) + Bridge.Entity.Set(entityData.id, "scenarios", entityData.scenarios) end ClearPedTasks(entity) if entityData.follow.OnEnter then entityData.follow.OnEnter(entityData) end @@ -71,5 +71,5 @@ function Follow.OnUpdate(entityData) return Follow.PedWalkToPos(entityData) end -Bridge.ClientEntity.RegisterBehavior("follow", Follow) +Bridge.Entity.RegisterBehavior("follow", Follow) return Follow \ No newline at end of file diff --git a/lib/entities/shared/behaviors/particles.lua b/lib/entities/shared/behaviors/particles.lua index fecc6b7..1160360 100644 --- a/lib/entities/shared/behaviors/particles.lua +++ b/lib/entities/shared/behaviors/particles.lua @@ -76,5 +76,5 @@ function ParticlesBehaviors.OnMove(entityData) end end -Bridge.ClientEntity.RegisterBehavior("particles", ParticlesBehaviors) +Bridge.Entity.RegisterBehavior("particles", ParticlesBehaviors) return ParticlesBehaviors \ No newline at end of file diff --git a/lib/entities/shared/behaviors/scenarios.lua b/lib/entities/shared/behaviors/scenarios.lua index 20efb69..760af6c 100644 --- a/lib/entities/shared/behaviors/scenarios.lua +++ b/lib/entities/shared/behaviors/scenarios.lua @@ -23,7 +23,7 @@ function Scenarios.Play(entityData) ClearPedTasks(entity) if not entityData.scenarios.onComplete then return end entityData.scenarios.disabled = true - Bridge.ClientEntity.Set(entityData.id, "scenarios", entityData.scenarios) + Bridge.Entity.Set(entityData.id, "scenarios", entityData.scenarios) entityData.scenarios.onComplete(entityData) end) @@ -60,5 +60,5 @@ function Scenarios.OnUpdate(entityData) Scenarios.Play(entityData) end -Bridge.ClientEntity.RegisterBehavior("scenarios", Scenarios) +Bridge.Entity.RegisterBehavior("scenarios", Scenarios) return Scenarios \ No newline at end of file diff --git a/lib/entities/shared/behaviors/shop.lua b/lib/entities/shared/behaviors/shop.lua index 048e786..306752c 100644 --- a/lib/entities/shared/behaviors/shop.lua +++ b/lib/entities/shared/behaviors/shop.lua @@ -36,12 +36,12 @@ function Shop.OnCreate(entityData) ) end -if not IsDuplicityVersion() then return Bridge.ClientEntity.RegisterBehavior("shop", Shop) end +if not IsDuplicityVersion() then return Bridge.Entity.RegisterBehavior("shop", Shop) end RegisterNetEvent("community_bridge:server:OpenShop", function(id) local src = source if not src then return end - local entityData = Bridge.ServerEntity.Get(id) + local entityData = Bridge.Entity.Get(id) if not entityData or not entityData.shop then return print(string.format("[Shop] OpenShop: Entity %s does not exist or has no shop", id)) end diff --git a/lib/entities/shared/behaviors/stash.lua b/lib/entities/shared/behaviors/stash.lua index c006a11..994a7d0 100644 --- a/lib/entities/shared/behaviors/stash.lua +++ b/lib/entities/shared/behaviors/stash.lua @@ -26,7 +26,7 @@ function Stash.OnCreate(entityData) label = entityData.stash.target.label or Stash.default.target.label, icon = entityData.stash.target.icon or Stash.default.target.icon, canInteract = function(_) - local entData = Bridge.ClientEntity.Get(entityData.id) + local entData = Bridge.Entity.Get(entityData.id) return not entData.stash.disable end, onSelect = function() @@ -34,16 +34,16 @@ function Stash.OnCreate(entityData) end } - Bridge.ClientEntity.Set(entityData.id, 'targets', entityData.targets) + Bridge.Entity.Set(entityData.id, 'targets', entityData.targets) end end -if not IsDuplicityVersion() then return Bridge.ClientEntity.RegisterBehavior("stash", Stash) end +if not IsDuplicityVersion() then return Bridge.Entity.RegisterBehavior("stash", Stash) end RegisterNetEvent("community_bridge:server:OpenStash", function(id) local src = source if not src then return end - local entityData = Bridge.ServerEntity.Get(id) + local entityData = Bridge.Entity.Get(id) if not entityData or not entityData.stash then return print(string.format("[Stash] OpenStash: Entity %s does not exist or has no stash", id)) end @@ -56,4 +56,4 @@ RegisterNetEvent("community_bridge:server:OpenStash", function(id) Bridge.Inventory.OpenStash(src, "stash", id) end) -Bridge.ServerEntity.RegisterBehavior("stash", Stash) \ No newline at end of file +Bridge.Entity.RegisterBehavior("stash", Stash) \ No newline at end of file diff --git a/lib/entities/shared/behaviors/targets.lua b/lib/entities/shared/behaviors/targets.lua index cb15ac3..610b2ca 100644 --- a/lib/entities/shared/behaviors/targets.lua +++ b/lib/entities/shared/behaviors/targets.lua @@ -26,7 +26,7 @@ function Targets.OnSpawn(entityData) table.sort(numberedTargets, function(a, b) return (a.label < b.label) end) Bridge.Target.AddLocalEntity(entityData.spawned, numberedTargets) entityData.oldTargets = entityData.targets - Bridge.ClientEntity.Set(entityData.id, "oldTargets", entityData.oldTargets) + Bridge.Entity.Set(entityData.id, "oldTargets", entityData.oldTargets) end function Targets.OnRemove(entityData) @@ -57,5 +57,5 @@ function Targets.OnUpdate(entityData) Targets.OnSpawn(entityData) end end -Bridge.ClientEntity.RegisterBehavior("targets", Targets) +Bridge.Entity.RegisterBehavior("targets", Targets) return Targets \ No newline at end of file diff --git a/lib/entities/shared/behaviors/weapon.lua b/lib/entities/shared/behaviors/weapon.lua index d055ccd..24c6b7c 100644 --- a/lib/entities/shared/behaviors/weapon.lua +++ b/lib/entities/shared/behaviors/weapon.lua @@ -19,7 +19,7 @@ function Weapon.GiveWeapon(entityData) TaskSwapWeapon(entity, true) end entityData.oldWeapon = entityData.weapon - Bridge.ClientEntity.Set(entityData.id, "oldWeapon", entityData.oldWeapon) + Bridge.Entity.Set(entityData.id, "oldWeapon", entityData.oldWeapon) end function Weapon.OnSpawn(entityData) @@ -44,11 +44,11 @@ function Weapon.OnUpdate(entityData) SetTimeout(1000, function() if entityData.weapon then entityData.weapon.updating = false - Bridge.ClientEntity.Set(entityData.id, "weapon", entityData.weapon) + Bridge.Entity.Set(entityData.id, "weapon", entityData.weapon) end end) - Bridge.ClientEntity.Set(entityData.id, "weapon", entityData.weapon) + Bridge.Entity.Set(entityData.id, "weapon", entityData.weapon) end -Bridge.ClientEntity.RegisterBehavior("weapon", Weapon) +Bridge.Entity.RegisterBehavior("weapon", Weapon) return Weapon \ No newline at end of file diff --git a/lib/init.lua b/lib/init.lua index e8676e0..48cbce8 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -59,7 +59,11 @@ cLib.Cache = Cache or Require("lib/cache/shared/cache.lua") cLib.Marker = Marker or Require("lib/markers/server/server.lua") cLib.Particle = Particle or Require("lib/particles/server/particles.lua") cLib.Shell = Shells or Require("lib/shells/server/shells.lua") -cLib.ServerEntity = ServerEntity or Require("lib/entities/server/server_entity.lua") +cLib.Entity = ServerEntity or Require("lib/entities/server/server_entity.lua") + +-- Depricated +cLib.ServerEntity = cLib.Entity + if IsDuplicityVersion() then return cLib end ::client:: @@ -71,10 +75,13 @@ cLib.Raycast = Raycast or Require("lib/raycast/client/raycast.lua") cLib.Point = Point or Require("lib/points/client/points.lua") cLib.Particle = Particle or Require("lib/particles/client/particles.lua") cLib.Cache = Cache or Require("lib/cache/client/cache.lua") -cLib.ClientEntity = ClientEntity or Require("lib/entities/client/client_entity.lua") cLib.Marker = Marker or Require("lib/markers/client/markers.lua") cLib.Anim = Anim or Require("lib/anim/client/client.lua") cLib.Cutscene = Cutscene or Require("lib/cutscenes/client/cutscene.lua") cLib.Particle = Particle or Require("lib/particles/client/particles.lua") +cLib.Entity = ClientEntity or Require("lib/entities/client/client_entity.lua") + +-- Deprecated +cLib.ClientEntity = cLib.Entity return cLib From 744369525424a7c4fcc7936d8f46de938a31e611 Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Wed, 3 Sep 2025 08:57:39 -0500 Subject: [PATCH 44/62] Improve entity spawning and target behaviors Refactored client entity spawning to handle missing models and improved coordinate update sensitivity. Removed model assertion from server entity creation. Enhanced resource start event handling for both server and client. Updated stash and target behaviors to support additional properties and better zone handling for entities without spawned objects. --- lib/entities/client/client_entity.lua | 56 ++++++++++++----------- lib/entities/server/server_entity.lua | 2 - lib/entities/shared/behaviors.lua | 16 +++++-- lib/entities/shared/behaviors/stash.lua | 2 + lib/entities/shared/behaviors/targets.lua | 19 ++++++-- 5 files changed, 59 insertions(+), 36 deletions(-) diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index 443baec..bde8323 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -12,33 +12,35 @@ ClientEntity.Behaviors = Behaviors local function SpawnEntity(entityData) if entityData.spawned and DoesEntityExist(entityData.spawned) then return end -- Already spawned - local loaded, model = Utility.LoadModel(entityData.model) - if not loaded then - print(string.format("[ClientEntity] Failed to load model %s for entity %s", entityData.model, entityData.id)) - return - end + if entityData.model then + local loaded, model = Utility.LoadModel(entityData.model) + if not loaded then + print(string.format("[ClientEntity] Failed to load model %s for entity %s", entityData.model, entityData.id)) + return + end - local entity = nil - local coords = entityData.coords - local rotation = entityData.rotation or vector3(0.0, 0.0, entityData.heading or 0.0) -- Default rotation if not provided + local entity = nil + local coords = entityData.coords + local rotation = entityData.rotation or vector3(0.0, 0.0, entityData.heading or 0.0) -- Default rotation if not provided - if entityData.entityType == 'object' then - entity = CreateObject(model, coords.x, coords.y, coords.z, false, false, false) - SetEntityRotation(entity, rotation.x, rotation.y, rotation.z, 2, true) - elseif entityData.entityType == 'ped' then - entity = CreatePed(4, model, coords.x, coords.y, coords.z, type(rotation) == 'number' and rotation or rotation.z, false, false) - elseif entityData.entityType == 'vehicle' then - entity = CreateVehicle(model, coords.x, coords.y, coords.z, type(rotation) == 'number' and rotation or rotation.z, false, false) - else - print(string.format("[ClientEntity] Unknown entity type '%s' for entity %s", entityData.entityType, entityData.id)) - end - if entity and model then - entityData.spawned = entity - SetModelAsNoLongerNeeded(model) - SetEntityAsMissionEntity(entity, true, true) - FreezeEntityPosition(entity, true) - else - SetModelAsNoLongerNeeded(model) + if entityData.entityType == 'object' then + entity = CreateObject(model, coords.x, coords.y, coords.z, false, false, false) + SetEntityRotation(entity, rotation.x, rotation.y, rotation.z, 2, true) + elseif entityData.entityType == 'ped' then + entity = CreatePed(4, model, coords.x, coords.y, coords.z, type(rotation) == 'number' and rotation or rotation.z, false, false) + elseif entityData.entityType == 'vehicle' then + entity = CreateVehicle(model, coords.x, coords.y, coords.z, type(rotation) == 'number' and rotation or rotation.z, false, false) + else + print(string.format("[ClientEntity] Unknown entity type '%s' for entity %s", entityData.entityType, entityData.id)) + end + if entity and model then + entityData.spawned = entity + SetModelAsNoLongerNeeded(model) + SetEntityAsMissionEntity(entity, true, true) + FreezeEntityPosition(entity, true) + else + SetModelAsNoLongerNeeded(model) + end end if entityData.OnSpawn then pcall(function (...) @@ -78,9 +80,8 @@ local function UpdateEntity(_entityData) local coords = vector3(entityData.coords.x, entityData.coords.y, entityData.coords.z) entityData.oldCoords = vector3(entityData.oldCoords.x, entityData.oldCoords.y, entityData.oldCoords.z) local dist = #(coords.xyz - entityData.oldCoords.xyz) - if dist > 1.0 then + if dist > 0.5 then if entityData.spawned then - print("Moving entity:", entityData.id) SetEntityCoords(entityData.spawned, coords.x, coords.y, coords.z, false, false, false, true) end -- ClientEntity.UpdateCoords(entityData.id, entityData.coords) @@ -243,6 +244,7 @@ end) RegisterNetEvent("community_bridge:client:UpdateEntity", function(id, data) for k, v in pairs(data) do + print(json.encode({k, v})) ClientEntity.Set(id, k, v) end end) diff --git a/lib/entities/server/server_entity.lua b/lib/entities/server/server_entity.lua index c9950c0..c135432 100644 --- a/lib/entities/server/server_entity.lua +++ b/lib/entities/server/server_entity.lua @@ -14,8 +14,6 @@ local Invoked = {} -- @param meta table Optional additional data -- @return table The created entity data function ServerEntity.New(id, entityType, model, coords, rotation, args) - assert(entityType, "EntityType is required") - assert(model, "Model is required for entity creation") assert(coords, "Coords are required for entity creation") local self = args or {} self.id = id or Ids.CreateUniqueId(Entities) diff --git a/lib/entities/shared/behaviors.lua b/lib/entities/shared/behaviors.lua index e30b3d2..d85b4b1 100644 --- a/lib/entities/shared/behaviors.lua +++ b/lib/entities/shared/behaviors.lua @@ -104,8 +104,18 @@ AddEventHandler("onResourceStop", function(resourceName) end end) -AddEventHandler("onResourceStart", function(resourceName) - Behaviors.Init() -end) +if IsDuplicityVersion() then + RegisterNetEvent("onResourceStart", function(resourceName) + if resourceName ~= GetCurrentResourceName() then return end + Wait(500) + Behaviors.Init() + end) +else + RegisterNetEvent("onClientResourceStart", function(resource) + if resource ~= GetCurrentResourceName() then return end + Wait(500) + Behaviors.Init() + end) +end return Behaviors diff --git a/lib/entities/shared/behaviors/stash.lua b/lib/entities/shared/behaviors/stash.lua index 994a7d0..0c83b66 100644 --- a/lib/entities/shared/behaviors/stash.lua +++ b/lib/entities/shared/behaviors/stash.lua @@ -25,6 +25,8 @@ function Stash.OnCreate(entityData) entityData.targets['stash'] = { label = entityData.stash.target.label or Stash.default.target.label, icon = entityData.stash.target.icon or Stash.default.target.icon, + description = entityData.stash.target.description, + groups = entityData.stash.target.groups, canInteract = function(_) local entData = Bridge.Entity.Get(entityData.id) return not entData.stash.disable diff --git a/lib/entities/shared/behaviors/targets.lua b/lib/entities/shared/behaviors/targets.lua index 610b2ca..99f30d7 100644 --- a/lib/entities/shared/behaviors/targets.lua +++ b/lib/entities/shared/behaviors/targets.lua @@ -4,15 +4,17 @@ local Targets = { default = { label = "Default Target Label", distance = 2, + size = vector3(2.0, 2.0, 2.0), } } function Targets.OnSpawn(entityData) - if not entityData.spawned or not entityData.targets then return end + if not entityData.targets then return end if entityData.targets?.label then local temp = entityData.targets entityData.targets = {temp} end + print("Spawned targets:", entityData.targets) local numberedTargets = {} for k, v in pairs(entityData.targets) do local onSelect = v.onSelect @@ -24,18 +26,26 @@ function Targets.OnSpawn(entityData) table.insert(numberedTargets, v) end table.sort(numberedTargets, function(a, b) return (a.label < b.label) end) - Bridge.Target.AddLocalEntity(entityData.spawned, numberedTargets) + if not entityData.spawned then + local size = Targets.default.size + Bridge.Target.AddBoxZone(entityData.id, entityData.coords, entityData.size, entityData.heading, numberedTargets, entityData.debug) + else + Bridge.Target.AddLocalEntity(entityData.spawned, numberedTargets) + end entityData.oldTargets = entityData.targets Bridge.Entity.Set(entityData.id, "oldTargets", entityData.oldTargets) end function Targets.OnRemove(entityData) - if not entityData.spawned or not entityData.oldTargets then return end + if not entityData.oldTargets then return end + if not entityData.spawned then + return Bridge.Target.RemoveZone(entityData.id) + end Bridge.Target.RemoveLocalEntity(entityData.spawned) end function Targets.OnUpdate(entityData) - if not entityData.spawned or not entityData.oldTargets then return end + if not entityData.oldTargets then return end local doesntMatch = false for k, v in pairs(entityData.targets) do if not entityData.oldTargets or not entityData.oldTargets[k] then @@ -52,6 +62,7 @@ function Targets.OnUpdate(entityData) end end if doesntMatch then + print("ASDFASDFASDF") Targets.OnRemove(entityData) Wait(100) Targets.OnSpawn(entityData) From 18ac3ce0ca63bba2c8dda11ed3adeed3a7d25f58 Mon Sep 17 00:00:00 2001 From: Solaire Date: Wed, 3 Sep 2025 22:58:17 +0100 Subject: [PATCH 45/62] Round the result --- modules/framework/es_extended/server.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/framework/es_extended/server.lua b/modules/framework/es_extended/server.lua index 8371e3f..279da4c 100644 --- a/modules/framework/es_extended/server.lua +++ b/modules/framework/es_extended/server.lua @@ -257,7 +257,7 @@ Framework.GetHunger = function(src) for _, entry in ipairs(status) do if entry.name == "hunger" then - return entry.percent + return math.floor(entry.percent) end end end @@ -271,7 +271,7 @@ Framework.GetThirst = function(src) for _, entry in ipairs(status) do if entry.name == "thirst" then - return entry.percent + return math.floor(entry.percent) end end end From debfb062317cb6c81abcb1a003c4d8402d9de4c8 Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Thu, 4 Sep 2025 08:21:48 -0500 Subject: [PATCH 46/62] Refactor stash and targets behavior logic Simplifies stash target assignment by returning early when registering a stash, ensuring consistent target setup. Enhances target update logic to check for removed targets and removes debug print statement. --- lib/entities/shared/behaviors/stash.lua | 36 +++++++++++------------ lib/entities/shared/behaviors/targets.lua | 8 ++++- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/entities/shared/behaviors/stash.lua b/lib/entities/shared/behaviors/stash.lua index 0c83b66..badbebc 100644 --- a/lib/entities/shared/behaviors/stash.lua +++ b/lib/entities/shared/behaviors/stash.lua @@ -20,24 +20,24 @@ function Stash.OnCreate(entityData) local owner = entityData.stash.owner local groups = entityData.stash.groups Bridge.Inventory.RegisterStash(entityData.id, label, slots, weight, owner, groups) - else - entityData.targets = entityData.targets or {} - entityData.targets['stash'] = { - label = entityData.stash.target.label or Stash.default.target.label, - icon = entityData.stash.target.icon or Stash.default.target.icon, - description = entityData.stash.target.description, - groups = entityData.stash.target.groups, - canInteract = function(_) - local entData = Bridge.Entity.Get(entityData.id) - return not entData.stash.disable - end, - onSelect = function() - TriggerServerEvent("community_bridge:server:OpenStash", entityData.id) - end - } - - Bridge.Entity.Set(entityData.id, 'targets', entityData.targets) - end + return + end + entityData.targets = entityData.targets or {} + entityData.targets['stash'] = { + label = entityData.stash.target.label or Stash.default.target.label, + icon = entityData.stash.target.icon or Stash.default.target.icon, + description = entityData.stash.target.description, + groups = entityData.stash.target.groups, + canInteract = function(_) + local entData = Bridge.Entity.Get(entityData.id) + return not entData.stash.disable + end, + onSelect = function() + TriggerServerEvent("community_bridge:server:OpenStash", entityData.id) + end + } + + Bridge.Entity.Set(entityData.id, 'targets', entityData.targets) end if not IsDuplicityVersion() then return Bridge.Entity.RegisterBehavior("stash", Stash) end diff --git a/lib/entities/shared/behaviors/targets.lua b/lib/entities/shared/behaviors/targets.lua index 99f30d7..c11afc4 100644 --- a/lib/entities/shared/behaviors/targets.lua +++ b/lib/entities/shared/behaviors/targets.lua @@ -61,8 +61,14 @@ function Targets.OnUpdate(entityData) break end end + + for k, v in pairs(entityData.oldTargets) do + if not entityData.targets or not entityData.targets[k] then + doesntMatch = true + break + end + end if doesntMatch then - print("ASDFASDFASDF") Targets.OnRemove(entityData) Wait(100) Targets.OnSpawn(entityData) From 18748bd7754c19fd35792d2306012ace3c8c9d7d Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Thu, 4 Sep 2025 11:42:59 -0500 Subject: [PATCH 47/62] Refactor entity movement and add Math.Nearest function Simplifies entity movement logic in client_entity.lua by improving coordinate comparison and updating behavior triggers. Adds a new Math.Nearest function in math.lua to round values to the nearest whole number. --- lib/entities/client/client_entity.lua | 33 ++++++++++++--------------- lib/utility/shared/math.lua | 9 +++++++- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index bde8323..6a627df 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -76,24 +76,21 @@ local function UpdateEntity(_entityData) end) end Behaviors.Trigger("OnUpdate", entityData) - if entityData.oldCoords and entityData.oldCoords ~= entityData.coords then - local coords = vector3(entityData.coords.x, entityData.coords.y, entityData.coords.z) - entityData.oldCoords = vector3(entityData.oldCoords.x, entityData.oldCoords.y, entityData.oldCoords.z) - local dist = #(coords.xyz - entityData.oldCoords.xyz) - if dist > 0.5 then - if entityData.spawned then - SetEntityCoords(entityData.spawned, coords.x, coords.y, coords.z, false, false, false, true) - end - -- ClientEntity.UpdateCoords(entityData.id, entityData.coords) - if entityData.OnMove then - pcall(function (...) - return entityData.OnMove(entityData) - end) - end - Behaviors.Trigger("OnMove", entityData, entityData.oldCoords, entityData.coords) - end - entityData.oldCoords = entityData.coords - end + local coords = vector3(entityData.coords.x, entityData.coords.y, entityData.coords.z) + entityData.oldCoords = entityData.oldCoords and vector3(entityData.oldCoords.x, entityData.oldCoords.y, entityData.oldCoords.z) or coords + local dist = #(coords - entityData.oldCoords) + if entityData.oldCoords and dist > 0.5 then + if entityData.spawned then + SetEntityCoords(entityData.spawned, coords.x, coords.y, coords.z, false, false, false, true) + end + -- ClientEntity.UpdateCoords(entityData.id, entityData.coords) + if entityData.OnMove then + pcall(function (...) + return entityData.OnMove(entityData) + end) + end + Behaviors.Trigger("OnMove", entityData, entityData.oldCoords, entityData.coords) + end if not entityData.oldRotation or entityData.oldRotation ~= entityData.rotation then if entityData.spawned and DoesEntityExist(entityData.spawned) then diff --git a/lib/utility/shared/math.lua b/lib/utility/shared/math.lua index 499d8c4..3691d66 100644 --- a/lib/utility/shared/math.lua +++ b/lib/utility/shared/math.lua @@ -3,7 +3,7 @@ Math = Math or {} ---@class Math -------@field public name string @add name field to class Car, you'll see it in code completion +---@field public name string @add name field to class Car, you'll see it in code completion Math = {} @@ -44,6 +44,13 @@ function Math.Smooth(value, min, max) return value * value * (3 - 2 * value) end +--- Gets the nearest whole number. +--- @param value number The value to round. +--- @return number The rounded value. +function Math.Nearest(value) + return math.floor(value + 0.5) +end + --- Maps a value from one range to another. ---@param value number The value to map. ---@param inMin number The minimum value for the provided value. From 46574bef95df33041ec4a0b3b16a2276360e15bf Mon Sep 17 00:00:00 2001 From: StrixLuca <110634650+StrixLuca@users.noreply.github.com> Date: Sat, 6 Sep 2025 09:30:01 +0100 Subject: [PATCH 48/62] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 316045d..6316feb 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ By bridging core game systems including inventory, dispatch, targeting, door loc ## Documentation Complete developer documentation is available at: -[Community Bridge Documentation](https://mrnewbs-scrips.gitbook.io/the-order-of-the-sacred-framework) +[Community Bridge Documentation](https://tootsf.github.io/#Community%20Bridge/overview) --- From de0f7b9492e201612b3ee70b7d6f009a75cc7ea6 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Sun, 7 Sep 2025 08:59:24 -0400 Subject: [PATCH 49/62] Update Community Bridge Documentation link --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 6316feb..e5caeb4 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,7 @@ By bridging core game systems including inventory, dispatch, targeting, door loc ## Documentation Complete developer documentation is available at: -[Community Bridge Documentation](https://tootsf.github.io/#Community%20Bridge/overview) - +[Community Bridge Documentation](https://theorderfivem.github.io/public_docs/) --- ## Community and Support From 66df77cc3f622035ac2af74021d13a53c8717c7d Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Wed, 10 Sep 2025 10:42:15 -0400 Subject: [PATCH 50/62] fix manifest warning --- fxmanifest.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/fxmanifest.lua b/fxmanifest.lua index 5e430ad..d9c4c3d 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -11,7 +11,6 @@ shared_scripts { '@ox_lib/init.lua', 'settings/sharedConfig.lua', 'lib/init.lua', - 'modules/math/*.lua', 'modules/locales/*.lua', 'modules/clothing/**/shared.lua', } From f472232273b95d21f1757cbb6fc216e36963a400 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Wed, 10 Sep 2025 11:07:58 -0400 Subject: [PATCH 51/62] Add vehicle properties system and update attributions Introduces a comprehensive vehicle properties handler in lib/vehicles/client.lua, inspired by ESX, QB-Core, and ox_lib frameworks. Updates Attributions.md to document the new vehicle system, clarify licensing, and improve formatting. Registers Vehicles in lib/init.lua for client use. --- Attributions.md | 116 +++++---- lib/init.lua | 1 + lib/vehicles/client.lua | 510 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 581 insertions(+), 46 deletions(-) create mode 100644 lib/vehicles/client.lua diff --git a/Attributions.md b/Attributions.md index bad4521..d21b523 100644 --- a/Attributions.md +++ b/Attributions.md @@ -1,98 +1,122 @@ # Attributions -> **Community Bridge** This project incorporates code from several outstanding libraries and resources, all licensed under GPLv3. We're grateful to the talented developers who made their work available to the community. +> **Community Bridge** incorporates code from several outstanding libraries and resources, all licensed under GPLv3. We’re grateful to the talented developers who made their work available to the community. --- ## Libraries & Resources -### r\_bridge - -**Purpose:** Code for codem-inventory bridging, and initial targeting -**Repository:** [r\_bridge](https://github.com/rumaier/r_bridge) -
-Implementation Details +r_bridge + +**Purpose:** Code for codem-inventory bridging, and initial targeting +**Repository:** [r_bridge](https://github.com/rumaier/r_bridge) **Code we use:** -* Inventory bridging code for codem-inventory integration -* Targeting system foundation +- Inventory bridging code for codem-inventory integration +- Targeting system foundation **Modifications made:** -* Adapted inventory bridge for codem compatibility in alternative structure +- Adapted inventory bridge for codem compatibility in alternative structure
--- -### ox\_lib - -**Purpose:** External compatibility and architectural inspiration -**Repository:** [ox\_lib](https://github.com/overextended/ox_lib) -
-Implementation Details +ox_lib + +**Purpose:** Architectural inspiration +**Repository:** [ox_lib](https://github.com/overextended/ox_lib) **Compatibility features:** -* External resource integration for raycasting utilities -* Shared conventions +- External resource integration for raycasting utilities +- Shared conventions **Implementation approach:** -* No direct code usage - maintains compatibility as external resource -* Follows ox\_lib conventions for seamless integration -* Provides bridge compatibility for servers using ox\_lib ecosystem +- No direct code usage — maintains compatibility as external resource +- Follows ox_lib conventions for seamless integration +- Provides bridge compatibility for servers using ox_lib ecosystem
--- -### renewed\_lib - -**Purpose:** Object placer functionality -**Repository:** [renewed\_lib](https://github.com/Renewed-Scripts/Renewed-Lib) -
-Implementation Details +renewed_lib + +**Purpose:** Object placer functionality +**Repository:** [renewed_lib](https://github.com/Renewed-Scripts/Renewed-Lib) **Code we use:** -* Object placement system +- Object placement system **Modifications made:** -* Updated variable naming for consistency -* Added missing parameters for native functions -* Updated deprecated ox\_lib raycast camera export -* Enhanced showtext UI to work with multiple systems -* Moved placement text to locales for internationalization -* Replaced ox\_lib model request exports with our bridge functions +- Updated variable naming for consistency +- Added missing parameters for native functions +- Updated deprecated ox_lib raycast camera export +- Enhanced showtext UI to work with multiple systems +- Moved placement text to locales for internationalization +- Replaced ox_lib model request exports with our bridge functions
--- -### duff +
+duff -**Purpose:** Version checker system and update notifications +**Purpose:** Version checker system and update notifications **Repository:** [duff](https://github.com/DonHulieo/duff/blob/d89ed3b0051194babf5711114a0c437d4e41f433/server/init.lua#L10C1-L28C4) -
-Implementation Details - **Code we use:** -* Version checker formatting patterns -* Repository information handling +- Version checker formatting patterns +- Repository information handling **Modifications made:** -* Removed unnecessary variables -* Enhanced to pull repository information from passed strings -* Adapted print formatting for our use case +- Removed unnecessary variables +- Enhanced to pull repository information from passed strings +- Adapted print formatting for our use case + +
+ +--- + +
+Vehicle Properties System + +**Purpose:** Set and manage vehicle properties in the game world, inspired by multiple community frameworks. +**Repositories referenced:** + +- [ESX-Framework (ESX.Game.SetVehicleProperties)](https://github.com/esx-framework/es_extended) +- [QB-Core (qb-core)](https://github.com/qbcore-framework/qb-core) +- [ox_lib](https://github.com/overextended/ox_lib) (architectural inspiration and modifications) + +**Code origin and inspiration:** + +- Primarily draws on concepts and structures from ESX and QB-Core, with ox_lib serving as architectural inspiration. +- ESX and QB-Core implementations use similar approaches for setting vehicle mods, colors, damages, and extras. +- ox_lib adapts and extends these approaches within its framework, showing overlapping code patterns. + +**Modifications made:** + +- Combined and refactored logic to suit Community Bridge project needs. +- Adapted license to GPLv3 for compatibility and open-source compliance. +- Added explicit handling of custom colors, mod toggles, and damage states. + +**Licensing notes:** + +- Original ESX and QB-Core frameworks are GPLv3 licensed. +- ox_lib is LGPL licensed, used here as architectural inspiration only. +- This project’s vehicle properties code inherits GPLv3 licensing consistent with ESX/QB-Core, honoring their licensing terms and attributions.
@@ -100,7 +124,7 @@ ## Special Thanks -A heartfelt thank you to all the creators and maintainers of these libraries, bridges, and resources. Your dedication to open-source development and the FiveM community makes projects like Community Bridge possible. +A heartfelt thank you to all creators and maintainers of these libraries, bridges, and resources. Your dedication to open-source development and the FiveM community makes projects like Community Bridge possible. Your willingness to share knowledge and code under GPLv3 licensing enables the entire community to build better, more compatible systems together. @@ -114,4 +138,4 @@ For detailed license information, see the [LICENSE](LICENSE) file in the project --- -> *"If I have seen further it is by standing on the shoulders of Giants."* - Isaac Newton +> *"If I have seen further it is by standing on the shoulders of Giants."* – Isaac Newton diff --git a/lib/init.lua b/lib/init.lua index 48cbce8..6e84715 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -80,6 +80,7 @@ cLib.Anim = Anim or Require("lib/anim/client/client.lua") cLib.Cutscene = Cutscene or Require("lib/cutscenes/client/cutscene.lua") cLib.Particle = Particle or Require("lib/particles/client/particles.lua") cLib.Entity = ClientEntity or Require("lib/entities/client/client_entity.lua") +cLib.Vehicles = Vehicles or Require("lib/vehicles/client.lua") -- Deprecated cLib.ClientEntity = cLib.Entity diff --git a/lib/vehicles/client.lua b/lib/vehicles/client.lua new file mode 100644 index 0000000..c5f3c70 --- /dev/null +++ b/lib/vehicles/client.lua @@ -0,0 +1,510 @@ +---@diagnostic disable: duplicate-set-field +Vehicles = Vehicles or {} + +-- Vehicle properties setter function +-- +-- Inspired by and derived from vehicle property handlers in: +-- ESX Framework (https://github.com/esx-framework/esx_core) [License: GPLv3] +-- QBCore Framework (https://github.com/qbcore-framework/qb-core) [License: GPLv3] +-- +-- Note: The ox_lib version (https://github.com/overextended/ox_lib) [License: LGPLv3] also draws heavily from these projects. +-- +-- This code is licensed under the GNU General Public License v3.0 (GPLv3). +-- You may use, modify, and distribute this code under the terms of the GPLv3. +-- See LICENSE file for full details. + +if not DecorIsRegisteredAsType("Player_Vehicle", 3) then DecorRegister("Player_Vehicle", 3) end + +---@alias RGBColor number[] RGB color array [r, g, b] where each component is 0-255 +---@alias VehicleExtras table Vehicle extras where key is extra ID and value is state (0=enabled, 1=disabled) + +---@class VehicleProperties +---@field model? number Vehicle model hash +---@field plate? string License plate text +---@field plateIndex? number License plate style index (0-5) +---@field bodyHealth? number Body health (0-1000) +---@field engineHealth? number Engine health (0-1000) +---@field tankHealth? number Tank health (0-1000) +---@field fuelLevel? number Fuel level (0-100) +---@field oilLevel? number Oil level (0-100) +---@field dirtLevel? number Dirt level (0-15) +---@field paintType1? number Primary paint type +---@field paintType2? number Secondary paint type +---@field color1? number|RGBColor Primary color (color index or RGB values) +---@field color2? number|RGBColor Secondary color (color index or RGB values) +---@field pearlescentColor? number Pearlescent color index +---@field interiorColor? number Interior color index +---@field dashboardColor? number Dashboard color index +---@field wheelColor? number Wheel color index +---@field wheelWidth? number Wheel width +---@field wheelSize? number Wheel size +---@field wheels? number Wheel type +---@field windowTint? number Window tint level (0-6) +---@field xenonColor? number Xenon headlight color +---@field neonEnabled? boolean[] Neon light states [left, right, front, back] +---@field neonColor? RGBColor Neon light color RGB values +---@field extras? VehicleExtras Vehicle extras configuration +---@field tyreSmokeColor? RGBColor Tyre smoke color RGB values +---@field modSpoilers? number Spoiler modification (-1 to max) +---@field modFrontBumper? number Front bumper modification (-1 to max) +---@field modRearBumper? number Rear bumper modification (-1 to max) +---@field modSideSkirt? number Side skirt modification (-1 to max) +---@field modExhaust? number Exhaust modification (-1 to max) +---@field modFrame? number Frame modification (-1 to max) +---@field modGrille? number Grille modification (-1 to max) +---@field modHood? number Hood modification (-1 to max) +---@field modFender? number Fender modification (-1 to max) +---@field modRightFender? number Right fender modification (-1 to max) +---@field modRoof? number Roof modification (-1 to max) +---@field modEngine? number Engine modification (-1 to max) +---@field modBrakes? number Brakes modification (-1 to max) +---@field modTransmission? number Transmission modification (-1 to max) +---@field modSuspension? number Suspension modification (-1 to max) +---@field modArmor? number Armor modification (-1 to max) +---@field modNitrous? number Nitrous modification (-1 to max) +---@field modHorns? number Horn modification (-1 to max) +---@field modSubwoofer? number Subwoofer modification (-1 to max) +---@field modTurbo? boolean Turbo toggle +---@field modSmokeEnabled? boolean Tyre smoke toggle +---@field modHydraulics? boolean Hydraulics toggle +---@field modXenon? boolean Xenon lights toggle +---@field modFrontWheels? number Front wheels modification (-1 to max) +---@field modBackWheels? number Back wheels modification (-1 to max) +---@field modCustomTiresF? boolean Custom front tires enabled +---@field modCustomTiresR? boolean Custom rear tires enabled +---@field modPlateHolder? number Plate holder modification (-1 to max) +---@field modVanityPlate? number Vanity plate modification (-1 to max) +---@field modTrimA? number Trim A modification (-1 to max) +---@field modOrnaments? number Ornaments modification (-1 to max) +---@field modDashboard? number Dashboard modification (-1 to max) +---@field modDial? number Dial modification (-1 to max) +---@field modDoorSpeaker? number Door speaker modification (-1 to max) +---@field modSeats? number Seats modification (-1 to max) +---@field modSteeringWheel? number Steering wheel modification (-1 to max) +---@field modShifterLeavers? number Shifter levers modification (-1 to max) +---@field modAPlate? number A-plate modification (-1 to max) +---@field modSpeakers? number Speakers modification (-1 to max) +---@field modTrunk? number Trunk modification (-1 to max) +---@field modHydrolic? number Hydraulic modification (-1 to max) +---@field modEngineBlock? number Engine block modification (-1 to max) +---@field modAirFilter? number Air filter modification (-1 to max) +---@field modStruts? number Struts modification (-1 to max) +---@field modArchCover? number Arch cover modification (-1 to max) +---@field modAerials? number Aerials modification (-1 to max) +---@field modTrimB? number Trim B modification (-1 to max) +---@field modTank? number Tank modification (-1 to max) +---@field modWindows? number Windows modification (-1 to max) +---@field modDoorR? number Door R modification (-1 to max) +---@field modLivery? number Livery modification (-1 to max) +---@field modLightbar? number Lightbar modification (-1 to max) +---@field modRoofLivery? number Roof livery modification (-1 to max) +---@field livery? number Vehicle livery (-1 to max) +---@field windows? number[] Array of damaged window indices +---@field doors? number[] Array of damaged door indices +---@field tyres? table Map of tyre index to damage state (1=burst, 2=destroyed) +---@field bulletProofTyres? boolean Bulletproof tyres enabled +---@field driftTyres? boolean Drift tyres enabled +---@field doorLockStatus? number Door lock status (0=none, 1=unlocked, 2=locked, 3=lockout, 4=can't enter) +---@field brokenWheels? number|number[] Single wheel index or array of wheel indices to break off (0-7) + +-- Handle state bag changes for vehicle properties +AddStateBagChangeHandler('community_bridge:SetVehicleProperties', '', function(bagName, _, value) + if not value or not GetEntityFromStateBagName then return end + + -- Wait for entity to exist with timeout + local entity = nil + local attempts = 0 + local maxAttempts = 100 -- 10 seconds at 100ms intervals + + while not entity and attempts < maxAttempts do + local tempEntity = GetEntityFromStateBagName(bagName) + if tempEntity and tempEntity > 0 and DoesEntityExist(tempEntity) then + entity = tempEntity + break + end + attempts = attempts + 1 + Wait(100) + end + + if not entity then return end + + -- Apply vehicle properties from state bag (prevents infinite loops) + Vehicles.SetVehicleProperties(entity, value, true) + Wait(500) + + -- Clear state if we own the entity (prevents accumulation) + if NetworkGetEntityOwner(entity) == PlayerId() then + Vehicles.SetVehicleProperties(entity, value, true) + Entity(entity).state:set('community_bridge:SetVehicleProperties', nil, false) + end +end) + +local gameBuild = GetGameBuildNumber() + +---Get comprehensive vehicle properties +---@param vehicle number The vehicle entity handle +---@return VehicleProperties|nil properties Table containing all vehicle properties, or nil if vehicle doesn't exist +function Vehicles.GetVehicleProperties(vehicle) + if not DoesEntityExist(vehicle) then return end + + local colorPrimary, colorSecondary = GetVehicleColours(vehicle) + local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle) + local paintType1 = GetVehicleModColor_1(vehicle) + local paintType2 = GetVehicleModColor_2(vehicle) + + -- Handle custom colors (can be either number or table) + local primaryColor = colorPrimary --[[@as number|table]] + local secondaryColor = colorSecondary --[[@as number|table]] + + if GetIsVehiclePrimaryColourCustom(vehicle) then + local r, g, b = GetVehicleCustomPrimaryColour(vehicle) + primaryColor = { r, g, b } + end + + if GetIsVehicleSecondaryColourCustom(vehicle) then + local r, g, b = GetVehicleCustomSecondaryColour(vehicle) + secondaryColor = { r, g, b } + end + + -- Get vehicle extras + local extras = {} + for i = 1, 15 do + if DoesExtraExist(vehicle, i) then + extras[i] = IsVehicleExtraTurnedOn(vehicle, i) and 0 or 1 + end + end + + -- Get vehicle damage information + local damage = { + windows = {}, + doors = {}, + tyres = {}, + brokenWheels = {}, + } + + -- Check window damage + local windows = 0 + for i = 0, 7 do + RollUpWindow(vehicle, i) + if not IsVehicleWindowIntact(vehicle, i) then + windows += 1 + damage.windows[windows] = i + end + end + + -- Check door damage + local doors = 0 + for i = 0, 5 do + if IsVehicleDoorDamaged(vehicle, i) then + doors += 1 + damage.doors[doors] = i + end + end + + -- Check tyre damage + for i = 0, 7 do + if IsVehicleTyreBurst(vehicle, i, false) then + damage.tyres[i] = IsVehicleTyreBurst(vehicle, i, true) and 2 or 1 + end + end + + -- Check broken wheels + for i = 0, 7 do + if IsVehicleWheelBrokenOff(vehicle, i) then + table.insert(damage.brokenWheels, i) + end + end + + -- Get neon light status + local neons = {} + for i = 0, 3 do + neons[i + 1] = IsVehicleNeonLightEnabled(vehicle, i) + end + + return { + model = GetEntityModel(vehicle), + plate = GetVehicleNumberPlateText(vehicle), + plateIndex = GetVehicleNumberPlateTextIndex(vehicle), + bodyHealth = math.floor(GetVehicleBodyHealth(vehicle) + 0.5), + engineHealth = math.floor(GetVehicleEngineHealth(vehicle) + 0.5), + tankHealth = math.floor(GetVehiclePetrolTankHealth(vehicle) + 0.5), + fuelLevel = math.floor(GetVehicleFuelLevel(vehicle) + 0.5), + oilLevel = math.floor(GetVehicleOilLevel(vehicle) + 0.5), + dirtLevel = math.floor(GetVehicleDirtLevel(vehicle) + 0.5), + paintType1 = paintType1, + paintType2 = paintType2, + color1 = primaryColor, + color2 = secondaryColor, + pearlescentColor = pearlescentColor, + interiorColor = GetVehicleInteriorColor(vehicle), + dashboardColor = GetVehicleDashboardColour(vehicle), + wheelColor = wheelColor, + wheelWidth = GetVehicleWheelWidth(vehicle), + wheelSize = GetVehicleWheelSize(vehicle), + wheels = GetVehicleWheelType(vehicle), + windowTint = GetVehicleWindowTint(vehicle), + xenonColor = GetVehicleXenonLightsColor(vehicle), + neonEnabled = neons, + neonColor = { GetVehicleNeonLightsColour(vehicle) }, + extras = extras, + tyreSmokeColor = { GetVehicleTyreSmokeColor(vehicle) }, + modSpoilers = GetVehicleMod(vehicle, 0), + modFrontBumper = GetVehicleMod(vehicle, 1), + modRearBumper = GetVehicleMod(vehicle, 2), + modSideSkirt = GetVehicleMod(vehicle, 3), + modExhaust = GetVehicleMod(vehicle, 4), + modFrame = GetVehicleMod(vehicle, 5), + modGrille = GetVehicleMod(vehicle, 6), + modHood = GetVehicleMod(vehicle, 7), + modFender = GetVehicleMod(vehicle, 8), + modRightFender = GetVehicleMod(vehicle, 9), + modRoof = GetVehicleMod(vehicle, 10), + modEngine = GetVehicleMod(vehicle, 11), + modBrakes = GetVehicleMod(vehicle, 12), + modTransmission = GetVehicleMod(vehicle, 13), + modHorns = GetVehicleMod(vehicle, 14), + modSuspension = GetVehicleMod(vehicle, 15), + modArmor = GetVehicleMod(vehicle, 16), + modNitrous = GetVehicleMod(vehicle, 17), + modTurbo = IsToggleModOn(vehicle, 18), + modSubwoofer = GetVehicleMod(vehicle, 19), + modSmokeEnabled = IsToggleModOn(vehicle, 20), + modHydraulics = IsToggleModOn(vehicle, 21), + modXenon = IsToggleModOn(vehicle, 22), + modFrontWheels = GetVehicleMod(vehicle, 23), + modBackWheels = GetVehicleMod(vehicle, 24), + modCustomTiresF = GetVehicleModVariation(vehicle, 23), + modCustomTiresR = GetVehicleModVariation(vehicle, 24), + modPlateHolder = GetVehicleMod(vehicle, 25), + modVanityPlate = GetVehicleMod(vehicle, 26), + modTrimA = GetVehicleMod(vehicle, 27), + modOrnaments = GetVehicleMod(vehicle, 28), + modDashboard = GetVehicleMod(vehicle, 29), + modDial = GetVehicleMod(vehicle, 30), + modDoorSpeaker = GetVehicleMod(vehicle, 31), + modSeats = GetVehicleMod(vehicle, 32), + modSteeringWheel = GetVehicleMod(vehicle, 33), + modShifterLeavers = GetVehicleMod(vehicle, 34), + modAPlate = GetVehicleMod(vehicle, 35), + modSpeakers = GetVehicleMod(vehicle, 36), + modTrunk = GetVehicleMod(vehicle, 37), + modHydrolic = GetVehicleMod(vehicle, 38), + modEngineBlock = GetVehicleMod(vehicle, 39), + modAirFilter = GetVehicleMod(vehicle, 40), + modStruts = GetVehicleMod(vehicle, 41), + modArchCover = GetVehicleMod(vehicle, 42), + modAerials = GetVehicleMod(vehicle, 43), + modTrimB = GetVehicleMod(vehicle, 44), + modTank = GetVehicleMod(vehicle, 45), + modWindows = GetVehicleMod(vehicle, 46), + modDoorR = GetVehicleMod(vehicle, 47), + modLivery = GetVehicleMod(vehicle, 48), + modRoofLivery = GetVehicleRoofLivery(vehicle), + modLightbar = GetVehicleMod(vehicle, 49), + livery = GetVehicleLivery(vehicle), + windows = damage.windows, + doors = damage.doors, + tyres = damage.tyres, + brokenWheels = damage.brokenWheels, + bulletProofTyres = GetVehicleTyresCanBurst(vehicle), + driftTyres = gameBuild >= 2372 and GetDriftTyresEnabled(vehicle), + doorLockStatus = GetVehicleDoorLockStatus(vehicle), + } +end + +---Apply vehicle properties to a vehicle +---@param vehicle number The vehicle entity handle +---@param props VehicleProperties Table containing vehicle properties to apply +---@param fromStateBag? boolean Internal flag to prevent infinite loops when called from state bag handler +function Vehicles.SetVehicleProperties(vehicle, props, fromStateBag) + if not DoesEntityExist(vehicle) then return false end + + local colorPrimary, colorSecondary = GetVehicleColours(vehicle) + local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle) + + SetVehicleModKit(vehicle, 0) + + -- Apply vehicle extras + if props.extras then + for id, disable in pairs(props.extras) do + local extraId = tonumber(id) + if extraId then + SetVehicleExtra(vehicle, extraId, disable == 1) + end + end + end + + if props.plate then SetVehicleNumberPlateText(vehicle, props.plate) end + if props.plateIndex then SetVehicleNumberPlateTextIndex(vehicle, props.plateIndex) end + if props.bodyHealth then SetVehicleBodyHealth(vehicle, props.bodyHealth + 0.0) end + if props.engineHealth then SetVehicleEngineHealth(vehicle, props.engineHealth + 0.0) end + if props.tankHealth then SetVehiclePetrolTankHealth(vehicle, props.tankHealth + 0.0) end + if props.fuelLevel then SetVehicleFuelLevel(vehicle, props.fuelLevel + 0.0) end + if props.oilLevel then SetVehicleOilLevel(vehicle, props.oilLevel + 0.0) end + if props.dirtLevel then SetVehicleDirtLevel(vehicle, props.dirtLevel + 0.0) end + + -- Apply vehicle colors + if props.color1 then + if type(props.color1) == 'number' then + ClearVehicleCustomPrimaryColour(vehicle) + SetVehicleColours(vehicle, props.color1 --[[@as number]], colorSecondary --[[@as number]]) + else + if props.paintType1 then + SetVehicleModColor_1(vehicle, props.paintType1, 0, props.pearlescentColor or 0) + end + SetVehicleCustomPrimaryColour(vehicle, props.color1[1], props.color1[2], props.color1[3]) + end + end + + if props.color2 then + if type(props.color2) == 'number' then + ClearVehicleCustomSecondaryColour(vehicle) + SetVehicleColours(vehicle, props.color1 or colorPrimary --[[@as number]], props.color2 --[[@as number]]) + else + if props.paintType2 then + SetVehicleModColor_2(vehicle, props.paintType2, 0) + end + SetVehicleCustomSecondaryColour(vehicle, props.color2[1], props.color2[2], props.color2[3]) + end + end + + if props.pearlescentColor or props.wheelColor then + SetVehicleExtraColours(vehicle, props.pearlescentColor or pearlescentColor, props.wheelColor or wheelColor) + end + + if props.interiorColor then SetVehicleInteriorColor(vehicle, props.interiorColor) end + + if props.dashboardColor then SetVehicleDashboardColor(vehicle, props.dashboardColor) end + + -- Apply wheel properties + if props.wheels then SetVehicleWheelType(vehicle, props.wheels) end + + if props.wheelSize then SetVehicleWheelSize(vehicle, props.wheelSize) end + + if props.wheelWidth then + SetVehicleWheelWidth(vehicle, props.wheelWidth) + end + + -- Apply window and lighting properties + if props.windowTint then SetVehicleWindowTint(vehicle, props.windowTint) end + + if props.neonEnabled then + for i = 1, #props.neonEnabled do + SetVehicleNeonLightEnabled(vehicle, i - 1, props.neonEnabled[i]) + end + end + + if props.neonColor then SetVehicleNeonLightsColour(vehicle, props.neonColor[1], props.neonColor[2], props.neonColor[3]) end + + -- Apply vehicle damage + if props.windows then + for i = 1, #props.windows do + RemoveVehicleWindow(vehicle, props.windows[i]) + end + end + + if props.doors then + for i = 1, #props.doors do + SetVehicleDoorBroken(vehicle, props.doors[i], true) + end + end + + if props.tyres then + for tyre, state in pairs(props.tyres) do + SetVehicleTyreBurst(vehicle, tonumber(tyre) --[[@as number]], state == 2, 1000.0) + end + end + + if props.brokenWheels then + if type(props.brokenWheels) == 'number' then + BreakOffVehicleWheel(vehicle, props.brokenWheels --[[@as number]], false, true, true, false) + else + for i = 1, #props.brokenWheels do + BreakOffVehicleWheel(vehicle, props.brokenWheels[i], false, true, true, false) + end + end + end + + if props.modSmokeEnabled ~= nil then ToggleVehicleMod(vehicle, 20, props.modSmokeEnabled) end + + if props.tyreSmokeColor then SetVehicleTyreSmokeColor(vehicle, props.tyreSmokeColor[1], props.tyreSmokeColor[2], props.tyreSmokeColor[3]) end + + if props.modSpoilers then SetVehicleMod(vehicle, 0, props.modSpoilers, false) end + if props.modFrontBumper then SetVehicleMod(vehicle, 1, props.modFrontBumper, false) end + if props.modRearBumper then SetVehicleMod(vehicle, 2, props.modRearBumper, false) end + if props.modSideSkirt then SetVehicleMod(vehicle, 3, props.modSideSkirt, false) end + if props.modExhaust then SetVehicleMod(vehicle, 4, props.modExhaust, false) end + if props.modFrame then SetVehicleMod(vehicle, 5, props.modFrame, false) end + if props.modGrille then SetVehicleMod(vehicle, 6, props.modGrille, false) end + if props.modHood then SetVehicleMod(vehicle, 7, props.modHood, false) end + if props.modFender then SetVehicleMod(vehicle, 8, props.modFender, false) end + if props.modRightFender then SetVehicleMod(vehicle, 9, props.modRightFender, false) end + if props.modRoof then SetVehicleMod(vehicle, 10, props.modRoof, false) end + + if props.modEngine then SetVehicleMod(vehicle, 11, props.modEngine, false) end + if props.modBrakes then SetVehicleMod(vehicle, 12, props.modBrakes, false) end + if props.modTransmission then SetVehicleMod(vehicle, 13, props.modTransmission, false) end + if props.modSuspension then SetVehicleMod(vehicle, 15, props.modSuspension, false) end + if props.modArmor then SetVehicleMod(vehicle, 16, props.modArmor, false) end + if props.modNitrous then SetVehicleMod(vehicle, 17, props.modNitrous, false) end + + if props.modTurbo ~= nil then ToggleVehicleMod(vehicle, 18, props.modTurbo) end + if props.modSubwoofer ~= nil then ToggleVehicleMod(vehicle, 19, props.modSubwoofer) end + if props.modHydraulics ~= nil then ToggleVehicleMod(vehicle, 21, props.modHydraulics) end + if props.modXenon ~= nil then ToggleVehicleMod(vehicle, 22, props.modXenon) end + + if props.modHorns then SetVehicleMod(vehicle, 14, props.modHorns, false) end + if props.xenonColor then SetVehicleXenonLightsColor(vehicle, props.xenonColor) end + + if props.modFrontWheels then SetVehicleMod(vehicle, 23, props.modFrontWheels, props.modCustomTiresF) end + if props.modBackWheels then SetVehicleMod(vehicle, 24, props.modBackWheels, props.modCustomTiresR) end + + if props.modPlateHolder then SetVehicleMod(vehicle, 25, props.modPlateHolder, false) end + if props.modVanityPlate then SetVehicleMod(vehicle, 26, props.modVanityPlate, false) end + if props.modTrimA then SetVehicleMod(vehicle, 27, props.modTrimA, false) end + if props.modOrnaments then SetVehicleMod(vehicle, 28, props.modOrnaments, false) end + if props.modDashboard then SetVehicleMod(vehicle, 29, props.modDashboard, false) end + if props.modDial then SetVehicleMod(vehicle, 30, props.modDial, false) end + if props.modDoorSpeaker then SetVehicleMod(vehicle, 31, props.modDoorSpeaker, false) end + if props.modSeats then SetVehicleMod(vehicle, 32, props.modSeats, false) end + if props.modSteeringWheel then SetVehicleMod(vehicle, 33, props.modSteeringWheel, false) end + if props.modShifterLeavers then SetVehicleMod(vehicle, 34, props.modShifterLeavers, false) end + + if props.modAPlate then SetVehicleMod(vehicle, 35, props.modAPlate, false) end + if props.modSpeakers then SetVehicleMod(vehicle, 36, props.modSpeakers, false) end + if props.modTrunk then SetVehicleMod(vehicle, 37, props.modTrunk, false) end + if props.modHydrolic then SetVehicleMod(vehicle, 38, props.modHydrolic, false) end + if props.modEngineBlock then SetVehicleMod(vehicle, 39, props.modEngineBlock, false) end + if props.modAirFilter then SetVehicleMod(vehicle, 40, props.modAirFilter, false) end + if props.modStruts then SetVehicleMod(vehicle, 41, props.modStruts, false) end + if props.modArchCover then SetVehicleMod(vehicle, 42, props.modArchCover, false) end + if props.modAerials then SetVehicleMod(vehicle, 43, props.modAerials, false) end + if props.modTrimB then SetVehicleMod(vehicle, 44, props.modTrimB, false) end + if props.modTank then SetVehicleMod(vehicle, 45, props.modTank, false) end + if props.modWindows then SetVehicleMod(vehicle, 46, props.modWindows, false) end + if props.modDoorR then SetVehicleMod(vehicle, 47, props.modDoorR, false) end + if props.modLivery then SetVehicleMod(vehicle, 48, props.modLivery, false) end + if props.modLightbar then SetVehicleMod(vehicle, 49, props.modLightbar, false) end + + if props.modRoofLivery then SetVehicleRoofLivery(vehicle, props.modRoofLivery) end + if props.livery then SetVehicleLivery(vehicle, props.livery) end + + if props.bulletProofTyres ~= nil then SetVehicleTyresCanBurst(vehicle, props.bulletProofTyres) end + if gameBuild >= 2372 and props.driftTyres then SetDriftTyresEnabled(vehicle, true) end + + if props.doorLockStatus then + SetVehicleDoorsLocked(vehicle, props.doorLockStatus) + end + + if not DecorExistOn(vehicle, "Player_Vehicle") then DecorSetInt(vehicle, "Player_Vehicle", -1) end + + -- Only sync to other clients if not called from state bag AND we own the entity + if not fromStateBag and NetworkGetEntityIsNetworked(vehicle) and NetworkGetEntityOwner(vehicle) == PlayerId() then + Entity(vehicle).state:set('community_bridge:SetVehicleProperties', props, true) + if props.doorLockStatus then Entity(vehicle).state:set('door', tonumber(props.doorLockStatus), true) end + end + + return true +end + +return Vehicles \ No newline at end of file From 87345fafce71df8825b6d9687cd1e6cb967d3c4b Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Thu, 4 Sep 2025 07:27:40 -0400 Subject: [PATCH 52/62] Add GetHunger and GetThirst functions to frameworks Introduced GetHunger and GetThirst functions to client and server files for es_extended, qb-core, and qbx_core frameworks. These functions return the player's hunger and thirst values rounded to the nearest integer, improving consistency in status retrieval. --- modules/framework/es_extended/client.lua | 18 ++++++++++++++++++ modules/framework/es_extended/server.lua | 4 ++-- modules/framework/qb-core/client.lua | 18 ++++++++++++++++++ modules/framework/qb-core/server.lua | 4 ++-- modules/framework/qbx_core/client.lua | 18 ++++++++++++++++++ 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/modules/framework/es_extended/client.lua b/modules/framework/es_extended/client.lua index a37df82..c3abf66 100644 --- a/modules/framework/es_extended/client.lua +++ b/modules/framework/es_extended/client.lua @@ -124,6 +124,24 @@ Framework.GetPlayerJobData = function() } end +---This will get the hunger of a player +---@return number +Framework.GetHunger = function() + local playerData = Framework.GetPlayerData() + if not playerData then return 0 end + local status = playerData.variables.status + return math.floor((status.hunger.percent) + 0.5) or 0 +end + +---This will get the thirst of a player +---@return number +Framework.GetThirst = function() + local playerData = Framework.GetPlayerData() + if not playerData then return 0 end + local status = playerData.variables.status + return math.floor((status.thirst.percent) + 0.5) or 0 +end + --- @description This will return if the player has the specified item in their inventory --- @param item string --- @return boolean diff --git a/modules/framework/es_extended/server.lua b/modules/framework/es_extended/server.lua index f4a68a6..5f27420 100644 --- a/modules/framework/es_extended/server.lua +++ b/modules/framework/es_extended/server.lua @@ -257,7 +257,7 @@ Framework.GetHunger = function(src) for _, entry in ipairs(status) do if entry.name == "hunger" then - return math.floor(entry.percent) + return math.floor((entry.percent) + 0.5) or 0 end end end @@ -271,7 +271,7 @@ Framework.GetThirst = function(src) for _, entry in ipairs(status) do if entry.name == "thirst" then - return math.floor(entry.percent) + return math.floor((entry.percent) + 0.5) or 0 end end end diff --git a/modules/framework/qb-core/client.lua b/modules/framework/qb-core/client.lua index f734482..55a4725 100644 --- a/modules/framework/qb-core/client.lua +++ b/modules/framework/qb-core/client.lua @@ -109,6 +109,24 @@ Framework.GetItemInfo = function(item) return repackedTable end +---This will get the hunger of a player +---@return number +Framework.GetHunger = function() + local player = Framework.GetPlayerData() + if not player then return 0 end + local playerData = player.PlayerData + return math.floor((playerData.metadata.hunger) + 0.5) or 0 +end + +---This will get the thirst of a player +---@return number +Framework.GetThirst = function() + local player = Framework.GetPlayerData() + if not player then return 0 end + local playerData = player.PlayerData + return math.floor((playerData.metadata.thirst) + 0.5) or 0 +end + ---This will get the players identifier (citizenid) etc. ---@return string Framework.GetPlayerIdentifier = function() diff --git a/modules/framework/qb-core/server.lua b/modules/framework/qb-core/server.lua index 1ba3d10..f346988 100644 --- a/modules/framework/qb-core/server.lua +++ b/modules/framework/qb-core/server.lua @@ -303,7 +303,7 @@ Framework.GetHunger = function(src) if not player then return end local playerData = player.PlayerData local newHunger = (playerData.metadata.hunger or 0) - return newHunger + return math.floor((newHunger) + 0.5) or 0 end ---This will return a boolean if the player is dead or in last stand. @@ -335,7 +335,7 @@ Framework.GetThirst = function(src) if not player then return end local playerData = player.PlayerData local newThirst = (playerData.metadata.thirst or 0) - return newThirst + return math.floor((newThirst) + 0.5) or 0 end -- Framework.GetPlayerPhone(src) diff --git a/modules/framework/qbx_core/client.lua b/modules/framework/qbx_core/client.lua index 7ba21b9..31eb326 100644 --- a/modules/framework/qbx_core/client.lua +++ b/modules/framework/qbx_core/client.lua @@ -68,6 +68,24 @@ Framework.Notify = function(message, type, time) return QBox:Notify("Notification", type, time, message) end +---This will get the hunger of a player +---@return number +Framework.GetHunger = function() + local player = Framework.GetPlayerData() + if not player then return 0 end + local playerData = player.PlayerData + return math.floor((playerData.metadata.hunger) + 0.5) or 0 +end + +---This will get the thirst of a player +---@return number +Framework.GetThirst = function() + local player = Framework.GetPlayerData() + if not player then return 0 end + local playerData = player.PlayerData + return math.floor((playerData.metadata.thirst) + 0.5) or 0 +end + ---This will get the players identifier (citizenid) etc. ---@return string Framework.GetPlayerIdentifier = function() From cfd746d889be777e6be49dc18af047097e4d8224 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Thu, 4 Sep 2025 07:35:21 -0400 Subject: [PATCH 53/62] Refactor hunger and thirst retrieval logic Introduced Framework.GetStatusData to centralize status lookup. Updated GetHunger and GetThirst to use the new function, improving code reuse and maintainability. --- modules/framework/es_extended/client.lua | 25 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/modules/framework/es_extended/client.lua b/modules/framework/es_extended/client.lua index c3abf66..1980d6d 100644 --- a/modules/framework/es_extended/client.lua +++ b/modules/framework/es_extended/client.lua @@ -124,22 +124,31 @@ Framework.GetPlayerJobData = function() } end +--This is an internal function to get status data +--- @param search string +Framework.GetStatusData = function(search) + local playerData = Framework.GetPlayerData() + local status = playerData.variables.status + for _, entry in ipairs(status) do + if entry.name == search then + return entry.percent or 0 + end + end + return 0 +end + ---This will get the hunger of a player ---@return number Framework.GetHunger = function() - local playerData = Framework.GetPlayerData() - if not playerData then return 0 end - local status = playerData.variables.status - return math.floor((status.hunger.percent) + 0.5) or 0 + local status = Framework.GetStatusData("hunger") + return math.floor((status) + 0.5) or 0 end ---This will get the thirst of a player ---@return number Framework.GetThirst = function() - local playerData = Framework.GetPlayerData() - if not playerData then return 0 end - local status = playerData.variables.status - return math.floor((status.thirst.percent) + 0.5) or 0 + local status = Framework.GetStatusData("thirst") + return math.floor((status) + 0.5) or 0 end --- @description This will return if the player has the specified item in their inventory From 943f86d47bc2a468ad32fc7b1e3939f8a9a0e467 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Thu, 4 Sep 2025 07:38:50 -0400 Subject: [PATCH 54/62] Add nil check for player data in GetStatusData Prevents errors by returning 0 if player data is unavailable when calling Framework.GetStatusData. --- modules/framework/es_extended/client.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/framework/es_extended/client.lua b/modules/framework/es_extended/client.lua index 1980d6d..e8f1d34 100644 --- a/modules/framework/es_extended/client.lua +++ b/modules/framework/es_extended/client.lua @@ -128,6 +128,7 @@ end --- @param search string Framework.GetStatusData = function(search) local playerData = Framework.GetPlayerData() + if not playerData then return 0 end local status = playerData.variables.status for _, entry in ipairs(status) do if entry.name == search then From aae3d540ff914b43141e861f8635107fac5bbbaa Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Thu, 4 Sep 2025 08:13:47 -0400 Subject: [PATCH 55/62] Update server.lua --- modules/framework/es_extended/server.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/framework/es_extended/server.lua b/modules/framework/es_extended/server.lua index 5f27420..6af30ab 100644 --- a/modules/framework/es_extended/server.lua +++ b/modules/framework/es_extended/server.lua @@ -252,9 +252,9 @@ end --- @param src number --- @return number | nil Framework.GetHunger = function(src) - local status = Framework.GetStatus(src, "status") - if not status then return nil end - + local status = Framework.GetStatus(src, "hunger") + if not status then return end + if type(status) ~= "table" then return end for _, entry in ipairs(status) do if entry.name == "hunger" then return math.floor((entry.percent) + 0.5) or 0 @@ -266,9 +266,9 @@ end --- @param src any --- @return number | nil Framework.GetThirst = function(src) - local status = Framework.GetStatus(src, "status") + local status = Framework.GetStatus(src, "thirst") if not status then return nil end - + if type(status) ~= "table" then return end for _, entry in ipairs(status) do if entry.name == "thirst" then return math.floor((entry.percent) + 0.5) or 0 From 8bf02f6372a0d57f2cf14e959eeb9ae5dd13c47d Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Thu, 4 Sep 2025 08:15:02 -0400 Subject: [PATCH 56/62] Fix hunger and thirst status retrieval Changed Framework.GetHunger and Framework.GetThirst to fetch the 'status' instead of 'hunger' or 'thirst' directly. This ensures the functions correctly iterate over the status table to find the relevant values. --- modules/framework/es_extended/server.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/framework/es_extended/server.lua b/modules/framework/es_extended/server.lua index 6af30ab..e1abfc0 100644 --- a/modules/framework/es_extended/server.lua +++ b/modules/framework/es_extended/server.lua @@ -252,7 +252,7 @@ end --- @param src number --- @return number | nil Framework.GetHunger = function(src) - local status = Framework.GetStatus(src, "hunger") + local status = Framework.GetStatus(src, "status") if not status then return end if type(status) ~= "table" then return end for _, entry in ipairs(status) do @@ -266,7 +266,7 @@ end --- @param src any --- @return number | nil Framework.GetThirst = function(src) - local status = Framework.GetStatus(src, "thirst") + local status = Framework.GetStatus(src, "status") if not status then return nil end if type(status) ~= "table" then return end for _, entry in ipairs(status) do From 08c3d937d61fa4ed4702d433b95312109fdbb679 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Wed, 10 Sep 2025 11:19:55 -0400 Subject: [PATCH 57/62] Round hunger and thirst values to nearest integer Updated GetHunger and GetThirst functions to return rounded integer values using math.floor(value + 0.5) for consistency and to avoid floating point results. --- modules/framework/qbx_core/server.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/framework/qbx_core/server.lua b/modules/framework/qbx_core/server.lua index de994dd..e20c2c5 100644 --- a/modules/framework/qbx_core/server.lua +++ b/modules/framework/qbx_core/server.lua @@ -234,7 +234,7 @@ Framework.GetHunger = function(src) if not player then return end local playerData = player.PlayerData local newHunger = (playerData.metadata.hunger or 0) - return newHunger + return math.floor((newHunger) + 0.5) or 0 end ---This will return a boolean if the player is dead or in last stand. @@ -265,7 +265,7 @@ Framework.GetThirst = function(src) if not player then return end local playerData = player.PlayerData local newThirst = (playerData.metadata.thirst or 0) - return newThirst + return math.floor((newThirst) + 0.5) or 0 end ---Returns the phone number of the player. From f4e5d9485f38460e4c9473dc43bcc9c4a364430f Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Wed, 10 Sep 2025 11:29:19 -0400 Subject: [PATCH 58/62] Refactor hunger and thirst retrieval methods Simplified Framework.GetHunger and Framework.GetThirst functions in both qb-core and qbx_core by using Framework.GetPlayerMetaData instead of accessing player data directly. This improves code readability and consistency. --- modules/framework/qb-core/client.lua | 12 ++++-------- modules/framework/qbx_core/client.lua | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/modules/framework/qb-core/client.lua b/modules/framework/qb-core/client.lua index 55a4725..b85410b 100644 --- a/modules/framework/qb-core/client.lua +++ b/modules/framework/qb-core/client.lua @@ -112,19 +112,15 @@ end ---This will get the hunger of a player ---@return number Framework.GetHunger = function() - local player = Framework.GetPlayerData() - if not player then return 0 end - local playerData = player.PlayerData - return math.floor((playerData.metadata.hunger) + 0.5) or 0 + local hunger = Framework.GetPlayerMetaData("hunger") or 0 + return math.floor((hunger) + 0.5) or 0 end ---This will get the thirst of a player ---@return number Framework.GetThirst = function() - local player = Framework.GetPlayerData() - if not player then return 0 end - local playerData = player.PlayerData - return math.floor((playerData.metadata.thirst) + 0.5) or 0 + local thirst = Framework.GetPlayerMetaData("thirst") or 0 + return math.floor((thirst) + 0.5) or 0 end ---This will get the players identifier (citizenid) etc. diff --git a/modules/framework/qbx_core/client.lua b/modules/framework/qbx_core/client.lua index 31eb326..5f90b59 100644 --- a/modules/framework/qbx_core/client.lua +++ b/modules/framework/qbx_core/client.lua @@ -71,19 +71,15 @@ end ---This will get the hunger of a player ---@return number Framework.GetHunger = function() - local player = Framework.GetPlayerData() - if not player then return 0 end - local playerData = player.PlayerData - return math.floor((playerData.metadata.hunger) + 0.5) or 0 + local hunger = Framework.GetPlayerMetaData("hunger") or 0 + return math.floor((hunger) + 0.5) or 0 end ---This will get the thirst of a player ---@return number Framework.GetThirst = function() - local player = Framework.GetPlayerData() - if not player then return 0 end - local playerData = player.PlayerData - return math.floor((playerData.metadata.thirst) + 0.5) or 0 + local thirst = Framework.GetPlayerMetaData("thirst") or 0 + return math.floor((thirst) + 0.5) or 0 end ---This will get the players identifier (citizenid) etc. From e7de2972fd32945c4f4a256b05b194ea80c29d3d Mon Sep 17 00:00:00 2001 From: "Mr.Crowley" Date: Wed, 10 Sep 2025 10:44:57 -0500 Subject: [PATCH 59/62] Add client/server entity examples and improve 3D help text Added new example scripts for client and server entity creation, demonstrating features like clothing, particles, scenarios, and targets. Enhanced Utility.Draw3DHelpText to support multi-line text and improved background rendering for better readability. --- examples/cliententities.lua | 367 +++++++++++++++++++++++++++++++++ examples/serverentities.lua | 115 +++++++++++ lib/utility/client/utility.lua | 37 +++- 3 files changed, 508 insertions(+), 11 deletions(-) create mode 100644 examples/cliententities.lua create mode 100644 examples/serverentities.lua diff --git a/examples/cliententities.lua b/examples/cliententities.lua new file mode 100644 index 0000000..a303466 --- /dev/null +++ b/examples/cliententities.lua @@ -0,0 +1,367 @@ +Bridge = Bridge or exports['community_bridge']:Bridge() +-- RegisterCommand("ClientEntityParticles", function() +-- local position = GetEntityCoords(PlayerPedId()) +-- local data = Bridge.ClientEntity.Create({ +-- id = "particle_" .. math.random(1, 10000), +-- model = "mp_m_freemode_01", +-- coords = position, +-- entityType = "ped", +-- freeze = false, +-- follow = { +-- target = 1, +-- }, +-- weapon = { +-- name = "WEAPON_PISTOL", +-- ammo = 100 +-- }, +-- stash = { +-- -- id = "generate from server", +-- label = "Test Stash", +-- target = { +-- label = "Open Stash", +-- description = "Access the stash to store or retrieve items.", +-- icon = "fas fa-boxes" +-- } +-- }, +-- attach = { +-- target = 1, +-- bone = 57005, -- right hand +-- }, +-- scenarios = { +-- name = "WORLD_HUMAN_CLIPBOARD", +-- introClip = true, +-- duration = 20000 +-- }, +-- anim = { +-- dict = "anim@mp_player_intcelebrationmale@wave", +-- name = "wave", +-- flags = 49, +-- duration = -1, +-- onComplete = function(entityData) +-- Bridge.ClientEntity.Set(entityData.id, "anim", { +-- dict = "rcmnigel1c", +-- name = "hailing_whistle_waive_a", +-- flags = entityData.anim.flags, +-- duration = 10000, +-- onComplete = function(entityData) +-- Bridge.ClientEntity.Set(entityData.id, "anim", { +-- dict = "timetable@denice@ig_1", +-- name = "idle_b", +-- flags = entityData.anim.flags, +-- duration = 10000, +-- onComplete = function(entityData) +-- print("hello") +-- end +-- }) +-- end +-- }) +-- end +-- }, +-- clothing = { +-- components = { +-- { drawable = 0, texture = 0, component_id = 0 }, +-- { drawable = 0, texture = 0, component_id = 1 }, +-- { drawable = 19, texture = 0, component_id = 2 }, +-- { drawable = 6, texture = 0, component_id = 3 }, +-- { drawable = 0, texture = 0, component_id = 4 }, +-- { drawable = 0, texture = 0, component_id = 5 }, +-- { drawable = 0, texture = 0, component_id = 6 }, +-- { drawable = 0, texture = 0, component_id = 7 }, +-- { drawable = 23, texture = 0, component_id = 8 }, +-- { drawable = 0, texture = 0, component_id = 9 }, +-- { drawable = 0, texture = 0, component_id = 10 }, +-- { drawable = 4, texture = 2, component_id = 11 } +-- }, +-- props = { +-- { drawable = 27, prop_id = 0, texture = 0 }, +-- { drawable = 0, prop_id = 1, texture = 0 }, +-- { drawable = 0, prop_id = 2, texture = 0 }, +-- { drawable = 0, prop_id = 3, texture = 0 }, +-- { drawable = 0, prop_id = 4, texture = 0 }, +-- { drawable = 0, prop_id = 5, texture = 0 }, +-- { drawable = 0, prop_id = 6, texture = 0 }, +-- { drawable = 0, prop_id = 7, texture = 0 }, +-- { drawable = 0, prop_id = 8, texture = 0 }, +-- { drawable = 0, prop_id = 9, texture = 0 }, +-- { drawable = 0, prop_id = 10, texture = 0 }, +-- { drawable = 0, prop_id = 11, texture = 0 }, +-- { drawable = 0, prop_id = 12, texture = 0 }, +-- { drawable = 0, prop_id = 13, texture = 0 } +-- } +-- }, +-- particles = { +-- { +-- dict = "core", +-- ptfx = "ent_dst_electrical", +-- offset = vector3(0.0, 1.0, 0.0), +-- looped = true +-- }, +-- { +-- dict = "core", +-- ptfx = "ent_dst_electrical", +-- offset = vector3(0.0, -1.0, 0.0), +-- rotation = vector3(0.0, 0.0, 180.0), +-- looped = true, +-- loopLength = 1000 +-- } +-- }, +-- targets = { +-- { +-- label = "Follow Test", +-- distance = 2, +-- description = "A test particle for demonstration purposes.", +-- onSelect = function (entityData, entity) +-- FreezeEntityPosition(entity, false) +-- Bridge.ClientEntity.Set(entityData.id, "follow", { +-- target = PlayerPedId() +-- }) +-- end +-- } +-- }, +-- -- OnUpdate = function(entityData) + +-- -- end, +-- }) +-- -- Wait(5000) +-- Bridge.ClientEntity.Set(data.id, "targets", { +-- label = "This should be the new label", +-- distance = 2, +-- description = "Herpa derpa gihad", +-- onSelect = function (entityData, entity) +-- print("round 2 baby", entityData.id) +-- end +-- }) +-- end, false) + + +-- Bridge.ClientEntity.Behaviors.Create("plate", { +-- tag = "something", +-- OnCreate = function(entityData) + +-- end, +-- OnSpawn = function(entityData) + +-- end, +-- OnUpdate = function(entityData) +-- -- Update logic here +-- end, +-- OnRemove = function(entityData) + +-- end, +-- OnDestroy = function(entityData) + +-- end +-- }) + +RegisterCommand("ClientEntityFreeze", function() + local position = GetEntityCoords(PlayerPedId()) + local data = Bridge.ClientEntity.Create({ + model = "mp_m_freemode_01", + coords = position, + entityType = "ped", + freeze = true + }) + Wait(10000) + Bridge.ClientEntity.Set(data.id, "freeze", false) +end, false) + +RegisterCommand("ClientEntityFollow", function() + local position = GetEntityCoords(PlayerPedId()) + local serverId = GetPlayerServerId(PlayerId()) + local data = Bridge.ClientEntity.Create({ + model = "mp_m_freemode_01", + coords = position, + entityType = "ped", + freeze = false, + follow = { + speed = 3.0, + target = serverId, + distance = 5.0 + } + }) + print(data.id) +end, false) + +RegisterCommand("ClientEntityWeapon", function() + local position = GetEntityCoords(PlayerPedId()) + local data = Bridge.ClientEntity.Create({ + model = "mp_m_freemode_01", + coords = position, + entityType = "ped", + weapon = { + name = "WEAPON_PISTOL", + ammo = 100 + } + }) +end, false) + + +RegisterCommand("ClientEntityAttach", function() + local position = GetEntityCoords(PlayerPedId()) + local serverId = GetPlayerServerId(PlayerId()) + Bridge.ClientEntity.Create({ + id = "attach_" .. math.random(1, 10000), + model = "mp_m_freemode_01", + coords = position, + entityType = "ped", + attach = { + target = serverId, + bone = 57005 + } + }) +end, false) + +RegisterCommand("ClientEntityScenarios", function() + local position = GetEntityCoords(PlayerPedId()) + Bridge.ClientEntity.Create({ + id = "scenarios_" .. math.random(1, 10000), + model = "mp_m_freemode_01", + coords = position, + entityType = "ped", + scenarios = { + name = "WORLD_HUMAN_CLIPBOARD", + introClip = true, + duration = 20000 + } + }) +end, false) + +RegisterCommand("ClientEntityAnim", function() + local position = GetEntityCoords(PlayerPedId()) + Bridge.ClientEntity.Create({ + id = "anim_" .. math.random(1, 10000), + model = "mp_m_freemode_01", + coords = position, + entityType = "ped", + anim = { + dict = "anim@mp_player_intcelebrationmale@wave", + name = "wave", + flags = 49, + duration = -1, + onComplete = function(entityData) + Bridge.ClientEntity.Set(entityData.id, "anim", { + dict = "rcmnigel1c", + name = "hailing_whistle_waive_a", + flags = entityData.anim.flags, + duration = 10000, + onComplete = function(entityData) + Bridge.ClientEntity.Set(entityData.id, "anim", { + dict = "timetable@denice@ig_1", + name = "idle_b", + flags = entityData.anim.flags, + duration = 10000, + onComplete = function(entityData) + print("hello") + end + }) + end + }) + end + } + }) +end, false) + +RegisterCommand("ClientEntityClothing", function() + local position = GetEntityCoords(PlayerPedId()) + Bridge.ClientEntity.Create({ + id = "clothing_" .. math.random(1, 10000), + model = "mp_m_freemode_01", + coords = position, + entityType = "ped", + clothing = { + components = { + { drawable = 0, texture = 0, component_id = 0 }, + { drawable = 0, texture = 0, component_id = 1 }, + { drawable = 19, texture = 0, component_id = 2 }, + { drawable = 6, texture = 0, component_id = 3 }, + { drawable = 0, texture = 0, component_id = 4 }, + { drawable = 0, texture = 0, component_id = 5 }, + { drawable = 0, texture = 0, component_id = 6 }, + { drawable = 0, texture = 0, component_id = 7 }, + { drawable = 23, texture = 0, component_id = 8 }, + { drawable = 0, texture = 0, component_id = 9 }, + { drawable = 0, texture = 0, component_id = 10 }, + { drawable = 4, texture = 2, component_id = 11 } + }, + props = { + { drawable = 27, prop_id = 0, texture = 0 }, + { drawable = 0, prop_id = 1, texture = 0 }, + { drawable = 0, prop_id = 2, texture = 0 }, + { drawable = 0, prop_id = 3, texture = 0 }, + { drawable = 0, prop_id = 4, texture = 0 }, + { drawable = 0, prop_id = 5, texture = 0 }, + { drawable = 0, prop_id = 6, texture = 0 }, + { drawable = 0, prop_id = 7, texture = 0 }, + { drawable = 0, prop_id = 8, texture = 0 }, + { drawable = 0, prop_id = 9, texture = 0 }, + { drawable = 0, prop_id = 10, texture = 0 }, + { drawable = 0, prop_id = 11, texture = 0 }, + { drawable = 0, prop_id = 12, texture = 0 }, + { drawable = 0, prop_id = 13, texture = 0 } + } + } + }) +end, false) + +RegisterCommand("ClientEntityParticles", function() + local position = GetEntityCoords(PlayerPedId()) + Bridge.ClientEntity.Create({ + id = "particles_" .. math.random(1, 10000), + model = "mp_m_freemode_01", + coords = position, + entityType = "ped", + particles = { + { + dict = "core", + ptfx = "ent_dst_electrical", + offset = vector3(0.0, 1.0, 0.0), + looped = true + }, + { + dict = "core", + ptfx = "ent_dst_electrical", + offset = vector3(0.0, -1.0, 0.0), + rotation = vector3(0.0, 0.0, 180.0), + looped = true, + loopLength = 1000 + } + } + }) +end, false) + +RegisterCommand("ClientEntityTargets", function() + local position = GetEntityCoords(PlayerPedId()) + local derp = Bridge.ClientEntity.Create({ + id = "targets_" .. math.random(1, 10000), + model = "mp_m_freemode_01", + coords = position, + entityType = "ped", + targets = { + { + label = "Initial test", + distance = 2, + description = "A test particle for demonstration purposes.", + onSelect = function (entityData, entity) + print("Selected entity:", entityData.id) + end + } + } + }) + Wait(10000) + Bridge.ClientEntity.Set(derp.id, "targets", + { + { + label = "Follow Test", + distance = 2, + description = "A test particle for demonstration purposes.", + onSelect = function (entityData, entity) + Bridge.ClientEntity.Set(entityData.id, "freeze", false) + Bridge.ClientEntity.Set(entityData.id, "follow", { + target = PlayerPedId() + }) + end + } + } + ) +end, false) + diff --git a/examples/serverentities.lua b/examples/serverentities.lua new file mode 100644 index 0000000..bc9a558 --- /dev/null +++ b/examples/serverentities.lua @@ -0,0 +1,115 @@ +Bridge = Bridge or exports['community_bridge']:Bridge() + +RegisterCommand("ServerEntityStash", function(src) + local position = GetEntityCoords(GetPlayerPed(src)) - vector3(0,0,1) + Bridge.ServerEntity.Create({ + model = "mp_m_freemode_01", + coords = position, + entityType = "ped", + stash = { + label = "Test Stash", + slots = 20, + maxWeight = 10000, + target = { + label = "Open Stash", + description = "Access the stash to store or retrieve items.", + icon = "fas fa-boxes" + } + } + }) +end, false) + +RegisterCommand("ServerEntityScenarios", function(src) + local position = GetEntityCoords(GetPlayerPed(src)) - vector3(0,0,1) + Bridge.ServerEntity.Create({ + model = "mp_m_freemode_01", + coords = position, + entityType = "ped", + scenarios = { + name = "WORLD_HUMAN_CLIPBOARD", + introClip = true, + duration = 20000 + } + }) +end, false) + +RegisterCommand("ServerEntityAnim", function(src) + local position = GetEntityCoords(GetPlayerPed(src)) - vector3(0,0,1) + Bridge.ServerEntity.Create({ + model = "mp_m_freemode_01", + coords = position, + entityType = "ped", + anim = { + dict = "anim@mp_player_intcelebrationmale@wave", + name = "wave", + flags = 49, + duration = -1, + } + }) +end, false) + +RegisterCommand("ServerEntityParticles", function(src) + local position = GetEntityCoords(GetPlayerPed(src)) - vector3(0,0,1) + Bridge.ServerEntity.Create({ + model = "mp_m_freemode_01", + coords = position, + entityType = "ped", + particles = { + { + dict = "core", + ptfx = "ent_dst_electrical", + offset = vector3(0.0, 1.0, 0.0), + looped = true + }, + { + dict = "core", + ptfx = "ent_dst_electrical", + offset = vector3(0.0, -1.0, 0.0), + rotation = vector3(0.0, 0.0, 180.0), + looped = true, + loopLength = 1000 + } + } + }) +end, false) + +RegisterCommand("ServerEntityClothing", function(src) + local position = GetEntityCoords(GetPlayerPed(src)) - vector3(0,0,1) + Bridge.ServerEntity.Create({ + model = "mp_m_freemode_01", + coords = position, + entityType = "ped", + clothing = { + components = { + { drawable = 0, texture = 0, component_id = 0 }, + { drawable = 0, texture = 0, component_id = 1 }, + { drawable = 19, texture = 0, component_id = 2 }, + { drawable = 6, texture = 0, component_id = 3 }, + { drawable = 0, texture = 0, component_id = 4 }, + { drawable = 0, texture = 0, component_id = 5 }, + { drawable = 0, texture = 0, component_id = 6 }, + { drawable = 0, texture = 0, component_id = 7 }, + { drawable = 23, texture = 0, component_id = 8 }, + { drawable = 0, texture = 0, component_id = 9 }, + { drawable = 0, texture = 0, component_id = 10 }, + { drawable = 4, texture = 2, component_id = 11 } + }, + props = { + { drawable = 27, prop_id = 0, texture = 0 }, + { drawable = 0, prop_id = 1, texture = 0 }, + { drawable = 0, prop_id = 2, texture = 0 }, + { drawable = 0, prop_id = 3, texture = 0 }, + { drawable = 0, prop_id = 4, texture = 0 }, + { drawable = 0, prop_id = 5, texture = 0 }, + { drawable = 0, prop_id = 6, texture = 0 }, + { drawable = 0, prop_id = 7, texture = 0 }, + { drawable = 0, prop_id = 8, texture = 0 }, + { drawable = 0, prop_id = 9, texture = 0 }, + { drawable = 0, prop_id = 10, texture = 0 }, + { drawable = 0, prop_id = 11, texture = 0 }, + { drawable = 0, prop_id = 12, texture = 0 }, + { drawable = 0, prop_id = 13, texture = 0 } + } + } + }) +end, false) diff --git a/lib/utility/client/utility.lua b/lib/utility/client/utility.lua index 762d26f..f2e99f6 100644 --- a/lib/utility/client/utility.lua +++ b/lib/utility/client/utility.lua @@ -304,18 +304,33 @@ end ---@param scale number function Utility.Draw3DHelpText(coords, text, scale) local onScreen, x, y = GetScreenCoordFromWorldCoord(coords.x, coords.y, coords.z) - if onScreen then - SetTextScale(scale or 0.35, scale or 0.35) - SetTextFont(4) - SetTextProportional(true) - SetTextColour(255, 255, 255, 215) - SetTextEntry("STRING") - SetTextCentre(true) - AddTextComponentString(text) - DrawText(x, y) - local factor = (string.len(text)) / 370 - DrawRect(x, y + 0.0125, 0.015 + factor, 0.03, 41, 11, 41, 100) + if not onScreen then return end + local lineCount = 0 + local maxLineLen = 0 + for line in string.gmatch(text, "[^\n]+") do + lineCount = lineCount + 1 + maxLineLen = math.max(maxLineLen, string.len(line)) end + local widthFactor = maxLineLen * 0.012 * scale + local height = 0.06 * scale * lineCount + + -- Set text properties + SetTextScale(scale or 0.35, scale or 0.35) + SetTextFont(4) + SetTextProportional(true) + SetTextColour(255, 255, 255, 215) + SetTextEntry("STRING") + SetTextCentre(true) + AddTextComponentString(text) + DrawText(x, y) + + -- Draw background rectangle + DrawRect(x, y + height / 2, widthFactor + 0.015 + 0.006, height + 0.015 + 0.006, 10, 25, 47, 200) + DrawRect(x, y + height / 2, widthFactor + 0.015, height + 0.015, 17, 45, 78, 50) +end + +function Utility.Draw3DHelpTextExt(coords, text, scale) + end ---Show a native notification From 90c65dc55e361f6f68c18cffe2660d8ce4e01e4f Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Wed, 10 Sep 2025 12:27:12 -0400 Subject: [PATCH 60/62] Add GetResourceName function to all modules Introduces a standardized GetResourceName function to banking, clothing, dispatch, doorlock, framework, fuel, helptext, housing, and other modules. This function returns the name of the in-use resource, improving resource identification and interoperability across the codebase. --- modules/banking/_default/server.lua | 6 ++++++ modules/banking/fd_banking/server.lua | 6 ++++++ modules/banking/kartik-banking/server.lua | 6 ++++++ modules/banking/okokBanking/server.lua | 6 ++++++ modules/banking/qb-banking/server.lua | 6 ++++++ modules/banking/renewed-banking/server.lua | 6 ++++++ modules/banking/tgg-banking/server.lua | 6 ++++++ modules/banking/tgiann-bank/server.lua | 6 ++++++ modules/banking/wasabi_banking/server.lua | 6 ++++++ modules/clothing/_default/client.lua | 7 +++++++ modules/clothing/_default/server.lua | 6 ++++++ modules/clothing/esx_skin/client.lua | 6 ++++++ modules/clothing/esx_skin/server.lua | 6 ++++++ modules/clothing/fivem-appearance/client.lua | 6 ++++++ modules/clothing/fivem-appearance/server.lua | 6 ++++++ .../clothing/illenium-appearance/client.lua | 6 ++++++ .../clothing/illenium-appearance/server.lua | 6 ++++++ modules/clothing/qb-clothing/client.lua | 6 ++++++ modules/clothing/qb-clothing/server.lua | 6 ++++++ modules/clothing/rcore_clothing/client.lua | 6 ++++++ modules/dispatch/_default/client/client.lua | 6 ++++++ modules/dispatch/_default/server/server.lua | 6 ++++++ modules/dispatch/bub-mdt/client/client.lua | 6 ++++++ modules/dispatch/bub-mdt/server/server.lua | 6 ++++++ .../dispatch/cd_dispatch/client/client.lua | 6 ++++++ .../dispatch/cd_dispatch/server/server.lua | 6 ++++++ modules/dispatch/kartik-mdt/client/client.lua | 6 ++++++ modules/dispatch/kartik-mdt/server/server.lua | 6 ++++++ modules/dispatch/lb-tablet/client/client.lua | 6 ++++++ modules/dispatch/lb-tablet/server/server.lua | 6 ++++++ .../linden_outlawalert/client/client.lua | 6 ++++++ .../linden_outlawalert/server/server.lua | 6 ++++++ .../dispatch/origen_police/server/server.lua | 6 ++++++ .../dispatch/piotreq_gpt/client/client.lua | 6 ++++++ .../dispatch/piotreq_gpt/server/server.lua | 6 ++++++ .../dispatch/ps-dispatch/client/client.lua | 6 ++++++ .../dispatch/ps-dispatch/server/server.lua | 6 ++++++ .../dispatch/qs_dispatch/client/client.lua | 7 +++++++ .../dispatch/qs_dispatch/server/server.lua | 7 +++++++ .../dispatch/redutzu-mdt/client/client.lua | 7 +++++++ .../dispatch/redutzu-mdt/server/server.lua | 6 ++++++ .../dispatch/tk_dispatch/client/client.lua | 6 ++++++ .../dispatch/tk_dispatch/server/server.lua | 6 ++++++ modules/doorlock/_default/server.lua | 6 ++++++ modules/doorlock/doors_creator/client.lua | 6 ++++++ modules/doorlock/doors_creator/server.lua | 6 ++++++ modules/doorlock/ox_doorlock/client.lua | 6 ++++++ modules/doorlock/ox_doorlock/server.lua | 6 ++++++ modules/doorlock/qb-doorlock/client.lua | 6 ++++++ modules/doorlock/qb-doorlock/server.lua | 6 ++++++ modules/doorlock/rcore_doorlock/client.lua | 6 ++++++ modules/doorlock/rcore_doorlock/server.lua | 7 +++++++ modules/framework/_default/client.lua | 6 ++++++ modules/framework/_default/server.lua | 6 ++++++ modules/framework/es_extended/client.lua | 6 ++++++ modules/framework/es_extended/server.lua | 6 ++++++ modules/framework/qb-core/client.lua | 6 ++++++ modules/framework/qb-core/server.lua | 6 ++++++ modules/framework/qbx_core/client.lua | 6 ++++++ modules/framework/qbx_core/server.lua | 6 ++++++ modules/fuel/_default/client.lua | 1 + modules/helptext/_default/client.lua | 6 ++++++ modules/helptext/_default/server.lua | 6 ++++++ modules/helptext/cd_drawtextui/client.lua | 6 ++++++ modules/helptext/jg-textui/client.lua | 6 ++++++ modules/helptext/lab-HintUI/client.lua | 6 ++++++ modules/helptext/lation_ui/client.lua | 6 ++++++ modules/helptext/okokTextUI/client.lua | 6 ++++++ modules/helptext/ox_lib/client.lua | 6 ++++++ modules/housing/_default/client.lua | 6 ++++++ modules/housing/_default/server.lua | 6 ++++++ modules/housing/bcs-housing/client.lua | 6 ++++++ modules/housing/bcs-housing/server.lua | 6 ++++++ modules/housing/esx_property/client.lua | 6 ++++++ modules/housing/esx_property/server.lua | 6 ++++++ modules/housing/ps-housing/client.lua | 6 ++++++ modules/housing/ps-housing/server.lua | 6 ++++++ modules/housing/qb-appartments/client.lua | 6 ++++++ modules/housing/qb-appartments/server.lua | 7 +++++++ modules/housing/qb-houses/client.lua | 6 ++++++ modules/housing/qb-houses/server.lua | 6 ++++++ modules/inventory/_default/client.lua | 6 ++++++ modules/inventory/_default/server.lua | 7 +++++++ modules/inventory/codem-inventory/client.lua | 7 +++++++ modules/inventory/codem-inventory/server.lua | 7 +++++++ modules/inventory/core_inventory/client.lua | 7 +++++++ modules/inventory/core_inventory/server.lua | 8 ++++++++ modules/inventory/jpr-inventory/client.lua | 8 ++++++++ modules/inventory/jpr-inventory/server.lua | 6 ++++++ modules/inventory/origen_inventory/client.lua | 6 ++++++ modules/inventory/origen_inventory/server.lua | 6 ++++++ modules/inventory/ox_inventory/client.lua | 6 ++++++ modules/inventory/ox_inventory/server.lua | 6 ++++++ modules/inventory/ps-inventory/client.lua | 6 ++++++ modules/inventory/ps-inventory/server.lua | 6 ++++++ modules/inventory/qb-inventory/client.lua | 6 ++++++ modules/inventory/qb-inventory/server.lua | 6 ++++++ modules/inventory/qs-inventory/client.lua | 6 ++++++ modules/inventory/qs-inventory/server.lua | 6 ++++++ modules/inventory/tgiann-inventory/client.lua | 6 ++++++ modules/inventory/tgiann-inventory/server.lua | 6 ++++++ modules/notify/_default/client.lua | 2 +- modules/notify/_default/server.lua | 4 ++++ modules/phone/_default/client.lua | 4 ++++ modules/phone/_default/server.lua | 4 ++++ modules/phone/gksphone/client.lua | 4 ++++ modules/phone/gksphone/server.lua | 4 ++++ modules/phone/lb-phone/client.lua | 4 ++++ modules/phone/lb-phone/server.lua | 4 ++++ modules/phone/okokPhone/client.lua | 4 ++++ modules/phone/okokPhone/server.lua | 4 ++++ modules/phone/qs-smartphone/client.lua | 4 ++++ modules/phone/qs-smartphone/server.lua | 4 ++++ modules/phone/yseries/client.lua | 4 ++++ modules/phone/yseries/server.lua | 4 ++++ modules/progressbar/lation_ui/client.lua | 5 +++++ modules/progressbar/ox_lib/client.lua | 4 ++++ modules/progressbar/qb-progressbar/client.lua | 4 ++++ modules/skills/_default/client.lua | 9 +++------ modules/skills/_default/server.lua | 3 +-- modules/target/_default/client.lua | 4 ++++ modules/target/ox_target/client.lua | 4 ++++ modules/target/qb-target/client.lua | 4 ++++ modules/target/sleepless_interact/client.lua | 4 ++++ .../F_RealCarKeysSystem/client/client.lua | 19 +++++++++---------- .../MrNewbVehicleKeys/client/client.lua | 4 ++++ .../Renewed-Vehiclekeys/client/client.lua | 4 ++++ modules/vehicleKey/_default/client/client.lua | 8 ++++++-- .../vehicleKey/cd_garage/client/client.lua | 8 ++++++-- modules/vehicleKey/jacksam/client.lua | 4 ++++ modules/vehicleKey/mVehicle/client/client.lua | 6 +++++- .../mk_vehiclekeys/client/client.lua | 4 ++++ .../vehicleKey/okokGarage/client/client.lua | 4 ++++ .../qb-vehiclekeys/client/client.lua | 4 ++++ .../qbx_vehiclekeys/client/client.lua | 4 ++++ .../qs-vehiclekeys/client/client.lua | 4 ++++ .../vehicleKey/t1ger_keys/client/client.lua | 6 +++++- .../wasabi_carlock/client/client.lua | 4 ++++ modules/weather/_default/client.lua | 4 ++++ modules/weather/cd_easytime/client.lua | 4 ++++ .../weather/qb-weathersync/client/client.lua | 4 ++++ .../renewed-weathersync/client/client.lua | 4 ++++ 142 files changed, 784 insertions(+), 25 deletions(-) diff --git a/modules/banking/_default/server.lua b/modules/banking/_default/server.lua index 4f17414..54f4ae2 100644 --- a/modules/banking/_default/server.lua +++ b/modules/banking/_default/server.lua @@ -7,6 +7,12 @@ Banking.GetManagmentName = function() return 'default' end +---This will get the name of the in use resource. +---@return string +Banking.GetResourceName = function() + return 'default' +end + ---This will return a number ---@param account string ---@return number diff --git a/modules/banking/fd_banking/server.lua b/modules/banking/fd_banking/server.lua index ad74b7b..29f9135 100644 --- a/modules/banking/fd_banking/server.lua +++ b/modules/banking/fd_banking/server.lua @@ -10,6 +10,12 @@ Banking.GetManagmentName = function() return 'fd_banking' end +---This will get the name of the in use resource. +---@return string +Banking.GetResourceName = function() + return 'fd_banking' +end + ---This will return a number ---@param account string ---@return number diff --git a/modules/banking/kartik-banking/server.lua b/modules/banking/kartik-banking/server.lua index 078f7d1..f19e7e6 100644 --- a/modules/banking/kartik-banking/server.lua +++ b/modules/banking/kartik-banking/server.lua @@ -10,6 +10,12 @@ Banking.GetManagmentName = function() return 'kartik-banking' end +---This will get the name of the in use resource. +---@return string +Banking.GetResourceName = function() + return 'kartik-banking' +end + ---This will return a number ---@param account string ---@return number diff --git a/modules/banking/okokBanking/server.lua b/modules/banking/okokBanking/server.lua index 33bf69d..734d496 100644 --- a/modules/banking/okokBanking/server.lua +++ b/modules/banking/okokBanking/server.lua @@ -10,6 +10,12 @@ Banking.GetManagmentName = function() return 'okokBanking' end +---This will get the name of the in use resource. +---@return string +Banking.GetResourceName = function() + return 'okokBanking' +end + ---This will return a number ---@param account string ---@return number diff --git a/modules/banking/qb-banking/server.lua b/modules/banking/qb-banking/server.lua index e275daa..554eaef 100644 --- a/modules/banking/qb-banking/server.lua +++ b/modules/banking/qb-banking/server.lua @@ -10,6 +10,12 @@ Banking.GetManagmentName = function() return 'qb-banking' end +---This will get the name of the in use resource. +---@return string +Banking.GetResourceName = function() + return 'qb-banking' +end + ---This will return a number ---@param account string ---@return number diff --git a/modules/banking/renewed-banking/server.lua b/modules/banking/renewed-banking/server.lua index 4ae9c21..924c392 100644 --- a/modules/banking/renewed-banking/server.lua +++ b/modules/banking/renewed-banking/server.lua @@ -10,6 +10,12 @@ Banking.GetManagmentName = function() return 'Renewed-Banking' end +---This will get the name of the in use resource. +---@return string +Banking.GetResourceName = function() + return 'Renewed-Banking' +end + ---This will return a number ---@param account string ---@return number diff --git a/modules/banking/tgg-banking/server.lua b/modules/banking/tgg-banking/server.lua index fc276e7..ec09c69 100644 --- a/modules/banking/tgg-banking/server.lua +++ b/modules/banking/tgg-banking/server.lua @@ -10,6 +10,12 @@ Banking.GetManagmentName = function() return 'tgg-banking' end +---This will get the name of the in use resource. +---@return string +Banking.GetResourceName = function() + return 'tgg-banking' +end + ---This will return a number ---@param account string ---@return number diff --git a/modules/banking/tgiann-bank/server.lua b/modules/banking/tgiann-bank/server.lua index 082ee73..9e90902 100644 --- a/modules/banking/tgiann-bank/server.lua +++ b/modules/banking/tgiann-bank/server.lua @@ -10,6 +10,12 @@ Banking.GetManagmentName = function() return 'tgiann-bank' end +---This will get the name of the in use resource. +---@return string +Banking.GetResourceName = function() + return 'tgiann-bank' +end + ---This will return a number ---@param account string ---@return number diff --git a/modules/banking/wasabi_banking/server.lua b/modules/banking/wasabi_banking/server.lua index 5d6cea6..15c9d77 100644 --- a/modules/banking/wasabi_banking/server.lua +++ b/modules/banking/wasabi_banking/server.lua @@ -10,6 +10,12 @@ Banking.GetManagmentName = function() return 'wasabi_banking' end +---This will get the name of the in use resource. +---@return string +Banking.GetResourceName = function() + return 'wasabi_banking' +end + ---This will return a number ---@param account string ---@return number diff --git a/modules/clothing/_default/client.lua b/modules/clothing/_default/client.lua index 47f0380..7183d2d 100644 --- a/modules/clothing/_default/client.lua +++ b/modules/clothing/_default/client.lua @@ -16,6 +16,13 @@ function Clothing.IsMale() return false end + +---This will get the name of the in use resource. +---@return string +Clothing.GetResourceName = function() + return 'default' +end + ---Get the skin data of a ped ---@param entity number ---@return table diff --git a/modules/clothing/_default/server.lua b/modules/clothing/_default/server.lua index 312df50..c368691 100644 --- a/modules/clothing/_default/server.lua +++ b/modules/clothing/_default/server.lua @@ -9,6 +9,12 @@ function Clothing.IsMale(src) return GetEntityModel(ped) == `mp_m_freemode_01` end +---This will get the name of the in use resource. +---@return string +Clothing.GetResourceName = function() + return 'default' +end + function Clothing.GetAppearance(src) return Callback.Trigger('community_bridge:cb:GetAppearance', src) end diff --git a/modules/clothing/esx_skin/client.lua b/modules/clothing/esx_skin/client.lua index bfc6326..d5e4592 100644 --- a/modules/clothing/esx_skin/client.lua +++ b/modules/clothing/esx_skin/client.lua @@ -6,3 +6,9 @@ Clothing = Clothing or {} function Clothing.OpenMenu() TriggerEvent('esx_skin:openMenu', function() end, function() end, true) end + +---This will get the name of the in use resource. +---@return string +Clothing.GetResourceName = function() + return 'esx_skin' +end \ No newline at end of file diff --git a/modules/clothing/esx_skin/server.lua b/modules/clothing/esx_skin/server.lua index 9a8bfcf..a96ef52 100644 --- a/modules/clothing/esx_skin/server.lua +++ b/modules/clothing/esx_skin/server.lua @@ -35,6 +35,12 @@ function Clothing.GetFullAppearanceData(src) return Clothing.Players[citId] end +---This will get the name of the in use resource. +---@return string +Clothing.GetResourceName = function() + return 'esx_skin' +end + ---Retrieves a player's converted appearance data for easy use across modules ---@param src number The server ID of the player ---@param fullData boolean Optional - If true, returns the full data object including skin and model diff --git a/modules/clothing/fivem-appearance/client.lua b/modules/clothing/fivem-appearance/client.lua index 8030831..add4d6c 100644 --- a/modules/clothing/fivem-appearance/client.lua +++ b/modules/clothing/fivem-appearance/client.lua @@ -6,3 +6,9 @@ Clothing = Clothing or {} function Clothing.OpenMenu() TriggerEvent('qb-clothing:client:openMenu') end + +---This will get the name of the in use resource. +---@return string +Clothing.GetResourceName = function() + return 'fivem-appearance' +end diff --git a/modules/clothing/fivem-appearance/server.lua b/modules/clothing/fivem-appearance/server.lua index 34ce624..c57ef48 100644 --- a/modules/clothing/fivem-appearance/server.lua +++ b/modules/clothing/fivem-appearance/server.lua @@ -44,6 +44,12 @@ function Clothing.GetFullAppearanceData(src) return Clothing.Players[citId] end +---This will get the name of the in use resource. +---@return string +Clothing.GetResourceName = function() + return 'fivem-appearance' +end + --- Retrieves a player's converted appearance data for easy use across modules ---@param src number The server ID of the player ---@param fullData boolean Optional - If true, returns the full data object including skin and model diff --git a/modules/clothing/illenium-appearance/client.lua b/modules/clothing/illenium-appearance/client.lua index adadeeb..5c49c5d 100644 --- a/modules/clothing/illenium-appearance/client.lua +++ b/modules/clothing/illenium-appearance/client.lua @@ -6,3 +6,9 @@ Clothing = Clothing or {} function Clothing.OpenMenu() TriggerEvent('qb-clothing:client:openMenu') end + +---This will get the name of the in use resource. +---@return string +Clothing.GetResourceName = function() + return 'illenium-appearance' +end \ No newline at end of file diff --git a/modules/clothing/illenium-appearance/server.lua b/modules/clothing/illenium-appearance/server.lua index c65879d..492840e 100644 --- a/modules/clothing/illenium-appearance/server.lua +++ b/modules/clothing/illenium-appearance/server.lua @@ -35,6 +35,12 @@ function Clothing.GetFullAppearanceData(src) return Clothing.Players[citId] end +---This will get the name of the in use resource. +---@return string +Clothing.GetResourceName = function() + return 'illenium-appearance' +end + --- Retrieves a player's converted appearance data for easy use across modules ---@param src number The server ID of the player ---@param fullData boolean Optional - If true, returns the full data object including skin and model diff --git a/modules/clothing/qb-clothing/client.lua b/modules/clothing/qb-clothing/client.lua index cae21e0..3b7cb4d 100644 --- a/modules/clothing/qb-clothing/client.lua +++ b/modules/clothing/qb-clothing/client.lua @@ -6,3 +6,9 @@ Clothing = Clothing or {} function Clothing.OpenMenu() TriggerEvent('qb-clothing:client:openMenu') end + +---This will get the name of the in use resource. +---@return string +Clothing.GetResourceName = function() + return 'qb-clothing' +end \ No newline at end of file diff --git a/modules/clothing/qb-clothing/server.lua b/modules/clothing/qb-clothing/server.lua index 9f3113c..05fca20 100644 --- a/modules/clothing/qb-clothing/server.lua +++ b/modules/clothing/qb-clothing/server.lua @@ -38,6 +38,12 @@ function Clothing.GetFullAppearanceData(src) return Clothing.Players[citId] end +---This will get the name of the in use resource. +---@return string +Clothing.GetResourceName = function() + return 'qb-clothing' +end + --- Retrieves a player's converted appearance data for easy use across modules ---@param src number The server ID of the player ---@param fullData boolean Optional - If true, returns the full data object including skin and model diff --git a/modules/clothing/rcore_clothing/client.lua b/modules/clothing/rcore_clothing/client.lua index 11486f6..fee5fb9 100644 --- a/modules/clothing/rcore_clothing/client.lua +++ b/modules/clothing/rcore_clothing/client.lua @@ -4,4 +4,10 @@ Clothing = Clothing or {} function Clothing.OpenMenu() TriggerEvent('qb-clothing:client:openMenu') +end + +---This will get the name of the in use resource. +---@return string +Clothing.GetResourceName = function() + return 'rcore_clothing' end \ No newline at end of file diff --git a/modules/dispatch/_default/client/client.lua b/modules/dispatch/_default/client/client.lua index 15bccc0..8eeb384 100644 --- a/modules/dispatch/_default/client/client.lua +++ b/modules/dispatch/_default/client/client.lua @@ -30,4 +30,10 @@ RegisterNetEvent('community_bridge:Client:DispatchAlert', function(alert) Bridge.Utility.RemoveBlip(blip) end) +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'default' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/_default/server/server.lua b/modules/dispatch/_default/server/server.lua index 039944b..e2cb3bf 100644 --- a/modules/dispatch/_default/server/server.lua +++ b/modules/dispatch/_default/server/server.lua @@ -10,4 +10,10 @@ RegisterNetEvent("community_bridge:Server:DispatchAlert", function(data) end end) +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'default' +end + return Dispatch diff --git a/modules/dispatch/bub-mdt/client/client.lua b/modules/dispatch/bub-mdt/client/client.lua index 8bdedda..4b88b42 100644 --- a/modules/dispatch/bub-mdt/client/client.lua +++ b/modules/dispatch/bub-mdt/client/client.lua @@ -16,4 +16,10 @@ Dispatch.SendAlert = function(data) exports["bub-mdt"]:CustomAlert(alertData) end +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'bub-mdt' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/bub-mdt/server/server.lua b/modules/dispatch/bub-mdt/server/server.lua index a95dfde..f7809e8 100644 --- a/modules/dispatch/bub-mdt/server/server.lua +++ b/modules/dispatch/bub-mdt/server/server.lua @@ -1,4 +1,10 @@ if GetResourceState('bub-mdt') == 'missing' then return end Dispatch = Dispatch or {} +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'bub-mdt' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/cd_dispatch/client/client.lua b/modules/dispatch/cd_dispatch/client/client.lua index 799b1fe..abc85a9 100644 --- a/modules/dispatch/cd_dispatch/client/client.lua +++ b/modules/dispatch/cd_dispatch/client/client.lua @@ -24,4 +24,10 @@ Dispatch.SendAlert = function(data) }) end +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'cd_dispatch' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/cd_dispatch/server/server.lua b/modules/dispatch/cd_dispatch/server/server.lua index 856546e..97773e6 100644 --- a/modules/dispatch/cd_dispatch/server/server.lua +++ b/modules/dispatch/cd_dispatch/server/server.lua @@ -1,4 +1,10 @@ if GetResourceState('cd_dispatch') == 'missing' then return end Dispatch = Dispatch or {} +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'cd_dispatch' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/kartik-mdt/client/client.lua b/modules/dispatch/kartik-mdt/client/client.lua index 596aa93..3950531 100644 --- a/modules/dispatch/kartik-mdt/client/client.lua +++ b/modules/dispatch/kartik-mdt/client/client.lua @@ -27,4 +27,10 @@ Dispatch.SendAlert = function(data) exports['kartik-mdt']:CustomAlert(alertOptions) end +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'kartik-mdt' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/kartik-mdt/server/server.lua b/modules/dispatch/kartik-mdt/server/server.lua index 9567f5d..ef8f0d6 100644 --- a/modules/dispatch/kartik-mdt/server/server.lua +++ b/modules/dispatch/kartik-mdt/server/server.lua @@ -1,4 +1,10 @@ if GetResourceState('kartik-mdt') == 'missing' then return end Dispatch = Dispatch or {} +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'kartik-mdt' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/lb-tablet/client/client.lua b/modules/dispatch/lb-tablet/client/client.lua index c8aa413..23114d7 100644 --- a/modules/dispatch/lb-tablet/client/client.lua +++ b/modules/dispatch/lb-tablet/client/client.lua @@ -40,4 +40,10 @@ Dispatch.SendAlert = function(data) TriggerServerEvent("community_bridge:server:dispatch:sendAlert", alertData) end +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'lb-tablet' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/lb-tablet/server/server.lua b/modules/dispatch/lb-tablet/server/server.lua index e23d4b4..460f33f 100644 --- a/modules/dispatch/lb-tablet/server/server.lua +++ b/modules/dispatch/lb-tablet/server/server.lua @@ -5,4 +5,10 @@ RegisterNetEvent("community_bridge:server:dispatch:sendAlert", function(data) exports["lb-tablet"]:AddDispatch(data) -- this has a return value but we dont really have a use for it atm. end) +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'lb-tablet' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/linden_outlawalert/client/client.lua b/modules/dispatch/linden_outlawalert/client/client.lua index c783e98..6543e66 100644 --- a/modules/dispatch/linden_outlawalert/client/client.lua +++ b/modules/dispatch/linden_outlawalert/client/client.lua @@ -19,4 +19,10 @@ Dispatch.SendAlert = function(data) }) end +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'linden_outlawalert' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/linden_outlawalert/server/server.lua b/modules/dispatch/linden_outlawalert/server/server.lua index d8d9fd6..4657722 100644 --- a/modules/dispatch/linden_outlawalert/server/server.lua +++ b/modules/dispatch/linden_outlawalert/server/server.lua @@ -1,4 +1,10 @@ if GetResourceState('linden_outlawalert') == 'missing' then return end Dispatch = Dispatch or {} +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'linden_outlawalert' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/origen_police/server/server.lua b/modules/dispatch/origen_police/server/server.lua index d3ed01e..4cd83f4 100644 --- a/modules/dispatch/origen_police/server/server.lua +++ b/modules/dispatch/origen_police/server/server.lua @@ -1,4 +1,10 @@ if GetResourceState('origen_police') == 'missing' then return end Dispatch = Dispatch or {} +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'origen_police' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/piotreq_gpt/client/client.lua b/modules/dispatch/piotreq_gpt/client/client.lua index c0bc509..b5fcef1 100644 --- a/modules/dispatch/piotreq_gpt/client/client.lua +++ b/modules/dispatch/piotreq_gpt/client/client.lua @@ -7,4 +7,10 @@ Dispatch.SendAlert = function(data) TriggerServerEvent('community_bridge:Server:piotreq_gpt', data) end +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'piotreq_gpt' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/piotreq_gpt/server/server.lua b/modules/dispatch/piotreq_gpt/server/server.lua index 3c8f4ad..c3d8645 100644 --- a/modules/dispatch/piotreq_gpt/server/server.lua +++ b/modules/dispatch/piotreq_gpt/server/server.lua @@ -36,4 +36,10 @@ RegisterNetEvent('community_bridge:Server:piotreq_gpt', function(data) Dispatch.SendAlert(src, data) end) +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'piotreq_gpt' +end + return Dispatch diff --git a/modules/dispatch/ps-dispatch/client/client.lua b/modules/dispatch/ps-dispatch/client/client.lua index 142bc21..1c66d2e 100644 --- a/modules/dispatch/ps-dispatch/client/client.lua +++ b/modules/dispatch/ps-dispatch/client/client.lua @@ -27,4 +27,10 @@ Dispatch.SendAlert = function(data) exports["ps-dispatch"]:CustomAlert(alertData) end +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'ps-dispatch' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/ps-dispatch/server/server.lua b/modules/dispatch/ps-dispatch/server/server.lua index b60c698..62ae3c2 100644 --- a/modules/dispatch/ps-dispatch/server/server.lua +++ b/modules/dispatch/ps-dispatch/server/server.lua @@ -2,4 +2,10 @@ if GetResourceState('ps-dispatch') == 'missing' then return end if GetResourceState('lb-tablet') == 'started' then return end Dispatch = Dispatch or {} +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'ps-dispatch' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/qs_dispatch/client/client.lua b/modules/dispatch/qs_dispatch/client/client.lua index 3762ddc..e84d3c7 100644 --- a/modules/dispatch/qs_dispatch/client/client.lua +++ b/modules/dispatch/qs_dispatch/client/client.lua @@ -38,4 +38,11 @@ Dispatch.SendAlert = function(data) end) end +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'qs-dispatch' +end + + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/qs_dispatch/server/server.lua b/modules/dispatch/qs_dispatch/server/server.lua index ae08560..8bb7316 100644 --- a/modules/dispatch/qs_dispatch/server/server.lua +++ b/modules/dispatch/qs_dispatch/server/server.lua @@ -1,4 +1,11 @@ if GetResourceState('qs-dispatch') == 'missing' then return end Dispatch = Dispatch or {} +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'qs-dispatch' +end + + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/redutzu-mdt/client/client.lua b/modules/dispatch/redutzu-mdt/client/client.lua index 8b0ef79..c803a77 100644 --- a/modules/dispatch/redutzu-mdt/client/client.lua +++ b/modules/dispatch/redutzu-mdt/client/client.lua @@ -14,4 +14,11 @@ Dispatch.SendAlert = function(data) TriggerServerEvent("community_bridge:server:dispatch:sendAlert", alertData) end +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'redutzu-mdt' +end + + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/redutzu-mdt/server/server.lua b/modules/dispatch/redutzu-mdt/server/server.lua index c1c0ac0..a872c4c 100644 --- a/modules/dispatch/redutzu-mdt/server/server.lua +++ b/modules/dispatch/redutzu-mdt/server/server.lua @@ -11,4 +11,10 @@ RegisterNetEvent("community_bridge:server:dispatch:sendAlert", function(data) }) end) +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'redutzu-mdt' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/tk_dispatch/client/client.lua b/modules/dispatch/tk_dispatch/client/client.lua index 61de466..f7c0740 100644 --- a/modules/dispatch/tk_dispatch/client/client.lua +++ b/modules/dispatch/tk_dispatch/client/client.lua @@ -20,4 +20,10 @@ Dispatch.SendAlert = function(data) }) end +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'tk_dispatch' +end + return Dispatch \ No newline at end of file diff --git a/modules/dispatch/tk_dispatch/server/server.lua b/modules/dispatch/tk_dispatch/server/server.lua index aeeb8dc..33e3867 100644 --- a/modules/dispatch/tk_dispatch/server/server.lua +++ b/modules/dispatch/tk_dispatch/server/server.lua @@ -1,4 +1,10 @@ if GetResourceState('tk_dispatch') == 'missing' then return end Dispatch = Dispatch or {} +---This will get the name of the in use resource. +---@return string +Dispatch.GetResourceName = function() + return 'tk_dispatch' +end + return Dispatch \ No newline at end of file diff --git a/modules/doorlock/_default/server.lua b/modules/doorlock/_default/server.lua index 882615b..6d7369a 100644 --- a/modules/doorlock/_default/server.lua +++ b/modules/doorlock/_default/server.lua @@ -10,4 +10,10 @@ Doorlock.ToggleDoorLock = function(doorID, toggle) return true end +---This will get the name of the in use resource. +---@return string +Doorlock.GetResourceName = function() + return 'default' +end + return Doorlock \ No newline at end of file diff --git a/modules/doorlock/doors_creator/client.lua b/modules/doorlock/doors_creator/client.lua index d4da080..eea726c 100644 --- a/modules/doorlock/doors_creator/client.lua +++ b/modules/doorlock/doors_creator/client.lua @@ -9,4 +9,10 @@ Doorlock.GetClosestDoor = function() return exports["doors_creator"]:getClosestActiveDoor() end +---This will get the name of the in use resource. +---@return string +Doorlock.GetResourceName = function() + return 'doors_creator' +end + return Doorlock \ No newline at end of file diff --git a/modules/doorlock/doors_creator/server.lua b/modules/doorlock/doors_creator/server.lua index 89223e8..7594105 100644 --- a/modules/doorlock/doors_creator/server.lua +++ b/modules/doorlock/doors_creator/server.lua @@ -18,4 +18,10 @@ Doorlock.ToggleDoorLock = function(doorID, toggle) return true end +---This will get the name of the in use resource. +---@return string +Doorlock.GetResourceName = function() + return 'doors_creator' +end + return Doorlock \ No newline at end of file diff --git a/modules/doorlock/ox_doorlock/client.lua b/modules/doorlock/ox_doorlock/client.lua index fc35fa0..4fdc35d 100644 --- a/modules/doorlock/ox_doorlock/client.lua +++ b/modules/doorlock/ox_doorlock/client.lua @@ -11,4 +11,10 @@ Doorlock.GetClosestDoor = function() return tostring(doorData.id) or nil end +---This will get the name of the in use resource. +---@return string +Doorlock.GetResourceName = function() + return 'ox_doorlock' +end + return Doorlock \ No newline at end of file diff --git a/modules/doorlock/ox_doorlock/server.lua b/modules/doorlock/ox_doorlock/server.lua index b7f8461..4c86f85 100644 --- a/modules/doorlock/ox_doorlock/server.lua +++ b/modules/doorlock/ox_doorlock/server.lua @@ -20,4 +20,10 @@ Doorlock.ToggleDoorLock = function(doorID, toggle) return true end +---This will get the name of the in use resource. +---@return string +Doorlock.GetResourceName = function() + return 'ox_doorlock' +end + return Doorlock \ No newline at end of file diff --git a/modules/doorlock/qb-doorlock/client.lua b/modules/doorlock/qb-doorlock/client.lua index a7356db..f7ea9fe 100644 --- a/modules/doorlock/qb-doorlock/client.lua +++ b/modules/doorlock/qb-doorlock/client.lua @@ -23,4 +23,10 @@ Doorlock.GetClosestDoor = function() return door end +---This will get the name of the in use resource. +---@return string +Doorlock.GetResourceName = function() + return 'qb-doorlock' +end + return Doorlock \ No newline at end of file diff --git a/modules/doorlock/qb-doorlock/server.lua b/modules/doorlock/qb-doorlock/server.lua index a88a9b9..9b2f123 100644 --- a/modules/doorlock/qb-doorlock/server.lua +++ b/modules/doorlock/qb-doorlock/server.lua @@ -12,4 +12,10 @@ Doorlock.ToggleDoorLock = function(doorID, toggle) return true end +---This will get the name of the in use resource. +---@return string +Doorlock.GetResourceName = function() + return 'qb-doorlock' +end + return Doorlock \ No newline at end of file diff --git a/modules/doorlock/rcore_doorlock/client.lua b/modules/doorlock/rcore_doorlock/client.lua index 5c9cd6c..4a61f89 100644 --- a/modules/doorlock/rcore_doorlock/client.lua +++ b/modules/doorlock/rcore_doorlock/client.lua @@ -21,4 +21,10 @@ Doorlock.GetClosestDoor = function() return door end +---This will get the name of the in use resource. +---@return string +Doorlock.GetResourceName = function() + return 'rcore_doorlock' +end + return Doorlock \ No newline at end of file diff --git a/modules/doorlock/rcore_doorlock/server.lua b/modules/doorlock/rcore_doorlock/server.lua index 176e23e..f4ef635 100644 --- a/modules/doorlock/rcore_doorlock/server.lua +++ b/modules/doorlock/rcore_doorlock/server.lua @@ -16,4 +16,11 @@ Doorlock.ToggleDoorLock = function(doorID, toggle) end return true end + +---This will get the name of the in use resource. +---@return string +Doorlock.GetResourceName = function() + return 'rcore_doorlock' +end + return Doorlock \ No newline at end of file diff --git a/modules/framework/_default/client.lua b/modules/framework/_default/client.lua index 0f6cbb0..77042d7 100644 --- a/modules/framework/_default/client.lua +++ b/modules/framework/_default/client.lua @@ -8,6 +8,12 @@ AddStateBagChangeHandler('jobcounts', 'global', function(bagName, key, value) currentJobCounts = value end) +---This will get the name of the in use resource. +---@return string +Framework.GetResourceName = function() + return 'default' +end + ---This is an internal function that will be used to retrieve job counts later. ---@param jobName string ---@return number diff --git a/modules/framework/_default/server.lua b/modules/framework/_default/server.lua index 40161ff..6e675f2 100644 --- a/modules/framework/_default/server.lua +++ b/modules/framework/_default/server.lua @@ -7,6 +7,12 @@ local globalState = GlobalState globalState.jobcounts = {} +---This will get the name of the in use resource. +---@return string +Framework.GetResourceName = function() + return 'default' +end + ---This is an internal function that will be used to retrieve job counts later. ---@param jobName string ---@return number diff --git a/modules/framework/es_extended/client.lua b/modules/framework/es_extended/client.lua index e8f1d34..c363a45 100644 --- a/modules/framework/es_extended/client.lua +++ b/modules/framework/es_extended/client.lua @@ -22,6 +22,12 @@ Framework.GetFrameworkName = function() return 'es_extended' end +---This will get the name of the in use resource. +---@return string +Framework.GetResourceName = function() + return 'es_extended' +end + --- @description This will return true if the player is loaded, false otherwise. --- This could be useful in scripts that rely on player loaded events and offer a debug mode to hit this function --- @return boolean diff --git a/modules/framework/es_extended/server.lua b/modules/framework/es_extended/server.lua index e1abfc0..80243a0 100644 --- a/modules/framework/es_extended/server.lua +++ b/modules/framework/es_extended/server.lua @@ -16,6 +16,12 @@ Framework.GetFrameworkName = function() return 'es_extended' end +---This will get the name of the in use resource. +---@return string +Framework.GetResourceName = function() + return 'es_extended' +end + --- @description This is an internal function, its here to attempt to emulate qbs shared items mainly Framework.ItemList = function() if cachedItemList then return cachedItemList end diff --git a/modules/framework/qb-core/client.lua b/modules/framework/qb-core/client.lua index b85410b..21b5dac 100644 --- a/modules/framework/qb-core/client.lua +++ b/modules/framework/qb-core/client.lua @@ -14,6 +14,12 @@ Framework.GetFrameworkName = function() return 'qb-core' end +---This will get the name of the in use resource. +---@return string +Framework.GetResourceName = function() + return 'qb-core' +end + ---This will return true if the player is loaded, false otherwise. ---This could be useful in scripts that rely on player loaded events and offer a debug mode to hit this function. ---@return boolean diff --git a/modules/framework/qb-core/server.lua b/modules/framework/qb-core/server.lua index f346988..765855d 100644 --- a/modules/framework/qb-core/server.lua +++ b/modules/framework/qb-core/server.lua @@ -14,6 +14,12 @@ Framework.GetFrameworkName = function() return 'qb-core' end +---This will get the name of the in use resource. +---@return string +Framework.GetResourceName = function() + return 'qb-core' +end + ---This will return if the player is an admin in the framework. ---@param src any ---@return boolean diff --git a/modules/framework/qbx_core/client.lua b/modules/framework/qbx_core/client.lua index 5f90b59..59c4dbd 100644 --- a/modules/framework/qbx_core/client.lua +++ b/modules/framework/qbx_core/client.lua @@ -11,6 +11,12 @@ Framework.GetFrameworkName = function() return 'qbx_core' end +---This will get the name of the in use resource. +---@return string +Framework.GetResourceName = function() + return 'qbx_core' +end + ---This will return true if the player is loaded, false otherwise. ---This could be useful in scripts that rely on player loaded events and offer a debug mode to hit this function. ---@return boolean diff --git a/modules/framework/qbx_core/server.lua b/modules/framework/qbx_core/server.lua index e20c2c5..bf29bfe 100644 --- a/modules/framework/qbx_core/server.lua +++ b/modules/framework/qbx_core/server.lua @@ -11,6 +11,12 @@ Framework.GetFrameworkName = function() return 'qbx_core' end +---This will get the name of the in use resource. +---@return string +Framework.GetResourceName = function() + return 'qbx_core' +end + ---This will return if the player is an admin in the framework. ---@param src any ---@return boolean diff --git a/modules/fuel/_default/client.lua b/modules/fuel/_default/client.lua index 8430733..53748be 100644 --- a/modules/fuel/_default/client.lua +++ b/modules/fuel/_default/client.lua @@ -8,6 +8,7 @@ Fuel = Fuel or {} Fuel.GetResourceName = function() return 'default' end + ---Returns the current fuel level of a vehicle. ---@param vehicle number The vehicle entity handle. ---@return number The vehicle fuel level. diff --git a/modules/helptext/_default/client.lua b/modules/helptext/_default/client.lua index 8494c66..0d1d546 100644 --- a/modules/helptext/_default/client.lua +++ b/modules/helptext/_default/client.lua @@ -9,6 +9,12 @@ HelpText.ShowHelpText = function(message, _position) return Framework.ShowHelpText(message, _position) end +---This will get the name of the in use resource. +---@return string +HelpText.GetResourceName = function() + return "default" +end + ---This will hide the help text message on the screen ---@return nil HelpText.HideHelpText = function() diff --git a/modules/helptext/_default/server.lua b/modules/helptext/_default/server.lua index fe80525..4f795d1 100644 --- a/modules/helptext/_default/server.lua +++ b/modules/helptext/_default/server.lua @@ -9,6 +9,12 @@ HelpText.ShowHelpText = function(src, message, position) TriggerClientEvent('community_bridge:Client:ShowHelpText', src, message, position) end +---This will get the name of the in use resource. +---@return string +HelpText.GetResourceName = function() + return "default" +end + ---This will hide the help text message on the screen for the specified player ---@param src number HelpText.HideHelpText = function(src) diff --git a/modules/helptext/cd_drawtextui/client.lua b/modules/helptext/cd_drawtextui/client.lua index d257822..0622925 100644 --- a/modules/helptext/cd_drawtextui/client.lua +++ b/modules/helptext/cd_drawtextui/client.lua @@ -13,6 +13,12 @@ HelpText.ShowHelpText = function(message, _position) return TriggerEvent('cd_drawtextui:ShowUI', 'show', message) end +---This will get the name of the in use resource. +---@return string +HelpText.GetResourceName = function() + return resourceName +end + ---This will hide the help text message on the screen ---@return nil HelpText.HideHelpText = function() diff --git a/modules/helptext/jg-textui/client.lua b/modules/helptext/jg-textui/client.lua index bceec6d..8e38246 100644 --- a/modules/helptext/jg-textui/client.lua +++ b/modules/helptext/jg-textui/client.lua @@ -12,6 +12,12 @@ HelpText.ShowHelpText = function(message, _position) return exports['jg-textui']:DrawText(message) end +---This will get the name of the in use resource. +---@return string +HelpText.GetResourceName = function() + return resourceName +end + ---This will hide the help text message on the screen ---@return nil HelpText.HideHelpText = function() diff --git a/modules/helptext/lab-HintUI/client.lua b/modules/helptext/lab-HintUI/client.lua index f72fdd9..033fffa 100644 --- a/modules/helptext/lab-HintUI/client.lua +++ b/modules/helptext/lab-HintUI/client.lua @@ -12,6 +12,12 @@ HelpText.ShowHelpText = function(message, _position) return exports['lab-HintUI']:Show(message, "Hint Text") end +---This will get the name of the in use resource. +---@return string +HelpText.GetResourceName = function() + return resourceName +end + ---This will hide the help text message on the screen ---@return nil HelpText.HideHelpText = function() diff --git a/modules/helptext/lation_ui/client.lua b/modules/helptext/lation_ui/client.lua index 2fd5f4b..42f9341 100644 --- a/modules/helptext/lation_ui/client.lua +++ b/modules/helptext/lation_ui/client.lua @@ -12,6 +12,12 @@ HelpText.ShowHelpText = function(message, position) return exports.lation_ui:showText({description = tostring(message), position = position or 'right-center'}) end +---This will get the name of the in use resource. +---@return string +HelpText.GetResourceName = function() + return resourceName +end + ---This will hide the help text message on the screen ---@return nil HelpText.HideHelpText = function() diff --git a/modules/helptext/okokTextUI/client.lua b/modules/helptext/okokTextUI/client.lua index 7ad8a0e..c5fcef3 100644 --- a/modules/helptext/okokTextUI/client.lua +++ b/modules/helptext/okokTextUI/client.lua @@ -12,6 +12,12 @@ HelpText.ShowHelpText = function(message, _position) return exports['okokTextUI']:Open(message, 'darkblue', _position, false) end +---This will get the name of the in use resource. +---@return string +HelpText.GetResourceName = function() + return resourceName +end + ---This will hide the help text message on the screen ---@return nil HelpText.HideHelpText = function() diff --git a/modules/helptext/ox_lib/client.lua b/modules/helptext/ox_lib/client.lua index 4a3837a..a02a914 100644 --- a/modules/helptext/ox_lib/client.lua +++ b/modules/helptext/ox_lib/client.lua @@ -14,6 +14,12 @@ HelpText.ShowHelpText = function(message, position) }) end +---This will get the name of the in use resource. +---@return string +HelpText.GetResourceName = function() + return resourceName +end + ---This will hide the help text message on the screen ---@return nil HelpText.HideHelpText = function() diff --git a/modules/housing/_default/client.lua b/modules/housing/_default/client.lua index ae77287..ea7d77b 100644 --- a/modules/housing/_default/client.lua +++ b/modules/housing/_default/client.lua @@ -1,3 +1,9 @@ Housing = Housing or {} +---This will get the name of the in use resource. +---@return string +Housing.GetResourceName = function() + return "default" +end + return Housing \ No newline at end of file diff --git a/modules/housing/_default/server.lua b/modules/housing/_default/server.lua index 4566d0a..5d1815c 100644 --- a/modules/housing/_default/server.lua +++ b/modules/housing/_default/server.lua @@ -11,4 +11,10 @@ RegisterNetEvent('community_bridge:Server:_OnPlayerInside', function(src, inside TriggerEvent('community_bridge:Client:OnPlayerInside', src, insideId, currentBucket, playerCoords) end) +---This will get the name of the in use resource. +---@return string +Housing.GetResourceName = function() + return "default" +end + return Housing \ No newline at end of file diff --git a/modules/housing/bcs-housing/client.lua b/modules/housing/bcs-housing/client.lua index ab420d2..fea2049 100644 --- a/modules/housing/bcs-housing/client.lua +++ b/modules/housing/bcs-housing/client.lua @@ -10,4 +10,10 @@ RegisterNetEvent("Housing:client:DeleteFurnitures", function() TriggerServerEvent('community_bridge:Server:_OnPlayerInside', false) end) +---This will get the name of the in use resource. +---@return string +Housing.GetResourceName = function() + return "bcs-housing" +end + return Housing \ No newline at end of file diff --git a/modules/housing/bcs-housing/server.lua b/modules/housing/bcs-housing/server.lua index 3745ce9..cc42a1f 100644 --- a/modules/housing/bcs-housing/server.lua +++ b/modules/housing/bcs-housing/server.lua @@ -2,4 +2,10 @@ if GetResourceState('bcs-housing') == 'missing' then return end Housing = Housing or {} +---This will get the name of the in use resource. +---@return string +Housing.GetResourceName = function() + return "bcs-housing" +end + return Housing \ No newline at end of file diff --git a/modules/housing/esx_property/client.lua b/modules/housing/esx_property/client.lua index 50ca417..91b2b94 100644 --- a/modules/housing/esx_property/client.lua +++ b/modules/housing/esx_property/client.lua @@ -2,4 +2,10 @@ if GetResourceState('esx_property') == 'missing' then return end Housing = Housing or {} +---This will get the name of the in use resource. +---@return string +Housing.GetResourceName = function() + return "esx_property" +end + return Housing \ No newline at end of file diff --git a/modules/housing/esx_property/server.lua b/modules/housing/esx_property/server.lua index 420a2f0..2e0fe58 100644 --- a/modules/housing/esx_property/server.lua +++ b/modules/housing/esx_property/server.lua @@ -12,4 +12,10 @@ RegisterNetEvent('esx_property:leave', function(insideId) TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId) end) +---This will get the name of the in use resource. +---@return string +Housing.GetResourceName = function() + return "esx_property" +end + return Housing \ No newline at end of file diff --git a/modules/housing/ps-housing/client.lua b/modules/housing/ps-housing/client.lua index a174c0f..aca6b40 100644 --- a/modules/housing/ps-housing/client.lua +++ b/modules/housing/ps-housing/client.lua @@ -2,4 +2,10 @@ if GetResourceState('ps-housing') == 'missing' then return end Housing = Housing or {} +---This will get the name of the in use resource. +---@return string +Housing.GetResourceName = function() + return "ps-housing" +end + return Housing \ No newline at end of file diff --git a/modules/housing/ps-housing/server.lua b/modules/housing/ps-housing/server.lua index e4640d2..8e4ced9 100644 --- a/modules/housing/ps-housing/server.lua +++ b/modules/housing/ps-housing/server.lua @@ -12,4 +12,10 @@ RegisterNetEvent('ps-housing:server:leaveProperty', function(insideId) TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId) end) +---This will get the name of the in use resource. +---@return string +Housing.GetResourceName = function() + return "ps-housing" +end + return Housing \ No newline at end of file diff --git a/modules/housing/qb-appartments/client.lua b/modules/housing/qb-appartments/client.lua index 415e0da..16a8d9b 100644 --- a/modules/housing/qb-appartments/client.lua +++ b/modules/housing/qb-appartments/client.lua @@ -2,4 +2,10 @@ if GetResourceState('qb-appartments') == 'missing' then return end Housing = Housing or {} +---This will get the name of the in use resource. +---@return string +Housing.GetResourceName = function() + return "qb-appartments" +end + return Housing \ No newline at end of file diff --git a/modules/housing/qb-appartments/server.lua b/modules/housing/qb-appartments/server.lua index 9b92c1f..a187785 100644 --- a/modules/housing/qb-appartments/server.lua +++ b/modules/housing/qb-appartments/server.lua @@ -8,4 +8,11 @@ RegisterNetEvent('qb-apartments:server:SetInsideMeta', function(house, insideId, TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId) end) +---This will get the name of the in use resource. +---@return string +Housing.GetResourceName = function() + return "qb-appartments" +end + + return Housing \ No newline at end of file diff --git a/modules/housing/qb-houses/client.lua b/modules/housing/qb-houses/client.lua index 1733b77..f7749ac 100644 --- a/modules/housing/qb-houses/client.lua +++ b/modules/housing/qb-houses/client.lua @@ -2,4 +2,10 @@ if GetResourceState('qb-houses') == 'missing' then return end Housing = Housing or {} +---This will get the name of the in use resource. +---@return string +Housing.GetResourceName = function() + return "qb-houses" +end + return Housing \ No newline at end of file diff --git a/modules/housing/qb-houses/server.lua b/modules/housing/qb-houses/server.lua index f2d4265..baeff73 100644 --- a/modules/housing/qb-houses/server.lua +++ b/modules/housing/qb-houses/server.lua @@ -8,4 +8,10 @@ RegisterNetEvent('qb-houses:server:SetInsideMeta', function(insideId, bool) TriggerEvent('community_bridge:Server:_OnPlayerInside', src, insideId) end) +---This will get the name of the in use resource. +---@return string +Housing.GetResourceName = function() + return "qb-houses" +end + return Housing \ No newline at end of file diff --git a/modules/inventory/_default/client.lua b/modules/inventory/_default/client.lua index 3d989f7..4ff2b77 100644 --- a/modules/inventory/_default/client.lua +++ b/modules/inventory/_default/client.lua @@ -8,6 +8,12 @@ Inventory.GetItemInfo = function(item) return Framework.GetItemInfo(item) end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "default" +end + ---Will return boolean if the player has the item. ---@param item string ---@return boolean diff --git a/modules/inventory/_default/server.lua b/modules/inventory/_default/server.lua index ccc4df1..7075b84 100644 --- a/modules/inventory/_default/server.lua +++ b/modules/inventory/_default/server.lua @@ -13,6 +13,13 @@ Inventory.AddItem = function(src, item, count, slot, metadata) return Framework.AddItem(src, item, count, slot, metadata) end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "default" +end + + ---This will remove an item, and return true or false based on success ---@param src number ---@param item string diff --git a/modules/inventory/codem-inventory/client.lua b/modules/inventory/codem-inventory/client.lua index 7c34524..2fe7e66 100644 --- a/modules/inventory/codem-inventory/client.lua +++ b/modules/inventory/codem-inventory/client.lua @@ -21,6 +21,13 @@ Inventory.GetItemInfo = function(item) } end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "codem-inventory" +end + + ---This will return the entire items table from the inventory. ---@return table Inventory.Items = function() diff --git a/modules/inventory/codem-inventory/server.lua b/modules/inventory/codem-inventory/server.lua index 2927e6e..a0b3e0a 100644 --- a/modules/inventory/codem-inventory/server.lua +++ b/modules/inventory/codem-inventory/server.lua @@ -18,6 +18,13 @@ Inventory.AddItem = function(src, item, count, slot, metadata) return codem:AddItem(src, item, count, slot, metadata) end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "codem-inventory" +end + + ---This will remove an item, and return true or false based on success ---@param src number ---@param item string diff --git a/modules/inventory/core_inventory/client.lua b/modules/inventory/core_inventory/client.lua index da9124d..943491b 100644 --- a/modules/inventory/core_inventory/client.lua +++ b/modules/inventory/core_inventory/client.lua @@ -24,6 +24,13 @@ Inventory.GetItemInfo = function(item) return {name = dataRepack.name, label = dataRepack.label, stack = dataRepack.stack, weight = dataRepack.weight, description = dataRepack.description, image = Inventory.GetImagePath(dataRepack.name) } end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "core_inventory" +end + + ---This will return the entire items table from the inventory. ---@return table Inventory.Items = function() diff --git a/modules/inventory/core_inventory/server.lua b/modules/inventory/core_inventory/server.lua index e2a4771..e2dc3ad 100644 --- a/modules/inventory/core_inventory/server.lua +++ b/modules/inventory/core_inventory/server.lua @@ -18,6 +18,14 @@ Inventory.AddItem = function(src, item, count, slot, metadata) return core:addItem(src, item, count, metadata) end + +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "core_inventory" +end + + ---This will remove an item, and return true or false based on success ---@param src number ---@param item string diff --git a/modules/inventory/jpr-inventory/client.lua b/modules/inventory/jpr-inventory/client.lua index e2448dc..489878c 100644 --- a/modules/inventory/jpr-inventory/client.lua +++ b/modules/inventory/jpr-inventory/client.lua @@ -20,6 +20,14 @@ Inventory.GetItemInfo = function(item) } end + +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "jpr-inventory" +end + + ---Will return boolean if the player has the item. ---@param item string ---@return boolean diff --git a/modules/inventory/jpr-inventory/server.lua b/modules/inventory/jpr-inventory/server.lua index e0f31ff..6e0eb82 100644 --- a/modules/inventory/jpr-inventory/server.lua +++ b/modules/inventory/jpr-inventory/server.lua @@ -19,6 +19,12 @@ Inventory.AddItem = function(src, item, count, slot, metadata) return exports['jpr-inventory']:AddItem(src, item, count, slot, metadata, 'community_bridge Item added') end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "jpr-inventory" +end + ---This will remove an item, and return true or false based on success ---@param src number ---@param item string diff --git a/modules/inventory/origen_inventory/client.lua b/modules/inventory/origen_inventory/client.lua index 77d7adb..eccc81b 100644 --- a/modules/inventory/origen_inventory/client.lua +++ b/modules/inventory/origen_inventory/client.lua @@ -19,6 +19,12 @@ Inventory.GetItemInfo = function(item) } end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "origen_inventory" +end + ---This will return the entire items table from the inventory. ---@return table Inventory.Items = function() diff --git a/modules/inventory/origen_inventory/server.lua b/modules/inventory/origen_inventory/server.lua index 784cb9b..55e3f2d 100644 --- a/modules/inventory/origen_inventory/server.lua +++ b/modules/inventory/origen_inventory/server.lua @@ -18,6 +18,12 @@ Inventory.AddItem = function(src, item, count, slot, metadata) return origin:AddItem(src, item, count, metadata, slot, true) end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "origen_inventory" +end + ---This will remove an item, and return true or false based on success ---@param src number ---@param item string diff --git a/modules/inventory/ox_inventory/client.lua b/modules/inventory/ox_inventory/client.lua index 9a676e8..f8623ba 100644 --- a/modules/inventory/ox_inventory/client.lua +++ b/modules/inventory/ox_inventory/client.lua @@ -23,6 +23,12 @@ Inventory.GetItemInfo = function(item) } end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "ox_inventory" +end + ---This will return the entire items table from the inventory. ---@return table Inventory.Items = function() diff --git a/modules/inventory/ox_inventory/server.lua b/modules/inventory/ox_inventory/server.lua index 66aeaaa..ff5e4a4 100644 --- a/modules/inventory/ox_inventory/server.lua +++ b/modules/inventory/ox_inventory/server.lua @@ -22,6 +22,12 @@ Inventory.AddItem = function(src, item, count, slot, metadata) return ox_inventory:AddItem(src, item, count, metadata) end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "ox_inventory" +end + ---This will remove an item, and return true or false based on success ---@param src number ---@param item string diff --git a/modules/inventory/ps-inventory/client.lua b/modules/inventory/ps-inventory/client.lua index 86b4e55..69ced4f 100644 --- a/modules/inventory/ps-inventory/client.lua +++ b/modules/inventory/ps-inventory/client.lua @@ -20,6 +20,12 @@ Inventory.GetItemInfo = function(item) } end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "ps-inventory" +end + ---This will return the entire items table from the inventory. ---@return table Inventory.Items = function() diff --git a/modules/inventory/ps-inventory/server.lua b/modules/inventory/ps-inventory/server.lua index 0b53263..53194e4 100644 --- a/modules/inventory/ps-inventory/server.lua +++ b/modules/inventory/ps-inventory/server.lua @@ -19,6 +19,12 @@ Inventory.AddItem = function(src, item, count, slot, metadata) return sloth:AddItem(src, item, count, slot, metadata, 'community_bridge') end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "ps-inventory" +end + ---This will remove an item, and return true or false based on success ---@param src number ---@param item string diff --git a/modules/inventory/qb-inventory/client.lua b/modules/inventory/qb-inventory/client.lua index b71db1a..195441e 100644 --- a/modules/inventory/qb-inventory/client.lua +++ b/modules/inventory/qb-inventory/client.lua @@ -20,6 +20,12 @@ Inventory.GetItemInfo = function(item) } end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "qb-inventory" +end + ---This will return the entire items table from the inventory. ---@return table Inventory.Items = function() diff --git a/modules/inventory/qb-inventory/server.lua b/modules/inventory/qb-inventory/server.lua index eb92534..9abd7cb 100644 --- a/modules/inventory/qb-inventory/server.lua +++ b/modules/inventory/qb-inventory/server.lua @@ -27,6 +27,12 @@ Inventory.AddItem = function(src, item, count, slot, metadata) return qbInventory:AddItem(src, item, count, slot, metadata, 'community_bridge') end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "qb-inventory" +end + ---This will remove an item, and return true or false based on success ---@param src number ---@param item string diff --git a/modules/inventory/qs-inventory/client.lua b/modules/inventory/qs-inventory/client.lua index 31775f2..35d60e8 100644 --- a/modules/inventory/qs-inventory/client.lua +++ b/modules/inventory/qs-inventory/client.lua @@ -22,6 +22,12 @@ Inventory.GetItemInfo = function(item) } end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "qs-inventory" +end + ---This will return the entire items table from the inventory. ---@return table Inventory.Items = function() diff --git a/modules/inventory/qs-inventory/server.lua b/modules/inventory/qs-inventory/server.lua index 52a542c..0593105 100644 --- a/modules/inventory/qs-inventory/server.lua +++ b/modules/inventory/qs-inventory/server.lua @@ -19,6 +19,12 @@ Inventory.AddItem = function(src, item, count, slot, metadata) return quasar:AddItem(src, item, count, slot, metadata) end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "qs-inventory" +end + ---This will remove an item, and return true or false based on success ---@param src number ---@param item string diff --git a/modules/inventory/tgiann-inventory/client.lua b/modules/inventory/tgiann-inventory/client.lua index ad4c874..aa62432 100644 --- a/modules/inventory/tgiann-inventory/client.lua +++ b/modules/inventory/tgiann-inventory/client.lua @@ -21,6 +21,12 @@ Inventory.GetItemInfo = function(item) } end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "tgiann-inventory" +end + ---Will return boolean if the player has the item. ---@param item string ---@return boolean diff --git a/modules/inventory/tgiann-inventory/server.lua b/modules/inventory/tgiann-inventory/server.lua index 4393d58..92f7a59 100644 --- a/modules/inventory/tgiann-inventory/server.lua +++ b/modules/inventory/tgiann-inventory/server.lua @@ -19,6 +19,12 @@ Inventory.AddItem = function(src, item, count, slot, metadata) return tgiann:AddItem(src, item, count, slot, metadata, false) end +---This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "tgiann-inventory" +end + ---This will remove an item, and return true or false based on success ---@param src number ---@param item string diff --git a/modules/notify/_default/client.lua b/modules/notify/_default/client.lua index 7aef40d..3dc7dc5 100644 --- a/modules/notify/_default/client.lua +++ b/modules/notify/_default/client.lua @@ -2,7 +2,7 @@ Notify = Notify or {} Notify.GetResourceName = function() - return "none" + return "default" end ---This will send a notify message of the type and time passed diff --git a/modules/notify/_default/server.lua b/modules/notify/_default/server.lua index fab0ddc..ddceb67 100644 --- a/modules/notify/_default/server.lua +++ b/modules/notify/_default/server.lua @@ -10,6 +10,10 @@ Notify.SendNotify = function(src, message, _type, time) TriggerClientEvent('community_bridge:Client:Notify', src, message, _type, time) end +Notify.GetResourceName = function() + return "default" +end + ---------[[Depricated Stuff Below, please adjust to the HelpText module instead]]-------- ---Depricated -- This will show a help text message to the specified player at the screen position passed ---@param src number diff --git a/modules/phone/_default/client.lua b/modules/phone/_default/client.lua index bd3d2fe..529df0c 100644 --- a/modules/phone/_default/client.lua +++ b/modules/phone/_default/client.lua @@ -7,6 +7,10 @@ Phone.GetPhoneName = function() return 'default' end +Phone.GetResourceName = function() + return "default" +end + ---This will send an email to the passed email address with the title and message. ---@param email string ---@param title string diff --git a/modules/phone/_default/server.lua b/modules/phone/_default/server.lua index 01bb488..c945be4 100644 --- a/modules/phone/_default/server.lua +++ b/modules/phone/_default/server.lua @@ -7,6 +7,10 @@ Phone.GetPhoneName = function() return 'default' end +Phone.GetResourceName = function() + return "default" +end + ---This will get the phone number of the passed source. ---@param src number ---@return number|boolean diff --git a/modules/phone/gksphone/client.lua b/modules/phone/gksphone/client.lua index f253028..31cc403 100644 --- a/modules/phone/gksphone/client.lua +++ b/modules/phone/gksphone/client.lua @@ -10,6 +10,10 @@ Phone.GetPhoneName = function() return resourceName end +Phone.GetResourceName = function() + return resourceName +end + ---This will send an email to the passed email address with the title and message. ---@param email string ---@param title string diff --git a/modules/phone/gksphone/server.lua b/modules/phone/gksphone/server.lua index 4efc6db..0ac2f56 100644 --- a/modules/phone/gksphone/server.lua +++ b/modules/phone/gksphone/server.lua @@ -9,6 +9,10 @@ Phone.GetPhoneName = function() return resourceName end +Phone.GetResourceName = function() + return resourceName +end + ---This will get the phone number of the passed source. ---@param src number ---@return number|boolean diff --git a/modules/phone/lb-phone/client.lua b/modules/phone/lb-phone/client.lua index 6a0cccc..7d4c369 100644 --- a/modules/phone/lb-phone/client.lua +++ b/modules/phone/lb-phone/client.lua @@ -9,6 +9,10 @@ Phone.GetPhoneName = function() return resourceName end +Phone.GetResourceName = function() + return resourceName +end + ---This will send an email to the passed email address with the title and message. ---@param email string ---@param title string diff --git a/modules/phone/lb-phone/server.lua b/modules/phone/lb-phone/server.lua index 0bedbe6..2b03f4a 100644 --- a/modules/phone/lb-phone/server.lua +++ b/modules/phone/lb-phone/server.lua @@ -9,6 +9,10 @@ Phone.GetPhoneName = function() return resourceName end +Phone.GetResourceName = function() + return resourceName +end + ---This will get the phone number of the passed source. ---@param src number ---@return number|boolean diff --git a/modules/phone/okokPhone/client.lua b/modules/phone/okokPhone/client.lua index e4231ea..c0545e8 100644 --- a/modules/phone/okokPhone/client.lua +++ b/modules/phone/okokPhone/client.lua @@ -10,6 +10,10 @@ Phone.GetPhoneName = function() return resourceName end +Phone.GetResourceName = function() + return resourceName +end + ---This will send an email to the passed email address with the title and message. ---@param email string ---@param title string diff --git a/modules/phone/okokPhone/server.lua b/modules/phone/okokPhone/server.lua index ce59722..af9b01d 100644 --- a/modules/phone/okokPhone/server.lua +++ b/modules/phone/okokPhone/server.lua @@ -25,6 +25,10 @@ Phone.GetPhoneName = function() return resourceName end +Phone.GetResourceName = function() + return resourceName +end + ---This will get the phone number of the passed source. ---@param src number ---@return number|boolean diff --git a/modules/phone/qs-smartphone/client.lua b/modules/phone/qs-smartphone/client.lua index 72b1cda..44dd051 100644 --- a/modules/phone/qs-smartphone/client.lua +++ b/modules/phone/qs-smartphone/client.lua @@ -9,6 +9,10 @@ Phone.GetPhoneName = function() return resourceName end +Phone.GetResourceName = function() + return resourceName +end + ---This will send an email to the passed email address with the title and message. ---@param email string ---@param title string diff --git a/modules/phone/qs-smartphone/server.lua b/modules/phone/qs-smartphone/server.lua index fbcc6c9..f845a6d 100644 --- a/modules/phone/qs-smartphone/server.lua +++ b/modules/phone/qs-smartphone/server.lua @@ -9,6 +9,10 @@ Phone.GetPhoneName = function() return resourceName end +Phone.GetResourceName = function() + return resourceName +end + ---This will get the phone number of the passed source. ---@param src number ---@return number|boolean diff --git a/modules/phone/yseries/client.lua b/modules/phone/yseries/client.lua index a9ddf47..1d92151 100644 --- a/modules/phone/yseries/client.lua +++ b/modules/phone/yseries/client.lua @@ -9,6 +9,10 @@ Phone.GetPhoneName = function() return resourceName end +Phone.GetResourceName = function() + return resourceName +end + ---This will send an email to the passed email address with the title and message. ---@param email string ---@param title string diff --git a/modules/phone/yseries/server.lua b/modules/phone/yseries/server.lua index d460be6..d8bee21 100644 --- a/modules/phone/yseries/server.lua +++ b/modules/phone/yseries/server.lua @@ -9,6 +9,10 @@ Phone.GetPhoneName = function() return resourceName end +Phone.GetResourceName = function() + return resourceName +end + ---This will get the phone number of the passed source. ---@param src number ---@return number|boolean diff --git a/modules/progressbar/lation_ui/client.lua b/modules/progressbar/lation_ui/client.lua index 34ac775..2d08e3a 100644 --- a/modules/progressbar/lation_ui/client.lua +++ b/modules/progressbar/lation_ui/client.lua @@ -103,4 +103,9 @@ function ProgressBar.Open(options, cb, isQBInput) return success end + +ProgressBar.GetResourceName = function() + return "lation_ui" +end + return ProgressBar \ No newline at end of file diff --git a/modules/progressbar/ox_lib/client.lua b/modules/progressbar/ox_lib/client.lua index 36b6b77..96ba26b 100644 --- a/modules/progressbar/ox_lib/client.lua +++ b/modules/progressbar/ox_lib/client.lua @@ -64,4 +64,8 @@ function ProgressBar.Open(options, cb, isQBInput) return success end +ProgressBar.GetResourceName = function() + return "ox_lib" +end + return ProgressBar \ No newline at end of file diff --git a/modules/progressbar/qb-progressbar/client.lua b/modules/progressbar/qb-progressbar/client.lua index 67095a0..94a7a10 100644 --- a/modules/progressbar/qb-progressbar/client.lua +++ b/modules/progressbar/qb-progressbar/client.lua @@ -63,4 +63,8 @@ function ProgressBar.Open(options, cb, qbFormat) return Citizen.Await(prom) end +ProgressBar.GetResourceName = function() + return "progressbar" +end + return ProgressBar \ No newline at end of file diff --git a/modules/skills/_default/client.lua b/modules/skills/_default/client.lua index 7d3cd9e..3acf9ae 100644 --- a/modules/skills/_default/client.lua +++ b/modules/skills/_default/client.lua @@ -1,12 +1,6 @@ ---@diagnostic disable: duplicate-set-field Skills = Skills or {} ----This will get the name of the Skills system being being used. ----@return string -Skills.GetResourceName = function() - return "community_bridge" -end - XP_CACHE = {} -- Calculate XP required for a level using RuneScape algorithm (with caching) @@ -68,6 +62,9 @@ Skills.GetXP = function(skillName) return plyrSkills[skillName].currentXP or 1 end +Skills.GetResourceName = function() + return "default" +end -- RegisterCommand("getfishingLevel", function(source, args) -- local level = Skills.GetSkillLevel("fishing") diff --git a/modules/skills/_default/server.lua b/modules/skills/_default/server.lua index afe9cd5..7ec6d55 100644 --- a/modules/skills/_default/server.lua +++ b/modules/skills/_default/server.lua @@ -141,9 +141,8 @@ Skills.SetXP = function(src, skillName, xp) return true end --- Get resource name Skills.GetResourceName = function() - return "community_bridge" + return "default" end -- Debug Commands diff --git a/modules/target/_default/client.lua b/modules/target/_default/client.lua index 33416e7..ef3f214 100644 --- a/modules/target/_default/client.lua +++ b/modules/target/_default/client.lua @@ -175,4 +175,8 @@ Target.RemoveZone = function(name) warnUser() end +Target.GetResourceName = function() + return "default" +end + return Target \ No newline at end of file diff --git a/modules/target/ox_target/client.lua b/modules/target/ox_target/client.lua index 129af5b..f98c26b 100644 --- a/modules/target/ox_target/client.lua +++ b/modules/target/ox_target/client.lua @@ -205,4 +205,8 @@ AddEventHandler('onResourceStop', function(resource) targetZones = {} end) +Target.GetResourceName = function() + return "ox_target" +end + return Target \ No newline at end of file diff --git a/modules/target/qb-target/client.lua b/modules/target/qb-target/client.lua index c1a4b63..6dc9adb 100644 --- a/modules/target/qb-target/client.lua +++ b/modules/target/qb-target/client.lua @@ -230,4 +230,8 @@ AddEventHandler('onResourceStop', function(resource) targetZones = {} end) +Target.GetResourceName = function() + return "qb-target" +end + return Target \ No newline at end of file diff --git a/modules/target/sleepless_interact/client.lua b/modules/target/sleepless_interact/client.lua index c9909da..194e308 100644 --- a/modules/target/sleepless_interact/client.lua +++ b/modules/target/sleepless_interact/client.lua @@ -188,4 +188,8 @@ AddEventHandler('onResourceStop', function(resource) targetZones = {} end) +Target.GetResourceName = function() + return "sleepless_interact" +end + return Target \ No newline at end of file diff --git a/modules/vehicleKey/F_RealCarKeysSystem/client/client.lua b/modules/vehicleKey/F_RealCarKeysSystem/client/client.lua index 9426293..2861a9d 100644 --- a/modules/vehicleKey/F_RealCarKeysSystem/client/client.lua +++ b/modules/vehicleKey/F_RealCarKeysSystem/client/client.lua @@ -11,11 +11,8 @@ VehicleKey = VehicleKey or {} VehicleKey.GiveKeys = function(vehicle, plate) assert(vehicle, "vehicle is nil") assert(DoesEntityExist(vehicle), "vehicle does not exist") - - if not plate then - plate = GetVehicleNumberPlateText(vehicle) - end - + if not plate then plate = GetVehicleNumberPlateText(vehicle) end + TriggerServerEvent('F_RealCarKeysSystem:generateVehicleKeys', plate) end @@ -28,12 +25,14 @@ end VehicleKey.RemoveKeys = function(vehicle, plate) assert(vehicle, "vehicle is nil") assert(DoesEntityExist(vehicle), "vehicle does not exist") - - if not plate then - plate = GetVehicleNumberPlateText(vehicle) - end - + + if not plate then plate = GetVehicleNumberPlateText(vehicle) end + TriggerServerEvent('F_RealCarKeysSystem:removeVehicleKeysByPlate', plate) end +VehicleKey.GetResourceName = function() + return resourceName +end + return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/MrNewbVehicleKeys/client/client.lua b/modules/vehicleKey/MrNewbVehicleKeys/client/client.lua index bfd4a99..6f6b8fa 100644 --- a/modules/vehicleKey/MrNewbVehicleKeys/client/client.lua +++ b/modules/vehicleKey/MrNewbVehicleKeys/client/client.lua @@ -34,4 +34,8 @@ VehicleKey.RemoveKeys = function(vehicle, plate) return exports.MrNewbVehicleKeys:RemoveKeysByPlate(plate) end +VehicleKey.GetResourceName = function() + return resourceName +end + return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/Renewed-Vehiclekeys/client/client.lua b/modules/vehicleKey/Renewed-Vehiclekeys/client/client.lua index 69653bc..77d75ec 100644 --- a/modules/vehicleKey/Renewed-Vehiclekeys/client/client.lua +++ b/modules/vehicleKey/Renewed-Vehiclekeys/client/client.lua @@ -34,4 +34,8 @@ VehicleKey.RemoveKeys = function(vehicle, plate) return exports['Renewed-Vehiclekeys']:removeKey(plate) end +VehicleKey.GetResourceName = function() + return resourceName +end + return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/_default/client/client.lua b/modules/vehicleKey/_default/client/client.lua index 6d66938..7ab8d33 100644 --- a/modules/vehicleKey/_default/client/client.lua +++ b/modules/vehicleKey/_default/client/client.lua @@ -6,7 +6,7 @@ VehicleKey = VehicleKey or {} ---@param plate? string The plate of the vehicle. ---@return nil VehicleKey.GiveKeys = function(vehicle, plate) - Prints.Info("There is no compatible vehicle key resource.") + print("There is no compatible vehicle key resource.") end ---Removes the keys of the specified vehicle from the player (self). @@ -14,7 +14,11 @@ end ---@param plate? string The plate of the vehicle. ---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - Prints.Info("There is no compatible vehicle key resource.") + print("There is no compatible vehicle key resource.") +end + +VehicleKey.GetResourceName = function() + return "default" end return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/cd_garage/client/client.lua b/modules/vehicleKey/cd_garage/client/client.lua index d45dc23..56f5313 100644 --- a/modules/vehicleKey/cd_garage/client/client.lua +++ b/modules/vehicleKey/cd_garage/client/client.lua @@ -11,7 +11,7 @@ VehicleKey = VehicleKey or {} VehicleKey.GiveKeys = function(vehicle, plate) assert(vehicle, "vehicle is nil") assert(DoesEntityExist(vehicle), "vehicle does not exist") - + if not plate then plate = GetVehicleNumberPlateText(vehicle) end @@ -24,7 +24,11 @@ end ---@param plate? string The plate of the vehicle. ---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - Prints.Info("cd_garage doesnt support removing keys.") + print("cd_garage doesnt support removing keys.") +end + +VehicleKey.GetResourceName = function() + return resourceName end return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/jacksam/client.lua b/modules/vehicleKey/jacksam/client.lua index d47b413..f1f1b32 100644 --- a/modules/vehicleKey/jacksam/client.lua +++ b/modules/vehicleKey/jacksam/client.lua @@ -34,4 +34,8 @@ VehicleKey.RemoveKeys = function(vehicle, plate) TriggerServerEvent("vehicles_keys:selfRemoveKeys", plate) end +VehicleKey.GetResourceName = function() + return resourceName +end + return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/mVehicle/client/client.lua b/modules/vehicleKey/mVehicle/client/client.lua index 5216aac..e89acc9 100644 --- a/modules/vehicleKey/mVehicle/client/client.lua +++ b/modules/vehicleKey/mVehicle/client/client.lua @@ -20,7 +20,11 @@ end ---@param plate? string The plate of the vehicle. ---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - Prints.Info("mVehicle doesnt support removing keys.") + print("mVehicle doesnt support removing keys.") +end + +VehicleKey.GetResourceName = function() + return resourceName end return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/mk_vehiclekeys/client/client.lua b/modules/vehicleKey/mk_vehiclekeys/client/client.lua index cf2c004..e70ebca 100644 --- a/modules/vehicleKey/mk_vehiclekeys/client/client.lua +++ b/modules/vehicleKey/mk_vehiclekeys/client/client.lua @@ -26,4 +26,8 @@ VehicleKey.RemoveKeys = function(vehicle, plate) exports["mk_vehiclekeys"]:RemoveKey(vehicle) end +VehicleKey.GetResourceName = function() + return resourceName +end + return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/okokGarage/client/client.lua b/modules/vehicleKey/okokGarage/client/client.lua index fee3fa4..84e09d8 100644 --- a/modules/vehicleKey/okokGarage/client/client.lua +++ b/modules/vehicleKey/okokGarage/client/client.lua @@ -35,4 +35,8 @@ VehicleKey.RemoveKeys = function(vehicle, plate) TriggerServerEvent("okokGarage:RemoveKeys", plate, source) end +VehicleKey.GetResourceName = function() + return resourceName +end + return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/qb-vehiclekeys/client/client.lua b/modules/vehicleKey/qb-vehiclekeys/client/client.lua index bc01002..52f2fbd 100644 --- a/modules/vehicleKey/qb-vehiclekeys/client/client.lua +++ b/modules/vehicleKey/qb-vehiclekeys/client/client.lua @@ -34,4 +34,8 @@ VehicleKey.RemoveKeys = function(vehicle, plate) TriggerEvent("qb-vehiclekeys:client:RemoveKeys", plate) end +VehicleKey.GetResourceName = function() + return resourceName +end + return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/qbx_vehiclekeys/client/client.lua b/modules/vehicleKey/qbx_vehiclekeys/client/client.lua index 69c4ac9..2735ab8 100644 --- a/modules/vehicleKey/qbx_vehiclekeys/client/client.lua +++ b/modules/vehicleKey/qbx_vehiclekeys/client/client.lua @@ -34,4 +34,8 @@ VehicleKey.RemoveKeys = function(vehicle, plate) TriggerEvent("qb-vehiclekeys:client:RemoveKeys", plate) end +VehicleKey.GetResourceName = function() + return resourceName +end + return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/qs-vehiclekeys/client/client.lua b/modules/vehicleKey/qs-vehiclekeys/client/client.lua index 06bdfdd..36708d8 100644 --- a/modules/vehicleKey/qs-vehiclekeys/client/client.lua +++ b/modules/vehicleKey/qs-vehiclekeys/client/client.lua @@ -36,4 +36,8 @@ VehicleKey.RemoveKeys = function(vehicle, plate) return exports['qs-vehiclekeys']:RemoveKeys(plate, model) end +VehicleKey.GetResourceName = function() + return resourceName +end + return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/t1ger_keys/client/client.lua b/modules/vehicleKey/t1ger_keys/client/client.lua index e996071..7ad97c5 100644 --- a/modules/vehicleKey/t1ger_keys/client/client.lua +++ b/modules/vehicleKey/t1ger_keys/client/client.lua @@ -25,7 +25,11 @@ end ---@param plate? string The plate of the vehicle. ---@return nil VehicleKey.RemoveKeys = function(vehicle, plate) - Prints.Info("t1ger_keys doesnt support removing keys.") + print("t1ger_keys doesnt support removing keys.") +end + +VehicleKey.GetResourceName = function() + return resourceName end return VehicleKey \ No newline at end of file diff --git a/modules/vehicleKey/wasabi_carlock/client/client.lua b/modules/vehicleKey/wasabi_carlock/client/client.lua index 328699d..6b3a49c 100644 --- a/modules/vehicleKey/wasabi_carlock/client/client.lua +++ b/modules/vehicleKey/wasabi_carlock/client/client.lua @@ -34,4 +34,8 @@ VehicleKey.RemoveKeys = function(vehicle, plate) exports.wasabi_carlock:RemoveKey(plate) end +VehicleKey.GetResourceName = function() + return resourceName +end + return VehicleKey \ No newline at end of file diff --git a/modules/weather/_default/client.lua b/modules/weather/_default/client.lua index 7625ab6..7fc0ed6 100644 --- a/modules/weather/_default/client.lua +++ b/modules/weather/_default/client.lua @@ -8,4 +8,8 @@ Weather.ToggleSync = function(toggle) end +Weather.GetResourceName = function() + return "default" +end + return Weather \ No newline at end of file diff --git a/modules/weather/cd_easytime/client.lua b/modules/weather/cd_easytime/client.lua index 210ca56..1b6cf2e 100644 --- a/modules/weather/cd_easytime/client.lua +++ b/modules/weather/cd_easytime/client.lua @@ -9,4 +9,8 @@ Weather.ToggleSync = function(toggle) TriggerEvent('cd_easytime:PauseSync', toggle) end +Weather.GetResourceName = function() + return "cd_easytime" +end + return Weather \ No newline at end of file diff --git a/modules/weather/qb-weathersync/client/client.lua b/modules/weather/qb-weathersync/client/client.lua index 548bc23..bbcaa24 100644 --- a/modules/weather/qb-weathersync/client/client.lua +++ b/modules/weather/qb-weathersync/client/client.lua @@ -13,4 +13,8 @@ Weather.ToggleSync = function(toggle) end end +Weather.GetResourceName = function() + return "qb-weathersync" +end + return Weather \ No newline at end of file diff --git a/modules/weather/renewed-weathersync/client/client.lua b/modules/weather/renewed-weathersync/client/client.lua index 9d4d460..a6ae316 100644 --- a/modules/weather/renewed-weathersync/client/client.lua +++ b/modules/weather/renewed-weathersync/client/client.lua @@ -9,4 +9,8 @@ Weather.ToggleSync = function(toggle) LocalPlayer.state.syncWeather = toggle end +Weather.GetResourceName = function() + return "renewed-weathersync" +end + return Weather \ No newline at end of file From d669f7ba16b6569272c025d449ac5482692a5ef2 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Wed, 10 Sep 2025 12:42:19 -0400 Subject: [PATCH 61/62] Remove debug print from UpdateEntity event Eliminated unnecessary json-encoded print statement from the UpdateEntity event handler to clean up console output. --- lib/entities/client/client_entity.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/entities/client/client_entity.lua b/lib/entities/client/client_entity.lua index 6a627df..6f16bf4 100644 --- a/lib/entities/client/client_entity.lua +++ b/lib/entities/client/client_entity.lua @@ -241,7 +241,6 @@ end) RegisterNetEvent("community_bridge:client:UpdateEntity", function(id, data) for k, v in pairs(data) do - print(json.encode({k, v})) ClientEntity.Set(id, k, v) end end) From 96d311c4d33610fbc1f1c31efbd56b0512e71a79 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Wed, 10 Sep 2025 13:23:02 -0400 Subject: [PATCH 62/62] Bump version to 0.12.0 in fxmanifest.lua Updated the resource version from 0.11.2 to 0.12.0 to reflect new changes or improvements in the community_bridge project. --- fxmanifest.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fxmanifest.lua b/fxmanifest.lua index d9c4c3d..83c03ef 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -5,7 +5,7 @@ use_experimental_fxv2_oal 'yes' author 'The Order of the Sacred Framework' name 'community_bridge' description 'A Universal Bridge for Our Community, created by a group of contributors with a shared vision to enhance both user and developer experiences. This bridge connects various frameworks, inventories, target systems, notification systems, and more, fostering compatibility and seamless integration.' -version '0.11.2' +version '0.12.0' shared_scripts { '@ox_lib/init.lua',