Files

250 lines
8.4 KiB
Lua
Raw Permalink Normal View History

2025-04-15 03:00:44 -04:00
---@diagnostic disable: duplicate-set-field
2025-01-08 06:33:31 -05:00
if GetResourceState('es_extended') ~= 'started' then return end
2025-08-31 18:41:12 +01:00
ESX = exports.es_extended:getSharedObject()
2025-01-08 06:33:31 -05:00
2025-05-09 19:07:17 -05:00
Framework = Framework or {}
2025-01-08 06:33:31 -05:00
2025-07-09 22:17:24 -04:00
local cachedItemList = nil
2025-08-31 18:41:12 +01:00
---@description This is an internal function, its here to attempt to emulate qbs shared items mainly. This should not be used outside of bridge.
Framework.ItemList = function()
2025-07-09 22:17:24 -04:00
if cachedItemList then return cachedItemList end
2026-08-17 03:49:37 -07:00
local items = lib.callback.await('community_bridge:Callback:GetFrameworkItems', false)
cachedItemList = { Items = items.Items or {} }
2025-07-09 22:17:24 -04:00
return cachedItemList
end
---@description This will get the name of the framework being used (if a supported framework).
---@return string
2025-01-31 19:23:47 -05:00
Framework.GetFrameworkName = function()
--print("This is depricated, please use Framework.GetResourceName() instead.")
return Framework.GetResourceName()
2025-01-31 19:23:47 -05:00
end
---@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 'es_extended'
end
---@description This will return true if the player is loaded, false otherwise.
---This could be useful in scripts that rely on player loaded events and offer a debug mode to hit this function.
---@return boolean
Framework.GetIsPlayerLoaded = function()
return ESX.IsPlayerLoaded()
end
---@description This is an internal function, do not use this outside of bridge as there is no standard format between the frameworks.
2025-08-31 18:41:12 +01:00
--- @return table
2025-01-08 06:33:31 -05:00
Framework.GetPlayerData = function()
2025-05-14 03:47:28 -04:00
return ESX.GetPlayerData()
2025-01-08 06:33:31 -05:00
end
---@description This will return a table of all the jobs in the framework.
---@return table
2025-03-10 01:17:18 -04:00
Framework.GetFrameworkJobs = function()
2026-08-17 03:49:37 -07:00
local jobs = lib.callback.await('community_bridge:Callback:GetFrameworkJobs', false)
2025-03-10 01:17:18 -04:00
return jobs
end
---@description This will get the players birth date
---@return string
2025-02-26 01:34:47 -05:00
Framework.GetPlayerDob = function()
2025-05-13 01:06:52 -04:00
local playerData = Framework.GetPlayerData()
2025-02-26 01:34:47 -05:00
local dob = playerData.dateofbirth
return dob
end
---@description This will return the players metadata for the specified metadata key.
---@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
---@description This will send a notification to the player.
---@param message string
---@param type string
---@param time number
---@return nil
Framework.Notify = function(message, type, time)
return ESX.ShowNotification(message, type, time)
end
---@description Will Display the help text message on the screen
---@param message string
---@param _position unknown
---@return nil
Framework.ShowHelpText = function(message, _position)
2025-08-31 18:41:12 +01:00
return exports.esx_textui:TextUI(message, "info")
2025-04-28 10:10:15 -04:00
end
---@description This will hide the help text message on the screen
---@return nil
2025-04-28 10:10:15 -04:00
Framework.HideHelpText = function()
2025-08-31 18:41:12 +01:00
return exports.esx_textui:HideUI()
2025-04-28 10:10:15 -04:00
end
---@description This will get the players identifier (citizenid) etc.
2025-03-03 01:37:29 -05:00
---@return string
2025-01-08 06:33:31 -05:00
Framework.GetPlayerIdentifier = function()
2025-05-13 01:06:52 -04:00
local playerData = Framework.GetPlayerData()
2025-02-22 20:20:08 -05:00
return playerData.identifier
2025-01-08 06:33:31 -05:00
end
---@description This will get the players name (first and last).
---@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.firstName, playerData.lastName
end
---@description Depricated : This will return the players job name, job label, job grade label and job grade level
---@return string
---@return string
---@return string
---@return string
2025-01-08 06:33:31 -05:00
Framework.GetPlayerJob = function()
--print("This is depricated, please use Framework.GetPlayerJobData() instead.")
local jobData = Framework.GetPlayerJobData()
return jobData.jobName, jobData.jobLabel, jobData.gradeName, jobData.gradeRank
2025-01-08 06:33:31 -05:00
end
2025-08-31 18:41:12 +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
--- @return table
2025-05-14 04:48:23 -04:00
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
---@description This is an internal function to get status data
2025-09-04 07:35:21 -04:00
--- @param search string
Framework.GetStatusData = function(search)
local playerData = Framework.GetPlayerData()
if not playerData then return 0 end
2025-09-04 07:35:21 -04:00
local status = playerData.variables.status
for _, entry in ipairs(status) do
if entry.name == search then
return entry.percent or 0
end
end
return 0
end
---@description This will get the hunger of a player
---@return number
Framework.GetHunger = function()
2025-09-04 07:35:21 -04:00
local status = Framework.GetStatusData("hunger")
return math.floor((status) + 0.5) or 0
end
---@description This will get the thirst of a player
---@return number
Framework.GetThirst = function()
2025-09-04 07:35:21 -04:00
local status = Framework.GetStatusData("thirst")
return math.floor((status) + 0.5) or 0
end
---@description Will return boolean if the player has the item.
---@param item string
---@param requiredCount number (optional)
---@return boolean
Framework.HasItem = function(item, requiredCount)
2025-02-17 14:16:18 -05:00
local hasItem = ESX.SearchInventory(item, true)
return hasItem >= (requiredCount or 1)
2025-02-17 14:16:18 -05:00
end
---@description This is an internal function used as a fallback, please use the Inventory.GetItemCount instead.
2025-08-31 18:41:12 +01:00
--- @param item string
--- @return number
2025-04-07 14:37:22 -04:00
Framework.GetItemCount = function(item)
local inventory = Framework.GetPlayerInventory()
if not inventory then return 0 end
return inventory[item].count or 0
end
---@description Return the item info in oxs format, {name, label, stack, weight, description, image}
---@param item string
---@return table
Framework.GetItemInfo = function(item)
return {}, print("ESX has not implemented GetItemInfo for this framework. Please ensure the inventory you are using is supported and start order is correct.")
end
---@description This is an internal function used as a fallback, please use the Inventory.GetPlayerInventory instead.
--- @return table {name, label, count, slot, metadata, stack, close, weight}
Framework.GetPlayerInventory = function()
local playerData = Framework.GetPlayerData()
if not playerData then return {} end
local repack = {}
for k, v in pairs(playerData.inventory) do
repack[k] = {
name = v.name,
label = v.label,
count = v.count,
slot = 0,
metadata = {},
stack = false,
close = v.usable or false,
weight = v.weight or 0,
}
end
return repack
end
---@description This will return the players money by type, I recommend not useing this as its the client and not secure or to be trusted.
---Use case is for a ui or a menu I guess.
---@param _type string
---@return number
2025-06-11 23:15:15 -04:00
Framework.GetAccountBalance = function(_type)
local player = Framework.GetPlayerData()
if not player then return 0 end
2025-06-12 06:49:41 -04:00
local accounts = player.accounts
2025-06-11 23:15:15 -04:00
if _type == 'cash' then _type = 'money' end
2025-06-12 06:49:41 -04:00
for _, account in ipairs(accounts) do
if account.name == _type then
if not account.money or account.money <= 0 then return 0 end
2025-06-12 06:49:41 -04:00
return account.money or 0
end
end
return 0
2025-06-11 23:15:15 -04:00
end
2025-08-31 18:41:12 +01:00
--- @description This will get a players dead status
--- @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.dead
2025-01-08 06:33:31 -05:00
end
---@description Event handler for when player is loaded in ESX framework
---@param xPlayer table
2025-01-08 06:33:31 -05:00
RegisterNetEvent('esx:playerLoaded', function(xPlayer)
Wait(1500)
2025-05-13 01:06:52 -04:00
TriggerEvent('community_bridge:Client:OnPlayerLoaded')
2025-01-08 06:33:31 -05:00
end)
---@description Event handler for when player logs out in ESX framework
2025-01-08 06:33:31 -05:00
RegisterNetEvent('esx:onPlayerLogout', function()
2025-05-13 01:06:52 -04:00
TriggerEvent('community_bridge:Client:OnPlayerUnload')
2025-01-08 06:33:31 -05:00
end)
---@description Event handler for when player job is updated in ESX framework
---@param data table Job data containing name, label, grade_label, and grade
2025-01-08 06:33:31 -05:00
RegisterNetEvent('esx:setJob', function(data)
2025-05-13 01:06:52 -04:00
TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', data.name, data.label, data.grade_label, data.grade)
end)
return Framework