- init changes
This commit is contained in:
1 parent
8accf38f97
commit
d6cffd01bc
38 files changed
+325
-3377
No files matched your search
@@ -11,7 +11,7 @@ local cachedItemList = nil
|
||||
---@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()
|
||||
if cachedItemList then return cachedItemList end
|
||||
local items = Callback.Trigger('community_bridge:Callback:GetFrameworkItems', false)
|
||||
local items = lib.callback.await('community_bridge:Callback:GetFrameworkItems', false)
|
||||
cachedItemList = { Items = items.Items or {} }
|
||||
return cachedItemList
|
||||
end
|
||||
@@ -45,7 +45,7 @@ end
|
||||
---@description 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)
|
||||
local jobs = lib.callback.await('community_bridge:Callback:GetFrameworkJobs', false)
|
||||
return jobs
|
||||
end
|
||||
|
||||
|
||||
@@ -69,6 +69,15 @@ Framework.GetPlayerDob = function(src)
|
||||
return dob
|
||||
end
|
||||
|
||||
Framework.GetPlayerDobByIdentifier = function(citizenid)
|
||||
local xPlayer = Framework.GetPlayerByIdentifier(citizenid)
|
||||
if xPlayer then
|
||||
return xPlayer.get("dateofbirth")
|
||||
end
|
||||
local result = MySQL.single.await("SELECT dateofbirth FROM users WHERE identifier = @identifier", {["@identifier"] = citizenid})
|
||||
return result and result.dateofbirth or nil
|
||||
|
||||
end
|
||||
--- @description Returns the player data of the specified source in the framework defualt format
|
||||
--- @param src any
|
||||
--- @return table | nil
|
||||
@@ -120,6 +129,15 @@ Framework.GetPlayerName = function(src)
|
||||
return xPlayer.variables.firstName, xPlayer.variables.lastName
|
||||
end
|
||||
|
||||
Framework.GetPlayerNameByIdentifier = function(citizenid)
|
||||
local xPlayer = Framework.GetPlayerByIdentifier(citizenid)
|
||||
if xPlayer then
|
||||
return xPlayer.variables.firstName, xPlayer.variables.lastName
|
||||
end
|
||||
local result = MySQL.single.await("SELECT firstname, lastname FROM users WHERE identifier = @identifier", {["@identifier"] = citizenid})
|
||||
return result and result.firstname or nil, result and result.lastname or nil
|
||||
end
|
||||
|
||||
---@description This will return a table of all logged in players
|
||||
--- @return table
|
||||
Framework.GetPlayers = function()
|
||||
@@ -340,6 +358,15 @@ Framework.GetPlayerPhone = function(src)
|
||||
return xPlayer.get("phone_number")
|
||||
end
|
||||
|
||||
Framework.GetPlayerPhoneByIdentifier = function(citizenid)
|
||||
local xPlayer = Framework.GetPlayerByIdentifier(citizenid)
|
||||
if xPlayer then
|
||||
return xPlayer.get("phone_number")
|
||||
end
|
||||
local result = MySQL.single.await("SELECT phone_number FROM users WHERE identifier = @identifier", {["@identifier"] = citizenid})
|
||||
return result and result.phone_number or nil
|
||||
end
|
||||
|
||||
---@description This will return the job name, label, grade name, and grade level of the player.
|
||||
---@deprecated
|
||||
---@param src number
|
||||
@@ -404,7 +431,10 @@ Framework.GetPlayerGang = function(src)
|
||||
print("ESX does not support gangs, please ensure you are using a supported gang system or that you have the correct start order.")
|
||||
return
|
||||
end
|
||||
|
||||
Framework.GetPlayerGangByIdentifier = function(citizenid)
|
||||
print("ESX does not support gangs, please ensure you are using a supported gang system or that you have the correct start order.")
|
||||
return
|
||||
end
|
||||
---@description This will get a table of player sources that have the specified job name.
|
||||
--- @param job string
|
||||
--- @return table
|
||||
@@ -441,6 +471,28 @@ Framework.AddAccountBalance = function(src, _type, amount)
|
||||
return true
|
||||
end
|
||||
|
||||
---@description This will add money based on the type of account (money/bank)
|
||||
--- @param src number
|
||||
--- @param _type string
|
||||
--- @param amount number
|
||||
--- @return boolean
|
||||
Framework.AddAccountBalanceByIdentifier = function(src, _type, amount)
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if _type == 'cash' then _type = 'money' end
|
||||
if amount <= 0 then return false end
|
||||
if xPlayer then
|
||||
xPlayer.addAccountMoney(_type, amount)
|
||||
return true
|
||||
end
|
||||
local money = MySQL.single.await("SELECT accounts FROM users WHERE identifier = @identifier", {["@identifier"] = src})
|
||||
if not money then return false end
|
||||
local accounts = json.decode(money.accounts)
|
||||
accounts[_type] = (accounts[_type] or 0) + amount
|
||||
MySQL.update.await("UPDATE users SET accounts = @accounts WHERE identifier = @identifier", {["@accounts"] = json.encode(accounts), ["@identifier"] = src})
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
---@description This will remove money based on the type of account (money/bank)
|
||||
--- @param src number
|
||||
--- @param _type string
|
||||
@@ -457,6 +509,30 @@ Framework.RemoveAccountBalance = function(src, _type, amount)
|
||||
return true
|
||||
end
|
||||
|
||||
---@description This will remove money based on the type of account (money/bank)
|
||||
--- @param src number
|
||||
--- @param _type string
|
||||
--- @param amount number
|
||||
--- @return boolean
|
||||
Framework.RemoveAccountBalanceByIdentifier = function(src, _type, amount)
|
||||
local xPlayer = Framework.GetPlayer(src)
|
||||
if _type == 'cash' then _type = 'money' end
|
||||
if amount <= 0 then return false end
|
||||
if xPlayer then
|
||||
local accountVal = Framework.GetAccountBalance(src, _type)
|
||||
if accountVal < amount then return false end
|
||||
xPlayer.removeAccountMoney(_type, amount)
|
||||
return true
|
||||
end
|
||||
local money = MySQL.single.await("SELECT accounts FROM users WHERE identifier = @identifier", {["@identifier"] = src})
|
||||
if not money then return false end
|
||||
local accounts = json.decode(money.accounts)
|
||||
if (accounts[_type] or 0) < amount then return false end
|
||||
accounts[_type] = (accounts[_type] or 0) - amount
|
||||
MySQL.update.await("UPDATE users SET accounts = @accounts WHERE identifier = @identifier", {["@accounts"] = json.encode(accounts), ["@identifier"] = src})
|
||||
return true
|
||||
end
|
||||
|
||||
---@description This will get money based on the type of account (money/bank)
|
||||
--- @param src number
|
||||
--- @param _type string
|
||||
@@ -470,6 +546,20 @@ Framework.GetAccountBalance = function(src, _type)
|
||||
return balance
|
||||
end
|
||||
|
||||
Framework.GetAccountBalanceByIdentifier = function(src, _type)
|
||||
local xPlayer = Framework.GetPlayerByIdentifier(src)
|
||||
if _type == 'cash' then _type = 'money' end
|
||||
if xPlayer then
|
||||
local balance = xPlayer.getAccount(_type).money or 0
|
||||
if balance <= 0 then return 0 end
|
||||
return balance
|
||||
end
|
||||
local money = MySQL.single.await("SELECT accounts FROM users WHERE identifier = @identifier", {["@identifier"] = src})
|
||||
if not money then return 0 end
|
||||
local accounts = json.decode(money.accounts)
|
||||
return accounts[_type] or 0
|
||||
end
|
||||
|
||||
---@description This will add an item, and return true or false based on success
|
||||
--- This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
|
||||
---@param src number
|
||||
@@ -600,13 +690,13 @@ end)
|
||||
|
||||
---@description Callback to get framework jobs list
|
||||
---@param source number
|
||||
Callback.Register('community_bridge:Callback:GetFrameworkJobs', function(source)
|
||||
lib.callback.register('community_bridge:Callback:GetFrameworkJobs', function(source)
|
||||
return Framework.GetFrameworkJobs() or {}
|
||||
end)
|
||||
|
||||
---@description This is linked to an internal function, its an attempt to standardize the item list across frameworks.
|
||||
---@param source number
|
||||
Callback.Register('community_bridge:Callback:GetFrameworkItems', function(source)
|
||||
lib.callback.register('community_bridge:Callback:GetFrameworkItems', function(source)
|
||||
return Framework.ItemList() or {}
|
||||
end)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ if GetResourceState('qbx_core') == 'started' then return end
|
||||
|
||||
Framework = Framework or {}
|
||||
|
||||
QBCore = exports['qb-core']:GetCoreObject()
|
||||
local QBCore = exports['qb-core']:GetCoreObject()
|
||||
|
||||
Framework.Shared = QBCore.Shared
|
||||
|
||||
@@ -93,6 +93,15 @@ Framework.GetPlayerName = function(src)
|
||||
return playerData.charinfo.firstname, playerData.charinfo.lastname
|
||||
end
|
||||
|
||||
---@description Returns the first and last name of the player.
|
||||
---@return string|nil, string|nil
|
||||
Framework.GetPlayerNameByIdentifier = function(id)
|
||||
local player = Framework.GetPlayerByIdentifier(id) or QBCore.Functions.GetOfflinePlayer(id)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
return playerData.charinfo.firstname, playerData.charinfo.lastname
|
||||
end
|
||||
|
||||
---@description Returns the player date of birth.
|
||||
---@param src number
|
||||
---@return string|nil
|
||||
@@ -103,6 +112,17 @@ Framework.GetPlayerDob = function(src)
|
||||
return playerData.charinfo.birthdate
|
||||
end
|
||||
|
||||
---@description Returns the player date of birth.
|
||||
---@param id number
|
||||
---@return string|nil
|
||||
Framework.GetPlayerDobByIdentifier = function(id)
|
||||
local player = Framework.GetPlayerByIdentifier(id) or QBCore.Functions.GetOfflinePlayer(id)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
return playerData.charinfo.birthdate
|
||||
end
|
||||
|
||||
|
||||
---@description Returns a table of items matching the specified name and if passed metadata from the player's inventory.
|
||||
---@param src number
|
||||
---@param item string
|
||||
@@ -240,6 +260,7 @@ Framework.SetPlayerMetadata = function(src, metadata, value)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
---@description Gets the specified metadata key to the player's data.
|
||||
---@param src number
|
||||
---@param metadata string
|
||||
@@ -370,6 +391,17 @@ Framework.GetPlayerPhone = function(src)
|
||||
return playerData.charinfo.phone
|
||||
end
|
||||
|
||||
---@description Returns the phone number of the player.
|
||||
---@param src number
|
||||
---@return string | nil
|
||||
Framework.GetPlayerPhoneByIdentifier = function(src)
|
||||
local player = Framework.GetPlayerByIdentifier(src) or QBCore.Functions.GetOfflinePlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
return playerData.charinfo.phone
|
||||
end
|
||||
|
||||
|
||||
---@description Returns the gang name of the player.
|
||||
---@param src number
|
||||
---@return string | nil
|
||||
@@ -380,6 +412,16 @@ Framework.GetPlayerGang = function(src)
|
||||
return playerData.gang.name
|
||||
end
|
||||
|
||||
---@description Returns the gang name of the player.
|
||||
---@param id number
|
||||
---@return string | nil
|
||||
Framework.GetPlayerGangByIdentifier = function(id)
|
||||
local player = Framework.GetPlayerByIdentifier(id) or QBCore.Functions.GetOfflinePlayer(id)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
return playerData.gang.name
|
||||
end
|
||||
|
||||
---@description This will get a table of player sources that have the specified job name.
|
||||
---@param job string
|
||||
---@return table
|
||||
@@ -400,6 +442,8 @@ Framework.GetPlayerJob = function(src)
|
||||
return jobData.jobName, jobData.jobLabel, jobData.gradeName, jobData.gradeLevel
|
||||
end
|
||||
|
||||
|
||||
|
||||
---@description 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
|
||||
@@ -467,6 +511,24 @@ Framework.AddAccountBalance = function(src, _type, amount)
|
||||
return player.Functions.AddMoney(_type, amount)
|
||||
end
|
||||
|
||||
---@description 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.AddAccountBalanceByIdentifier = function(id, _type, amount)
|
||||
local player = Framework.GetPlayerByIdentifier(id) or QBCore.Functions.GetOfflinePlayer(id)
|
||||
if not player then return false end
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
if amount <= 0 then return false end
|
||||
local paid = player.Functions.AddMoney(_type, amount)
|
||||
if paid and not player.PlayerData.source then
|
||||
player.Functions.Save()
|
||||
end
|
||||
return paid
|
||||
end
|
||||
|
||||
|
||||
---@description This will remove money based on the type of account (money/bank)
|
||||
---@param src number
|
||||
---@param _type string
|
||||
@@ -479,6 +541,22 @@ Framework.RemoveAccountBalance = function(src, _type, amount)
|
||||
return player.Functions.RemoveMoney(_type, amount)
|
||||
end
|
||||
|
||||
---@description 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.RemoveAccountBalanceByIdentifier = function(id, _type, amount)
|
||||
local player = Framework.GetPlayerByIdentifier(id) or QBCore.Functions.GetOfflinePlayer(id)
|
||||
if not player then return false end
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
local paid = player.Functions.RemoveMoney(_type, amount)
|
||||
if paid and not player.PlayerData.source then
|
||||
player.Functions.Save()
|
||||
end
|
||||
return paid
|
||||
end
|
||||
|
||||
---@description This will remove money based on the type of account (money/bank)
|
||||
---@param src number
|
||||
---@param _type string
|
||||
@@ -491,6 +569,14 @@ Framework.GetAccountBalance = function(src, _type)
|
||||
return playerData.money[_type]
|
||||
end
|
||||
|
||||
Framework.GetAccountBalanceByIdentifier = function(id, _type)
|
||||
local player = Framework.GetPlayerByIdentifier(id) or QBCore.Functions.GetOfflinePlayer(id)
|
||||
if not player then return 0 end
|
||||
local playerData = player.PlayerData
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
return playerData.money[_type]
|
||||
end
|
||||
|
||||
---@description This will add an item, and return true or false based on success
|
||||
---This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
|
||||
---@param src number
|
||||
|
||||
@@ -35,6 +35,17 @@ Framework.GetPlayerDob = function(src)
|
||||
return playerData.charinfo.birthdate
|
||||
end
|
||||
|
||||
---@description Returns the player date of birth.
|
||||
---@param id string
|
||||
---@return string|nil
|
||||
Framework.GetPlayerDobByIdentifier = function(id)
|
||||
local player = Framework.GetPlayerByIdentifier(id) or QBox:GetOfflinePlayer(id)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
return playerData.charinfo.birthdate
|
||||
end
|
||||
|
||||
|
||||
---@description Returns the player data of the specified source.
|
||||
---@param src any
|
||||
---@return table | nil
|
||||
@@ -102,6 +113,17 @@ Framework.GetPlayerName = function(src)
|
||||
return playerData.charinfo.firstname, playerData.charinfo.lastname
|
||||
end
|
||||
|
||||
---@description Returns the first and last name of the player.
|
||||
---@param src number
|
||||
---@return string | nil
|
||||
---@return string | nil
|
||||
Framework.GetPlayerNameByIdentifier = function(src)
|
||||
local player = Framework.GetPlayerByIdentifier(src) or QBox:GetOfflinePlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
return playerData.charinfo.firstname, playerData.charinfo.lastname
|
||||
end
|
||||
|
||||
---@description Adds the specified item to the player's inventory.
|
||||
---This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
|
||||
---@param src number
|
||||
@@ -350,6 +372,17 @@ Framework.GetPlayerPhone = function(src)
|
||||
return playerData.charinfo.phone
|
||||
end
|
||||
|
||||
---@description Returns the phone number of the player.
|
||||
---@param src number
|
||||
---@return string | nil
|
||||
Framework.GetPlayerPhoneByIdentifier = function(src)
|
||||
local player = Framework.GetPlayerByIdentifier(src) or QBox:GetOfflinePlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
return playerData.charinfo.phone
|
||||
end
|
||||
|
||||
|
||||
---@description Returns the gang name of the player.
|
||||
---@param src number
|
||||
---@return string | nil
|
||||
@@ -358,6 +391,17 @@ Framework.GetPlayerGang = function(src)
|
||||
return player.gang.name
|
||||
end
|
||||
|
||||
|
||||
---@description Returns the gang name of the player.
|
||||
---@param id number
|
||||
---@return string | nil
|
||||
Framework.GetPlayerGangByIdentifier = function(id)
|
||||
local player = Framework.GetPlayerByIdentifier(id) or QBox:GetOfflinePlayer(id)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
return playerData.gang.name
|
||||
end
|
||||
|
||||
---@description This will get a table of player sources that have the specified job name.
|
||||
---@param job string
|
||||
---@return table
|
||||
@@ -445,6 +489,24 @@ Framework.AddAccountBalance = function(src, _type, amount)
|
||||
return player.Functions.AddMoney(_type, amount)
|
||||
end
|
||||
|
||||
---@description Adds the specified amount to the player's account balance of the specified type.
|
||||
---@param id string
|
||||
---@param _type string
|
||||
---@param amount number
|
||||
---@return boolean | nil
|
||||
Framework.AddAccountBalanceByIdentifier = function(id, _type, amount)
|
||||
local player = Framework.GetPlayerByIdentifier(id) or QBox:GetOfflinePlayer(id)
|
||||
if not player then return end
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
if amount <= 0 then return false end
|
||||
local paid = player.Functions.AddMoney(_type, amount)
|
||||
if paid and not player.PlayerData.source then
|
||||
QBox:SaveOffline(player.PlayerData)
|
||||
end
|
||||
return paid
|
||||
end
|
||||
|
||||
|
||||
---@description Removes the specified amount from the player's account balance of the specified type.
|
||||
---@param src number
|
||||
---@param _type string
|
||||
@@ -458,6 +520,22 @@ Framework.RemoveAccountBalance = function(src, _type, amount)
|
||||
return player.Functions.RemoveMoney(_type, amount)
|
||||
end
|
||||
|
||||
---@description 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.RemoveAccountBalanceByIdentifier = function(id, _type, amount)
|
||||
local player = Framework.GetPlayerByIdentifier(id) or QBox:GetOfflinePlayer(id)
|
||||
if not player then return false end
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
local paid = player.Functions.RemoveMoney(_type, amount)
|
||||
if paid and not player.PlayerData.source then
|
||||
QBox:SaveOffline(player.PlayerData)
|
||||
end
|
||||
return paid
|
||||
end
|
||||
|
||||
---@description Returns the player's account balance of the specified type.
|
||||
---@param src number
|
||||
---@param _type string
|
||||
@@ -472,6 +550,18 @@ Framework.GetAccountBalance = function(src, _type)
|
||||
return balance
|
||||
end
|
||||
|
||||
---@description Returns the player's account balance of the specified type.
|
||||
---@param id string
|
||||
---@param _type string
|
||||
---@return number | nil
|
||||
Framework.GetAccountBalanceByIdentifier = function(id, _type)
|
||||
local player = Framework.GetPlayerByIdentifier(id) or QBox:GetOfflinePlayer(id)
|
||||
if not player then return 0 end
|
||||
local playerData = player.PlayerData
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
return playerData.money[_type]
|
||||
end
|
||||
|
||||
---@description Returns a table of owned vehicles for the player. format is {vehicle = vehicle, plate = plate}
|
||||
---@param src number
|
||||
---@return table
|
||||
|
||||
Reference in new issue
Block a user