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:
1 parent
c40a260ea2
commit
343af95794
100 files changed
+2403
-2755
No files matched your search
@@ -5,10 +5,11 @@ QBox = exports.qbx_core
|
||||
|
||||
Framework = Framework or {}
|
||||
|
||||
---This will get the name of the framework being used (if a supported framework).
|
||||
---@description This will get the name of the framework being used (if a supported framework).
|
||||
---@return string
|
||||
Framework.GetFrameworkName = function()
|
||||
return 'qbx_core'
|
||||
print("This is depricated, please use Framework.GetResourceName() instead.")
|
||||
return Framework.GetResourceName()
|
||||
end
|
||||
|
||||
---@description This will get the name of the in use resource.
|
||||
@@ -17,15 +18,13 @@ Framework.GetResourceName = function()
|
||||
return 'qbx_core'
|
||||
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.
|
||||
---@description This will return true if the player is loaded, false otherwise.
|
||||
---@return boolean
|
||||
Framework.GetIsPlayerLoaded = function()
|
||||
return LocalPlayer.state.isLoggedIn or false
|
||||
end
|
||||
|
||||
---@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.
|
||||
---@description This is an internal function, do not use this outside of bridge as there is no standard format between the frameworks.
|
||||
---@return table
|
||||
Framework.GetPlayerData = function()
|
||||
return QBox.GetPlayerData()
|
||||
@@ -37,14 +36,14 @@ Framework.GetFrameworkJobs = function()
|
||||
return QBox.GetJobs()
|
||||
end
|
||||
|
||||
---@descriptionThis will get the players birth date
|
||||
---@description This will get the players birth date
|
||||
---@return string
|
||||
Framework.GetPlayerDob = function()
|
||||
local playerData = Framework.GetPlayerData()
|
||||
return playerData.charinfo.birthdate
|
||||
end
|
||||
|
||||
---@description This will display the help text message on the screen
|
||||
---@description Will Display the help text message on the screen
|
||||
---@param message string
|
||||
---@param position string
|
||||
---@return nil
|
||||
@@ -102,18 +101,18 @@ Framework.GetPlayerName = function()
|
||||
return playerData.charinfo.firstname, playerData.charinfo.lastname
|
||||
end
|
||||
|
||||
---@deprecated Deprecated: This will return the players job name, job label, job grade label and job grade level
|
||||
---@description 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
|
||||
Framework.GetPlayerJob = function()
|
||||
local playerData = Framework.GetPlayerData()
|
||||
return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level
|
||||
print("This is depricated, please use Framework.GetPlayerJobData() instead.")
|
||||
local jobData = Framework.GetPlayerJobData()
|
||||
return jobData.jobName, jobData.jobLabel, jobData.gradeName, jobData.gradeRank
|
||||
end
|
||||
|
||||
---@description This will return the players job name, job label, job grade label job grade level, boss status,
|
||||
---and duty status in a 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()
|
||||
@@ -129,14 +128,14 @@ Framework.GetPlayerJobData = function()
|
||||
}
|
||||
end
|
||||
|
||||
---@description This will return the players inventory as a table in the ox_inventory style flormat.
|
||||
---@return table
|
||||
---@description This is an internal function used as a fallback, please use the Inventory.GetPlayerInventory instead.
|
||||
---@return table {name, label, count, slot, metadata, stack, close, weight}
|
||||
Framework.GetPlayerInventory = function()
|
||||
return Framework.GetPlayerData().items
|
||||
end
|
||||
|
||||
---@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. Use case is for a ui or a menu I guess.
|
||||
---@description 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
|
||||
Framework.GetAccountBalance = function(_type)
|
||||
@@ -144,46 +143,31 @@ Framework.GetAccountBalance = function(_type)
|
||||
if not player then return 0 end
|
||||
local account = player.money
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
return account[_type] or 0
|
||||
local balance = account[_type] or 0
|
||||
if balance <= 0 then return 0 end
|
||||
return balance
|
||||
end
|
||||
|
||||
---@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 = lib.getVehicleProperties(vehicle)
|
||||
return vehicleProps or {}
|
||||
end
|
||||
|
||||
---@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
|
||||
if NetworkGetEntityIsNetworked(vehicle) then
|
||||
local vehNetID = NetworkGetNetworkIdFromEntity(vehicle)
|
||||
local entOwner = GetPlayerServerId(NetworkGetEntityOwner(vehNetID))
|
||||
if entOwner ~= GetPlayerServerId(PlayerId()) then
|
||||
NetworkRequestControlOfEntity(vehicle)
|
||||
local count = 0
|
||||
while not NetworkHasControlOfEntity(vehicle) and count < 3000 do
|
||||
Wait(1)
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
return true, lib.setVehicleProperties(vehicle, properties)
|
||||
end
|
||||
|
||||
---@description This will return the item count for the specified item in the players inventory.
|
||||
---@param item string
|
||||
---@return number
|
||||
---@description This is an internal function used as a fallback, please use the Inventory.GetItemCount instead.
|
||||
--- @param item string
|
||||
--- @return number
|
||||
Framework.GetItemCount = function(item)
|
||||
-- This seems to be exclusively for ox_inventory, if other inventories are used, they need to be bridged in the inventory module. Until then we will return 0 and a print.
|
||||
return 0, print("Community_bridge:WARN: GetItemCount is not implemented for this framework, please use the inventory module to get the item count. If you are using a diffrent inventory please let us know so we can bridge it and have less nonsense.")
|
||||
return 0, print("Qbox has not implemented GetItemCount for this framework. Please ensure the inventory you are using is supported and start order is correct.")
|
||||
end
|
||||
|
||||
---@description This will return the item data for the specified item.
|
||||
--- @param item string
|
||||
--- @return table {name, label, stack, weight, description, image}
|
||||
Framework.GetItemInfo = function(item)
|
||||
return {}, print("Qbox has not implemented GetItemInfo for this framework. Please ensure the inventory you are using is supported and start order is correct.")
|
||||
end
|
||||
|
||||
---@description Will return boolean if the player has the item.
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Framework.HasItem = function(item, requiredCount)
|
||||
return false, print("Qbox has not implemented HasItem for this framework, Please ensure the inventory you are using is supported and start order is correct.")
|
||||
end
|
||||
|
||||
---@description This will get a players dead status.
|
||||
@@ -193,15 +177,19 @@ Framework.GetIsPlayerDead = function()
|
||||
return playerData.metadata["isdead"] or playerData.metadata["inlaststand"]
|
||||
end
|
||||
|
||||
---@description Event handler for when player is loaded in QBX Core framework
|
||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
||||
Wait(1500)
|
||||
TriggerEvent('community_bridge:Client:OnPlayerLoaded')
|
||||
end)
|
||||
|
||||
---@description Event handler for when player is unloaded in QBX Core framework
|
||||
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
|
||||
TriggerEvent('community_bridge:Client:OnPlayerUnload')
|
||||
end)
|
||||
|
||||
---@description Event handler for when player job is updated in QBX Core framework
|
||||
---@param data table Job data containing name, label, and grade information
|
||||
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(data)
|
||||
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', data.name, data.label, data.grade.name, data.grade.level)
|
||||
end)
|
||||
|
||||
@@ -5,7 +5,7 @@ Framework = Framework or {}
|
||||
|
||||
local QBox = exports.qbx_core
|
||||
|
||||
---Returns the name of the framework being used (if a supported framework).
|
||||
---@description Returns the name of the framework being used (if a supported framework).
|
||||
---@return string
|
||||
Framework.GetFrameworkName = function()
|
||||
return 'qbx_core'
|
||||
@@ -18,7 +18,7 @@ Framework.GetResourceName = function()
|
||||
end
|
||||
|
||||
---@description This will return if the player is an admin in the framework.
|
||||
---@param src any
|
||||
---@param src number
|
||||
---@return boolean
|
||||
Framework.GetIsFrameworkAdmin = function(src)
|
||||
if not src then return false end
|
||||
@@ -83,62 +83,110 @@ Framework.GetPlayerName = function(src)
|
||||
return playerData.charinfo.firstname, playerData.charinfo.lastname
|
||||
end
|
||||
|
||||
---@description Adds the specified item to the player's inventory.
|
||||
---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)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return false 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)
|
||||
end
|
||||
|
||||
---@description Removes the specified item from the player's inventory.
|
||||
---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.RemoveItem = function(src, item, amount, slot, metadata)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return false 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)
|
||||
end
|
||||
|
||||
---@description Sets the metadata for the specified item in the player's inventory.
|
||||
---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 slot number
|
||||
---@param metadata table
|
||||
---@return boolean | nil
|
||||
Framework.SetMetadata = function(src, item, slot, metadata)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return false end
|
||||
player.Functions.RemoveItem(item, 1, slot)
|
||||
return player.Functions.AddItem(item, 1, slot, metadata)
|
||||
end
|
||||
|
||||
---@description Returns a table of items matching the specified name and if passed metadata from the player's inventory.
|
||||
---This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
|
||||
---returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table
|
||||
---@return table|nil {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
|
||||
Framework.GetItem = function(src, item, metadata)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerInventory = player.PlayerData.items
|
||||
if not player then return { } end
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerInventory) do
|
||||
for _, v in pairs(player.PlayerData.items) do
|
||||
if v.name == item and (not metadata or v.info == metadata) then
|
||||
table.insert(repackedTable, {
|
||||
repackedTable[#repackedTable + 1] = {
|
||||
name = v.name,
|
||||
count = v.amount,
|
||||
metadata = v.info,
|
||||
count = v.amount or v.count,
|
||||
metadata = v.info or v.metadata,
|
||||
slot = v.slot,
|
||||
})
|
||||
}
|
||||
end
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
---@description Returns the count of items matching the specified name and if passed metadata from the player's inventory.
|
||||
---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
|
||||
---@return number | nil
|
||||
Framework.GetItemCount = function(src, item, metadata)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
if not player then return 0 end
|
||||
local playerInventory = player.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
|
||||
count = count + (v.amount or v.count)
|
||||
end
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
---@description Returns boolean if the player has the specified item in their inventory.
|
||||
---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
|
||||
---@return boolean
|
||||
Framework.HasItem = function(src, item)
|
||||
local getCount = Framework.GetItemCount(src, item, nil)
|
||||
local getCount = Framework.GetItemCount(src, item)
|
||||
return getCount > 0
|
||||
end
|
||||
|
||||
---@description Returns the entire inventory of the player as a table.
|
||||
---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
|
||||
---@return table | nil
|
||||
Framework.GetPlayerInventory = function(src)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
if not player then return { } end
|
||||
local playerItems = player.PlayerData.items
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
@@ -236,7 +284,7 @@ end
|
||||
---@return number | nil
|
||||
Framework.GetHunger = 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 newHunger = (playerData.metadata.hunger or 0)
|
||||
return math.floor((newHunger) + 0.5) or 0
|
||||
@@ -247,7 +295,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 false
|
||||
end
|
||||
@@ -267,7 +315,7 @@ end
|
||||
---@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
|
||||
@@ -298,7 +346,8 @@ Framework.GetPlayersByJob = function(job)
|
||||
return Framework.GetPlayerSourcesByJob(job) or {}
|
||||
end
|
||||
|
||||
---@Deprecated Deprecated: Returns the job name, label, grade name, and grade level of the player.
|
||||
---@description Depricated: Returns the job name, label, grade name, and grade level of the player.
|
||||
---Please use GetPlayerJobData instead.
|
||||
---@param src number
|
||||
---@return string | string | string | number | nil
|
||||
---@return string | string | string | number | nil
|
||||
@@ -308,6 +357,7 @@ Framework.GetPlayerJob = function(src)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
print("This function is depricated, please use GetPlayerJobData instead.")
|
||||
return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level
|
||||
end
|
||||
|
||||
@@ -352,7 +402,7 @@ Framework.SetPlayerDuty = function(src, status)
|
||||
TriggerEvent('QBCore:Server:SetDuty', src, player.PlayerData.job.onduty)
|
||||
end
|
||||
|
||||
---@descriptionReturns the players duty status.
|
||||
---@description Returns the players duty status.
|
||||
---@param src number
|
||||
---@return boolean | nil
|
||||
Framework.GetPlayerDuty = function(src)
|
||||
@@ -372,6 +422,7 @@ Framework.AddAccountBalance = function(src, _type, amount)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
if amount <= 0 then return false end
|
||||
return player.Functions.AddMoney(_type, amount)
|
||||
end
|
||||
|
||||
@@ -384,6 +435,7 @@ Framework.RemoveAccountBalance = function(src, _type, amount)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
if amount <= 0 then return false end
|
||||
return player.Functions.RemoveMoney(_type, amount)
|
||||
end
|
||||
|
||||
@@ -396,48 +448,9 @@ Framework.GetAccountBalance = function(src, _type)
|
||||
if not player then return 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.
|
||||
---@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 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)
|
||||
end
|
||||
|
||||
---@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 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)
|
||||
end
|
||||
|
||||
---@description Sets the metadata for the specified item in the player's inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param slot number
|
||||
---@param metadata table
|
||||
---@return boolean | nil
|
||||
Framework.SetMetadata = function(src, item, slot, metadata)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
player.Functions.RemoveItem(item, 1, slot)
|
||||
return player.Functions.AddItem(item, 1, slot, metadata)
|
||||
local balance = playerData.money[_type] or 0
|
||||
if balance <= 0 then return 0 end
|
||||
return balance
|
||||
end
|
||||
|
||||
---@description Returns a table of owned vehicles for the player. format is {vehicle = vehicle, plate = plate}
|
||||
@@ -469,6 +482,8 @@ Framework.RegisterUsableItem = function(itemName, cb)
|
||||
return QBox:CreateUseableItem(itemName, func)
|
||||
end
|
||||
|
||||
---@description Event handler for when a player is loaded in QBX Core framework
|
||||
---@param src number
|
||||
RegisterNetEvent("QBCore:Server:OnPlayerLoaded", function(src)
|
||||
src = src or source
|
||||
TriggerEvent("community_bridge:Server:OnPlayerLoaded", src)
|
||||
@@ -477,17 +492,23 @@ RegisterNetEvent("QBCore:Server:OnPlayerLoaded", function(src)
|
||||
Framework.AddJobCount(src, jobData.jobName)
|
||||
end)
|
||||
|
||||
---@description Event handler for when a player is unloaded in QBX 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 QBX 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)
|
||||
|
||||
Reference in new issue
Block a user