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
@@ -8,7 +8,7 @@ Framework = Framework or {}
|
||||
|
||||
local cachedItemList = nil
|
||||
|
||||
--- @description 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. This should not be used outside of bridge.
|
||||
Framework.ItemList = function()
|
||||
if cachedItemList then return cachedItemList end
|
||||
local items = Callback.Trigger('community_bridge:Callback:GetFrameworkItems', false)
|
||||
@@ -16,100 +16,101 @@ Framework.ItemList = function()
|
||||
return cachedItemList
|
||||
end
|
||||
|
||||
--- @description 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'
|
||||
print("This is depricated, please use Framework.GetResourceName() instead.")
|
||||
return Framework.GetResourceName()
|
||||
end
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@description 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
|
||||
---@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
|
||||
|
||||
--- @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 ESX.GetPlayerData()
|
||||
end
|
||||
|
||||
--- @description 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
|
||||
|
||||
--- @description This will return the players birth date
|
||||
--- @return string
|
||||
---@description This will get the players birth date
|
||||
---@return string
|
||||
Framework.GetPlayerDob = function()
|
||||
local playerData = Framework.GetPlayerData()
|
||||
local dob = playerData.dateofbirth
|
||||
return dob
|
||||
end
|
||||
|
||||
--- @description 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
|
||||
|
||||
--- @description 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
|
||||
|
||||
--- @description This will display the help text message on the screen
|
||||
--- @param message string
|
||||
--- @param _ unknown
|
||||
--- @return nil
|
||||
Framework.ShowHelpText = function(message, _)
|
||||
---@description Will Display the help text message on the screen
|
||||
---@param message string
|
||||
---@param _position unknown
|
||||
---@return nil
|
||||
Framework.ShowHelpText = function(message, _position)
|
||||
return exports.esx_textui:TextUI(message, "info")
|
||||
end
|
||||
|
||||
--- @description 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()
|
||||
end
|
||||
|
||||
--- @description 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
|
||||
|
||||
--- @description 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
|
||||
|
||||
--- @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
|
||||
---@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_label, playerData.job.grade
|
||||
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,
|
||||
@@ -130,7 +131,7 @@ Framework.GetPlayerJobData = function()
|
||||
}
|
||||
end
|
||||
|
||||
--This is an internal function to get status data
|
||||
---@description This is an internal function to get status data
|
||||
--- @param search string
|
||||
Framework.GetStatusData = function(search)
|
||||
local playerData = Framework.GetPlayerData()
|
||||
@@ -144,29 +145,30 @@ Framework.GetStatusData = function(search)
|
||||
return 0
|
||||
end
|
||||
|
||||
---This will get the hunger of a player
|
||||
---@description This will get the hunger of a player
|
||||
---@return number
|
||||
Framework.GetHunger = function()
|
||||
local status = Framework.GetStatusData("hunger")
|
||||
return math.floor((status) + 0.5) or 0
|
||||
end
|
||||
|
||||
---This will get the thirst of a player
|
||||
---@description This will get the thirst of a player
|
||||
---@return number
|
||||
Framework.GetThirst = function()
|
||||
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
|
||||
--- @param item string
|
||||
--- @return boolean
|
||||
Framework.HasItem = function(item)
|
||||
---@description Will return boolean if the player has the item.
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Framework.HasItem = function(item, requiredCount)
|
||||
local hasItem = ESX.SearchInventory(item, true)
|
||||
return hasItem > 0 and true or false
|
||||
return hasItem >= (requiredCount or 1)
|
||||
end
|
||||
|
||||
--- @description This will return the item count for the specified item in the players inventory
|
||||
---@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)
|
||||
@@ -175,16 +177,38 @@ Framework.GetItemCount = function(item)
|
||||
return inventory[item].count or 0
|
||||
end
|
||||
|
||||
--- @description This will return a table of the players inventory
|
||||
--- @return table
|
||||
Framework.GetPlayerInventory = function()
|
||||
local playerData = Framework.GetPlayerData()
|
||||
return playerData.inventory
|
||||
---@description Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Framework.GetItemInfo = function(item)
|
||||
return {}, print("ESX has not implemented GetItemInfo for this framework. Please ensure the inventory you are using is supported and start order is correct.")
|
||||
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
|
||||
--- @param _type string
|
||||
--- @return number
|
||||
---@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()
|
||||
local playerData = Framework.GetPlayerData()
|
||||
if not playerData then return {} end
|
||||
local repack = {}
|
||||
for k, v in pairs(playerData.inventory) do
|
||||
repack[k] = {
|
||||
name = v.name,
|
||||
label = v.label,
|
||||
count = v.count,
|
||||
slot = 0,
|
||||
metadata = {},
|
||||
stack = false,
|
||||
close = v.usable or false,
|
||||
weight = v.weight or 0,
|
||||
}
|
||||
end
|
||||
return repack
|
||||
end
|
||||
|
||||
---@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)
|
||||
local player = Framework.GetPlayerData()
|
||||
if not player then return 0 end
|
||||
@@ -192,52 +216,13 @@ Framework.GetAccountBalance = function(_type)
|
||||
if _type == 'cash' then _type = 'money' end
|
||||
for _, account in ipairs(accounts) do
|
||||
if account.name == _type then
|
||||
if not account.money or account.money <= 0 then return 0 end
|
||||
return account.money or 0
|
||||
end
|
||||
end
|
||||
return 0
|
||||
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 = ESX.Game.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
|
||||
-- Every framework version does this just a diffrent key I guess?
|
||||
if properties.color1 and type(properties.color1) == 'table' then
|
||||
properties.customPrimaryColor = {properties.color1[1], properties.color1[2], properties.color1[3]}
|
||||
properties.color1 = nil
|
||||
end
|
||||
if properties.color2 and type(properties.color2) == 'table' then
|
||||
properties.customSecondaryColor = {properties.color2[1], properties.color2[2], properties.color2[3]}
|
||||
properties.color2 = nil
|
||||
end
|
||||
return true, ESX.Game.SetVehicleProperties(vehicle, properties)
|
||||
end
|
||||
|
||||
--- @description This will get a players dead status
|
||||
--- @return boolean
|
||||
Framework.GetIsPlayerDead = function()
|
||||
@@ -245,15 +230,20 @@ Framework.GetIsPlayerDead = function()
|
||||
return playerData.dead
|
||||
end
|
||||
|
||||
---@description Event handler for when player is loaded in ESX framework
|
||||
---@param xPlayer table
|
||||
RegisterNetEvent('esx:playerLoaded', function(xPlayer)
|
||||
Wait(1500)
|
||||
TriggerEvent('community_bridge:Client:OnPlayerLoaded')
|
||||
end)
|
||||
|
||||
---@description Event handler for when player logs out in ESX framework
|
||||
RegisterNetEvent('esx:onPlayerLogout', function()
|
||||
TriggerEvent('community_bridge:Client:OnPlayerUnload')
|
||||
end)
|
||||
|
||||
---@description Event handler for when player job is updated in ESX framework
|
||||
---@param data table Job data containing name, label, grade_label, and grade
|
||||
RegisterNetEvent('esx:setJob', function(data)
|
||||
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', data.name, data.label, data.grade_label, data.grade)
|
||||
end)
|
||||
|
||||
@@ -13,16 +13,17 @@ local cachedItemList = nil
|
||||
--- @description This will return the name of the framework in use
|
||||
--- @return string
|
||||
Framework.GetFrameworkName = function()
|
||||
return 'es_extended'
|
||||
print("This is deprecated, please use Framework.GetResourceName() instead.")
|
||||
return Framework.GetResourceName()
|
||||
end
|
||||
|
||||
---This will get the name of the in use resource.
|
||||
---@return string
|
||||
---@description 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
|
||||
---@description This is an internal function, its here to attempt to emulate qbs shared items mainly, do not use this outside of bridge.
|
||||
Framework.ItemList = function()
|
||||
if cachedItemList then return cachedItemList end
|
||||
local items = ESX.Items
|
||||
@@ -46,9 +47,9 @@ Framework.ItemList = function()
|
||||
return cachedItemList
|
||||
end
|
||||
|
||||
--- @description 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 number
|
||||
---@return boolean
|
||||
Framework.GetIsFrameworkAdmin = function(src)
|
||||
if not src then return false end
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
@@ -58,7 +59,8 @@ Framework.GetIsFrameworkAdmin = function(src)
|
||||
return false
|
||||
end
|
||||
|
||||
--- @description This will get the players birth date
|
||||
---@description Returns the player date of birth.
|
||||
--- @param src number
|
||||
--- @return string|nil
|
||||
Framework.GetPlayerDob = function(src)
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
@@ -99,7 +101,7 @@ Framework.GetPlayerName = function(src)
|
||||
return xPlayer.variables.firstName, xPlayer.variables.lastName
|
||||
end
|
||||
|
||||
--- @description This will return a table of all logged in players
|
||||
---@description This will return a table of all logged in players
|
||||
--- @return table
|
||||
Framework.GetPlayers = function()
|
||||
local players = ESX.GetExtendedPlayers()
|
||||
@@ -110,14 +112,16 @@ Framework.GetPlayers = function()
|
||||
return playerList
|
||||
end
|
||||
|
||||
--- @description This will return a table of items matching the specified name and if passed metadata from the player's inventory
|
||||
---@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.
|
||||
--- @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, _)
|
||||
--- @param metadata table
|
||||
--- @return table {name, count, metadata, slot}
|
||||
Framework.GetItem = function(src, item, metadata)
|
||||
print("ESX does not support item metadata searches, please ensure you are using a supported inventory system or that you have the correct start order.")
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
if not xPlayer then return {} end
|
||||
local playerItems = xPlayer.getInventory()
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
@@ -125,40 +129,57 @@ Framework.GetItem = function(src, item, _)
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
--metadata = v.metadata,
|
||||
--slot = v.slot,
|
||||
metadata = {}, -- ESX does not support item metadata
|
||||
slot = 0, -- ESX does not support item slots
|
||||
})
|
||||
end
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
--- @param src number
|
||||
---@description This will return a table with the item info, {name, label, stack, weight, description, image}
|
||||
--- This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
|
||||
--- @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, _)
|
||||
--- @return table {name, label, stack, weight, description, image}
|
||||
Framework.GetItemInfo = function(item)
|
||||
local items = Framework.ItemList()
|
||||
if not items[item] then return {} end
|
||||
return {name = item, label = items[item].label, stack = false, weight = items[item].weight, description = items[item].description, image = items[item].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)
|
||||
if metadata then
|
||||
print("ESX does not support item metadata searches, please ensure you are using a supported inventory system or that you have the correct start order.")
|
||||
end
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
if not xPlayer then return 0 end
|
||||
return xPlayer.getInventoryItem(item).count
|
||||
end
|
||||
|
||||
--- @description This will return true if the player has the item, false otherwise
|
||||
---@description This will return a boolean if the player has the item.
|
||||
--- 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 returns true if the player has the item, false otherwise.
|
||||
--- @return boolean
|
||||
Framework.HasItem = function(src, item)
|
||||
local getCount = Framework.GetItemCount(src, item, nil)
|
||||
return getCount > 0
|
||||
end
|
||||
|
||||
--- @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}
|
||||
---@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 {name, count, metadata, slot}
|
||||
Framework.GetPlayerInventory = function(src)
|
||||
print("ESX does not support item metadata or slots, please ensure you are using a supported inventory system or that you have the correct start order.")
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
if not xPlayer then return {} end
|
||||
local playerItems = xPlayer.getInventory()
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
@@ -166,15 +187,25 @@ Framework.GetPlayerInventory = function(src)
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
--metadata = v.metadata,
|
||||
--slot = v.slot,
|
||||
metadata = {}, -- ESX does not support item metadata
|
||||
slot = 0, -- ESX does not support item slots
|
||||
})
|
||||
end
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
--- @description Adds the specified metadata key and number value to the player's data.
|
||||
---@description This will return the item data for the specified slot.
|
||||
--- 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 slot number
|
||||
--- @return table {name, label, weight, count, metadata, slot, stack, description}
|
||||
Framework.GetItemBySlot = function(src, slot)
|
||||
print("ESX does not support item slots, please ensure you are using a supported inventory system or that you have the correct start order.")
|
||||
return {} -- ESX does not support item slots
|
||||
end
|
||||
|
||||
---@description Adds the specified metadata key and number value to the player's data.
|
||||
--- @param src number
|
||||
--- @param metadata string
|
||||
--- @param value any
|
||||
@@ -186,8 +217,7 @@ Framework.SetPlayerMetadata = function(src, metadata, value)
|
||||
return true
|
||||
end
|
||||
|
||||
-- Framework.GetMetadata(src, metadata)
|
||||
--- @description Gets the specified metadata key to the player's data.
|
||||
---@description Gets the specified metadata key to the player's data.
|
||||
--- @param src number
|
||||
--- @param metadata string
|
||||
--- @return any|nil
|
||||
@@ -197,7 +227,7 @@ Framework.GetPlayerMetadata = function(src, metadata)
|
||||
return xPlayer.getMeta(metadata) or false
|
||||
end
|
||||
|
||||
--- @description This will return the specified status column of the player.
|
||||
---@description This is an internal function and should not be used outside of bridge, this is only present in the esx portion.
|
||||
--- @param src number
|
||||
--- @param column string
|
||||
--- @return string|nil
|
||||
@@ -213,16 +243,16 @@ Framework.GetStatus = function(src, column)
|
||||
return xPlayer.get(column) or nil
|
||||
end
|
||||
|
||||
--- @description This will return a boolean if the player is dead or in last stand
|
||||
---@description This will return a boolean if the player is dead or in last stand.
|
||||
--- @param src number
|
||||
--- @return boolean|nil
|
||||
--- @return boolean
|
||||
Framework.GetIsPlayerDead = function(src)
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
if not xPlayer then return false end
|
||||
return xPlayer.get("is_dead") or false
|
||||
end
|
||||
|
||||
--- @description This will revive a player, if the player is dead or in last stand
|
||||
---@description This will revive a player, if the player is dead or in last stand.
|
||||
--- @param src number
|
||||
--- @return boolean
|
||||
Framework.RevivePlayer = function(src)
|
||||
@@ -254,13 +284,13 @@ Framework.AddHunger = function(src, value)
|
||||
return levelForEsx
|
||||
end
|
||||
|
||||
--- @description This will get the hunger of a player (ESX we get the percent of the status)
|
||||
---@description This will get the hunger of a player
|
||||
--- @param src number
|
||||
--- @return number | nil
|
||||
--- @return number
|
||||
Framework.GetHunger = function(src)
|
||||
local status = Framework.GetStatus(src, "status")
|
||||
if not status then return end
|
||||
if type(status) ~= "table" then return end
|
||||
if not status then return 0 end
|
||||
if type(status) ~= "table" then return 0 end
|
||||
for _, entry in ipairs(status) do
|
||||
if entry.name == "hunger" then
|
||||
return math.floor((entry.percent) + 0.5) or 0
|
||||
@@ -268,13 +298,13 @@ Framework.GetHunger = function(src)
|
||||
end
|
||||
end
|
||||
|
||||
--- @description This will get the thirst of a player (ESX we get the percent of the status)
|
||||
---@description This will get the thirst of a player
|
||||
--- @param src any
|
||||
--- @return number | nil
|
||||
--- @return number
|
||||
Framework.GetThirst = function(src)
|
||||
local status = Framework.GetStatus(src, "status")
|
||||
if not status then return nil end
|
||||
if type(status) ~= "table" then return end
|
||||
if not status then return 0 end
|
||||
if type(status) ~= "table" then return 0 end
|
||||
for _, entry in ipairs(status) do
|
||||
if entry.name == "thirst" then
|
||||
return math.floor((entry.percent) + 0.5) or 0
|
||||
@@ -282,16 +312,17 @@ Framework.GetThirst = function(src)
|
||||
end
|
||||
end
|
||||
|
||||
--- @description This will get the phone number of a player
|
||||
---@description Returns the phone number of the player.
|
||||
--- @param src number
|
||||
--- @return string | nil return the phone number of the player
|
||||
--- @return string | nil
|
||||
Framework.GetPlayerPhone = function(src)
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
return xPlayer.get("phone_number")
|
||||
end
|
||||
|
||||
---@deprecated This will return the job name, label, grade name, and grade level of the player.
|
||||
---@description This will return the job name, label, grade name, and grade level of the player.
|
||||
---@deprecated
|
||||
---@param src number
|
||||
---@return string | nil
|
||||
---@return string | nil
|
||||
@@ -304,13 +335,12 @@ Framework.GetPlayerJob = function(src)
|
||||
return job.name, job.label, job.grade_label, job.grade
|
||||
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
|
||||
--- @param src number
|
||||
--- @return table | nil
|
||||
--- @return table {jobName, jobLabel, gradeName, gradeLabel, gradeRank, boss, onDuty}
|
||||
Framework.GetPlayerJobData = function(src)
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
if not xPlayer then return {} end
|
||||
local job = xPlayer.getJob()
|
||||
local isBoss = (job.grade_name == "boss")
|
||||
return {
|
||||
@@ -324,9 +354,9 @@ Framework.GetPlayerJobData = function(src)
|
||||
}
|
||||
end
|
||||
|
||||
--- @description This will return the players duty status, true if on duty false otherwise
|
||||
---@description Returns the players duty status.
|
||||
--- @param src number
|
||||
--- @return boolean return the players duty status
|
||||
--- @return boolean
|
||||
Framework.GetPlayerDuty = function(src)
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return false end
|
||||
@@ -335,7 +365,7 @@ Framework.GetPlayerDuty = function(src)
|
||||
return true
|
||||
end
|
||||
|
||||
--- @description This will toggle a players duty status
|
||||
---@description This will toggle a players duty status
|
||||
--- @param src number
|
||||
--- @param status boolean
|
||||
--- @return boolean
|
||||
@@ -348,95 +378,131 @@ Framework.SetPlayerDuty = function(src, status)
|
||||
return true
|
||||
end
|
||||
|
||||
--- @description This will get a table of player sources that have the specified job name
|
||||
---@description Returns the gang name of the player.
|
||||
---@param src number
|
||||
---@return string | nil
|
||||
Framework.GetPlayerGang = function(src)
|
||||
print("ESX does not support gangs, please ensure you are using a supported gang system or that you have the correct start order.")
|
||||
return
|
||||
end
|
||||
|
||||
---@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
|
||||
|
||||
--- @description This will set the player's job to the specified name and grade
|
||||
---@description Sets 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
|
||||
if not ESX.DoesJobExist(name, grade) then
|
||||
Prints.Error("Job Does Not Exsist In Framework :NAME " .. name .. " Grade:" .. grade)
|
||||
print("^6 Job Does Not Exsist In Framework :NAME " .. name .. " Grade:" .. grade .. " ^0 ")
|
||||
return
|
||||
end
|
||||
xPlayer.setJob(name, grade, true)
|
||||
return true
|
||||
end
|
||||
|
||||
--- @description This will add money based on the type of account (money/bank)
|
||||
---@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
|
||||
--- @return boolean
|
||||
Framework.AddAccountBalance = function(src, _type, amount)
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
if not xPlayer then return false end
|
||||
if _type == 'cash' then _type = 'money' end
|
||||
if amount <= 0 then return false end
|
||||
xPlayer.addAccountMoney(_type, amount)
|
||||
return true
|
||||
end
|
||||
|
||||
--- @description This will remove money based on the type of account (money/bank)
|
||||
---@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
|
||||
--- @return boolean
|
||||
Framework.RemoveAccountBalance = function(src, _type, amount)
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
if not xPlayer then return false end
|
||||
if _type == 'cash' then _type = 'money' end
|
||||
if amount <= 0 then return false end
|
||||
local accountVal = Framework.GetAccountBalance(src, _type)
|
||||
if accountVal < amount then return false end
|
||||
xPlayer.removeAccountMoney(_type, amount)
|
||||
return true
|
||||
end
|
||||
|
||||
--- @description This will get the account balance based on the type of account (money/bank)
|
||||
---@description This will get money based on the type of account (money/bank)
|
||||
--- @param src number
|
||||
--- @param _type string
|
||||
--- @return string | nil
|
||||
--- @return number
|
||||
Framework.GetAccountBalance = function(src, _type)
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
if not xPlayer then return 0 end
|
||||
if _type == 'cash' then _type = 'money' end
|
||||
return xPlayer.getAccount(_type).money
|
||||
local balance = xPlayer.getAccount(_type).money or 0
|
||||
if balance <= 0 then return 0 end
|
||||
return balance
|
||||
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)
|
||||
---@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 count number
|
||||
---@param slot number (optional)
|
||||
---@param metadata table (optional)
|
||||
---@return boolean
|
||||
Framework.AddItem = function(src, item, count, slot, metadata)
|
||||
if slot then print("ESX does not support item slots, please ensure you are using a supported inventory system or that you have the correct start order.") end
|
||||
if metadata then print("ESX does not support item metadata, please ensure you are using a supported inventory system or that you have the correct start order.") end
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
xPlayer.addInventoryItem(item, amount)
|
||||
if not xPlayer then return false end
|
||||
xPlayer.addInventoryItem(item, count)
|
||||
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, { action = "add", item = item, count = count, slot = slot, metadata = metadata })
|
||||
return true
|
||||
end
|
||||
|
||||
--- @description Removes the specified item from the player's inventory
|
||||
---@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
|
||||
--- @param slot number (optional)
|
||||
--- @param metadata table (optional)
|
||||
--- @return boolean
|
||||
Framework.RemoveItem = function(src, item, amount, slot, metadata)
|
||||
if slot then
|
||||
print("ESX does not support item slots, please ensure you are using a supported inventory system or that you have the correct start order.")
|
||||
end
|
||||
if metadata then
|
||||
print("ESX does not support item metadata, please ensure you are using a supported inventory system or that you have the correct start order.")
|
||||
end
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
if not xPlayer then return false end
|
||||
xPlayer.removeInventoryItem(item, amount)
|
||||
return true
|
||||
end
|
||||
|
||||
--- @description This will get all owned vehicles for the player
|
||||
---@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
|
||||
Framework.SetMetadata = function(src, item, slot, metadata)
|
||||
print("ESX does not support item metadata, please ensure you are using a supported inventory system or that you have the correct start order.")
|
||||
return false
|
||||
end
|
||||
|
||||
---@description This will get all owned vehicles for the player
|
||||
--- @param src number
|
||||
--- @return table
|
||||
Framework.GetOwnedVehicles = function(src)
|
||||
@@ -452,7 +518,7 @@ Framework.GetOwnedVehicles = function(src)
|
||||
return vehicles
|
||||
end
|
||||
|
||||
--- @description Registers a usable item with a callback function
|
||||
---@description Registers a usable item with a callback function.
|
||||
--- @param itemName string
|
||||
--- @param cb function
|
||||
Framework.RegisterUsableItem = function(itemName, cb)
|
||||
@@ -465,6 +531,8 @@ Framework.RegisterUsableItem = function(itemName, cb)
|
||||
ESX.RegisterUsableItem(itemName, func)
|
||||
end
|
||||
|
||||
---@description Event handler for when a player is loaded in ESX framework
|
||||
---@param src number
|
||||
RegisterNetEvent("esx:playerLoaded", function(src)
|
||||
src = src or source
|
||||
TriggerEvent("community_bridge:Server:OnPlayerLoaded", src)
|
||||
@@ -473,32 +541,50 @@ RegisterNetEvent("esx:playerLoaded", function(src)
|
||||
Framework.AddJobCount(src, jobData.jobName)
|
||||
end)
|
||||
|
||||
---@description Event handler for when a player logs out in ESX framework
|
||||
---@param src number
|
||||
RegisterNetEvent("esx:playerLogout", 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 ESX framework
|
||||
---@param src number
|
||||
---@param job table
|
||||
---@param lastJob table
|
||||
RegisterNetEvent("esx:setJob", function(src, job, lastJob)
|
||||
src = src or source
|
||||
if not job or not lastJob 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)
|
||||
|
||||
---@description Callback to get framework jobs list
|
||||
---@param source number
|
||||
Callback.Register('community_bridge:Callback:GetFrameworkJobs', function(source)
|
||||
return Framework.GetFrameworkJobs() or {}
|
||||
end)
|
||||
|
||||
-- This is linked to an internal function, its an attempt to standardize the item list across frameworks.
|
||||
---@description This is linked to an internal function, its an attempt to standardize the item list across frameworks.
|
||||
---@param source number
|
||||
Callback.Register('community_bridge:Callback:GetFrameworkItems', function(source)
|
||||
return Framework.ItemList() or {}
|
||||
end)
|
||||
|
||||
Framework.Commands = {}
|
||||
---@description Adds a command to the ESX 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, ...)
|
||||
ESX.RegisterCommand(name, permission, function(xPlayer, args, showError)
|
||||
callback(xPlayer, args)
|
||||
|
||||
@@ -11,7 +11,8 @@ Framework.Shared = QBCore.Shared
|
||||
---@description This will get the name of the framework being used (if a supported framework).
|
||||
---@return string
|
||||
Framework.GetFrameworkName = function()
|
||||
return 'qb-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.
|
||||
@@ -149,8 +150,9 @@ end
|
||||
---@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
|
||||
@@ -169,11 +171,12 @@ Framework.GetPlayerJobData = function()
|
||||
}
|
||||
end
|
||||
|
||||
---@description This will return if the player has the specified item in their inventory
|
||||
---@description Will return boolean if the player has the item.
|
||||
---@param item string
|
||||
---@param requiredCount number (optional)
|
||||
---@return boolean
|
||||
Framework.HasItem = function(item)
|
||||
return QBCore.Functions.HasItem(item)
|
||||
Framework.HasItem = function(item, requiredCount)
|
||||
return QBCore.Functions.HasItem(item, requiredCount or 1)
|
||||
end
|
||||
|
||||
---@description This will return the item count for the specified item in the players inventory
|
||||
@@ -201,7 +204,7 @@ Framework.GetPlayerInventory = function()
|
||||
label = v.label,
|
||||
count = v.amount or v.count,
|
||||
slot = v.slot,
|
||||
metadata = v.info,
|
||||
metadata = v.info or v.metadata or {},
|
||||
stack = v.unique,
|
||||
close = v.useable,
|
||||
weight = v.weight
|
||||
@@ -248,28 +251,21 @@ Framework.GetIsPlayerDead = function()
|
||||
return playerData.metadata["isdead"] or playerData.metadata["inlaststand"]
|
||||
end
|
||||
|
||||
---@description Event handler for when player is loaded in QB-Core framework
|
||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
||||
Wait(1500)
|
||||
TriggerEvent('community_bridge:Client:OnPlayerLoaded')
|
||||
end)
|
||||
|
||||
---@description Event handler for when player is unloaded in QB-Core framework
|
||||
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
|
||||
TriggerEvent('community_bridge:Client:OnPlayerUnload')
|
||||
end)
|
||||
|
||||
---@description Event handler for when player job is updated in QB-Core framework
|
||||
---@param data table Job data containing name, label, grade_label, and grade
|
||||
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(data)
|
||||
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', data.name, data.label, data.grade_label, data.grade)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Client:OnGangUpdate', function(data)
|
||||
-- Unsure what data is passed in this, but considering the gang data isnt updating I doubt this was tested.
|
||||
--[[
|
||||
PlayerJobName = data.name
|
||||
PlayerJobLabel = data.label
|
||||
PlayerJobGradeName = data.grade.name
|
||||
PlayerJobGradeLevel = data.grade.level
|
||||
TriggerEvent('community_bridge:Client:OnPlayerGangUpdate', PlayerGangName, PlayerGangLabel, PlayerGangGradeName, PlayerGangGradeLevel)
|
||||
--]]
|
||||
end)
|
||||
|
||||
return Framework
|
||||
@@ -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
|
||||
|
||||
@@ -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