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-04-16 05:24:03 -05:00
|
|
|
Framework.Shared = QBCore.Shared
|
2025-05-18 23:45:37 -04:00
|
|
|
|
2025-05-30 03:21:32 -04:00
|
|
|
---This will return the name of the framework in use.
|
|
|
|
|
---@return string
|
2025-01-31 19:23:47 -05:00
|
|
|
Framework.GetFrameworkName = function()
|
|
|
|
|
return 'qb-core'
|
|
|
|
|
end
|
|
|
|
|
|
2025-06-01 23:12:32 -04:00
|
|
|
---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
|
|
|
|
|
|
2025-01-08 06:33:31 -05:00
|
|
|
-- Framework.GetPlayerIdentifier(src)
|
|
|
|
|
-- Returns the citizen ID of the player.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param src number
|
|
|
|
|
---@return string | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetPlayerIdentifier = function(src)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-02-26 01:34:47 -05:00
|
|
|
local playerData = player.PlayerData
|
|
|
|
|
return playerData.citizenid
|
2025-01-08 06:33:31 -05:00
|
|
|
end
|
|
|
|
|
|
2025-05-30 03:21:32 -04:00
|
|
|
--- Returns the player data of the specified source in the framework defualt format.
|
2025-05-09 23:06:01 -03:00
|
|
|
---@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
|
|
|
|
|
|
2025-05-30 03:21:32 -04:00
|
|
|
---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
|
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-01-08 06:33:31 -05:00
|
|
|
-- Framework.GetPlayerName(src)
|
|
|
|
|
-- Returns the first and last name of the player.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@return string|nil, string|nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetPlayerName = function(src)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-02-26 01:34:47 -05:00
|
|
|
local playerData = player.PlayerData
|
2025-01-08 06:33:31 -05:00
|
|
|
return playerData.charinfo.firstname, playerData.charinfo.lastname
|
|
|
|
|
end
|
|
|
|
|
|
2025-05-30 03:21:32 -04:00
|
|
|
---Returns the player date of birth.
|
|
|
|
|
---@param src number
|
|
|
|
|
---@return string|nil
|
2025-02-26 01:34:47 -05:00
|
|
|
Framework.GetPlayerDob = function(src)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-02-26 01:34:47 -05:00
|
|
|
local playerData = player.PlayerData
|
|
|
|
|
return playerData.charinfo.birthdate
|
|
|
|
|
end
|
|
|
|
|
|
2025-05-30 03:21:32 -04:00
|
|
|
---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
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetItem = function(src, item, metadata)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-02-26 01:34:47 -05:00
|
|
|
local playerData = player.PlayerData
|
|
|
|
|
local playerInventory = playerData.items
|
2025-01-08 06:33:31 -05:00
|
|
|
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
|
|
|
|
|
|
2025-05-09 06:03:09 -04:00
|
|
|
---This will return a table with the item info, {name, label, stack, weight, description, image}
|
2025-04-12 02:30:38 -04:00
|
|
|
---@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
|
|
|
|
|
|
2025-05-09 06:03:09 -04:00
|
|
|
---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
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetItemCount = function(src, item, metadata)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-05-30 03:21:32 -04:00
|
|
|
if not player then return 0 end
|
2025-02-26 01:34:47 -05:00
|
|
|
local playerData = player.PlayerData
|
|
|
|
|
local playerInventory = playerData.items
|
2025-01-08 06:33:31 -05:00
|
|
|
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
|
|
|
|
|
|
2025-05-09 06:03:09 -04:00
|
|
|
---This will return a boolean if the player has the item.
|
2025-03-07 04:08:40 -05:00
|
|
|
---@param src number
|
|
|
|
|
---@param item string
|
|
|
|
|
---@return boolean
|
|
|
|
|
Framework.HasItem = function(src, item)
|
|
|
|
|
local getCount = Framework.GetItemCount(src, item, nil)
|
|
|
|
|
return getCount > 0
|
|
|
|
|
end
|
|
|
|
|
|
2025-01-08 06:33:31 -05:00
|
|
|
-- 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}
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param src number
|
|
|
|
|
---@return table | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetPlayerInventory = function(src)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-02-26 01:34:47 -05:00
|
|
|
local playerData = player.PlayerData
|
|
|
|
|
local playerInventory = playerData.items
|
2025-01-08 06:33:31 -05:00
|
|
|
local repackedTable = {}
|
2025-02-26 01:34:47 -05:00
|
|
|
for _, v in pairs(playerInventory) do
|
2025-01-08 06:33:31 -05:00
|
|
|
table.insert(repackedTable, {
|
|
|
|
|
name = v.name,
|
|
|
|
|
count = v.amount,
|
|
|
|
|
metadata = v.info,
|
|
|
|
|
slot = v.slot,
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
return repackedTable
|
|
|
|
|
end
|
|
|
|
|
|
2025-04-14 01:16:06 -04:00
|
|
|
---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
|
|
|
|
|
|
2025-05-30 03:21:32 -04:00
|
|
|
---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
|
2025-01-31 19:15:33 -05:00
|
|
|
Framework.GetItemBySlot = function(src, slot)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-02-26 01:34:47 -05:00
|
|
|
local playerData = player.PlayerData
|
|
|
|
|
local playerInventory = playerData.items
|
2025-01-31 19:15:33 -05:00
|
|
|
local repack = {}
|
2025-02-26 01:34:47 -05:00
|
|
|
for _, v in pairs(playerInventory) do
|
2025-01-31 19:15:33 -05:00
|
|
|
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
|
|
|
|
|
|
2025-01-08 06:33:31 -05:00
|
|
|
-- Framework.SetMetadata(src, metadata, value)
|
|
|
|
|
-- Adds the specified metadata key and number value to the player's data.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@return boolean|nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.SetPlayerMetadata = function(src, metadata, value)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-01-08 06:33:31 -05:00
|
|
|
player.Functions.SetMetaData(metadata, value)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Framework.GetMetadata(src, metadata)
|
|
|
|
|
-- Gets the specified metadata key to the player's data.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param src number
|
|
|
|
|
---@param metadata string
|
|
|
|
|
---@return any|nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetPlayerMetadata = function(src, metadata)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-01-08 06:33:31 -05:00
|
|
|
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.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param src number
|
|
|
|
|
---@param value number
|
2025-04-08 19:10:02 -04:00
|
|
|
---@return number | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.AddStress = function(src, value)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-01-08 06:33:31 -05:00
|
|
|
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.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param src number
|
|
|
|
|
---@param value number
|
2025-04-08 19:10:02 -04:00
|
|
|
---@return number | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.RemoveStress = function(src, value)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-01-08 06:33:31 -05:00
|
|
|
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.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param src number
|
|
|
|
|
---@param value number
|
2025-04-08 19:10:02 -04:00
|
|
|
---@return number | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.AddHunger = function(src, value)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-01-08 06:33:31 -05:00
|
|
|
local playerData = player.PlayerData
|
|
|
|
|
local newHunger = (playerData.metadata.hunger or 0) + value
|
|
|
|
|
player.Functions.SetMetaData('hunger', Math.Clamp(newHunger, 0, 100))
|
2025-04-16 05:24:03 -05:00
|
|
|
TriggerClientEvent('hud:client:UpdateNeeds', src, newHunger, playerData.metadata.thirst)
|
2025-01-08 06:33:31 -05:00
|
|
|
--TriggerClientEvent('hud:client:UpdateStress', src, newStress)
|
|
|
|
|
return newHunger
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Framework.AddThirst(src, value)
|
|
|
|
|
-- Adds the specified value from the player's thirst level.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param src number
|
|
|
|
|
---@param value number
|
2025-04-08 19:10:02 -04:00
|
|
|
---@return number | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.AddThirst = function(src, value)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-01-08 06:33:31 -05:00
|
|
|
local playerData = player.PlayerData
|
|
|
|
|
local newThirst = (playerData.metadata.thirst or 0) + value
|
|
|
|
|
player.Functions.SetMetaData('thirst', Math.Clamp(newThirst, 0, 100))
|
2025-04-16 05:24:03 -05:00
|
|
|
TriggerClientEvent('hud:client:UpdateNeeds', src, playerData.metadata.hunger, newThirst)
|
2025-01-08 06:33:31 -05:00
|
|
|
--TriggerClientEvent('hud:client:UpdateStress', src, newStress)
|
|
|
|
|
return newThirst
|
|
|
|
|
end
|
|
|
|
|
|
2025-04-08 19:10:02 -04:00
|
|
|
---This will get the hunger of a player
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param src number
|
2025-04-08 19:10:02 -04:00
|
|
|
---@return number | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetHunger = function(src)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-01-08 06:33:31 -05:00
|
|
|
local playerData = player.PlayerData
|
|
|
|
|
local newHunger = (playerData.metadata.hunger or 0)
|
|
|
|
|
return newHunger
|
|
|
|
|
end
|
|
|
|
|
|
2025-05-30 03:21:32 -04:00
|
|
|
---This will return a boolean if the player is dead or in last stand.
|
|
|
|
|
---@param src number
|
|
|
|
|
---@return boolean|nil
|
2025-05-02 03:13:07 -05:00
|
|
|
Framework.GetIsPlayerDead = function(src)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-05-02 03:13:07 -05:00
|
|
|
if not player then return end
|
|
|
|
|
local playerData = player.PlayerData
|
2025-05-04 11:06:55 -05:00
|
|
|
return playerData.metadata.isdead or playerData.metadata.inlaststand or false
|
2025-05-02 03:13:07 -05:00
|
|
|
end
|
|
|
|
|
|
2025-05-30 03:21:32 -04:00
|
|
|
---This will revive a player, if the player is dead or in last stand.
|
|
|
|
|
---@param src number
|
|
|
|
|
---@return boolean
|
2025-05-09 19:06:50 -05:00
|
|
|
Framework.RevivePlayer = function(src)
|
|
|
|
|
src = tonumber(src)
|
|
|
|
|
if not src then return false end
|
2025-05-09 22:27:48 -03:00
|
|
|
TriggerClientEvent('hospital:client:Revive', src)
|
2025-05-09 19:06:50 -05:00
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
2025-04-08 19:10:02 -04:00
|
|
|
|
|
|
|
|
---This will get the thirst of a player
|
|
|
|
|
---@param src any
|
|
|
|
|
---@return number | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetThirst = function(src)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-02-26 01:34:47 -05:00
|
|
|
local playerData = player.PlayerData
|
|
|
|
|
local newThirst = (playerData.metadata.thirst or 0)
|
2025-01-08 06:33:31 -05:00
|
|
|
return newThirst
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Framework.GetPlayerPhone(src)
|
|
|
|
|
-- Returns the phone number of the player.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param src number
|
|
|
|
|
---@return string | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetPlayerPhone = function(src)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-02-26 01:34:47 -05:00
|
|
|
local playerData = player.PlayerData
|
2025-01-08 06:33:31 -05:00
|
|
|
return playerData.charinfo.phone
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Framework.GetPlayerGang(src)
|
|
|
|
|
-- Returns the gang name of the player.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param src number
|
|
|
|
|
---@return string | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetPlayerGang = function(src)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-02-26 01:34:47 -05:00
|
|
|
local playerData = player.PlayerData
|
|
|
|
|
return playerData.gang.name
|
2025-01-08 06:33:31 -05:00
|
|
|
end
|
|
|
|
|
|
2025-04-08 19:10:02 -04:00
|
|
|
---This will get a table of player sources that have the specified job name.
|
|
|
|
|
---@param job any
|
|
|
|
|
---@return table
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetPlayersByJob = function(job)
|
|
|
|
|
local playerList = {}
|
2025-04-12 02:30:38 -04:00
|
|
|
local players = QBCore.Functions.GetPlayers()
|
2025-01-08 06:33:31 -05:00
|
|
|
for _, src in pairs(players) do
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src).PlayerData
|
2025-01-08 06:33:31 -05:00
|
|
|
if player.job.name == job then
|
|
|
|
|
table.insert(playerList, src)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return playerList
|
|
|
|
|
end
|
|
|
|
|
|
2025-05-14 04:48:23 -04:00
|
|
|
---Depricated: Returns the job name, label, grade name, and grade level of the player.
|
2025-04-08 19:10:02 -04:00
|
|
|
---@param src number
|
2025-05-14 04:48:23 -04:00
|
|
|
---@return string | string | string | number | nil
|
|
|
|
|
---@return string | string | string | number | nil
|
|
|
|
|
---@return string | string | string | number | nil
|
|
|
|
|
---@return string | string | string | number | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetPlayerJob = function(src)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-02-26 01:34:47 -05:00
|
|
|
local playerData = player.PlayerData
|
|
|
|
|
return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level
|
2025-01-08 06:33:31 -05:00
|
|
|
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
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param src number
|
2025-05-14 04:48:23 -04:00
|
|
|
---@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
|
|
|
|
|
|
2025-04-15 08:04:43 -04:00
|
|
|
---Returns the players duty status.
|
2025-04-08 19:10:02 -04:00
|
|
|
---@param src number
|
2025-04-15 08:04:43 -04:00
|
|
|
---@return boolean | nil
|
|
|
|
|
Framework.GetPlayerDuty = function(src)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-04-15 08:04:43 -04:00
|
|
|
local playerData = player.PlayerData
|
|
|
|
|
if not playerData.job.onduty then return false end
|
|
|
|
|
return true
|
2025-01-08 06:33:31 -05:00
|
|
|
end
|
|
|
|
|
|
2025-04-08 19:10:02 -04:00
|
|
|
---This will toggle a players duty status
|
|
|
|
|
---@param src number
|
|
|
|
|
---@param status boolean
|
2025-05-30 03:21:32 -04:00
|
|
|
---@return boolean
|
2025-04-15 08:04:43 -04:00
|
|
|
Framework.SetPlayerDuty = function(src, status)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-05-30 03:21:32 -04:00
|
|
|
if not player then return false end
|
2025-01-12 12:55:29 -05:00
|
|
|
player.Functions.SetJobDuty(status)
|
|
|
|
|
TriggerEvent('QBCore:Server:SetDuty', src, player.PlayerData.job.onduty)
|
2025-05-30 03:21:32 -04:00
|
|
|
return true
|
2025-01-12 12:55:29 -05:00
|
|
|
end
|
|
|
|
|
|
2025-04-15 08:04:43 -04:00
|
|
|
-- 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)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-04-15 08:04:43 -04:00
|
|
|
if not player then return end
|
|
|
|
|
return player.Functions.SetJob(name, grade)
|
|
|
|
|
end
|
2025-04-08 19:10:02 -04:00
|
|
|
|
|
|
|
|
---This will add money based on the type of account (money/bank)
|
|
|
|
|
---@param src number
|
|
|
|
|
---@param _type string
|
|
|
|
|
---@param amount number
|
|
|
|
|
---@return boolean | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.AddAccountBalance = function(src, _type, amount)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-01-08 06:33:31 -05:00
|
|
|
if _type == 'money' then _type = 'cash' end
|
|
|
|
|
return player.Functions.AddMoney(_type, amount)
|
|
|
|
|
end
|
|
|
|
|
|
2025-04-08 19:10:02 -04:00
|
|
|
---This will remove money based on the type of account (money/bank)
|
|
|
|
|
---@param src number
|
|
|
|
|
---@param _type string
|
|
|
|
|
---@param amount number
|
|
|
|
|
---@return boolean | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.RemoveAccountBalance = function(src, _type, amount)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-01-08 06:33:31 -05:00
|
|
|
if _type == 'money' then _type = 'cash' end
|
|
|
|
|
return player.Functions.RemoveMoney(_type, amount)
|
|
|
|
|
end
|
|
|
|
|
|
2025-04-08 19:10:02 -04:00
|
|
|
---This will remove money based on the type of account (money/bank)
|
|
|
|
|
---@param src number
|
|
|
|
|
---@param _type string
|
|
|
|
|
---@return string | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.GetAccountBalance = function(src, _type)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
|
|
|
|
local playerData = player.PlayerData
|
2025-01-08 06:33:31 -05:00
|
|
|
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.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param src number
|
|
|
|
|
---@param item string
|
|
|
|
|
---@param amount number
|
|
|
|
|
---@param slot number
|
|
|
|
|
---@param metadata table
|
|
|
|
|
---@return boolean | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.AddItem = function(src, item, amount, slot, metadata)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-05-30 03:21:32 -04:00
|
|
|
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, { action = "add", item = item, count = amount, slot = slot, metadata = metadata })
|
2025-01-08 06:33:31 -05:00
|
|
|
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.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param src number
|
|
|
|
|
---@param item string
|
|
|
|
|
---@param amount number
|
|
|
|
|
---@param slot number
|
|
|
|
|
---@param metadata table
|
|
|
|
|
---@return boolean | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.RemoveItem = function(src, item, amount, slot, metadata)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-05-30 03:21:32 -04:00
|
|
|
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, { action = "remove", item = item, count = amount, slot = slot, metadata = metadata })
|
2025-01-08 06:33:31 -05:00
|
|
|
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
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param src number
|
|
|
|
|
---@param item string
|
|
|
|
|
---@param slot number
|
|
|
|
|
---@param metadata table
|
|
|
|
|
---@return boolean | nil
|
2025-01-08 06:33:31 -05:00
|
|
|
Framework.SetMetadata = function(src, item, slot, metadata)
|
2025-05-13 01:06:52 -04:00
|
|
|
local player = Framework.GetPlayer(src)
|
2025-03-03 02:05:53 -05:00
|
|
|
if not player then return end
|
2025-01-08 06:33:31 -05:00
|
|
|
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
|
2025-04-16 05:24:03 -05:00
|
|
|
if not player.Functions.RemoveItem(item, 1, itemSlot) then return false end
|
|
|
|
|
return player.Functions.AddItem(item, 1, slot, metadata)
|
2025-01-08 06:33:31 -05:00
|
|
|
end
|
|
|
|
|
|
2025-04-08 19:10:02 -04:00
|
|
|
---This will get all owned vehicles for the player
|
|
|
|
|
---@param src number
|
|
|
|
|
---@return table
|
2025-02-03 10:26:05 -05:00
|
|
|
Framework.GetOwnedVehicles = function(src)
|
|
|
|
|
local citizenId = Framework.GetPlayerIdentifier(src)
|
2025-05-30 03:21:32 -04:00
|
|
|
local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM player_vehicles WHERE citizenid = '" .. citizenId .. "'")
|
2025-02-03 10:26:05 -05:00
|
|
|
local vehicles = {}
|
2025-05-09 22:27:48 -03:00
|
|
|
for i = 1, #result do
|
2025-02-03 10:26:05 -05:00
|
|
|
local vehicle = result[i].vehicle
|
|
|
|
|
local plate = result[i].plate
|
2025-05-09 22:27:48 -03:00
|
|
|
table.insert(vehicles, { vehicle = vehicle, plate = plate })
|
2025-02-03 10:26:05 -05:00
|
|
|
end
|
|
|
|
|
return vehicles
|
|
|
|
|
end
|
|
|
|
|
|
2025-01-08 12:51:46 -05:00
|
|
|
-- Framework.RegisterUsableItem(item, cb)
|
2025-01-08 06:33:31 -05:00
|
|
|
-- Registers a usable item with a callback function.
|
2025-05-30 03:21:32 -04:00
|
|
|
---@param itemName string
|
|
|
|
|
---@param cb function
|
2025-01-14 10:55:14 -06:00
|
|
|
Framework.RegisterUsableItem = function(itemName, cb)
|
|
|
|
|
local func = function(src, item, itemData)
|
|
|
|
|
itemData = itemData or item
|
|
|
|
|
itemData.metadata = itemData.metadata or itemData.info or {}
|
2025-05-06 14:39:29 -04:00
|
|
|
itemData.slot = itemData.id or itemData.slot
|
2025-01-26 12:07:26 -06:00
|
|
|
cb(src, itemData)
|
2025-01-14 10:55:14 -06:00
|
|
|
end
|
|
|
|
|
QBCore.Functions.CreateUseableItem(itemName, func)
|
2025-01-12 15:48:41 +02:00
|
|
|
end
|
|
|
|
|
|
2025-06-02 22:19:42 -05:00
|
|
|
RegisterNetEvent("QBCore:Server:OnPlayerLoaded", function(src)
|
|
|
|
|
src = src or source
|
2025-03-09 23:13:03 -05:00
|
|
|
TriggerEvent("community_bridge:Server:OnPlayerLoaded", src)
|
|
|
|
|
end)
|
|
|
|
|
|
2025-06-02 22:19:42 -05:00
|
|
|
RegisterNetEvent("QBCore:Server:OnPlayerUnload", function(src)
|
|
|
|
|
src = src or source
|
2025-02-10 02:02:33 -05:00
|
|
|
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
|
2025-01-27 14:41:16 -05:00
|
|
|
end)
|
|
|
|
|
|
2025-01-27 18:42:38 -05:00
|
|
|
AddEventHandler("playerDropped", function()
|
|
|
|
|
local src = source
|
|
|
|
|
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
|
|
|
|
|
end)
|
|
|
|
|
|
2025-01-12 15:48:41 +02:00
|
|
|
Framework.Commands = {}
|
|
|
|
|
Framework.Commands.Add = function(name, help, arguments, argsrequired, callback, permission, ...)
|
|
|
|
|
QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission, ...)
|
2025-04-16 05:24:03 -05:00
|
|
|
end
|
2025-05-11 20:18:46 -04:00
|
|
|
|
|
|
|
|
return Framework
|