ed
This commit is contained in:
parent
510e3ffcf2
commit
f43cf424cf
305 changed files with 34683 additions and 0 deletions
|
@ -0,0 +1,3 @@
|
|||
Framework = Framework or {}
|
||||
|
||||
return Framework
|
|
@ -0,0 +1,3 @@
|
|||
Framework = Framework or {}
|
||||
|
||||
return Framework
|
|
@ -0,0 +1,226 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('es_extended') ~= 'started' then return end
|
||||
|
||||
ESX = exports["es_extended"]:getSharedObject()
|
||||
Callback = Callback or Require("lib/utility/shared/callbacks.lua")
|
||||
|
||||
Framework = Framework or {}
|
||||
|
||||
local cachedItemList = nil
|
||||
-- This is an internal function, its here to attempt to emulate qbs shared items mainly.
|
||||
Framework.ItemList = function()
|
||||
if cachedItemList then return cachedItemList end
|
||||
local items = Callback.Trigger('community_bridge:Callback:GetFrameworkItems', false)
|
||||
cachedItemList = { Items = items.Items or {} }
|
||||
return cachedItemList
|
||||
end
|
||||
|
||||
---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 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
|
||||
|
||||
---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()
|
||||
end
|
||||
|
||||
---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
|
||||
|
||||
---This will return the players birth date
|
||||
---@return string
|
||||
Framework.GetPlayerDob = function()
|
||||
local playerData = Framework.GetPlayerData()
|
||||
local dob = playerData.dateofbirth
|
||||
return dob
|
||||
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)
|
||||
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)
|
||||
return ESX.ShowNotification(message, type, time)
|
||||
end
|
||||
|
||||
---Will Display the help text message on the screen
|
||||
---@param message string
|
||||
---@param _ unknown
|
||||
---@return nil
|
||||
Framework.ShowHelpText = function(message, _)
|
||||
return exports['esx_textui']:TextUI(message, "info")
|
||||
end
|
||||
|
||||
---This will hide the help text message on the screen
|
||||
---@return nil
|
||||
Framework.HideHelpText = function()
|
||||
return exports['esx_textui']:HideUI()
|
||||
end
|
||||
|
||||
---This will get the players identifier (citizenid) etc.
|
||||
---@return string
|
||||
Framework.GetPlayerIdentifier = function()
|
||||
local playerData = Framework.GetPlayerData()
|
||||
return playerData.identifier
|
||||
end
|
||||
|
||||
---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
|
||||
|
||||
---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
|
||||
end
|
||||
|
||||
---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()
|
||||
local jobData = playerData.job
|
||||
local isBoss = (jobData.grade_name == "boss")
|
||||
return {
|
||||
jobName = jobData.name,
|
||||
jobLabel = jobData.label,
|
||||
gradeName = jobData.grade_name,
|
||||
gradeLabel = jobData.grade_label,
|
||||
gradeRank = jobData.grade,
|
||||
boss = isBoss,
|
||||
onDuty = jobData.onduty,
|
||||
}
|
||||
end
|
||||
|
||||
---This will return if the player has the specified item in their inventory.
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Framework.HasItem = function(item)
|
||||
local hasItem = ESX.SearchInventory(item, true)
|
||||
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()
|
||||
local playerData = Framework.GetPlayerData()
|
||||
return playerData.inventory
|
||||
end
|
||||
|
||||
---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
|
||||
local accounts = player.accounts
|
||||
if _type == 'cash' then _type = 'money' end
|
||||
for _, account in ipairs(accounts) do
|
||||
if account.name == _type then
|
||||
return account.money or 0
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
---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
|
||||
|
||||
---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
|
||||
|
||||
---This will get a players dead status.
|
||||
---@return boolean
|
||||
Framework.GetIsPlayerDead = function()
|
||||
local playerData = Framework.GetPlayerData()
|
||||
return playerData.dead
|
||||
end
|
||||
|
||||
RegisterNetEvent('esx:playerLoaded', function(xPlayer)
|
||||
Wait(1500)
|
||||
TriggerEvent('community_bridge:Client:OnPlayerLoaded')
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx:onPlayerLogout', function()
|
||||
TriggerEvent('community_bridge:Client:OnPlayerUnload')
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx:setJob', function(data)
|
||||
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', data.name, data.label, data.grade_label, data.grade)
|
||||
end)
|
||||
|
||||
return Framework
|
|
@ -0,0 +1,501 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('es_extended') ~= 'started' then return end
|
||||
|
||||
Prints = Prints or Require("lib/utility/shared/prints.lua")
|
||||
Callback = Callback or Require("lib/utility/shared/callbacks.lua")
|
||||
|
||||
ESX = exports["es_extended"]:getSharedObject()
|
||||
|
||||
Framework = Framework or {}
|
||||
|
||||
local cachedItemList = nil
|
||||
|
||||
---This will return the name of the framework in use.
|
||||
---@return string
|
||||
Framework.GetFrameworkName = function()
|
||||
return 'es_extended'
|
||||
end
|
||||
|
||||
-- This is an internal function, its here to attempt to emulate qbs shared items mainly.
|
||||
Framework.ItemList = function()
|
||||
if cachedItemList then return cachedItemList end
|
||||
local items = ESX.Items
|
||||
local repackedTable = {}
|
||||
for k, v in pairs(items) do
|
||||
if v.label then
|
||||
repackedTable[k] = {
|
||||
name = k,
|
||||
label = v.label,
|
||||
weight = v.weight,
|
||||
type = "item",
|
||||
image = k .. ".png",
|
||||
unique = false,
|
||||
useable = true,
|
||||
shouldClose = true,
|
||||
description = 'No description provided.',
|
||||
}
|
||||
end
|
||||
end
|
||||
cachedItemList = { Items = repackedTable or {} }
|
||||
return cachedItemList
|
||||
end
|
||||
|
||||
---This will return if the player is an admin in the framework.
|
||||
---@param src any
|
||||
---@return boolean
|
||||
Framework.GetIsFrameworkAdmin = function(src)
|
||||
if not src then return false end
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return false end
|
||||
local group = xPlayer.getGroup()
|
||||
if group == 'admin' or group == 'superadmin' then return true end
|
||||
return false
|
||||
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
|
||||
local dob = xPlayer.get("dateofbirth")
|
||||
return dob
|
||||
end
|
||||
|
||||
--- Returns the player data of the specified source in the framework defualt format.
|
||||
---@param src any
|
||||
---@return table | nil
|
||||
Framework.GetPlayer = function(src)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not xPlayer then return end
|
||||
return xPlayer
|
||||
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
|
||||
return xPlayer.variables.firstName, xPlayer.variables.lastName
|
||||
end
|
||||
|
||||
---This will return a table of all logged in players
|
||||
---@return table
|
||||
Framework.GetPlayers = function()
|
||||
local players = ESX.GetExtendedPlayers()
|
||||
local playerList = {}
|
||||
for _, xPlayer in pairs(players) do
|
||||
table.insert(playerList, xPlayer.source)
|
||||
end
|
||||
return playerList
|
||||
end
|
||||
|
||||
---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
|
||||
local playerItems = xPlayer.getInventory()
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
if v.name == item then
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
--metadata = v.metadata,
|
||||
--slot = v.slot,
|
||||
})
|
||||
end
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
---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
|
||||
|
||||
---This will return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Framework.HasItem = function(src, item)
|
||||
local getCount = Framework.GetItemCount(src, item, nil)
|
||||
return getCount > 0
|
||||
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 xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
local playerItems = xPlayer.getInventory()
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
if v.count > 0 then
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
--metadata = v.metadata,
|
||||
--slot = v.slot,
|
||||
})
|
||||
end
|
||||
end
|
||||
return repackedTable
|
||||
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
|
||||
xPlayer.setMeta(metadata, value, nil)
|
||||
return true
|
||||
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 xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
return xPlayer.getMeta(metadata) or false
|
||||
end
|
||||
|
||||
-- defualt esx Available tables are
|
||||
-- identifier, accounts, group, inventory, job, job_grade, loadout,
|
||||
-- metadata, position, firstname, lastname, dateofbirth, sex, height,
|
||||
-- skin, status, is_dead, id, disabled, last_property, created_at, last_seen,
|
||||
-- phone_number, pincode
|
||||
Framework.GetStatus = function(src, column)
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
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
|
||||
TriggerEvent('esx_ambulancejob:revive', src)
|
||||
return true
|
||||
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
|
||||
TriggerClientEvent('esx_status:add', src, 'thirst', levelForEsx)
|
||||
return levelForEsx
|
||||
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
|
||||
TriggerClientEvent('esx_status:add', src, 'hunger', levelForEsx)
|
||||
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
|
||||
return status.thirst
|
||||
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
|
||||
return xPlayer.get("phone_number")
|
||||
end
|
||||
|
||||
|
||||
---Depricated: Returns the job name, label, grade name, and grade level of the player.
|
||||
---@param src number
|
||||
---@return string | nil
|
||||
---@return string | nil
|
||||
---@return string | nil
|
||||
---@return string | nil
|
||||
Framework.GetPlayerJob = function(src)
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
local job = xPlayer.getJob()
|
||||
return job.name, job.label, job.grade_label, job.grade
|
||||
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 xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
local job = xPlayer.getJob()
|
||||
local isBoss = (job.grade_name == "boss")
|
||||
return {
|
||||
jobName = job.name,
|
||||
jobLabel = job.label,
|
||||
gradeName = job.grade_name,
|
||||
gradeLabel = job.grade_label,
|
||||
gradeRank = job.grade,
|
||||
boss = isBoss,
|
||||
onDuty = job.onduty,
|
||||
}
|
||||
end
|
||||
|
||||
---Returns the players duty status.
|
||||
---@param src number
|
||||
---@return boolean
|
||||
Framework.GetPlayerDuty = function(src)
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return false end
|
||||
local job = xPlayer.getJob()
|
||||
if not job.onDuty then return false end
|
||||
return true
|
||||
end
|
||||
|
||||
---This will toggle a players duty status
|
||||
---@param src number
|
||||
---@param status boolean
|
||||
---@return boolean
|
||||
Framework.SetPlayerDuty = function(src, status)
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return false end
|
||||
local job = xPlayer.getJob()
|
||||
if not job.onDuty then return false end
|
||||
xPlayer.setJob(job.name, job.grade, status)
|
||||
return true
|
||||
end
|
||||
|
||||
---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 and xPlayer.getJob().name == job then
|
||||
table.insert(playerList, src)
|
||||
end
|
||||
end
|
||||
return playerList
|
||||
end
|
||||
|
||||
-- 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)
|
||||
return
|
||||
end
|
||||
xPlayer.setJob(name, grade, true)
|
||||
return true
|
||||
end
|
||||
|
||||
---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
|
||||
if _type == 'cash' then _type = 'money' end
|
||||
xPlayer.addAccountMoney(_type, amount)
|
||||
return true
|
||||
end
|
||||
|
||||
---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
|
||||
if _type == 'cash' then _type = 'money' end
|
||||
xPlayer.removeAccountMoney(_type, amount)
|
||||
return true
|
||||
end
|
||||
|
||||
---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
|
||||
if _type == 'cash' then _type = 'money' end
|
||||
return xPlayer.getAccount(_type).money
|
||||
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 xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
xPlayer.addInventoryItem(item, amount)
|
||||
return true
|
||||
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 xPlayer = Framework.GetPlayer(src)
|
||||
if not xPlayer then return end
|
||||
xPlayer.removeInventoryItem(item, amount)
|
||||
return true
|
||||
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 .. "'")
|
||||
local vehicles = {}
|
||||
for i = 1, #result do
|
||||
local vehicle = result[i].vehicle
|
||||
local plate = result[i].plate
|
||||
local model = json.decode(vehicle).model
|
||||
table.insert(vehicles, { vehicle = model, plate = plate })
|
||||
end
|
||||
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
|
||||
itemData.metadata = itemData.metadata or itemData.info or {}
|
||||
itemData.slot = itemData.id or itemData.slot
|
||||
cb(src, itemData)
|
||||
end
|
||||
ESX.RegisterUsableItem(itemName, func)
|
||||
end
|
||||
|
||||
RegisterNetEvent("esx:playerLoaded", function(src)
|
||||
src = src or source
|
||||
TriggerEvent("community_bridge:Server:OnPlayerLoaded", src)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:playerLogout", function(src)
|
||||
src = src or source
|
||||
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
|
||||
end)
|
||||
|
||||
AddEventHandler("playerDropped", function()
|
||||
local src = source
|
||||
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
|
||||
end)
|
||||
|
||||
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.
|
||||
Callback.Register('community_bridge:Callback:GetFrameworkItems', function(source)
|
||||
return Framework.ItemList() or {}
|
||||
end)
|
||||
|
||||
Framework.Commands = {}
|
||||
Framework.Commands.Add = function(name, help, arguments, argsrequired, callback, permission, ...)
|
||||
ESX.RegisterCommand(name, permission, function(xPlayer, args, showError)
|
||||
callback(xPlayer, args)
|
||||
end, false, {
|
||||
help = help,
|
||||
arguments = arguments
|
||||
})
|
||||
end
|
||||
|
||||
return Framework
|
|
@ -0,0 +1,255 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('qb-core') ~= 'started' then return end
|
||||
if GetResourceState('qbx_core') == 'started' then return end
|
||||
|
||||
Framework = Framework or {}
|
||||
|
||||
QBCore = exports['qb-core']:GetCoreObject()
|
||||
|
||||
Framework.Shared = QBCore.Shared
|
||||
|
||||
---This will get the name of the framework being used (if a supported framework).
|
||||
---@return string
|
||||
Framework.GetFrameworkName = function()
|
||||
return 'qb-core'
|
||||
end
|
||||
|
||||
---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 LocalPlayer.state.isLoggedIn or false
|
||||
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
|
||||
|
||||
---This will return a table of all the jobs in the framework.
|
||||
---@return table
|
||||
Framework.GetFrameworkJobs = function()
|
||||
local jobs = {}
|
||||
for k, v in pairs(QBCore.Shared.Jobs) do
|
||||
table.insert(jobs, {
|
||||
name = k,
|
||||
label = v.label,
|
||||
grade = v.grades
|
||||
})
|
||||
end
|
||||
return jobs
|
||||
end
|
||||
|
||||
---This will get the players birth date
|
||||
---@return string
|
||||
Framework.GetPlayerDob = function()
|
||||
local player = Framework.GetPlayerData()
|
||||
local playerData = player.PlayerData
|
||||
return playerData.charinfo.birthdate
|
||||
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)
|
||||
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
|
||||
|
||||
---Will Display the help text message on the screen
|
||||
---@param message string
|
||||
---@param _position unknown
|
||||
---@return nil
|
||||
Framework.ShowHelpText = function(message, _position)
|
||||
return exports['qb-core']:DrawText(message, _position)
|
||||
end
|
||||
|
||||
---This will hide the help text message on the screen
|
||||
---@return nil
|
||||
Framework.HideHelpText = function()
|
||||
return exports['qb-core']:HideText()
|
||||
end
|
||||
|
||||
---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
|
||||
local account = player.money
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
return account[_type] or 0
|
||||
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
|
||||
local repackedTable = {
|
||||
name = itemData.name,
|
||||
label = itemData.label,
|
||||
stack = itemData.unique,
|
||||
weight = itemData.weight,
|
||||
description = itemData.description,
|
||||
image = itemData.image
|
||||
}
|
||||
return repackedTable
|
||||
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
|
||||
end
|
||||
|
||||
---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
|
||||
end
|
||||
|
||||
---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()
|
||||
local jobData = playerData.job
|
||||
return {
|
||||
jobName = jobData.name,
|
||||
jobLabel = jobData.label,
|
||||
gradeName = jobData.grade.name,
|
||||
gradeLabel = jobData.grade.name,
|
||||
gradeRank = jobData.grade.level,
|
||||
boss = jobData.isboss,
|
||||
onDuty = jobData.onduty,
|
||||
}
|
||||
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
|
||||
|
||||
---This will return the item count for the specified item in the players inventory.
|
||||
---@param item string
|
||||
---@return number
|
||||
Framework.GetItemCount = function(item)
|
||||
local frameworkInv = Framework.GetPlayerData().items
|
||||
local count = 0
|
||||
for _, v in pairs(frameworkInv) do
|
||||
if v.name == item then
|
||||
count = count + v.amount
|
||||
end
|
||||
end
|
||||
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
|
||||
for _, v in pairs(frameworkInv) do
|
||||
table.insert(items, {
|
||||
name = v.name,
|
||||
label = v.label,
|
||||
count = v.amount,
|
||||
slot = v.slot,
|
||||
metadata = v.info,
|
||||
stack = v.unique,
|
||||
close = v.useable,
|
||||
weight = v.weight
|
||||
})
|
||||
end
|
||||
return items
|
||||
end
|
||||
|
||||
---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 = QBCore.Functions.GetVehicleProperties(vehicle)
|
||||
return vehicleProps or {}
|
||||
end
|
||||
|
||||
---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, QBCore.Functions.SetVehicleProperties(vehicle, properties)
|
||||
end
|
||||
|
||||
---This will get a players dead status.
|
||||
---@return boolean
|
||||
Framework.GetIsPlayerDead = function()
|
||||
local playerData = Framework.GetPlayerData()
|
||||
return playerData.metadata["isdead"] or playerData.metadata["inlaststand"]
|
||||
end
|
||||
|
||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
||||
Wait(1500)
|
||||
TriggerEvent('community_bridge:Client:OnPlayerLoaded')
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
|
||||
TriggerEvent('community_bridge:Client:OnPlayerUnload')
|
||||
end)
|
||||
|
||||
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
|
|
@ -0,0 +1,585 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('qb-core') ~= 'started' then return end
|
||||
if GetResourceState('qbx_core') == 'started' then return end
|
||||
|
||||
Framework = Framework or {}
|
||||
|
||||
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
|
||||
|
||||
---This will return if the player is an admin in the framework.
|
||||
---@param src any
|
||||
---@return boolean
|
||||
Framework.GetIsFrameworkAdmin = function(src)
|
||||
if not src then return false end
|
||||
return QBCore.Functions.HasPermission(src, 'admin')
|
||||
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
|
||||
local playerData = player.PlayerData
|
||||
return playerData.citizenid
|
||||
end
|
||||
|
||||
--- Returns the player data of the specified source in the framework defualt format.
|
||||
---@param src any
|
||||
---@return table | nil
|
||||
Framework.GetPlayer = function(src)
|
||||
local player = QBCore.Functions.GetPlayer(src)
|
||||
if not player then return end
|
||||
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
|
||||
table.insert(jobs, {
|
||||
name = k,
|
||||
label = v.label,
|
||||
grade = v.grades
|
||||
})
|
||||
end
|
||||
return jobs
|
||||
end
|
||||
|
||||
-- Framework.GetPlayerName(src)
|
||||
-- Returns the first and last name of the player.
|
||||
---@return string|nil, string|nil
|
||||
Framework.GetPlayerName = function(src)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
return playerData.charinfo.firstname, playerData.charinfo.lastname
|
||||
end
|
||||
|
||||
---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
|
||||
local playerData = player.PlayerData
|
||||
return playerData.charinfo.birthdate
|
||||
end
|
||||
|
||||
---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
|
||||
local playerData = player.PlayerData
|
||||
local playerInventory = playerData.items
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerInventory) do
|
||||
if v.name == item and (not metadata or v.info == metadata) then
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.amount,
|
||||
metadata = v.info,
|
||||
slot = v.slot,
|
||||
})
|
||||
end
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
---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
|
||||
local repackedTable = {
|
||||
name = itemData.name,
|
||||
label = itemData.label,
|
||||
stack = itemData.unique,
|
||||
weight = itemData.weight,
|
||||
description = itemData.description,
|
||||
image = itemData.image
|
||||
}
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
---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.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@param metadata table
|
||||
---@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
|
||||
end
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
---This will return a boolean if the player has the item.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Framework.HasItem = function(src, item)
|
||||
local getCount = Framework.GetItemCount(src, item, nil)
|
||||
return getCount > 0
|
||||
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
|
||||
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,
|
||||
metadata = v.info,
|
||||
slot = v.slot,
|
||||
})
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
---This will return a table of all logged in players
|
||||
---@return table
|
||||
Framework.GetPlayers = function()
|
||||
local players = QBCore.Functions.GetPlayers()
|
||||
local playerList = {}
|
||||
for _, src in pairs(players) do
|
||||
table.insert(playerList, src)
|
||||
end
|
||||
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
|
||||
local playerData = player.PlayerData
|
||||
local playerInventory = playerData.items
|
||||
local repack = {}
|
||||
for _, v in pairs(playerInventory) do
|
||||
if v.slot == slot then
|
||||
return {
|
||||
name = v.name,
|
||||
label = v.label,
|
||||
weight = v.weight,
|
||||
count = v.amount,
|
||||
metadata = v.info,
|
||||
slot = v.slot,
|
||||
stack = v.unique or false,
|
||||
description = v.description or "none",
|
||||
}
|
||||
end
|
||||
end
|
||||
return repack
|
||||
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 player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
player.Functions.SetMetaData(metadata, value)
|
||||
return true
|
||||
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
|
||||
local playerData = player.PlayerData
|
||||
return playerData.metadata[metadata] or false
|
||||
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)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local newStress = playerData.metadata.stress + value
|
||||
player.Functions.SetMetaData('stress', Math.Clamp(newStress, 0, 100))
|
||||
TriggerClientEvent('hud:client:UpdateStress', src, newStress)
|
||||
return newStress
|
||||
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)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local newStress = (playerData.metadata.stress or 0) - value
|
||||
player.Functions.SetMetaData('stress', Math.Clamp(newStress, 0, 100))
|
||||
TriggerClientEvent('hud:client:UpdateStress', src, newStress)
|
||||
return newStress
|
||||
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)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
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
|
||||
|
||||
-- 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)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
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
|
||||
|
||||
---This will get the hunger of a player
|
||||
---@param src number
|
||||
---@return number | nil
|
||||
Framework.GetHunger = function(src)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local newHunger = (playerData.metadata.hunger or 0)
|
||||
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
|
||||
local playerData = player.PlayerData
|
||||
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
|
||||
TriggerClientEvent('hospital:client:Revive', src)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
---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
|
||||
local playerData = player.PlayerData
|
||||
local newThirst = (playerData.metadata.thirst or 0)
|
||||
return newThirst
|
||||
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
|
||||
local playerData = player.PlayerData
|
||||
return playerData.charinfo.phone
|
||||
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
|
||||
local playerData = player.PlayerData
|
||||
return playerData.gang.name
|
||||
end
|
||||
|
||||
---This will get a table of player sources that have the specified job name.
|
||||
---@param job any
|
||||
---@return table
|
||||
Framework.GetPlayersByJob = function(job)
|
||||
local playerList = {}
|
||||
local players = QBCore.Functions.GetPlayers()
|
||||
for _, src in pairs(players) do
|
||||
local player = Framework.GetPlayer(src).PlayerData
|
||||
if player.job.name == job then
|
||||
table.insert(playerList, src)
|
||||
end
|
||||
end
|
||||
return playerList
|
||||
end
|
||||
|
||||
---Depricated: Returns the job name, label, grade name, and grade level of the player.
|
||||
---@param src number
|
||||
---@return string | string | string | number | nil
|
||||
---@return string | string | string | number | nil
|
||||
---@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
|
||||
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)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local jobData = playerData.job
|
||||
return {
|
||||
jobName = jobData.name,
|
||||
jobLabel = jobData.label,
|
||||
gradeName = jobData.grade.name,
|
||||
gradeLabel = jobData.grade.name,
|
||||
gradeRank = jobData.grade.level,
|
||||
boss = jobData.isboss,
|
||||
onDuty = jobData.onduty,
|
||||
}
|
||||
end
|
||||
|
||||
---Returns the players duty status.
|
||||
---@param src number
|
||||
---@return boolean | nil
|
||||
Framework.GetPlayerDuty = function(src)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
if not playerData.job.onduty then return false end
|
||||
return true
|
||||
end
|
||||
|
||||
---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
|
||||
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.
|
||||
---@param src number
|
||||
---@param name string
|
||||
---@param grade string
|
||||
---@return nil
|
||||
Framework.SetPlayerJob = function(src, name, grade)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
return player.Functions.SetJob(name, grade)
|
||||
end
|
||||
|
||||
---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 player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
return player.Functions.AddMoney(_type, amount)
|
||||
end
|
||||
|
||||
---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 player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
return player.Functions.RemoveMoney(_type, amount)
|
||||
end
|
||||
|
||||
---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 player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
return playerData.money[_type]
|
||||
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 })
|
||||
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 })
|
||||
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
|
||||
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
|
||||
end
|
||||
end
|
||||
if not player.Functions.RemoveItem(item, 1, itemSlot) then return false end
|
||||
return player.Functions.AddItem(item, 1, slot, metadata)
|
||||
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 player_vehicles WHERE citizenid = '" .. citizenId .. "'")
|
||||
local vehicles = {}
|
||||
for i = 1, #result do
|
||||
local vehicle = result[i].vehicle
|
||||
local plate = result[i].plate
|
||||
table.insert(vehicles, { vehicle = vehicle, plate = plate })
|
||||
end
|
||||
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
|
||||
itemData.metadata = itemData.metadata or itemData.info or {}
|
||||
itemData.slot = itemData.id or itemData.slot
|
||||
cb(src, itemData)
|
||||
end
|
||||
QBCore.Functions.CreateUseableItem(itemName, func)
|
||||
end
|
||||
|
||||
RegisterNetEvent("QBCore:Server:OnPlayerLoaded", function(src)
|
||||
src = src or source
|
||||
TriggerEvent("community_bridge:Server:OnPlayerLoaded", src)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("QBCore:Server:OnPlayerUnload", function(src)
|
||||
src = src or source
|
||||
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
|
||||
end)
|
||||
|
||||
AddEventHandler("playerDropped", function()
|
||||
local src = source
|
||||
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
|
||||
end)
|
||||
|
||||
Framework.Commands = {}
|
||||
Framework.Commands.Add = function(name, help, arguments, argsrequired, callback, permission, ...)
|
||||
QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission, ...)
|
||||
end
|
||||
|
||||
return Framework
|
|
@ -0,0 +1,189 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('qbx_core') ~= 'started' then return end
|
||||
|
||||
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 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 LocalPlayer.state.isLoggedIn or false
|
||||
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
|
||||
end
|
||||
|
||||
---Will Display the help text message on the screen
|
||||
---@param message string
|
||||
---@param position string
|
||||
---@return nil
|
||||
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
|
||||
---@return nil
|
||||
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
|
||||
end
|
||||
|
||||
---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
|
||||
end
|
||||
|
||||
---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()
|
||||
local jobData = playerData.job
|
||||
return {
|
||||
jobName = jobData.name,
|
||||
jobLabel = jobData.label,
|
||||
gradeName = jobData.grade.name,
|
||||
gradeLabel = jobData.grade.name,
|
||||
gradeRank = jobData.grade.level,
|
||||
boss = jobData.isboss,
|
||||
onDuty = jobData.onduty,
|
||||
}
|
||||
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
|
||||
|
||||
---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
|
||||
local account = player.money
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
return account[_type] or 0
|
||||
end
|
||||
|
||||
---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
|
||||
|
||||
---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
|
||||
|
||||
---This will return the item count for the specified item in the players inventory.
|
||||
---@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.")
|
||||
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"]
|
||||
end
|
||||
|
||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
||||
Wait(1500)
|
||||
TriggerEvent('community_bridge:Client:OnPlayerLoaded')
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
|
||||
TriggerEvent('community_bridge:Client:OnPlayerUnload')
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(data)
|
||||
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', data.name, data.label, data.grade.name, data.grade.level)
|
||||
end)
|
||||
|
||||
return Framework
|
|
@ -0,0 +1,489 @@
|
|||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('qbx_core') ~= 'started' then return end
|
||||
|
||||
Framework = Framework or {}
|
||||
|
||||
local QBox = exports.qbx_core
|
||||
|
||||
---Returns the name of the framework being used (if a supported framework).
|
||||
---@return string
|
||||
Framework.GetFrameworkName = function()
|
||||
return 'qbx_core'
|
||||
end
|
||||
|
||||
---This will return if the player is an admin in the framework.
|
||||
---@param src any
|
||||
---@return boolean
|
||||
Framework.GetIsFrameworkAdmin = function(src)
|
||||
if not src then return false end
|
||||
return IsPlayerAceAllowed(src, 'admin')
|
||||
end
|
||||
|
||||
---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
|
||||
local playerData = player.PlayerData
|
||||
return playerData.charinfo.birthdate
|
||||
end
|
||||
|
||||
--- Returns the player data of the specified source.
|
||||
---@param src any
|
||||
---@return table | nil
|
||||
Framework.GetPlayer = function(src)
|
||||
local player = QBox:GetPlayer(src)
|
||||
if not player then return end
|
||||
return player
|
||||
end
|
||||
|
||||
---Returns a table of the jobs in the framework.
|
||||
---@return table
|
||||
Framework.GetFrameworkJobs = function()
|
||||
return QBox.GetJobs()
|
||||
end
|
||||
|
||||
---Returns the citizen ID of the player.
|
||||
---@param src number
|
||||
---@return string | boolean | nil
|
||||
Framework.GetPlayerIdentifier = function(src)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
if not playerData then return false end
|
||||
return playerData.citizenid
|
||||
end
|
||||
|
||||
---This will return a table of all logged in players
|
||||
---@return table
|
||||
Framework.GetPlayers = function()
|
||||
local players = QBox:GetQBPlayers()
|
||||
local playerList = {}
|
||||
for src, _ in pairs(players) do
|
||||
table.insert(playerList, src)
|
||||
end
|
||||
return playerList
|
||||
end
|
||||
|
||||
---Returns the first and last name of the player.
|
||||
---@param src number
|
||||
---@return string | nil
|
||||
---@return string | nil
|
||||
Framework.GetPlayerName = function(src)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
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 {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
|
||||
local playerInventory = player.PlayerData.items
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerInventory) do
|
||||
if v.name == item and (not metadata or v.info == metadata) then
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.amount,
|
||||
metadata = v.info,
|
||||
slot = v.slot,
|
||||
})
|
||||
end
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
---Returns the count of items matching the specified name and if passed metadata from the player's inventory.
|
||||
---@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
|
||||
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
|
||||
end
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
---Returns boolean if the player has the specified item in their inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Framework.HasItem = function(src, item)
|
||||
local getCount = Framework.GetItemCount(src, item, nil)
|
||||
return getCount > 0
|
||||
end
|
||||
|
||||
---Returns the entire inventory of the player as a table.
|
||||
---@param src number
|
||||
---@return table | nil
|
||||
Framework.GetPlayerInventory = function(src)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerItems = player.PlayerData.items
|
||||
local repackedTable = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
table.insert(repackedTable, {
|
||||
name = v.name,
|
||||
count = v.amount,
|
||||
metadata = v.metadata,
|
||||
slot = v.slot,
|
||||
})
|
||||
end
|
||||
return repackedTable
|
||||
end
|
||||
|
||||
---Adds the specified metadata key and number value to the player's data.
|
||||
---@param src number
|
||||
---@param metadata string
|
||||
---@param value string
|
||||
---@return boolean | nil
|
||||
Framework.SetPlayerMetadata = function(src, metadata, value)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
player.Functions.SetMetaData(metadata, value)
|
||||
return true
|
||||
end
|
||||
|
||||
---Gets the specified metadata key to the player's data.
|
||||
---@param src number
|
||||
---@param metadata string
|
||||
---@return string | boolean | nil
|
||||
Framework.GetPlayerMetadata = function(src, metadata)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
return playerData.metadata[metadata] or false
|
||||
end
|
||||
|
||||
---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)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local newStress = playerData.metadata.stress + value
|
||||
player.Functions.SetMetaData('stress', Math.Clamp(newStress, 0, 100))
|
||||
TriggerClientEvent('hud:client:UpdateStress', src, newStress)
|
||||
return newStress
|
||||
end
|
||||
|
||||
---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)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local newStress = (playerData.metadata.stress or 0) - value
|
||||
player.Functions.SetMetaData('stress', Math.Clamp(newStress, 0, 100))
|
||||
TriggerClientEvent('hud:client:UpdateStress', src, newStress)
|
||||
return newStress
|
||||
end
|
||||
|
||||
---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)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local newHunger = (playerData.metadata.hunger or 0) + value
|
||||
player.Functions.SetMetaData('hunger', Math.Clamp(newHunger, 0, 100))
|
||||
--TriggerClientEvent('hud:client:UpdateStress', src, newStress)
|
||||
return newHunger
|
||||
end
|
||||
|
||||
---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)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local newThirst = (playerData.metadata.thirst or 0) + value
|
||||
player.Functions.SetMetaData('thirst', Math.Clamp(newThirst, 0, 100))
|
||||
--TriggerClientEvent('hud:client:UpdateStress', src, newStress)
|
||||
return newThirst
|
||||
end
|
||||
|
||||
---This will return the players hunger level.
|
||||
---@param src number
|
||||
---@return number | nil
|
||||
Framework.GetHunger = function(src)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local newHunger = (playerData.metadata.hunger or 0)
|
||||
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
|
||||
local playerData = player.PlayerData
|
||||
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
|
||||
TriggerClientEvent('hospital:client:Revive', src)
|
||||
return true
|
||||
end
|
||||
|
||||
---This will return the players thirst level.
|
||||
---@param src number
|
||||
---@return number| nil
|
||||
Framework.GetThirst = function(src)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local newThirst = (playerData.metadata.thirst or 0)
|
||||
return newThirst
|
||||
end
|
||||
|
||||
---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
|
||||
local playerData = player.PlayerData
|
||||
return playerData.charinfo.phone
|
||||
end
|
||||
|
||||
---Returns the gang name of the player.
|
||||
---@param src number
|
||||
---@return string | nil
|
||||
Framework.GetPlayerGang = function(src)
|
||||
local player = Framework.GetPlayer(src).PlayerData
|
||||
return player.gang.name
|
||||
end
|
||||
|
||||
---This will return a table of all players with the specified job.
|
||||
---@param job string
|
||||
---@return table
|
||||
Framework.GetPlayersByJob = function(job)
|
||||
local playerList = {}
|
||||
local players = QBox:GetQBPlayers()
|
||||
for src, player in pairs(players) do
|
||||
if player.PlayerData.job.name == job then
|
||||
table.insert(playerList, src)
|
||||
end
|
||||
end
|
||||
return playerList
|
||||
end
|
||||
|
||||
---Depricated: Returns the job name, label, grade name, and grade level of the player.
|
||||
---@param src number
|
||||
---@return string | string | string | number | nil
|
||||
---@return string | string | string | number | nil
|
||||
---@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
|
||||
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)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local jobData = playerData.job
|
||||
return {
|
||||
jobName = jobData.name,
|
||||
jobLabel = jobData.label,
|
||||
gradeName = jobData.grade.name,
|
||||
gradeLabel = jobData.grade.name,
|
||||
gradeRank = jobData.grade.level,
|
||||
boss = jobData.isboss,
|
||||
onDuty = jobData.onduty,
|
||||
}
|
||||
end
|
||||
|
||||
---Sets the player's job to the specified name and grade.
|
||||
---@param src number
|
||||
---@param name string
|
||||
---@param grade string
|
||||
---@return boolean | nil
|
||||
Framework.SetPlayerJob = function(src, name, grade)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
return player.Functions.SetJob(name, grade)
|
||||
end
|
||||
|
||||
---This will toggle the duty status of the player.
|
||||
---@param src number
|
||||
---@param status boolean
|
||||
Framework.SetPlayerDuty = function(src, status)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
QBox:SetJobDuty(playerData.citizenid, status)
|
||||
TriggerEvent('QBCore:Server:SetDuty', src, player.PlayerData.job.onduty)
|
||||
end
|
||||
|
||||
---Returns the players duty status.
|
||||
---@param src number
|
||||
---@return boolean | nil
|
||||
Framework.GetPlayerDuty = function(src)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
if not playerData.job.onduty then return false end
|
||||
return true
|
||||
end
|
||||
|
||||
---Adds the specified amount to the player's account balance of the specified type.
|
||||
---@param src number
|
||||
---@param _type string
|
||||
---@param amount number
|
||||
---@return boolean | nil
|
||||
Framework.AddAccountBalance = function(src, _type, amount)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
return player.Functions.AddMoney(_type, amount)
|
||||
end
|
||||
|
||||
---Removes the specified amount from the player's account balance of the specified type.
|
||||
---@param src number
|
||||
---@param _type string
|
||||
---@param amount number
|
||||
---@return boolean | nil
|
||||
Framework.RemoveAccountBalance = function(src, _type, amount)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
return player.Functions.RemoveMoney(_type, amount)
|
||||
end
|
||||
|
||||
---Returns the player's account balance of the specified type.
|
||||
---@param src number
|
||||
---@param _type string
|
||||
---@return number | nil
|
||||
Framework.GetAccountBalance = function(src, _type)
|
||||
local player = Framework.GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
return playerData.money[_type]
|
||||
end
|
||||
|
||||
---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
|
||||
|
||||
---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
|
||||
|
||||
---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)
|
||||
end
|
||||
|
||||
---Returns a table of owned vehicles for the player. format is {vehicle = vehicle, plate = plate}
|
||||
---@param src number
|
||||
---@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 vehicles = {}
|
||||
for i = 1, #result do
|
||||
local vehicle = result[i].vehicle
|
||||
local plate = result[i].plate
|
||||
table.insert(vehicles, { vehicle = vehicle, plate = plate })
|
||||
end
|
||||
return vehicles
|
||||
end
|
||||
|
||||
---Registers a usable item with a callback function.
|
||||
---@param itemName string
|
||||
---@param cb function
|
||||
---@return function
|
||||
Framework.RegisterUsableItem = function(itemName, cb)
|
||||
local func = function(src, item, itemData)
|
||||
itemData = itemData or item
|
||||
itemData.metadata = itemData.metadata or itemData.info or {}
|
||||
itemData.slot = itemData.id or itemData.slot
|
||||
cb(src, itemData)
|
||||
end
|
||||
return QBox:CreateUseableItem(itemName, func)
|
||||
end
|
||||
|
||||
RegisterNetEvent("QBCore:Server:OnPlayerLoaded", function(src)
|
||||
src = src or source
|
||||
TriggerEvent("community_bridge:Server:OnPlayerLoaded", src)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("QBCore:Server:OnPlayerUnload", function(src)
|
||||
src = src or source
|
||||
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
|
||||
end)
|
||||
|
||||
AddEventHandler("playerDropped", function()
|
||||
local src = source
|
||||
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
|
||||
end)
|
||||
|
||||
return Framework
|
Loading…
Add table
Add a link
Reference in a new issue