2025-04-15 03:00:44 -04:00
|
|
|
---@diagnostic disable: duplicate-set-field
|
2025-01-08 06:33:31 -05:00
|
|
|
if GetResourceState('qb-core') ~= 'started' then return end
|
|
|
|
|
if GetResourceState('qbx_core') == 'started' then return end
|
|
|
|
|
|
2025-05-18 23:45:37 -04:00
|
|
|
Framework = Framework or {}
|
|
|
|
|
|
2025-01-08 06:33:31 -05:00
|
|
|
QBCore = exports['qb-core']:GetCoreObject()
|
|
|
|
|
|
2025-05-18 23:45:37 -04:00
|
|
|
Framework.Shared = QBCore.Shared
|
2025-01-08 06:33:31 -05:00
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will get the name of the framework being used (if a supported framework).
|
2025-04-08 19:10:02 -04:00
|
|
|
---@return string
|
2025-01-31 19:23:47 -05:00
|
|
|
Framework.GetFrameworkName = function()
|
2025-12-14 16:22:35 -05:00
|
|
|
print("This is depricated, please use Framework.GetResourceName() instead.")
|
|
|
|
|
return Framework.GetResourceName()
|
2025-01-31 19:23:47 -05:00
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will get the name of the in use resource.
|
2025-09-10 12:27:12 -04:00
|
|
|
---@return string
|
|
|
|
|
Framework.GetResourceName = function()
|
|
|
|
|
return 'qb-core'
|
|
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will return true if the player is loaded, false otherwise.
|
2025-07-10 13:50:47 -04:00
|
|
|
---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
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will return a table of the player data, this will be in the framework format.
|
2025-05-30 03:21:32 -04:00
|
|
|
---This is mainly for internal bridge use and should be avoided.
|
|
|
|
|
---@return table
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetPlayerData = function()
|
|
|
|
|
return QBCore.Functions.GetPlayerData()
|
|
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will return a table of all the jobs in the framework.
|
2025-04-08 19:10:02 -04:00
|
|
|
---@return table
|
2025-03-10 01:17:18 -04:00
|
|
|
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
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will get the players birth date
|
2025-04-08 19:10:02 -04:00
|
|
|
---@return string
|
2025-02-26 01:34:47 -05:00
|
|
|
Framework.GetPlayerDob = function()
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayerData()
|
2025-02-26 01:34:47 -05:00
|
|
|
local playerData = player.PlayerData
|
|
|
|
|
return playerData.charinfo.birthdate
|
|
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will return the players metadata for the specified metadata key.
|
2025-04-08 19:10:02 -04:00
|
|
|
---@param metadata table | string
|
|
|
|
|
---@return table | string | number | boolean
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetPlayerMetaData = function(metadata)
|
2025-05-13 01:06:52 -04:00
|
|
|
return Framework.GetPlayerData().metadata[metadata]
|
2025-01-08 06:33:31 -05:00
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will send a notification to the player.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param message string
|
|
|
|
|
---@param type string
|
|
|
|
|
---@param time number
|
|
|
|
|
---@return nil
|
2025-02-05 22:51:43 -05:00
|
|
|
Framework.Notify = function(message, type, time)
|
|
|
|
|
TriggerEvent('QBCore:Notify', message, 'primary', time)
|
|
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will display the help text message on the screen
|
2025-04-28 10:10:15 -04:00
|
|
|
---@param message string
|
|
|
|
|
---@param _position unknown
|
|
|
|
|
---@return nil
|
2025-02-05 22:51:43 -05:00
|
|
|
Framework.ShowHelpText = function(message, _position)
|
|
|
|
|
return exports['qb-core']:DrawText(message, _position)
|
|
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will hide the help text message on the screen
|
2025-04-28 10:10:15 -04:00
|
|
|
---@return nil
|
2025-02-05 22:51:43 -05:00
|
|
|
Framework.HideHelpText = function()
|
|
|
|
|
return exports['qb-core']:HideText()
|
|
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will return the players money by type, I recommend not using this
|
|
|
|
|
---as its the client and not secure or to be trusted. Use case is for a ui or a menu I guess.
|
2025-06-11 23:15:15 -04:00
|
|
|
---@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
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will return the item data for the specified item.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param item string
|
|
|
|
|
---@return table
|
2025-01-08 06:33:31 -05:00
|
|
|
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
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will get the hunger of a player
|
2025-09-04 07:27:40 -04:00
|
|
|
---@return number
|
|
|
|
|
Framework.GetHunger = function()
|
2025-09-10 11:29:19 -04:00
|
|
|
local hunger = Framework.GetPlayerMetaData("hunger") or 0
|
|
|
|
|
return math.floor((hunger) + 0.5) or 0
|
2025-09-04 07:27:40 -04:00
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will get the thirst of a player
|
2025-09-04 07:27:40 -04:00
|
|
|
---@return number
|
|
|
|
|
Framework.GetThirst = function()
|
2025-09-10 11:29:19 -04:00
|
|
|
local thirst = Framework.GetPlayerMetaData("thirst") or 0
|
|
|
|
|
return math.floor((thirst) + 0.5) or 0
|
2025-09-04 07:27:40 -04:00
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will get the players identifier (citizenid) etc.
|
2025-04-08 19:10:02 -04:00
|
|
|
---@return string
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetPlayerIdentifier = function()
|
2025-05-13 01:06:52 -04:00
|
|
|
return Framework.GetPlayerData().citizenid
|
2025-01-08 06:33:31 -05:00
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will get the players name (first and last).
|
2025-04-08 19:10:02 -04:00
|
|
|
---@return string
|
|
|
|
|
---@return string
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetPlayerName = function()
|
2025-05-13 01:06:52 -04:00
|
|
|
local playerData = Framework.GetPlayerData()
|
2025-01-08 06:33:31 -05:00
|
|
|
return playerData.charinfo.firstname, playerData.charinfo.lastname
|
|
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@deprecated Deprecated: This will return the players job name, job label, job grade label and job grade level
|
2025-04-08 19:10:02 -04:00
|
|
|
---@return string
|
|
|
|
|
---@return string
|
|
|
|
|
---@return string
|
|
|
|
|
---@return string
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetPlayerJob = function()
|
2025-12-23 19:27:27 -05:00
|
|
|
--print("This is depricated, please use Framework.GetPlayerJobData() instead.")
|
2025-12-14 16:22:35 -05:00
|
|
|
local jobData = Framework.GetPlayerJobData()
|
|
|
|
|
return jobData.jobName, jobData.jobLabel, jobData.gradeName, jobData.gradeRank
|
2025-01-08 06:33:31 -05:00
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will return the players job name, job label, job grade label job grade level, boss status, and duty status in a table
|
2025-05-14 04:48:23 -04:00
|
|
|
---@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
|
|
|
|
|
|
2025-12-14 16:22:35 -05:00
|
|
|
---@description Will return boolean if the player has the item.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param item string
|
2025-12-14 16:22:35 -05:00
|
|
|
---@param requiredCount number (optional)
|
2025-05-30 03:21:32 -04:00
|
|
|
---@return boolean
|
2025-12-14 16:22:35 -05:00
|
|
|
Framework.HasItem = function(item, requiredCount)
|
|
|
|
|
return QBCore.Functions.HasItem(item, requiredCount or 1)
|
2025-02-17 13:33:54 -05:00
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will return the item count for the specified item in the players inventory
|
2025-04-07 14:37:22 -04:00
|
|
|
---@param item string
|
|
|
|
|
---@return number
|
|
|
|
|
Framework.GetItemCount = function(item)
|
2025-05-13 01:06:52 -04:00
|
|
|
local frameworkInv = Framework.GetPlayerData().items
|
2025-04-07 14:37:22 -04:00
|
|
|
local count = 0
|
|
|
|
|
for _, v in pairs(frameworkInv) do
|
|
|
|
|
if v.name == item then
|
2025-09-26 19:02:30 +03:00
|
|
|
count = count + (v.amount or v.count)
|
2025-04-07 14:37:22 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return count
|
|
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will return the players inventory as a table in the ox_inventory style format
|
2025-05-30 03:21:32 -04:00
|
|
|
---@return table
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetPlayerInventory = function()
|
2025-02-05 01:54:55 -05:00
|
|
|
local items = {}
|
2025-05-13 01:06:52 -04:00
|
|
|
local frameworkInv = Framework.GetPlayerData().items
|
2025-02-05 01:54:55 -05:00
|
|
|
for _, v in pairs(frameworkInv) do
|
|
|
|
|
table.insert(items, {
|
|
|
|
|
name = v.name,
|
|
|
|
|
label = v.label,
|
2025-09-26 19:02:30 +03:00
|
|
|
count = v.amount or v.count,
|
2025-02-05 01:54:55 -05:00
|
|
|
slot = v.slot,
|
2025-12-14 16:22:35 -05:00
|
|
|
metadata = v.info or v.metadata or {},
|
2025-02-05 01:54:55 -05:00
|
|
|
stack = v.unique,
|
|
|
|
|
close = v.useable,
|
|
|
|
|
weight = v.weight
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
return items
|
2025-01-08 06:33:31 -05:00
|
|
|
end
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will return the vehicle properties for the specified vehicle
|
2025-06-08 19:40:49 -04:00
|
|
|
---@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
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will set the vehicle properties for the specified vehicle
|
2025-06-08 19:40:49 -04:00
|
|
|
---@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
|
|
|
|
|
|
2025-10-04 19:39:26 +01:00
|
|
|
---@description This will get a players dead status
|
2025-04-08 19:10:02 -04:00
|
|
|
---@return boolean
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetIsPlayerDead = function()
|
2025-05-13 01:06:52 -04:00
|
|
|
local playerData = Framework.GetPlayerData()
|
2025-02-22 20:20:08 -05:00
|
|
|
return playerData.metadata["isdead"] or playerData.metadata["inlaststand"]
|
2025-01-08 06:33:31 -05:00
|
|
|
end
|
|
|
|
|
|
2025-12-14 16:22:35 -05:00
|
|
|
---@description Event handler for when player is loaded in QB-Core framework
|
2025-01-08 06:33:31 -05:00
|
|
|
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
|
|
|
|
Wait(1500)
|
|
|
|
|
TriggerEvent('community_bridge:Client:OnPlayerLoaded')
|
|
|
|
|
end)
|
|
|
|
|
|
2025-12-14 16:22:35 -05:00
|
|
|
---@description Event handler for when player is unloaded in QB-Core framework
|
2025-01-08 06:33:31 -05:00
|
|
|
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
|
2025-05-13 01:06:52 -04:00
|
|
|
TriggerEvent('community_bridge:Client:OnPlayerUnload')
|
2025-01-08 06:33:31 -05:00
|
|
|
end)
|
|
|
|
|
|
2025-12-14 16:22:35 -05:00
|
|
|
---@description Event handler for when player job is updated in QB-Core framework
|
|
|
|
|
---@param data table Job data containing name, label, grade_label, and grade
|
2025-01-08 06:33:31 -05:00
|
|
|
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(data)
|
2025-05-13 01:06:52 -04:00
|
|
|
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', data.name, data.label, data.grade_label, data.grade)
|
2025-01-12 15:48:41 +02:00
|
|
|
end)
|
|
|
|
|
|
2025-05-10 00:01:56 -04:00
|
|
|
return Framework
|