Remove example scripts and update core logic

Deleted all files in the examples directory to clean up unused or test scripts. Updated fxmanifest.lua to enable ox_lib initialization. Improved error handling and entity tracking in utility functions, added prop removal, and made minor localization and code style adjustments throughout the codebase. Significant reword of inventory module, notification module, and framework module. Added support for wasabi_uikit, added support for keep-progressbars,
This commit is contained in:
MrNewb committed 2025-12-14 16:22:35 -05:00
1 parent c40a260ea2
commit 343af95794
100 files changed
+2403 -2755

No files matched your search

+173 -52
View File
@@ -11,7 +11,8 @@ Framework.Shared = QBCore.Shared
---@description This will return the name of the framework in use.
---@return string
Framework.GetFrameworkName = function()
return 'qb-core'
print("[Community Bridge] Warning: Framework.GetFrameworkName is deprecated, use Framework.GetResourceName instead.")
return Framework.GetResourceName()
end
---@description This will get the name of the in use resource.
@@ -228,7 +229,6 @@ Framework.GetPlayerMetadata = function(src, metadata)
return playerData.metadata[metadata] or false
end
---@description Adds the specified value to the player's stress level and updates the client HUD.
---@param src number
---@param value number
@@ -268,7 +268,6 @@ Framework.AddHunger = function(src, value)
local newHunger = (playerData.metadata.hunger or 0) + value
player.Functions.SetMetaData('hunger', Math.Clamp(newHunger, 0, 100))
TriggerClientEvent('hud:client:UpdateNeeds', src, newHunger, playerData.metadata.thirst)
--TriggerClientEvent('hud:client:UpdateStress', src, newStress)
return newHunger
end
@@ -283,7 +282,6 @@ Framework.AddThirst = function(src, value)
local newThirst = (playerData.metadata.thirst or 0) + value
player.Functions.SetMetaData('thirst', Math.Clamp(newThirst, 0, 100))
TriggerClientEvent('hud:client:UpdateNeeds', src, playerData.metadata.hunger, newThirst)
--TriggerClientEvent('hud:client:UpdateStress', src, newStress)
return newThirst
end
@@ -303,7 +301,7 @@ end
---@return boolean|nil
Framework.GetIsPlayerDead = function(src)
local player = Framework.GetPlayer(src)
if not player then return end
if not player then return false end
local playerData = player.PlayerData
return playerData.metadata.isdead or playerData.metadata.inlaststand or false
end
@@ -318,13 +316,23 @@ Framework.RevivePlayer = function(src)
return true
end
--- @description This will get the hunger of a player
--- @param src number
--- @return number
Framework.GetHunger = function(src)
local player = Framework.GetPlayer(src)
if not player then return 0 end
local playerData = player.PlayerData
local newHunger = (playerData.metadata.hunger or 0)
return math.floor((newHunger) + 0.5) or 0
end
---@description This will get the thirst of a player
---@param src any
---@return number | nil
Framework.GetThirst = function(src)
local player = Framework.GetPlayer(src)
if not player then return end
if not player then return 0 end
local playerData = player.PlayerData
local newThirst = (playerData.metadata.thirst or 0)
return math.floor((newThirst) + 0.5) or 0
@@ -364,10 +372,10 @@ end
---@return string | string | string | number | nil
---@return string | string | string | number | nil
Framework.GetPlayerJob = function(src)
local player = Framework.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level
print("[Community Bridge] Warning: Framework.GetPlayerJob is deprecated, use Framework.GetPlayerJobData instead.")
local jobData = Framework.GetPlayerJobData(src)
if not jobData then return end
return jobData.jobName, jobData.jobLabel, jobData.gradeName, jobData.gradeLevel
end
---@description This will return the players job name, job label, job grade label job grade level, boss status,
@@ -376,7 +384,7 @@ end
---@return table | nil
Framework.GetPlayerJobData = function(src)
local player = Framework.GetPlayer(src)
if not player then return end
if not player then return { } end
local playerData = player.PlayerData
local jobData = playerData.job
return {
@@ -395,16 +403,16 @@ end
---@return boolean | nil
Framework.GetPlayerDuty = function(src)
local player = Framework.GetPlayer(src)
if not player then return end
if not player then return false end
local playerData = player.PlayerData
if not playerData.job.onduty then return false end
return true
end
---@description 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 player = Framework.GetPlayer(src)
if not player then return false end
@@ -420,7 +428,7 @@ end
---@return nil
Framework.SetPlayerJob = function(src, name, grade)
local player = Framework.GetPlayer(src)
if not player then return end
if not player then return false end
return player.Functions.SetJob(name, grade)
end
@@ -431,8 +439,9 @@ end
---@return boolean | nil
Framework.AddAccountBalance = function(src, _type, amount)
local player = Framework.GetPlayer(src)
if not player then return end
if not player then return false end
if _type == 'money' then _type = 'cash' end
if amount <= 0 then return false end
return player.Functions.AddMoney(_type, amount)
end
@@ -443,7 +452,7 @@ end
---@return boolean | nil
Framework.RemoveAccountBalance = function(src, _type, amount)
local player = Framework.GetPlayer(src)
if not player then return end
if not player then return false end
if _type == 'money' then _type = 'cash' end
return player.Functions.RemoveMoney(_type, amount)
end
@@ -454,42 +463,66 @@ end
---@return string | nil
Framework.GetAccountBalance = function(src, _type)
local player = Framework.GetPlayer(src)
if not player then return end
if not player then return 0 end
local playerData = player.PlayerData
if _type == 'money' then _type = 'cash' end
return playerData.money[_type]
end
---@description Adds the specified item to the player's inventory.
---@description This will add an item, and return true or false based on success
---This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
---@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)
---@param count number
---@param slot number (optional)
---@param metadata table (optional)
---@return boolean
Framework.AddItem = function(src, item, count, slot, metadata)
local player = Framework.GetPlayer(src)
if not player then return end
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, { action = "add", item = item, count = amount, slot = slot, metadata = metadata })
return player.Functions.AddItem(item, amount, slot, metadata)
if not player then return false end
local success = player.Functions.AddItem(item, count, slot, 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 })
return success
end
---@description Removes the specified item from the player's inventory.
---@description Internal function to search for items with specific metadata in player inventory
---@param src number
---@param metadata table
---@return boolean, number|nil
local function runMetadataSearch(src, metadata)
local inv = Framework.GetPlayerInventory(src) or {}
for k, v in pairs(inv) do
if v.metadata and v.metadata == metadata then
return true, v.slot
end
end
return false
end
---@description This will remove an item, and return true or false based on success
---@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)
---@param count number
---@param slot number (optional)
---@param metadata table (optional)
---@return boolean
Framework.RemoveItem = function(src, item, count, slot, metadata)
local player = Framework.GetPlayer(src)
if not player then return end
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, { action = "remove", item = item, count = amount, slot = slot, metadata = metadata })
return player.Functions.RemoveItem(item, amount, slot or nil)
if not player then return false end
if metadata then
local found, itemSlot = runMetadataSearch(src, metadata)
if found then
slot = itemSlot
end
end
local success = player.Functions.RemoveItem(item, count, 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
end
---@description Sets the metadata for the specified item in the player's inventory.
---Notes, this is kinda a jank workaround. with the framework aside from updating the entire table theres not really a better way
---@description This will set the metadata of an item in the inventory.
---@param src number
---@param item string
---@param slot number
@@ -497,20 +530,92 @@ end
---@return boolean | nil
Framework.SetMetadata = function(src, item, slot, metadata)
local player = Framework.GetPlayer(src)
if not player then return end
local slotFinder = Framework.GetPlayerInventory(src)
local freeSlot = Table.FindFirstUnoccupiedSlot(slotFinder)
local itemSlot = slot or nil
if itemSlot == nil then
for _, v in pairs(slotFinder) do
if v.name == item then
slot = v.slot
break
end
if not player then return false end
local success = Framework.RemoveItem(src, item, 1, slot, nil)
if not success then return false end
Framework.AddItem(src, item, 1, slot, metadata)
end
---@description This will return a table with the item info, {name, label, stack, weight, description, image}
---@param item string
---@return table
Framework.GetItemInfo = function(item)
local itemData = QBCore.Shared.Items[item]
if not itemData then return {} end
return {
name = itemData.name,
label = itemData.label or itemData.name,
stack = itemData.unique,
weight = itemData.weight,
description = itemData.description,
image = itemData.image
}
end
---@description This will return the count of the item in the players inventory, if not found will return 0.
--- This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
---@param src number
---@param item string
---@param metadata table (optional)
---@return number
Framework.GetItemCount = function(src, item, metadata)
local player = Framework.GetPlayer(src)
if not player then return 0 end
local playerData = player.PlayerData
local playerInventory = playerData.items
local count = 0
for _, v in pairs(playerInventory) do
if v.name == item and (not metadata or v.info == metadata) then
count = count + (v.amount or v.count)
end
end
if not player.Functions.RemoveItem(item, 1, itemSlot) then return false end
return player.Functions.AddItem(item, 1, slot, metadata)
return count
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
Framework.HasItem = function(src, item, requiredCount)
local getCount = Framework.GetItemCount(src, item, nil)
return getCount >= (requiredCount or 1)
end
---@description This wil return the players inventory.
---@param src number
---@return table
Framework.GetPlayerInventory = function(src)
local player = Framework.GetPlayer(src)
if not player then return {} end
local playerData = player.PlayerData
local playerInventory = playerData.items
local repackedTable = {}
for _, v in pairs(playerInventory) do
table.insert(repackedTable, {
name = v.name,
count = v.amount or v.count,
metadata = v.info,
slot = v.slot,
})
end
return repackedTable
end
---@description Returns the specified slot data as a table.
---@param src number
---@param slot number
---@return table {name, label, weight, count, metadata, slot, stack, description, image}
Framework.GetItemBySlot = function(src, slot)
local inventory = Framework.GetPlayerInventory(src)
if not inventory or #inventory == 0 then return {} end
for _, v in pairs(inventory) do
if v.slot == slot then
local itemInfo = Framework.GetItemInfo(v.name)
return {v.name, itemInfo.label or v.name, itemInfo.weight or 0, v.count or 0, v.metadata or {}, v.slot, itemInfo.stack or false, itemInfo.description or "No description available", itemInfo.image or nil}
end
end
return {}
end
---@description This will get all owned vehicles for the player
@@ -541,6 +646,8 @@ Framework.RegisterUsableItem = function(itemName, cb)
QBCore.Functions.CreateUseableItem(itemName, func)
end
---@description Event handler for when a player is loaded in QB-Core framework
---@param src number
RegisterNetEvent("QBCore:Server:OnPlayerLoaded", function(src)
src = src or source
TriggerEvent("community_bridge:Server:OnPlayerLoaded", src)
@@ -549,23 +656,37 @@ RegisterNetEvent("QBCore:Server:OnPlayerLoaded", function(src)
Framework.AddJobCount(src, jobData.jobName)
end)
---@description Event handler for when a player is unloaded in QB-Core framework
---@param src number
RegisterNetEvent("QBCore:Server:OnPlayerUnload", function(src)
src = src or source
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
end)
---@description Event handler for when a player's job is updated in QB-Core framework
---@param src number
---@param job table
RegisterNetEvent("QBCore:Server:OnJobUpdate", function(src, job)
src = src or source
if not job then return end
TriggerEvent("community_bridge:Server:OnPlayerJobChange", src, job.name)
end)
---@description Event handler for when a player disconnects from the server
AddEventHandler("playerDropped", function()
local src = source
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
end)
Framework.Commands = {}
---@description Adds a command to the QB-Core 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, ...)
QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission, ...)
end