Files
community_bridge/modules/framework/es_extended/client.lua
T

226 lines
7.5 KiB
Lua
Raw 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
ESX = exports["es_extended"]:getSharedObject()
Callback = Callback or Require("lib/utility/shared/callbacks.lua")
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
-- This is an internal function, its here to attempt to emulate qbs shared items mainly.
Framework.ItemList = function()
2025-07-09 22:17:24 -04:00
if cachedItemList then return cachedItemList end
local items = Callback.Trigger('community_bridge:Callback:GetFrameworkItems', false)
cachedItemList = { Items = items.Items or {} }
2025-07-09 22:17:24 -04:00
return cachedItemList
end
---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()
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.
2025-03-03 01:37:29 -05: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
2025-04-28 10:10:15 -04:00
---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()
local jobs = Callback.Trigger('community_bridge:Callback:GetFrameworkJobs', false)
2025-03-10 01:17:18 -04:00
return jobs
end
2025-04-28 10:10:15 -04:00
---This will return the players birth date
2025-03-03 01:37:29 -05:00
---@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
2025-04-28 10:10:15 -04:00
---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
---This will send a notification to the player.
2025-03-03 01:37:29 -05:00
---@param message string
---@param type string
---@param time number
---@return nil
Framework.Notify = function(message, type, time)
return ESX.ShowNotification(message, type, time)
end
2025-04-28 10:10:15 -04:00
---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.
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
---This will get the players name (first and last).
2025-03-03 01:37:29 -05: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.firstName, playerData.lastName
end
2025-05-14 04:48:23 -04:00
---Depricated : This will return the players job name, job label, job grade label and job grade level
2025-03-03 01:37:29 -05:00
---@return string
---@return string
---@return string
---@return string
2025-01-08 06:33:31 -05:00
Framework.GetPlayerJob = function()
2025-05-13 01:06:52 -04:00
local playerData = Framework.GetPlayerData()
2025-01-08 06:33:31 -05:00
return playerData.job.name, playerData.job.label, playerData.job.grade_label, playerData.job.grade
end
2025-05-14 04:48:23 -04:00
---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.
2025-03-03 01:37:29 -05:00
---@param item string
---@return boolean
2025-02-17 14:26:54 -05:00
Framework.HasItem = function(item)
2025-02-17 14:16:18 -05:00
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.
2025-04-07 14:37:22 -04:00
---@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
2025-06-11 23:15:15 -04:00
---This will return the players money by type, I recommend not useing this as its the client and not secure or to be trusted.
2025-06-12 06:49:41 -04:00
---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
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
return account.money or 0
end
end
return 0
2025-06-11 23:15:15 -04:00
end
2025-06-08 19:40:49 -04:00
---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
2025-06-12 08:24:12 -04:00
-- 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
2025-06-12 07:47:06 -04:00
return true, ESX.Game.SetVehicleProperties(vehicle, properties)
2025-06-08 19:40:49 -04:00
end
---This will get a players dead status.
2025-03-03 01:37:29 -05: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.dead
2025-01-08 06:33:31 -05:00
end
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)
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)
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