docs: refine framework notes, params, and return documentation

This commit is contained in:
MrNewb committed 2025-05-30 03:21:32 -04:00
1 parent 38ce2e8f1e
commit 7fc9ee4956
6 files changed
+257 -80

No files matched your search

+20 -17
View File
@@ -5,11 +5,14 @@ ESX = exports["es_extended"]:getSharedObject()
Framework = Framework or {}
---This will get the name of the framework being used (if a supported framework).
---@return string
Framework.GetFrameworkName = function()
return 'es_extended'
end
---This will return a table of the players data, this is an internal table and should not be used.
---This will return a table of the player data, this will be in the framework format.
---This is mainly for internal bridge use and should be avoided.
---@return table
Framework.GetPlayerData = function()
return ESX.GetPlayerData()
@@ -32,13 +35,13 @@ Framework.GetPlayerDob = function()
end
---This will return the players metadata for the specified metadata key.
---@param metadata string
---@return table | nil
---@param metadata table | string
---@return table | string | number | boolean
Framework.GetPlayerMetaData = function(metadata)
return Framework.GetPlayerData().metadata[metadata]
end
---This will prompt the user with a notification message
---This will send a notification to the player.
---@param message string
---@param type string
---@param time number
@@ -61,14 +64,14 @@ Framework.HideHelpText = function()
return exports['esx_textui']:HideUI()
end
---This will return the players identifier
---This will get the players identifier (citizenid) etc.
---@return string
Framework.GetPlayerIdentifier = function()
local playerData = Framework.GetPlayerData()
return playerData.identifier
end
---This will return the players first name, and the last name
---This will get the players name (first and last).
---@return string
---@return string
Framework.GetPlayerName = function()
@@ -103,7 +106,7 @@ Framework.GetPlayerJobData = function()
}
end
---This will return a boolean if the player has the item in their inventory
---This will return if the player has the specified item in their inventory.
---@param item string
---@return boolean
Framework.HasItem = function(item)
@@ -111,6 +114,15 @@ Framework.HasItem = function(item)
return hasItem > 0 and true or false
end
---This will return the item count for the specified item in the players inventory.
---@param item string
---@return number
Framework.GetItemCount = function(item)
local inventory = Framework.GetPlayerInventory()
if not inventory then return 0 end
return inventory[item].count or 0
end
---This will return a table of the players inventory
---@return table
Framework.GetPlayerInventory = function()
@@ -118,16 +130,7 @@ Framework.GetPlayerInventory = function()
return playerData.inventory
end
---This will return a number of the item in the players inventory
---@param item string
---@return number
Framework.GetItemCount = function(item)
local inventory = Framework.GetPlayerInventory()
if not inventory then return 0 end
return inventory[item].count or 0
end
---This will return a boolean if the player is dead
---This will get a players dead status.
---@return boolean
Framework.GetIsPlayerDead = function()
local playerData = Framework.GetPlayerData()
+97 -26
View File
@@ -7,10 +7,14 @@ ESX = exports["es_extended"]:getSharedObject()
Framework = Framework or {}
---This will return the name of the framework in use.
---@return string
Framework.GetFrameworkName = function()
return 'es_extended'
end
---This will get the players birth date
---@return string|nil
Framework.GetPlayerDob = function(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
@@ -18,9 +22,7 @@ Framework.GetPlayerDob = function(src)
return dob
end
--- This will return a table of the players data
---
--- This table is in the framework format and not converted to any standard.
--- Returns the player data of the specified source in the framework defualt format.
---@param src any
---@return table | nil
Framework.GetPlayer = function(src)
@@ -31,18 +33,24 @@ end
-- Framework.GetPlayerIdentifier(src)
-- Returns the citizen ID of the player.
---@param src number
---@return string | nil
Framework.GetPlayerIdentifier = function(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
return xPlayer.getIdentifier()
end
---This will return the jobs registered in the framework in a table.
---Format of the table is:
---{name = jobName, label = jobLabel, grade = {name = gradeName, level = gradeLevel}}
---@return table
Framework.GetFrameworkJobs = function()
return ESX.GetJobs()
end
-- Framework.GetPlayerName(src)
-- Returns the first and last name of the player.
---@return string|nil, string|nil
Framework.GetPlayerName = function(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
@@ -60,9 +68,12 @@ Framework.GetPlayers = function()
return playerList
end
-- Framework.GetItem(src, item, metadata)
-- Returns a table of items matching the specified name and if passed metadata from the player's inventory.
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
---Returns a table of items matching the specified name and if passed metadata from the player's inventory.
---returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
---@param src number
---@param item string
---@param _ table
---@return table|nil
Framework.GetItem = function(src, item, _)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
@@ -81,15 +92,19 @@ Framework.GetItem = function(src, item, _)
return repackedTable
end
-- Framework.GetItemCount(src, item, _)
-- Returns the count of items matching the specified name and if passed metadata from the player's inventory.
---This will return the count of the item in the players inventory, if not found will return 0.
---if metadata is passed it will find the matching items count (esx_core does not feature metadata items).
---@param src number
---@param item string
---@param _ table
---@return number
Framework.GetItemCount = function(src, item, _)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
return xPlayer.getInventoryItem(item).count
end
---comment
---This will return a boolean if the player has the item.
---@param src number
---@param item string
---@return boolean
@@ -100,7 +115,9 @@ end
-- Framework.GetPlayerInventory(src)
-- Returns the entire inventory of the player as a table.
-- returns {name = v.name, count = v.amount, _, _}
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
---@param src number
---@return table | nil
Framework.GetPlayerInventory = function(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
@@ -121,6 +138,7 @@ end
-- Framework.SetMetadata(src, metadata, value)
-- Adds the specified metadata key and number value to the player's data.
---@return boolean|nil
Framework.SetPlayerMetadata = function(src, metadata, value)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
@@ -129,7 +147,10 @@ Framework.SetPlayerMetadata = function(src, metadata, value)
end
-- Framework.GetMetadata(src, metadata)
-- Gets the specified metadata key and value to the player's data.
-- Gets the specified metadata key to the player's data.
---@param src number
---@param metadata string
---@return any|nil
Framework.GetPlayerMetadata = function(src, metadata)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
@@ -147,12 +168,18 @@ Framework.GetStatus = function(src, column)
return xPlayer.get(column) or nil
end
---This will return a boolean if the player is dead or in last stand.
---@param src number
---@return boolean|nil
Framework.GetIsPlayerDead = function(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
return xPlayer.get("is_dead") or false
end
---This will revive a player, if the player is dead or in last stand.
---@param src number
---@return boolean
Framework.RevivePlayer = function(src)
src = tonumber(src)
if not src then return false end
@@ -162,6 +189,9 @@ end
-- Framework.AddThirst(src, value)
-- Adds the specified value from the player's thirst level.
---@param src number
---@param value number
---@return number | nil
Framework.AddThirst = function(src, value)
local clampIT = Math.Clamp(value, 0, 200000)
local levelForEsx = clampIT * 2000
@@ -171,6 +201,9 @@ end
-- Framework.AddHunger(src, value)
-- Adds the specified value from the player's hunger level.
---@param src number
---@param value number
---@return number | nil
Framework.AddHunger = function(src, value)
local clampIT = Math.Clamp(value, 0, 200000)
local levelForEsx = clampIT * 2000
@@ -178,12 +211,18 @@ Framework.AddHunger = function(src, value)
return levelForEsx
end
---This will get the hunger of a player
---@param src number
---@return number | nil
Framework.GetHunger = function(src)
local status = Framework.GetStatus(src, "status")
if not status then return 0 end
return status.hunger
end
---This will get the thirst of a player
---@param src any
---@return number | nil
Framework.GetThirst = function(src)
local status = Framework.GetStatus(src, "status")
if not status then return 0 end
@@ -192,6 +231,8 @@ end
-- Framework.GetPlayerPhone(src)
-- Returns the phone number of the player.
---@param src number
---@return string | nil
Framework.GetPlayerPhone = function(src)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
@@ -242,9 +283,9 @@ Framework.GetPlayerDuty = function(src)
return true
end
---Sets the players duty status.
---This will toggle a players duty status
---@param src number
---@param dutystatus boolean
---@param status boolean
---@return boolean
Framework.SetPlayerDuty = function(src, dutystatus)
local xPlayer = Framework.GetPlayer(src)
@@ -254,22 +295,26 @@ Framework.SetPlayerDuty = function(src, dutystatus)
return xPlayer.setJob(job.name, job.grade, dutystatus)
end
-- Framework.GetPlayersByJob(jobname)
-- returns a table of player sources that have the specified job name.
---This will get a table of player sources that have the specified job name.
---@param job any
---@return table
Framework.GetPlayersByJob = function(job)
local players = GetPlayers()
local playerList = {}
for _, src in pairs(players) do
local xPlayer = Framework.GetPlayer(src)
if xPlayer.getJob().name == job then
if xPlayer and xPlayer.getJob().name == job then
table.insert(playerList, src)
end
end
return playerList
end
-- Framework.SetPlayerJob(src, name, grade)
-- 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
@@ -280,8 +325,11 @@ Framework.SetPlayerJob = function(src, name, grade)
return xPlayer.setJob(name, grade, true)
end
-- Framework.AddAccountBalance(src, _type, amount)
-- Adds the specified amount to the player's account balance of the specified type.
---This will add money based on the type of account (money/bank)
---@param src number
---@param _type string
---@param amount number
---@return boolean | nil
Framework.AddAccountBalance = function(src, _type, amount)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
@@ -289,8 +337,11 @@ Framework.AddAccountBalance = function(src, _type, amount)
return xPlayer.addAccountMoney(_type, amount)
end
-- Framework.RemoveAccountBalance(src, _type, amount)
-- Removes the specified amount from the player's account balance of the specified type.
---This will remove money based on the type of account (money/bank)
---@param src number
---@param _type string
---@param amount number
---@return boolean | nil
Framework.RemoveAccountBalance = function(src, _type, amount)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
@@ -299,8 +350,10 @@ Framework.RemoveAccountBalance = function(src, _type, amount)
return true
end
-- Framework.GetAccountBalance(src, _type)
-- Returns the player's account balance of the specified type.
---This will remove money based on the type of account (money/bank)
---@param src number
---@param _type string
---@return string | nil
Framework.GetAccountBalance = function(src, _type)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
@@ -308,22 +361,37 @@ Framework.GetAccountBalance = function(src, _type)
return xPlayer.getAccount(_type).money
end
-- Framework.AddItem(src, item, amount, _, _)
-- Framework.AddItem(src, item, amount, slot, metadata)
-- Adds the specified item to the player's inventory.
---@param src number
---@param item string
---@param amount number
---@param slot number
---@param metadata table
---@return boolean | nil
Framework.AddItem = function(src, item, amount, slot, metadata)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
return xPlayer.addInventoryItem(item, amount)
end
-- Framework.RemoveItem(src, item, amount, _, _)
-- Framework.RemoveItem(src, item, amount, slot, metadata)
-- Removes the specified item from the player's inventory.
---@param src number
---@param item string
---@param amount number
---@param slot number
---@param metadata table
---@return boolean | nil
Framework.RemoveItem = function(src, item, amount, slot, metadata)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return end
return xPlayer.removeInventoryItem(item, amount)
end
---This will get all owned vehicles for the player
---@param src number
---@return table
Framework.GetOwnedVehicles = function(src)
local citizenId = Framework.GetPlayerIdentifier(src)
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM owned_vehicles WHERE owner = '" .. citizenId .. "'")
@@ -337,8 +405,11 @@ Framework.GetOwnedVehicles = function(src)
return vehicles
end
-- Framework.RegisterUsableItem(item, cb)
-- Registers a usable item with a callback function.
---@param itemName string
---@param cb function
Framework.RegisterUsableItem = function(itemName, cb)
local func = function(src, item, itemData)
itemData = itemData or item
+17 -1
View File
@@ -14,6 +14,9 @@ Framework.GetFrameworkName = function()
return 'qb-core'
end
---This will return a table of the player data, this will be in the framework format.
---This is mainly for internal bridge use and should be avoided.
---@return table
Framework.GetPlayerData = function()
return QBCore.Functions.GetPlayerData()
end
@@ -47,6 +50,11 @@ Framework.GetPlayerMetaData = function(metadata)
return Framework.GetPlayerData().metadata[metadata]
end
---This will send a notification to the player.
---@param message string
---@param type string
---@param time number
---@return nil
Framework.Notify = function(message, type, time)
TriggerEvent('QBCore:Notify', message, 'primary', time)
end
@@ -65,6 +73,9 @@ Framework.HideHelpText = function()
return exports['qb-core']:HideText()
end
---This will return the item data for the specified item.
---@param item string
---@return table
Framework.GetItemInfo = function(item)
local itemData = QBCore.Shared.Items[item]
if not itemData then return {} end
@@ -119,11 +130,14 @@ Framework.GetPlayerJobData = function()
}
end
---This will return if the player has the specified item in their inventory.
---@param item string
---@return boolean
Framework.HasItem = function(item)
return QBCore.Functions.HasItem(item)
end
---comment
---This will return the item count for the specified item in the players inventory.
---@param item string
---@return number
Framework.GetItemCount = function(item)
@@ -137,6 +151,8 @@ Framework.GetItemCount = function(item)
return count
end
---This will return the players inventory as a table in the ox_inventory style flormat.
---@return table
Framework.GetPlayerInventory = function()
local items = {}
local frameworkInv = Framework.GetPlayerData().items
+76 -19
View File
@@ -8,12 +8,16 @@ QBCore = exports['qb-core']:GetCoreObject()
Framework.Shared = QBCore.Shared
---This will return the name of the framework in use.
---@return string
Framework.GetFrameworkName = function()
return 'qb-core'
end
-- Framework.GetPlayerIdentifier(src)
-- Returns the citizen ID of the player.
---@param src number
---@return string | nil
Framework.GetPlayerIdentifier = function(src)
local player = Framework.GetPlayer(src)
if not player then return end
@@ -21,7 +25,7 @@ Framework.GetPlayerIdentifier = function(src)
return playerData.citizenid
end
--- Returns the player data of the specified source.
--- Returns the player data of the specified source in the framework defualt format.
---@param src any
---@return table | nil
Framework.GetPlayer = function(src)
@@ -30,6 +34,10 @@ Framework.GetPlayer = function(src)
return player
end
---This will return the jobs registered in the framework in a table.
---Format of the table is:
---{name = jobName, label = jobLabel, grade = {name = gradeName, level = gradeLevel}}
---@return table
Framework.GetFrameworkJobs = function()
local jobs = {}
for k, v in pairs(QBCore.Shared.Jobs) do
@@ -44,7 +52,7 @@ end
-- Framework.GetPlayerName(src)
-- Returns the first and last name of the player.
---@return string, string
---@return string|nil, string|nil
Framework.GetPlayerName = function(src)
local player = Framework.GetPlayer(src)
if not player then return end
@@ -52,8 +60,9 @@ Framework.GetPlayerName = function(src)
return playerData.charinfo.firstname, playerData.charinfo.lastname
end
---This will get the players birth date
---@return string
---Returns the player date of birth.
---@param src number
---@return string|nil
Framework.GetPlayerDob = function(src)
local player = Framework.GetPlayer(src)
if not player then return end
@@ -61,9 +70,12 @@ Framework.GetPlayerDob = function(src)
return playerData.charinfo.birthdate
end
-- Framework.GetItem(src, item, metadata)
-- Returns a table of items matching the specified name and if passed metadata from the player's inventory.
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
---Returns a table of items matching the specified name and if passed metadata from the player's inventory.
---returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
---@param src number
---@param item string
---@param metadata table
---@return table|nil
Framework.GetItem = function(src, item, metadata)
local player = Framework.GetPlayer(src)
if not player then return end
@@ -109,7 +121,7 @@ end
---@return number
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 playerData = player.PlayerData
local playerInventory = playerData.items
local count = 0
@@ -133,6 +145,8 @@ end
-- Framework.GetPlayerInventory(src)
-- Returns the entire inventory of the player as a table.
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
---@param src number
---@return table | nil
Framework.GetPlayerInventory = function(src)
local player = Framework.GetPlayer(src)
if not player then return end
@@ -161,6 +175,11 @@ Framework.GetPlayers = function()
return playerList
end
---This will return the item data for the specified slot.
---Format {name, label, weight, count, metadata, slot, stack, description}
---@param src number
---@param slot number
---@return table|nil
Framework.GetItemBySlot = function(src, slot)
local player = Framework.GetPlayer(src)
if not player then return end
@@ -186,7 +205,7 @@ end
-- Framework.SetMetadata(src, metadata, value)
-- Adds the specified metadata key and number value to the player's data.
---@return boolean | nil
---@return boolean|nil
Framework.SetPlayerMetadata = function(src, metadata, value)
local player = Framework.GetPlayer(src)
if not player then return end
@@ -196,6 +215,9 @@ end
-- Framework.GetMetadata(src, metadata)
-- Gets the specified metadata key to the player's data.
---@param src number
---@param metadata string
---@return any|nil
Framework.GetPlayerMetadata = function(src, metadata)
local player = Framework.GetPlayer(src)
if not player then return end
@@ -205,6 +227,8 @@ end
-- Framework.AddStress(src, value)
-- Adds the specified value to the player's stress level and updates the client HUD.
---@param src number
---@param value number
---@return number | nil
Framework.AddStress = function(src, value)
local player = Framework.GetPlayer(src)
@@ -218,6 +242,8 @@ end
-- Framework.RemoveStress(src, value)
-- Removes the specified value from the player's stress level and updates the client HUD.
---@param src number
---@param value number
---@return number | nil
Framework.RemoveStress = function(src, value)
local player = Framework.GetPlayer(src)
@@ -231,6 +257,8 @@ end
-- Framework.AddHunger(src, value)
-- Adds the specified value from the player's hunger level.
---@param src number
---@param value number
---@return number | nil
Framework.AddHunger = function(src, value)
local player = Framework.GetPlayer(src)
@@ -240,12 +268,13 @@ Framework.AddHunger = function(src, 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
-- Framework.AddThirst(src, value)
-- Adds the specified value from the player's thirst level.
---@param src number
---@param value number
---@return number | nil
Framework.AddThirst = function(src, value)
local player = Framework.GetPlayer(src)
@@ -259,7 +288,7 @@ Framework.AddThirst = function(src, value)
end
---This will get the hunger of a player
---@param src any
---@param src number
---@return number | nil
Framework.GetHunger = function(src)
local player = Framework.GetPlayer(src)
@@ -269,6 +298,9 @@ Framework.GetHunger = function(src)
return newHunger
end
---This will return a boolean if the player is dead or in last stand.
---@param src number
---@return boolean|nil
Framework.GetIsPlayerDead = function(src)
local player = Framework.GetPlayer(src)
if not player then return end
@@ -276,6 +308,9 @@ Framework.GetIsPlayerDead = function(src)
return playerData.metadata.isdead or playerData.metadata.inlaststand or false
end
---This will revive a player, if the player is dead or in last stand.
---@param src number
---@return boolean
Framework.RevivePlayer = function(src)
src = tonumber(src)
if not src then return false end
@@ -297,6 +332,8 @@ end
-- Framework.GetPlayerPhone(src)
-- Returns the phone number of the player.
---@param src number
---@return string | nil
Framework.GetPlayerPhone = function(src)
local player = Framework.GetPlayer(src)
if not player then return end
@@ -306,6 +343,8 @@ end
-- Framework.GetPlayerGang(src)
-- Returns the gang name of the player.
---@param src number
---@return string | nil
Framework.GetPlayerGang = function(src)
local player = Framework.GetPlayer(src)
if not player then return end
@@ -342,6 +381,7 @@ Framework.GetPlayerJob = function(src)
end
---This will return the players job name, job label, job grade label job grade level, boss status, and duty status in a table
---@param src number
---@return table | nil
Framework.GetPlayerJobData = function(src)
local player = Framework.GetPlayer(src)
@@ -373,12 +413,13 @@ end
---This will toggle a players duty status
---@param src number
---@param status boolean
---@return nil
---@return boolean
Framework.SetPlayerDuty = function(src, status)
local player = Framework.GetPlayer(src)
if not player then return end
if not player then return false end
player.Functions.SetJobDuty(status)
TriggerEvent('QBCore:Server:SetDuty', src, player.PlayerData.job.onduty)
return true
end
-- Sets the player's job to the specified name and grade.
@@ -430,27 +471,42 @@ end
-- Framework.AddItem(src, item, amount, slot, metadata)
-- Adds the specified item to the player's inventory.
---@param src number
---@param item string
---@param amount number
---@param slot number
---@param metadata table
---@return boolean | nil
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 })
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
-- Framework.RemoveItem(src, item, amount, slot, metadata)
-- Removes the specified item from the player's inventory.
---@param src number
---@param item string
---@param amount number
---@param slot number
---@param metadata table
---@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 })
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)
end
-- Framework.SetMetadata(src, item, slot, metadata)
-- 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
---@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
@@ -474,8 +530,7 @@ end
---@return table
Framework.GetOwnedVehicles = function(src)
local citizenId = Framework.GetPlayerIdentifier(src)
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM player_vehicles WHERE citizenid = '" ..
citizenId .. "'")
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM player_vehicles WHERE citizenid = '" .. citizenId .. "'")
local vehicles = {}
for i = 1, #result do
local vehicle = result[i].vehicle
@@ -487,6 +542,8 @@ end
-- Framework.RegisterUsableItem(item, cb)
-- Registers a usable item with a callback function.
---@param itemName string
---@param cb function
Framework.RegisterUsableItem = function(itemName, cb)
local func = function(src, item, itemData)
itemData = itemData or item
+30 -5
View File
@@ -5,18 +5,27 @@ QBox = exports.qbx_core
Framework = Framework or {}
---This will get the name of the framework being used (if a supported framework).
---@return string
Framework.GetFrameworkName = function()
return 'qbx_core'
end
---This will return a table of the player data, this will be in the framework format.
---This is mainly for internal bridge use and should be avoided.
---@return table
Framework.GetPlayerData = function()
return QBox.GetPlayerData()
end
---This will return a table of all the jobs in the framework.
---@return table
Framework.GetFrameworkJobs = function()
return QBox.GetJobs()
end
---This will get the players birth date
---@return string
Framework.GetPlayerDob = function()
local playerData = Framework.GetPlayerData()
return playerData.charinfo.birthdate
@@ -24,11 +33,10 @@ end
---Will Display the help text message on the screen
---@param message string
---@param _ unknown
---@param position string
---@return nil
Framework.ShowHelpText = function(message, _)
if _ == nil then _ = 'left-center' end
return exports.ox_lib:showTextUI(message, { position = _position })
Framework.ShowHelpText = function(message, position)
return exports.ox_lib:showTextUI(message, { position = position or 'top-center' })
end
---This will hide the help text message on the screen
@@ -37,19 +45,32 @@ Framework.HideHelpText = function()
return exports.ox_lib:hideTextUI()
end
---This will return the players metadata for the specified metadata key.
---@param metadata table | string
---@return table | string | number | boolean
Framework.GetPlayerMetaData = function(metadata)
local playerData = Framework.GetPlayerData()
return playerData.metadata[metadata]
end
---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 QBox:Notify("Notification", type, time, message)
end
---This will get the players identifier (citizenid) etc.
---@return string
Framework.GetPlayerIdentifier = function()
return Framework.GetPlayerData().citizenid
end
---This will get the players name (first and last).
---@return string
---@return string
Framework.GetPlayerName = function()
local playerData = Framework.GetPlayerData()
return playerData.charinfo.firstname, playerData.charinfo.lastname
@@ -81,11 +102,13 @@ Framework.GetPlayerJobData = function()
}
end
---This will return the players inventory as a table in the ox_inventory style flormat.
---@return table
Framework.GetPlayerInventory = function()
return Framework.GetPlayerData().items
end
---comment
---This will return the item count for the specified item in the players inventory.
---@param item string
---@return number
Framework.GetItemCount = function(item)
@@ -93,6 +116,8 @@ Framework.GetItemCount = function(item)
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.")
end
---This will get a players dead status.
---@return boolean
Framework.GetIsPlayerDead = function()
local platerData = Framework.GetPlayerData()
return platerData.metadata["isdead"] or platerData.metadata["inlaststand"]
+17 -12
View File
@@ -13,7 +13,7 @@ end
---Returns the player date of birth.
---@param src number
---@return string
---@return string|nil
Framework.GetPlayerDob = function(src)
local player = Framework.GetPlayer(src)
if not player then return end
@@ -69,11 +69,12 @@ Framework.GetPlayerName = function(src)
return playerData.charinfo.firstname, playerData.charinfo.lastname
end
-- Returns a table of items matching the specified name and if passed metadata from the player's inventory.
---Returns a table of items matching the specified name and if passed metadata from the player's inventory.
---returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
---@param src number
---@param item string
---@param metadata table
---@return table
---@return table|nil
Framework.GetItem = function(src, item, metadata)
local player = Framework.GetPlayer(src)
if not player then return end
@@ -203,7 +204,7 @@ Framework.AddHunger = function(src, value)
return newHunger
end
-- Adds the specified value from the player's thirst level.
---Adds the specified value from the player's thirst level.
---@param src number
---@param value number
---@return number | nil
@@ -228,6 +229,9 @@ Framework.GetHunger = function(src)
return newHunger
end
---This will return a boolean if the player is dead or in last stand.
---@param src number
---@return boolean|nil
Framework.GetIsPlayerDead = function(src)
local player = Framework.GetPlayer(src)
if not player then return end
@@ -235,6 +239,9 @@ Framework.GetIsPlayerDead = function(src)
return playerData.metadata.isdead or false
end
---This will revive a player, if the player is dead or in last stand.
---@param src number
---@return boolean
Framework.RevivePlayer = function(src)
src = tonumber(src)
if not src then return false end
@@ -244,7 +251,7 @@ end
---This will return the players thirst level.
---@param src number
---@return number
---@return number| nil
Framework.GetThirst = function(src)
local player = Framework.GetPlayer(src)
if not player then return end
@@ -299,6 +306,7 @@ Framework.GetPlayerJob = function(src)
end
---This will return the players job name, job label, job grade label job grade level, boss status, and duty status in a table
---@param src number
---@return table | nil
Framework.GetPlayerJobData = function(src)
local player = Framework.GetPlayer(src)
@@ -395,8 +403,7 @@ end
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 })
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
@@ -410,13 +417,12 @@ end
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 })
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
---Sets the metadata for the specified item in the player's inventory.
-----@param src number
---@param src number
---@param item string
---@param slot number
---@param metadata table
@@ -433,8 +439,7 @@ end
---@return table
Framework.GetOwnedVehicles = function(src)
local citizenId = Framework.GetPlayerIdentifier(src)
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM player_vehicles WHERE citizenid = '" ..
citizenId .. "'")
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM player_vehicles WHERE citizenid = '" .. citizenId .. "'")
local vehicles = {}
for i = 1, #result do
local vehicle = result[i].vehicle