mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-28 23:01:29 +00:00
combine functions
This commit is contained in:
+14
-69
@@ -27,47 +27,6 @@ function QBCore.Player.Login(source, citizenid, newData)
|
||||
return true
|
||||
end
|
||||
|
||||
function QBCore.Player.GetOfflinePlayer(citizenid)
|
||||
if not citizenid then return nil end
|
||||
local row = MySQL.prepare.await('SELECT * FROM players WHERE citizenid = ?', { citizenid })
|
||||
if not row then return nil end
|
||||
row.money = json.decode(row.money) or {}
|
||||
row.job = json.decode(row.job) or {}
|
||||
row.gang = json.decode(row.gang) or {}
|
||||
row.position = json.decode(row.position) or {}
|
||||
row.metadata = json.decode(row.metadata) or {}
|
||||
row.charinfo = json.decode(row.charinfo) or {}
|
||||
return QBCore.Player.CheckPlayerData(nil, row)
|
||||
end
|
||||
|
||||
function QBCore.Player.GetPlayerByLicense(license)
|
||||
if license then
|
||||
local source = QBCore.Functions.GetSource(license)
|
||||
if source > 0 then
|
||||
return QBCore.Players[source]
|
||||
else
|
||||
return QBCore.Player.GetOfflinePlayerByLicense(license)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function QBCore.Player.GetOfflinePlayerByLicense(license)
|
||||
if license then
|
||||
local PlayerData = MySQL.prepare.await('SELECT * FROM players where license = ?', { license })
|
||||
if PlayerData then
|
||||
PlayerData.money = json.decode(PlayerData.money)
|
||||
PlayerData.job = json.decode(PlayerData.job)
|
||||
PlayerData.gang = json.decode(PlayerData.gang)
|
||||
PlayerData.position = json.decode(PlayerData.position)
|
||||
PlayerData.metadata = json.decode(PlayerData.metadata)
|
||||
PlayerData.charinfo = json.decode(PlayerData.charinfo)
|
||||
return QBCore.Player.CheckPlayerData(nil, PlayerData)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- JSON DEFAULTS
|
||||
|
||||
local DynamicDefaults = {
|
||||
@@ -529,14 +488,20 @@ local playertables = { -- Add tables as needed
|
||||
{ table = 'player_vehicles' }
|
||||
}
|
||||
|
||||
function QBCore.Player.DeleteCharacter(source, citizenid)
|
||||
function QBCore.Player.DeleteCharacter(source, citizenid, force)
|
||||
local license = QBCore.Functions.GetIdentifier(source, 'license')
|
||||
local result = MySQL.scalar.await('SELECT license FROM players where citizenid = ?', { citizenid })
|
||||
if license == result then
|
||||
local result = MySQL.scalar.await('SELECT license FROM players WHERE citizenid = ?', { citizenid })
|
||||
|
||||
if force or (license == result) then
|
||||
local query = 'DELETE FROM %s WHERE citizenid = ?'
|
||||
local tableCount = #playertables
|
||||
local queries = table.create(tableCount, 0)
|
||||
|
||||
local Player = QBCore.Functions.GetPlayerByCitizenId(citizenid)
|
||||
if force and Player then
|
||||
DropPlayer(Player.PlayerData.source, 'An admin deleted the character which you are currently using')
|
||||
end
|
||||
|
||||
for i = 1, tableCount do
|
||||
local v = playertables[i]
|
||||
queries[i] = { query = query:format(v.table), values = { citizenid } }
|
||||
@@ -544,7 +509,11 @@ function QBCore.Player.DeleteCharacter(source, citizenid)
|
||||
|
||||
MySQL.transaction(queries, function(result2)
|
||||
if result2 then
|
||||
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Deleted', 'red', '**' .. GetPlayerName(source) .. '** ' .. license .. ' deleted **' .. citizenid .. '**..')
|
||||
if force then
|
||||
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Force Deleted', 'red', 'Character **' .. citizenid .. '** got deleted')
|
||||
else
|
||||
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Deleted', 'red', '**' .. GetPlayerName(source) .. '** ' .. license .. ' deleted **' .. citizenid .. '**..')
|
||||
end
|
||||
end
|
||||
end)
|
||||
else
|
||||
@@ -553,30 +522,6 @@ function QBCore.Player.DeleteCharacter(source, citizenid)
|
||||
end
|
||||
end
|
||||
|
||||
function QBCore.Player.ForceDeleteCharacter(citizenid)
|
||||
local result = MySQL.scalar.await('SELECT license FROM players where citizenid = ?', { citizenid })
|
||||
if result then
|
||||
local query = 'DELETE FROM %s WHERE citizenid = ?'
|
||||
local tableCount = #playertables
|
||||
local queries = table.create(tableCount, 0)
|
||||
local Player = QBCore.Functions.GetPlayerByCitizenId(citizenid)
|
||||
|
||||
if Player then
|
||||
DropPlayer(Player.PlayerData.source, 'An admin deleted the character which you are currently using')
|
||||
end
|
||||
for i = 1, tableCount do
|
||||
local v = playertables[i]
|
||||
queries[i] = { query = query:format(v.table), values = { citizenid } }
|
||||
end
|
||||
|
||||
MySQL.transaction(queries, function(result2)
|
||||
if result2 then
|
||||
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Force Deleted', 'red', 'Character **' .. citizenid .. '** got deleted')
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
-- Inventory Backwards Compatibility
|
||||
|
||||
function QBCore.Player.SaveInventory(source)
|
||||
|
||||
Reference in New Issue
Block a user