qbx_core
if not GetResourceState('qbx_core') == 'started' then return end
Framework = {
---@param source number
---@return string|nil
getIdentifierBySource = function(source)
if not source or type(source) ~= 'number' or not GetPlayerName(source) then
prints.error('Invalid source provided')
return nil
end
local player = exports.qbx_core:GetPlayer(source)
if not player then
prints.error('Player not found for source: %s', source)
return nil
end
local identifier = player.PlayerData.citizenid
if not identifier then
prints.error('Identifier not found for player: %s', player.PlayerData.citizenid)
return nil
end
return identifier
end,
---@param stateid string
---@return string
getPlayerGender = function(stateid)
local result = MySQL.single.await(
[[
SELECT
JSON_UNQUOTE(JSON_EXTRACT(`charinfo`, '$.gender')) AS gender
FROM
`players`
WHERE
`citizenid` = ?
]], { stateid }
)
if not result or not result.gender then
prints.error('Gender not found for stateid: %s', stateid)
return 'Unknown'
end
local gender = tonumber(result.gender)
if gender == 0 then
return 'Male'
elseif gender == 1 then
return 'Female'
else
prints.error('Invalid gender value for stateid: %s', stateid)
return 'Unknown'
end
end,
---@param stateid string
---@return table A list of jobs with keys: label, value, coords<optional>
getPlayerEmployment = function(stateid)
local result = MySQL.single.await(
[[
SELECT
JSON_UNQUOTE(JSON_EXTRACT(`job`, '$.label')) AS label,
JSON_UNQUOTE(JSON_EXTRACT(`job`, '$.grade.name')) AS value
FROM
`players`
WHERE
`citizenid` = ?
]], { stateid }
)
return { result }
end,
---@param author_stateid string
---@param stateid string
---@param amount number
---@return boolean
penalizePlayer = function(author_stateid, stateid, amount)
local authorIdentifier = exports.drx_mdt:GetIdentifierByStateId(author_stateid)
local playerIdentifier = exports.drx_mdt:GetIdentifierByStateId(stateid)
if not authorIdentifier or not playerIdentifier then
prints.error("Failed to retrieve identifier for penalization")
return false
end
local playerSource = exports.qbx_core:GetSource(playerIdentifier)
if not playerSource then
prints.error("Player source not found for identifier: %s", playerIdentifier)
return false
end
local player = exports.qbx_core:GetPlayer(playerSource)
if player then
-- player.Functions.RemoveMoney("bank", amount) -- Example: Remove money from player's bank account
print("Player fined successfully:", playerSource, amount)
return true
else
prints.error("Failed to find player entity for source: %s", playerSource)
return false
end
end,
---@param author_stateid string
---@param stateid string
---@param jailTime number
---@return boolean
detainPlayer = function(author_stateid, stateid, jailTime)
local authorIdentifier = exports.drx_mdt:GetIdentifierByStateId(author_stateid)
local playerIdentifier = exports.drx_mdt:GetIdentifierByStateId(stateid)
if not authorIdentifier or not playerIdentifier then
prints.error("Failed to retrieve identifiers for detainment")
return false
end
local playerSource = exports.qbx_core:GetSource(playerIdentifier)
if not playerSource then
prints.error("Player source not found for identifier: %s", playerIdentifier)
return false
end
-- Example: Assigning a jail sentence to the player
-- This requires a custom implementation depending on your jail system
-- TriggerEvent('police:server:jailPlayer', playerSource, jailTime) -- qbx_police event
print("Player jailed successfully:", playerSource, jailTime)
return true
end
}
Last updated
Was this helpful?