diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 52cc4c5..79fb8c7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,17 +4,16 @@ on: release: types: [published] +permissions: + contents: read + jobs: send-webhook: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Install jq - run: sudo apt-get update && sudo apt-get install -y jq - + # Reads only the release event payload, so no checkout is needed and jq + # is already present on the runner image. - name: Send webhook notification env: WEBHOOK_URL: ${{ secrets.RELEASE_WEBHOOK_URL }} @@ -57,7 +56,7 @@ jobs: "type": 2, "style": 5, "label": "Get The Latest Community Bridge Release", - "url": "https://github.com/The-Order-Of-The-Sacred-Framework/community_bridge/tree/main" + "url": "https://github.com/TheOrderFivem/community_bridge/releases/latest" } ] } diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d21748d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,122 @@ +name: Release + +# Publishes a release when a push to main bumps the fxmanifest.lua version. +# Tags/titles are bare versions (0.13.4) to match this repo's existing releases. +# +# The "Update Webhook Notification" workflow listens for release:published, and +# GitHub suppresses workflow triggers for events raised by GITHUB_TOKEN. Add a +# classic PAT with repo scope as the RELEASE_PAT secret to keep the Discord +# announcement firing; without it the release still publishes, silently. + +on: + push: + branches: + - main + paths: + - 'fxmanifest.lua' + workflow_dispatch: + +permissions: + contents: write + +jobs: + check-version: + runs-on: ubuntu-latest + outputs: + should_release: ${{ steps.meta.outputs.should_release }} + version: ${{ steps.meta.outputs.version }} + steps: + - name: Checkout + uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Detect fxmanifest version change + id: meta + run: | + CURRENT=$(grep -E '^version ' fxmanifest.lua | sed -E "s/^version[[:space:]]+['\"]([^'\"]+)['\"].*/\1/") + echo "version=$CURRENT" >> "$GITHUB_OUTPUT" + + if [ -z "$CURRENT" ]; then + echo "::error::No version found in fxmanifest.lua" + exit 1 + fi + + # Never re-release an existing version: a duplicate release would + # announce itself to Discord as if it were new. + if git rev-parse "refs/tags/$CURRENT" >/dev/null 2>&1; then + echo "should_release=false" >> "$GITHUB_OUTPUT" + echo "Tag $CURRENT already exists; skipping release." + exit 0 + fi + + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "should_release=true" >> "$GITHUB_OUTPUT" + echo "Manual run; releasing version $CURRENT" + exit 0 + fi + + BEFORE="${{ github.event.before }}" + if [ "$BEFORE" = "0000000000000000000000000000000000000000" ] || [ -z "$BEFORE" ]; then + echo "should_release=true" >> "$GITHUB_OUTPUT" + echo "Initial or force push; releasing version $CURRENT" + exit 0 + fi + + PREVIOUS=$(git show "$BEFORE:fxmanifest.lua" 2>/dev/null | grep -E '^version ' | sed -E "s/^version[[:space:]]+['\"]([^'\"]+)['\"].*/\1/" || true) + if [ "$CURRENT" = "$PREVIOUS" ]; then + echo "should_release=false" >> "$GITHUB_OUTPUT" + echo "fxmanifest changed but version is still $CURRENT; skipping release." + else + echo "should_release=true" >> "$GITHUB_OUTPUT" + echo "Version updated: ${PREVIOUS:-unknown} -> $CURRENT" + fi + + release: + runs-on: ubuntu-latest + needs: check-version + if: needs.check-version.outputs.should_release == 'true' + + steps: + - name: Checkout + uses: actions/checkout@v5 + + - name: Prepare release package + run: | + RELEASE_ROOT="release/community_bridge" + mkdir -p "$RELEASE_ROOT/web" + + rsync -a \ + --exclude '.git' \ + --exclude '.gitattributes' \ + --exclude '.gitignore' \ + --exclude '.github' \ + --exclude 'release' \ + --exclude 'node_modules' \ + --exclude 'web' \ + ./ "$RELEASE_ROOT/" + + # Pre-built web/dist/ is committed; ship the built UI only and leave + # the vite source and tooling (src/, package.json, configs) behind. + rsync -a web/dist/ "$RELEASE_ROOT/web/dist/" + rsync -a web/public/ "$RELEASE_ROOT/web/public/" + + - name: Create zip archive + run: | + cd release + zip -r "../community_bridge.zip" community_bridge + + - name: Upload workflow artifact + uses: actions/upload-artifact@v5 + with: + name: community_bridge + path: community_bridge.zip + + - name: Publish GitHub Release + uses: softprops/action-gh-release@v2 + with: + token: ${{ secrets.RELEASE_PAT || github.token }} + tag_name: ${{ needs.check-version.outputs.version }} + name: ${{ needs.check-version.outputs.version }} + files: community_bridge.zip + generate_release_notes: true diff --git a/README.md b/README.md index e5caeb4..bc3b7fd 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://theorderfivem.github.io/public_docs/) +[Community Bridge Documentation](https://theorderfivem.github.io/docs) --- ## Community and Support @@ -69,7 +69,6 @@ Join the Community Bridge Discord server for support, discussion, and contributi ## About Community Bridge community_bridge is developed by The Order of the Sacred Framework, a collaborative team focused on improving interoperability and reducing development friction in the FiveM ecosystem. The project is open source and licensed under GPLv3. -We also have a vscode extension located at https://marketplace.visualstudio.com/items?itemName=TheOrderOfTheSacredFramework.fivem-community-bridge-lua --- diff --git a/fxmanifest.lua b/fxmanifest.lua index 01eb242..b2f17b5 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.13.3' +version '0.13.5' shared_scripts { '@ox_lib/init.lua', @@ -45,7 +45,7 @@ client_scripts { 'modules/doorlock/**/client.lua', 'modules/phone/**/client.lua', 'modules/weather/**/client.lua', - 'modules/vehicleKey/**/client.lua', + 'modules/vehiclekey/**/client.lua', 'modules/fuel/**/client.lua', 'modules/target/**/client.lua', 'modules/dispatch/**/client.lua', diff --git a/lib/sql/server/sqlHandler.lua b/lib/sql/server/sqlHandler.lua index 644467e..9e35fec 100644 --- a/lib/sql/server/sqlHandler.lua +++ b/lib/sql/server/sqlHandler.lua @@ -1,21 +1,67 @@ +--[[ + DEPRECATED: the SQL helper module is deprecated in its entirety and will be + REMOVED on 2026-08-22. Migrate to oxmysql directly — MySQL.query.await(query, + params) with ? placeholders — which is safer and more flexible than these + wrappers ever were. +]] + SQL = {} Require("lib/MySQL.lua", "oxmysql") +local warnedResources = {} + +local function warnDeprecated() + local caller = GetInvokingResource() or GetCurrentResourceName() + if warnedResources[caller] then return end + warnedResources[caller] = true + print(("^3[community_bridge] SQL helpers are deprecated and will be REMOVED on 2026-08-22. '%s' should migrate to oxmysql directly (MySQL.query.await with ? placeholders).^0"):format(caller)) +end + +-- Identifiers (table/column names) cannot be parameterized, so they are +-- validated against a strict pattern and backtick-quoted instead. Values are +-- never concatenated into queries - they always go through ? placeholders. +local function quoteIdentifier(name) + assert(type(name) == "string" and name:match("^[%a_][%w_]*$"), + ("SQL: unsafe identifier '%s' - table/column names may only contain letters, digits and underscores"):format(tostring(name))) + return "`" .. name .. "`" +end + +--- Builds a parameterized WHERE clause from a table of column = value pairs. +-- Raw WHERE strings are intentionally rejected: they made SQL injection +-- unavoidable whenever a player-influenced value reached these helpers. +local function buildWhere(where) + assert(type(where) == "table" and next(where) ~= nil, + "SQL: where must be a non-empty table of column = value pairs (raw WHERE strings are no longer accepted)") + + local conditions = {} + local params = {} + + for column, value in pairs(where) do + table.insert(conditions, quoteIdentifier(column) .. " = ?") + table.insert(params, value) + end + + return table.concat(conditions, " AND "), params +end + --- Creates a table in the database if it does not exist. -- @param tableName The name of the table to create. Example: {{ name = "identifier", type = "VARCHAR(50)", primary = true }} -- @param columns A table containing column definitions, where each column is a table with 'name' and 'type'. ---@return nil +---@deprecated Removed on 2026-08-22 — use oxmysql directly. function SQL.Create(tableName, columns) + warnDeprecated() assert(MySQL, "Tried using module SQL without MySQL being loaded") local columnsList = {} for i, column in pairs(columns) do - table.insert(columnsList, string.format("%s %s", column.name, column.type)) + assert(type(column.type) == "string", "SQL: column type must be a string") + table.insert(columnsList, string.format("%s %s", quoteIdentifier(column.name), column.type)) end local query = string.format("CREATE TABLE IF NOT EXISTS %s (%s);", - tableName, + quoteIdentifier(tableName), table.concat(columnsList, ", ") ) @@ -23,50 +69,70 @@ function SQL.Create(tableName, columns) end -- insert if not exist otherwise update +---@deprecated Removed on 2026-08-22 — use oxmysql directly. function SQL.InsertOrUpdate(tableName, data) + warnDeprecated() assert(MySQL, "Tried using module SQL without MySQL being loaded") local columns = {} - local values = {} + local placeholders = {} local updates = {} + local params = {} for column, value in pairs(data) do - table.insert(columns, column) - table.insert(values, "'" .. value .. "'") -- Ensure values are properly quoted - table.insert(updates, column .. " = VALUES(" .. column .. ")") -- Use VALUES() for update + local quoted = quoteIdentifier(column) + table.insert(columns, quoted) + table.insert(placeholders, "?") + table.insert(updates, quoted .. " = VALUES(" .. quoted .. ")") -- Use VALUES() for update + table.insert(params, value) end local query = string.format( "INSERT INTO %s (%s) VALUES (%s) ON DUPLICATE KEY UPDATE %s;", - tableName, + quoteIdentifier(tableName), table.concat(columns, ", "), - table.concat(values, ", "), + table.concat(placeholders, ", "), table.concat(updates, ", ") ) - MySQL.query.await(query) + MySQL.query.await(query, params) end +--- Selects rows matching the given filters. +-- @param tableName The table to query. +-- @param where Table of column = value pairs, joined with AND. Example: { citizenid = cid } +---@deprecated Removed on 2026-08-22 — use oxmysql directly. function SQL.Get(tableName, where) + warnDeprecated() assert(MySQL, "Tried using module SQL without MySQL being loaded") - local query = string.format("SELECT * FROM %s WHERE %s;", tableName, where) - local result = MySQL.query.await(query) + local conditions, params = buildWhere(where) + local query = string.format("SELECT * FROM %s WHERE %s;", quoteIdentifier(tableName), conditions) + local result = MySQL.query.await(query, params) return result end +---@deprecated Removed on 2026-08-22 — use oxmysql directly. function SQL.GetAll(tableName) + warnDeprecated() assert(MySQL, "Tried using module SQL without MySQL being loaded") - local query = string.format("SELECT * FROM %s;", tableName) + local query = string.format("SELECT * FROM %s;", quoteIdentifier(tableName)) local result = MySQL.query.await(query) return result end +--- Deletes rows matching the given filters. +-- @param tableName The table to delete from. +-- @param where Table of column = value pairs, joined with AND. Example: { citizenid = cid } +---@deprecated Removed on 2026-08-22 — use oxmysql directly. function SQL.Delete(tableName, where) + warnDeprecated() assert(MySQL, "Tried using module SQL without MySQL being loaded") - local query = string.format("DELETE FROM %s WHERE %s;", tableName, where) - MySQL.query.await(query) + local conditions, params = buildWhere(where) + local query = string.format("DELETE FROM %s WHERE %s;", quoteIdentifier(tableName), conditions) + MySQL.query.await(query, params) end exports('SQL', function() + warnDeprecated() return SQL end) diff --git a/modules/banking/dhs-banking/server.lua b/modules/banking/dhs-banking/server.lua new file mode 100644 index 0000000..00e80db --- /dev/null +++ b/modules/banking/dhs-banking/server.lua @@ -0,0 +1,68 @@ +---@diagnostic disable: duplicate-set-field +if GetResourceState('DHS-BankingSim') == 'missing' then return end +Banking = Banking or {} + +local dhsBanking = exports['DHS-BankingSim'] + +--- Helper: resolve business account ID from a job/society name +---@param account string Job or society name (e.g. 'police', 'ambulance') +---@return number|nil businessId +local function ResolveBusinessId(account) + local row = MySQL.single.await( + 'SELECT id FROM business_accounts WHERE job_name = ? AND status = ? LIMIT 1', + { account, 'active' } + ) + return row and row.id or nil +end + +---This will get the name of the Managment system being being used. +---@return string +Banking.GetManagmentName = function() + return 'DHS-BankingSim' +end + +---This will get the name of the in use resource. +---@return string +Banking.GetResourceName = function() + return 'DHS-BankingSim' +end + +---This will return a number +---@param account string +---@return number +Banking.GetAccountMoney = function(account) + local businessId = ResolveBusinessId(account) + if not businessId then return 0 end + local balance = dhsBanking:GetBusinessBalance(businessId) + return balance or 0 +end + +---This will add money to the specified account of the passed amount +---@param account string +---@param amount number +---@param reason string +---@return boolean +Banking.AddAccountMoney = function(account, amount, reason) + local businessId = ResolveBusinessId(account) + if not businessId then return false end + reason = reason or 'Community Bridge deposit' + MySQL.update.await('UPDATE business_accounts SET balance = balance + ? WHERE id = ?', { amount, businessId }) + return true +end + +---This will remove money from the specified account of the passed amount +---@param account string +---@param amount number +---@param reason string +---@return boolean +Banking.RemoveAccountMoney = function(account, amount, reason) + local businessId = ResolveBusinessId(account) + if not businessId then return false end + reason = reason or 'Community Bridge withdrawal' + local row = MySQL.single.await('SELECT balance FROM business_accounts WHERE id = ?', { businessId }) + if not row or (tonumber(row.balance) or 0) < amount then return false end + MySQL.update.await('UPDATE business_accounts SET balance = balance - ? WHERE id = ?', { amount, businessId }) + return true +end + +return Banking diff --git a/modules/bossmenu/_default/client.lua b/modules/bossmenu/_default/client.lua index 63a8efa..0179a1d 100644 --- a/modules/bossmenu/_default/client.lua +++ b/modules/bossmenu/_default/client.lua @@ -18,6 +18,10 @@ RegisterNetEvent('community_bridge:client:OpenBossMenu', function(jobName, jobTy end, {wash = false}) elseif BossMenu.GetResourceName() == "qbx_management" then exports.qbx_management:OpenBossMenu(jobType) + elseif BossMenu.GetResourceName() == "tk_bosstablet" then + exports.tk_bosstablet:openBossMenu() + elseif BossMenu.GetResourceName() == "zat-bossmenu" then + exports['zat-bossmenu']:OpenBossMenu(jobType or 'job') end end) diff --git a/modules/bossmenu/tk_bosstablet/client.lua b/modules/bossmenu/tk_bosstablet/client.lua new file mode 100644 index 0000000..31fca1a --- /dev/null +++ b/modules/bossmenu/tk_bosstablet/client.lua @@ -0,0 +1,12 @@ +---@diagnostic disable: duplicate-set-field +if GetResourceState('tk_bosstablet') ~= 'started' then return end + +BossMenu = BossMenu or {} + +---This will get the name of the module being used. +---@return string +BossMenu.GetResourceName = function() + return "tk_bosstablet" +end + +return BossMenu diff --git a/modules/bossmenu/tk_bosstablet/server.lua b/modules/bossmenu/tk_bosstablet/server.lua new file mode 100644 index 0000000..1cc588b --- /dev/null +++ b/modules/bossmenu/tk_bosstablet/server.lua @@ -0,0 +1,16 @@ +---@diagnostic disable: duplicate-set-field +if GetResourceState('tk_bosstablet') ~= 'started' then return end + +BossMenu = BossMenu or {} + +---This will get the name of the module being used. +---@return string +BossMenu.GetResourceName = function() + return "tk_bosstablet" +end + +BossMenu.OpenBossMenu = function(src, jobName, jobType) + TriggerClientEvent("community_bridge:client:OpenBossMenu", src, jobName, jobType) +end + +return BossMenu diff --git a/modules/bossmenu/zat-bossmenu/client.lua b/modules/bossmenu/zat-bossmenu/client.lua new file mode 100644 index 0000000..7cddc27 --- /dev/null +++ b/modules/bossmenu/zat-bossmenu/client.lua @@ -0,0 +1,12 @@ +---@diagnostic disable: duplicate-set-field +if GetResourceState('zat-bossmenu') ~= 'started' then return end + +BossMenu = BossMenu or {} + +---This will get the name of the module being used. +---@return string +BossMenu.GetResourceName = function() + return "zat-bossmenu" +end + +return BossMenu diff --git a/modules/bossmenu/zat-bossmenu/server.lua b/modules/bossmenu/zat-bossmenu/server.lua new file mode 100644 index 0000000..e746baf --- /dev/null +++ b/modules/bossmenu/zat-bossmenu/server.lua @@ -0,0 +1,16 @@ +---@diagnostic disable: duplicate-set-field +if GetResourceState('zat-bossmenu') ~= 'started' then return end + +BossMenu = BossMenu or {} + +---This will get the name of the module being used. +---@return string +BossMenu.GetResourceName = function() + return "zat-bossmenu" +end + +BossMenu.OpenBossMenu = function(src, jobName, jobType) + TriggerClientEvent("community_bridge:client:OpenBossMenu", src, jobName, jobType) +end + +return BossMenu diff --git a/modules/dispatch/fd_dispatch/server/server.lua b/modules/dispatch/fd_dispatch/server/server.lua index ef9fa8f..9a62eef 100644 --- a/modules/dispatch/fd_dispatch/server/server.lua +++ b/modules/dispatch/fd_dispatch/server/server.lua @@ -8,4 +8,41 @@ Dispatch.GetResourceName = function() return 'fd_dispatch' end -return Dispatch \ No newline at end of file +Dispatch.SendAlert = function(data) + local metadata = {} + if data.vehicle then + table.insert(metadata, { + type = 'vehicle', + model = data.vehicle or locale('unknown_vehicle_model'), + plate = data.plate or nil, + color = data.colorHex or nil + }) + end + if type(data.job) == "string" then + data.job = {data.job} + end + local coords = data.coords or GetEntityCoords(GetPlayerPed(data.source)) + local alertData = { + source = data.source, + title = data.title or "No message provided", + description = data.message or "", + groups = data.jobs or data.job or {"police"}, + code = data.code or '10-80', + priority = data.priority or 2, + metadata = metadata, + blip = { + title = data.title or "No message provided", + coords = coords, + radius = data.blip and data.blip.radius or nil, + sprite = data.blip and data.blip.sprite or 161, + color = data.blip and data.blip.color or 1, + scale = data.blip and data.blip.scale or 1.2, + flashes = data.blip.flash or false, + time = data.time or (6 * 60000), + category = data.category or nil, + }, + } + exports.fd_dispatch:addAlert(alertData) +end + +return Dispatch diff --git a/modules/framework/qbx_core/server.lua b/modules/framework/qbx_core/server.lua index f8431aa..53071bd 100644 --- a/modules/framework/qbx_core/server.lua +++ b/modules/framework/qbx_core/server.lua @@ -547,4 +547,30 @@ AddEventHandler("playerDropped", function() TriggerEvent("community_bridge:Server:OnPlayerUnload", src) end) -return Framework \ No newline at end of file +Framework.Commands = Framework.Commands or {} + +---@description Adds a command to the Qbox framework +---@param name string +---@param help string +---@param arguments table +---@param argsrequired boolean +---@param callback function +---@param permission string +---@param ... any +Framework.Commands.Add = function(name, help, arguments, argsrequired, callback, permission, ...) + lib.addCommand(name, { + help = help or "", + params = arguments or {}, + restricted = false + }, function(source, args, raw) + if permission and permission ~= "user" then + if not Framework.GetIsFrameworkAdmin(source) then + return + end + end + + callback(source, args or {}, raw) + end) +end + +return Framework diff --git a/modules/inventory/core_inventory/client.lua b/modules/inventory/core_inventory/client.lua index 4ecfea0..39b4de0 100644 --- a/modules/inventory/core_inventory/client.lua +++ b/modules/inventory/core_inventory/client.lua @@ -1,8 +1,6 @@ ---@diagnostic disable: duplicate-set-field if GetResourceState('core_inventory') == 'missing' then return end local core = exports.core_inventory --- Core inventory docs available at https://docs.c8re.store/core-inventory/api/server#getitemslist -Callback = Callback or Require("lib/callback/shared/callback.lua") Inventory = Inventory or {} @@ -14,7 +12,7 @@ end local cachedItemList = nil --- Return the item info in oxs format, {name, label, stack, weight, description, image} ---- https://docs.c8re.store/core-inventory/api/server#getitemslist +--- https://docs.c8re.store/core-inventory/exports#client-exports-%E2%80%94-inventory-ui --- @param item string --- @return table Inventory.GetItemInfo = function(item) @@ -22,24 +20,22 @@ Inventory.GetItemInfo = function(item) return itemList[item] or {} end ----This will return the entire items table from the inventory. +---This will return the entire items table from the inventory in the ox format. ---@return table Inventory.Items = function() - local frameworkName = Framework.GetFrameworkName() - if not frameworkName then return {} end + if cachedItemList then return cachedItemList end + local allItems = core:getItemsList() + if not allItems then return {} end local dataRepack = {} - if frameworkName == 'es_extended' then - if not cachedItemList then cachedItemList = Callback.Trigger('community_bridge:Callback:core_inventory', false) end - dataRepack = cachedItemList or {} - elseif frameworkName == 'qb-core' then - dataRepack = Framework.Shared.Items or {} - end - for itemName, itemData in pairs(dataRepack) do + for itemName, itemData in pairs(allItems) do if itemData and itemData.name then - dataRepack[itemName].image = Inventory.GetImagePath(itemData.name) - dataRepack[itemName].stack = dataRepack[itemName].unique or false + dataRepack[itemName] = { + image = Inventory.GetImagePath(itemData.name), + stack = itemData.unique or false + } end end + cachedItemList = dataRepack return dataRepack end diff --git a/modules/inventory/core_inventory/server.lua b/modules/inventory/core_inventory/server.lua index 64e473f..8af0219 100644 --- a/modules/inventory/core_inventory/server.lua +++ b/modules/inventory/core_inventory/server.lua @@ -3,7 +3,6 @@ if GetResourceState('core_inventory') == 'missing' then return end Inventory = Inventory or {} Inventory.Stashes = Inventory.Stashes or {} -Callback = Callback or Require("lib/callback/shared/callback.lua") local core = exports.core_inventory ---This will get the name of the in use resource. @@ -20,8 +19,7 @@ end ---@param metadata table ---@return boolean Inventory.AddItem = function(src, item, count, slot, metadata) - -- docs specify a table returned on success, on failure it returns false. - -- https://docs.c8re.store/core-inventory/api/server#additem + -- https://docs.c8re.store/core-inventory/exports#server-exports-%E2%80%94-items local success = core:addItem(src, item, count, metadata) if not success then return false end TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) @@ -48,16 +46,8 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata) end TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) if slot then - local identifier = Framework.GetPlayerIdentifier(src) - if not identifier then return false end - local framework = Bridge.Framework.GetFrameworkName() - if framework == 'es_extended' then - identifier = string.gsub(identifier, ":", "") - end - local weirdInventoryName = 'content-' .. identifier - -- No return value specified in docs, so we assume none. - -- https://docs.c8re.store/core-inventory/api/server#removeitemexact - return core:removeItemExact(weirdInventoryName, slot, count) + -- https://docs.c8re.store/core-inventory/exports#server-exports-%E2%80%94-items + return core:removeItemExact(src, slot, count) end core:removeItem(src, item, count) return true @@ -249,12 +239,6 @@ Inventory.GetImagePath = function(item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" end ----This is used for the esx users, documentation doesnt show a client side available option for the inventory so we use jank callbacks to get this. -Callback.Register('community_bridge:Callback:core_inventory', function(source) - local items = core:getItemsList() - return items or {} -end) - ---This will return the entire items table from the inventory. ---@return table Inventory.Items = function() diff --git a/modules/inventory/one_inventory/client.lua b/modules/inventory/one_inventory/client.lua new file mode 100644 index 0000000..cd2ea9b --- /dev/null +++ b/modules/inventory/one_inventory/client.lua @@ -0,0 +1,72 @@ +--[[ + + Get this inventory here https://onestudios.gg/ + +]]-- + +---@diagnostic disable: duplicate-set-field +if GetResourceState('one_inventory') == 'missing' then return end +local inv = exports['one_inventory'] +Inventory = Inventory or {} + +---@description This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "one_inventory" +end + +---@description Return the item info in oxs format, {name, label, stack, weight, description, image} +---@param item string +---@return table +Inventory.GetItemInfo = function(item) + local itemData = inv:GetItemDefinition(item) + if not itemData then return {} end + return { + name = itemData.name, + label = itemData.label, + stack = itemData.unique, + weight = itemData.weight, + description = itemData.description, + image = Inventory.GetImagePath(itemData.image or itemData.name) + } +end + +---@description This will return the entire items table from the inventory. +---@return table +Inventory.Items = function() + return inv:GetAllItemDefinitions() +end + +---@description Will return boolean if the player has the item. +---@param item string +---@param requiredCount number (optional) +---@return boolean +Inventory.HasItem = function(item, requiredCount) + return inv:HasItem(item, requiredCount or 1) +end + +---@description This will return their count of the item in the players inventory, if not found will return 0. +---@param item string +---@return number +Inventory.GetItemCount = function(item) + return inv:GetItemCount(item, nil) +end + +---@description This will get the image path for this item, if not found will return placeholder. +---@param item string +---@return string +Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) + local file = LoadResourceFile("one_inventory", string.format("web/images/%s.png", item)) + local imagePath = file and string.format("nui://one_inventory/web/images/%s.png", item) + return imagePath or "https://avatars.githubusercontent.com/u/47620135" +end + +---@description This will return the players inventory in the format of {name, label, count, slot, metadata} +---@return table +Inventory.GetPlayerInventory = function() + return inv:GetInventoryItems() +end + + +return Inventory \ No newline at end of file diff --git a/modules/inventory/one_inventory/server.lua b/modules/inventory/one_inventory/server.lua new file mode 100644 index 0000000..819ef75 --- /dev/null +++ b/modules/inventory/one_inventory/server.lua @@ -0,0 +1,247 @@ +--[[ + + Get this inventory here https://onestudios.gg/ + +]]-- + +---@diagnostic disable: duplicate-set-field +if GetResourceState('one_inventory') == 'missing' then return end +local inv = exports['one_inventory'] +Inventory = Inventory or {} +Inventory.Stashes = Inventory.Stashes or {} +Inventory.Version = nil +Inventory.ShopData = {} + +---@description This will get the name of the in use resource. +---@return string +Inventory.GetResourceName = function() + return "one_inventory" +end + +---@description This will add an item, and return true or false based on success +---@param src number +---@param item string +---@param count number +---@param slot number (optional) +---@param metadata table (optional) +---@return boolean +Inventory.AddItem = function(src, item, count, slot, metadata) + local success = inv:AddItem(src, item, count, metadata, slot) + + if not success then return false end + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) + return success or false +end + +---@description This will remove an item, and return true or false based on success +---@param src number +---@param item string +---@param count number +---@param slot number (optional) +---@param metadata table (optional) +---@return boolean +Inventory.RemoveItem = function(src, item, count, slot, metadata) + local success = inv:RemoveItem(src, item, count, metadata, slot) + + if not success then return false end + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) + return success or false +end + +---@description This will return a table with the item info, {name, label, stack, weight, description, image} +---@param item string +---@return table +Inventory.GetItemInfo = function(item) + local itemData = inv:GetItemDefinition(item) + if not itemData then return {} end + return { + name = itemData.name, + label = itemData.label, + stack = itemData.unique, + weight = itemData.weight, + description = itemData.description, + image = Inventory.GetImagePath(itemData.image or itemData.name) + } +end + +---@description This will return the entire items table from the inventory. +---@return table +Inventory.Items = function() + return inv:GetAllItemDefinitions() +end + +---@description This will return the count of the item in the players inventory, if not found will return 0. +---@param src number +---@param item string +---@param metadata table (optional) +---@return number +Inventory.GetItemCount = function(src, item, metadata) + return inv:GetItemCount(src, item, metadata) +end + +---@description This wil return the players inventory. +---@param src number +---@return table +Inventory.GetPlayerInventory = function(src) + return inv:GetInventoryItems(src) +end + +---@description Returns the specified slot data as a table. +---@param src number +---@param slot number +---@return table {weight, name, metadata, slot, label, count} +Inventory.GetItemBySlot = function(src, slot) + local slotData = inv:GetSlot(src, slot) + print("GetItemBySlot".. json.encode(slotData), {indent = true}) + if not slotData then return {} end + return { + name = slotData.name, + label = slotData.name, + weight = slotData.weight, + slot = slotData.slot, + count = slotData.amount or slotData.count, + metadata = slotData.info or slotData.metadata, + stack = slotData.unique, + description = slotData.description + } +end + +---@description This will set the metadata of an item in the inventory. +---@param src number +---@param item string +---@param slot number +---@param metadata table +---@return nil +Inventory.SetMetadata = function(src, item, slot, metadata) + inv:SetItemMetadata(src, slot, metadata) +end + + +---@description This will open the specified stash for the src passed. +---@param src number +---@param _type string "stash", "trunk", "glovebox" +---@param id string +---@return nil +Inventory.OpenStash = function(src, _type, id) + _type = _type or "stash:" + if _type == "trunk" then + _type = "vehicle:trunk:" + elseif _type == "glovebox" then + _type = "vehicle:glovebox:" + elseif _type ~= "stash" then + _type = "stash:" + end + + return inv:OpenInventory(src, _type, {id = id}) +end + +---@description This will add items to a stash, and return true or false based on success +---@param id string +---@param items table {item, count, metadata} +---@return boolean +Inventory.AddStashItems = function(id, items) + if type(items) ~= "table" then return false end + local success = false + for _, item in pairs(items) do + success = inv:AddItem(id, item.item, item.amount or item.count, item.metadata or item.info or {}, nil) + end + return success +end + +---@description This will add items to a trunk, and return true or false based on success +---@param identifier string +---@param items table +---@return boolean +Inventory.AddTrunkItems = function(identifier, items) + if type(items) ~= "table" then return false end + local fullTrunkId = "vehicle:trunk:"..identifier + Wait(1000) + for i = 1, #items do + inv:AddItem(fullTrunkId, items[i].name, items[i].amount or items[i].count, items[i].metadata or items[i].info or {}, nil) + end + return true +end + +---@description This will clear the specified inventory, will always return true unless a value isnt passed correctly. +---@param id string +---@return boolean +Inventory.ClearStash = function(id, _type) + if type(id) ~= "string" then return false end + if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end + if _type == "trunk" then + id = "vehicle:trunk:"..id + elseif _type == "glovebox" then + id = "vehicle:glovebox:"..id + elseif _type ~= "stash" then + id = "stash:"..id + end + inv:ClearInventory(id, false, false) + + return true +end + +---@description This will return a boolean if the player has the item. +---@param src number +---@param item string +---@param requiredCount number (optional) +---@return boolean +Inventory.HasItem = function(src, item, requiredCount) + return inv:HasItem(src, item, requiredCount or 1, nil) + +end + +---@description This is to get if there is available space in the inventory, will return boolean. +---@param src number +---@param item string +---@param count number +---@return boolean +Inventory.CanCarryItem = function(src, item, count) + return inv:CanCarryItem(src, item, count) +end + +---@description This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus) +---@param item string +---@return string +Inventory.GetImagePath = function(item) + item = Inventory.StripPNG(item) + local file = LoadResourceFile("one_inventory", string.format("web/images/%s.png", item)) + local imagePath = file and string.format("nui://one_inventory/web/images/%s.png", item) + return imagePath or "https://avatars.githubusercontent.com/u/47620135" +end + +---@description This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it) +---@param oldplate string +---@param newplate string +---@return boolean +Inventory.UpdatePlate = function(oldplate, newplate) + inv:UpdateVehiclePlate(oldplate, newplate) + if GetResourceState('jg-mechanic') == 'missing' then return true end + return true, exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate) +end + +---@description This will open the specified shop for the src passed. +---@param src number +---@param shopTitle string +Inventory.OpenShop = function(src, shopTitle) + return inv:OpenInventory(src, "shop", shopTitle) +end + +---@description This will register a shop, if it already exists it will return true. +---@param shopTitle string +---@param inventory table +---@param shopCoords table +---@param shopGroups table +Inventory.RegisterShop = function(shopTitle, inventory, shopCoords, shopGroups) + return false, print(shopTitle.." is not a valid shop type for one_inventory, please use the shop types defined in the documentation.") +end + +---@description This will open a players inventory, used for admin purposes and stuff. +---@param src number +---@param target number +Inventory.OpenPlayerInventory = function(src, target) + assert(src, "OpenPlayerInventory: src is required") + assert(target, "OpenPlayerInventory: target is required") + inv:OpenInventory(src, "player:", target) +end + +return Inventory \ No newline at end of file diff --git a/modules/inventory/tgiann-inventory/server.lua b/modules/inventory/tgiann-inventory/server.lua index c77e0e1..a3d8e99 100644 --- a/modules/inventory/tgiann-inventory/server.lua +++ b/modules/inventory/tgiann-inventory/server.lua @@ -129,9 +129,10 @@ end ---@description This will return a boolean if the player has the item. ---@param src number ---@param item string +---@param requiredCount number (optional) ---@return boolean -Inventory.HasItem = function(src, item) - return tgiann:HasItem(src, item, 1) +Inventory.HasItem = function(src, item, requiredCount) + return tgiann:HasItem(src, item, requiredCount or 1) end ---@description This is to get if there is available space in the inventory, will return boolean. diff --git a/modules/notify/msk_core/client.lua b/modules/notify/msk_core/client.lua new file mode 100644 index 0000000..59838e6 --- /dev/null +++ b/modules/notify/msk_core/client.lua @@ -0,0 +1,38 @@ +---@diagnostic disable: duplicate-set-field +Notify = Notify or {} +local resourceName = "msk_core" +local configValue = BridgeSharedConfig.Notify +if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end + +Notify.GetResourceName = function() + return resourceName +end + +local Language = Language or Require("modules/locales/shared.lua") +local locale = Language.Locale +local placeHolderText = locale("Notifications.PlaceholderTitle") + +---DEPRICATED: PLEASE SWITCH TO Notify.SendNotification +---@param message string +---@param _type string +---@param time number +---@return nil +Notify.SendNotify = function(message, _type, time) + time = time or 3000 + return exports.msk_core:Notify(nil, message, _type, time) +end + +---This will send a notify message of the type and time passed +---@param title string +---@param message string +---@param _type string +---@param time number +---@param props table optional +---@return nil +Notify.SendNotification = function(title, message, _type, time, props) + time = time or 3000 + if not title then title = placeHolderText end + return exports.msk_core:Notify(title, message, _type or "success", time) +end + +return Notify diff --git a/modules/notify/solaire_notify/client.lua b/modules/notify/solaire_notify/client.lua new file mode 100644 index 0000000..02cd413 --- /dev/null +++ b/modules/notify/solaire_notify/client.lua @@ -0,0 +1,47 @@ +---@diagnostic disable: duplicate-set-field +Notify = Notify or {} +local resourceName = "solaire_notify" +local configValue = BridgeSharedConfig.Notify + +if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end + +Notify.GetResourceName = function() + return resourceName +end + +local Language = Language or Require("modules/locales/shared.lua") +local locale = Language.Locale +local placeHolderText = locale("Notifications.PlaceholderTitle") + +Notify.SendNotify = function(message, _type, time) + time = time or 3000 + + return exports.solaire_notify:Notify({ type = _type or "info", message = message, duration = time }) +end + +---This will send a notify message of the type and time passed +---@param title string +---@param message string +---@param _type string +---@param time number +---@param props table | nil +---@return nil +Notify.SendNotification = function(title, message, _type, time, props) + time = time or 3000 + if not title or title == "" then title = placeHolderText end + + props = props or {} + + return exports.solaire_notify:Notify({ + type = _type or "info", + title = title, + message = message, + duration = time, + position = props.position or "top-right", + sound = props.sound, + item = props.item, + volume = props.volume + }) +end + +return Notify \ No newline at end of file diff --git a/modules/progressbar/msk_core/client.lua b/modules/progressbar/msk_core/client.lua new file mode 100644 index 0000000..5c993d8 --- /dev/null +++ b/modules/progressbar/msk_core/client.lua @@ -0,0 +1,66 @@ +---@diagnostic disable: duplicate-set-field +local resourceName = "msk_core" +local configValue = BridgeClientConfig.ProgressBarSystem +if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end + +ProgressBar = ProgressBar or {} + +---Converts bridge/ox-style progress options into the msk_core Progress.Start format. +---@param options table +---@return table +local function convertToMsk(options) + options = options or {} + + -- QB exposes animation under .animation.animDict/.anim and disables under .controlDisables + local anim = options.anim or options.animation + local animation + if anim then + animation = { + dict = anim.dict or anim.animDict, + anim = anim.clip or anim.anim, + flag = anim.flag or anim.flags or 49, + } + end + + -- ox uses options.disable.{move,car,combat,mouse}, QB uses options.controlDisables.* + local d = options.disable or options.controlDisables or {} + local disable = { + move = d.move or d.disableMovement, + vehicle = d.car or d.disableCarMovement, + combat = d.combat or d.disableCombat, + mouse = d.mouse or d.disableMouse, + } + + return { + duration = options.duration, + text = options.label or options.text or '', + disable = disable, + animation = animation, + forceOverride = options.forceOverride, + } +end + +---This will open a progress bar (blocking until it completes). +---@param options table +---@param cb any optional callback receiving the success boolean +---@param isQBInput boolean optional +---@return boolean success true if the progress completed without being cancelled +function ProgressBar.Open(options, cb, isQBInput) + local data = convertToMsk(options) + + -- msk_core Progress.Start blocks for the full duration; if it is interrupted + -- it stops early. We treat a fully elapsed bar as success. + exports.msk_core:Progressbar(data) + + local active = exports.msk_core:ProgressActive() + local success = not active + + if cb then cb(success) end + return success +end + +ProgressBar.GetResourceName = function() + return resourceName +end + +return ProgressBar diff --git a/modules/target/ox_target/client.lua b/modules/target/ox_target/client.lua index 45ffd85..04100bf 100644 --- a/modules/target/ox_target/client.lua +++ b/modules/target/ox_target/client.lua @@ -7,6 +7,11 @@ local targetDebug = BridgeSharedConfig and BridgeSharedConfig.DebugLevel == 2 or local ox_target = exports.ox_target local targetZones = {} +local resourceTargets = {} +resourceTargets.models = {} +resourceTargets.entities = {} +resourceTargets.networkedEntities = {} + Target.GetResourceName = function() return "ox_target" end @@ -99,6 +104,9 @@ end function Target.AddLocalEntity(entities, options) options = Target.FixOptions(options) ox_target:addLocalEntity(entities, options) + local resource = GetInvokingResource() + resourceTargets.entities[resource] = resourceTargets.entities[resource] or {} + table.insert(resourceTargets.entities[resource], { entities = entities}) end ---This will remove the target options from a local entity. This is useful for when you want to remove target options from a specific entity. @@ -114,6 +122,9 @@ end function Target.AddNetworkedEntity(netids, options) options = Target.FixOptions(options) ox_target:addEntity(netids, options) + local resource = GetInvokingResource() + resourceTargets.networkedEntities[resource] = resourceTargets.networkedEntities[resource] or {} + table.insert(resourceTargets.networkedEntities[resource], { netids = netids}) end ---This will remove a networked entity from the target system. @@ -129,6 +140,9 @@ end function Target.AddModel(models, options) options = Target.FixOptions(options) ox_target:addModel(models, options) + local resource = GetInvokingResource() + resourceTargets.models[resource] = resourceTargets.models[resource] or {} + table.insert(resourceTargets.models[resource], { models = models}) end ---This will remove target options from all specified models. @@ -189,13 +203,32 @@ function Target.RemoveZone(name) end AddEventHandler('onResourceStop', function(resource) - if resource ~= GetCurrentResourceName() then return end for _, target in pairs(targetZones) do if target.creator == resource then ox_target:removeZone(target.id) end end targetZones = {} + if resourceTargets.entities[resource] and #resourceTargets.entities[resource] > 0 then + for _, data in pairs(resourceTargets.entities[resource]) do + Target.RemoveLocalEntity(data.entities) + end + end + resourceTargets.entities[resource] = nil + if resourceTargets.networkedEntities[resource] and #resourceTargets.networkedEntities[resource] > 0 then + for _, data in pairs(resourceTargets.networkedEntities[resource]) do + Target.RemoveNetworkedEntity(data.netids) + end + end + resourceTargets.networkedEntities[resource] = nil + if resourceTargets.models[resource] and #resourceTargets.models[resource] > 0 then + for _, data in pairs(resourceTargets.models[resource]) do + for _, model in pairs(data.models) do + ox_target:removeModel(model) + end + end + end + resourceTargets.models[resource] = nil end) -return Target \ No newline at end of file +return Target diff --git a/settings/clientConfig.lua b/settings/clientConfig.lua index f1d54d9..69dc9e5 100644 --- a/settings/clientConfig.lua +++ b/settings/clientConfig.lua @@ -1,7 +1,7 @@ BridgeClientConfig = {} BridgeClientConfig.InputSystem = "auto" -- [ auto | ox_lib | lation_ui | qb-input ] BridgeClientConfig.MenuSystem = "auto" -- [ auto | ox_lib | wasabi_uikit | lation_ui | qb-menu ] -BridgeClientConfig.ProgressBarSystem = "auto" -- [ auto | ox_lib | wasabi_uikit | lation_ui | ZSX_UIV2 | keep-progressbar | progressbar ] +BridgeClientConfig.ProgressBarSystem = "auto" -- [ auto | ox_lib | wasabi_uikit | lation_ui | ZSX_UIV2 | keep-progressbar | progressbar | msk_core ] BridgeClientConfig.VehicleKey = "auto" -- [ auto | qb-vehiclekeys | MrNewbVehicleKeys | jaksams_VehiclesKeys | wasabi_carlock | mk_vehiclekeys | qbx_vehiclekeys | qs-vehiclekeys | t1ger_keys | Renewed-Vehiclekeys | mono_carkeys| cd_garage | okokGarage | F_RealCarKeysSystem BridgeClientConfig.Fuel = "auto" -- [ auto | LegacyFuel | ox_fuel | ps-fuel | qs-fuelstations | Renewed-Fuel | ti_fuel | lc_fuel | x-fuel | cdn-fuel | esx-sna-fuel | BigDaddy-Fuel | okokGasStation ] BridgeClientConfig.TargetSystem = "auto" -- [ auto | ox_target | qb-target | sleepless_interact ] -- sleepless is only partially supported and would need another system in place diff --git a/settings/sharedConfig.lua b/settings/sharedConfig.lua index 3bc3a79..7b55311 100644 --- a/settings/sharedConfig.lua +++ b/settings/sharedConfig.lua @@ -1,7 +1,7 @@ BridgeSharedConfig = {} BridgeSharedConfig.Lang = "auto" -- Change this to your preferred language (must match the locale file name ex. en or fr etc) BridgeSharedConfig.DebugLevel = 0 -- Change this to your Debug level, 0 for none, 1 for some, 2 for all data -BridgeSharedConfig.Notify = "auto" -- [ auto | ox_lib | r_notify | wasabi_notify | lation_ui | ZSX_UIV2 | okokNotify | mythic_notify | pNotify | t-notify | brutal_notify | FL-Notify] +BridgeSharedConfig.Notify = "auto" -- [ auto | ox_lib | r_notify | wasabi_notify | lation_ui | ZSX_UIV2 | okokNotify | mythic_notify | pNotify | t-notify | brutal_notify | FL-Notify | msk_core] BridgeSharedConfig.HelpText = "auto" -- [ auto | ox_lib | jg-textui | lation_ui | ZSX_UIV2 | cd_drawtextui | lab-HintUI | okokTextUI] BridgeSharedConfig.Phone = "auto" -- [ auto | qs-smartphone | lb-phone | gksphone] BridgeSharedConfig.Skills = "auto" -- [ auto | OT_skills | evolent_skills | pickle_xp]