Merge branch 'main' into main

This commit is contained in:
Kakarot
2022-06-15 18:00:39 -07:00
committed by GitHub
38 changed files with 706 additions and 231 deletions
+14 -13
View File
@@ -6,7 +6,7 @@ QBCore.Commands.IgnoreList = { -- Ignore old perm levels while keeping backwards
}
CreateThread(function() -- Add ace to node for perm checking
for k,v in pairs(QBConfig.Server.Permissions) do
for _, v in pairs(QBConfig.Server.Permissions) do
ExecuteCommand(('add_ace qbcore.%s %s allow'):format(v, v))
end
end)
@@ -65,9 +65,9 @@ QBCore.Commands.Add('tp', 'TP To Player or Coords (Admin Only)', { { name = 'id/
end
else
if args[1] and args[2] and args[3] then
local x = tonumber(args[1])
local y = tonumber(args[2])
local z = tonumber(args[3])
local x = tonumber((args[1]:gsub(",",""))) + .0
local y = tonumber((args[2]:gsub(",",""))) + .0
local z = tonumber((args[3]:gsub(",",""))) + .0
if x ~= 0 and y ~= 0 and z ~= 0 then
TriggerClientEvent('QBCore:Command:TeleportToCoords', source, x, y, z)
else
@@ -208,7 +208,7 @@ end, 'admin')
-- Inventory (should be in qb-inventory?)
QBCore.Commands.Add('clearinv', 'Clear Players Inventory (Admin Only)', { { name = 'id', help = 'Player ID' } }, false, function(source, args)
local playerId = args[1] and args[1] ~= '' or source
local playerId = args[1] ~= '' and args[1] or source
local Player = QBCore.Functions.GetPlayer(tonumber(playerId))
if Player then
Player.Functions.ClearInventory()
@@ -224,7 +224,7 @@ QBCore.Commands.Add('ooc', 'OOC Chat Message', {}, false, function(source, args)
local Players = QBCore.Functions.GetPlayers()
local Player = QBCore.Functions.GetPlayer(source)
local playerCoords = GetEntityCoords(GetPlayerPed(source))
for k, v in pairs(Players) do
for _, v in pairs(Players) do
if v == source then
TriggerClientEvent('chat:addMessage', v, {
color = { 0, 0, 255},
@@ -253,16 +253,17 @@ end, 'user')
-- Me command
QBCore.Commands.Add('me', 'Show local message', {{name = 'message', help = 'Message to respond with'}}, false, function(source, args)
if #args < 1 then TriggerClientEvent('QBCore:Notify', source, Lang:t('error.missing_args2'), 'error') return end
local ped = GetPlayerPed(source)
local pCoords = GetEntityCoords(ped)
local msg = table.concat(args, ' ')
if msg == '' then return end
if string.match(msg, "<") then TriggerClientEvent('QBCore:Notify', source, Lang:t('error.wrong_format'), 'error') return end
for k,v in pairs(QBCore.Functions.GetPlayers()) do
local target = GetPlayerPed(v)
local msg = table.concat(args, ' '):gsub('[~<].-[>~]', '')
local Players = QBCore.Functions.GetPlayers()
for i=1, #Players do
local Player = Players[i]
local target = GetPlayerPed(Player)
local tCoords = GetEntityCoords(target)
if #(pCoords - tCoords) < 20 then
TriggerClientEvent('QBCore:Command:ShowMe3D', v, source, msg)
if target == ped or #(pCoords - tCoords) < 20 then
TriggerClientEvent('QBCore:Command:ShowMe3D', Player, source, msg)
end
end
end, 'user')
+1 -1
View File
@@ -42,4 +42,4 @@ end
function QBCore.ShowSuccess(resource, msg)
print('\x1b[32m['..resource..':LOG]\x1b[0m '..msg)
end
end
+42 -56
View File
@@ -1,10 +1,17 @@
-- Event Handler
AddEventHandler('playerDropped', function()
AddEventHandler('chatMessage', function(_, _, message)
if string.sub(message, 1, 1) == '/' then
CancelEvent()
return
end
end)
AddEventHandler('playerDropped', function(reason)
local src = source
if not QBCore.Players[src] then return end
local Player = QBCore.Players[src]
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Dropped', 'red', '**' .. GetPlayerName(src) .. '** (' .. Player.PlayerData.license .. ') left..')
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Dropped', 'red', '**' .. GetPlayerName(src) .. '** (' .. Player.PlayerData.license .. ') left..' ..'\n **Reason:** ' .. reason)
Player.Functions.Save()
QBCore.Player_Buckets[Player.PlayerData.license] = nil
QBCore.Players[src] = nil
@@ -27,7 +34,7 @@ local function onPlayerConnecting(name, setKickReason, deferrals)
end
end
deferrals.update(string.format('Hello %s. Validating Your Rockstar License', name))
deferrals.update(string.format(Lang:t('info.checking_ban'), name))
for _, v in pairs(identifiers) do
if string.find(v, 'license') then
@@ -39,7 +46,7 @@ local function onPlayerConnecting(name, setKickReason, deferrals)
-- Mandatory wait
Wait(2500)
deferrals.update(string.format('Hello %s. We are checking your allowance.', name))
deferrals.update(string.format(Lang:t('info.checking_whitelisted'), name))
local isBanned, Reason = QBCore.Functions.IsPlayerBanned(src)
local isLicenseAlreadyInUse = QBCore.Functions.IsLicenseInUse(license)
@@ -47,16 +54,16 @@ local function onPlayerConnecting(name, setKickReason, deferrals)
Wait(2500)
deferrals.update(string.format('Welcome %s to {Server Name}.', name))
deferrals.update(string.format(Lang:t('info.join_server'), name))
if not license then
deferrals.done('No Valid Rockstar License Found')
deferrals.done(Lang:t('error.no_valid_license'))
elseif isBanned then
deferrals.done(Reason)
elseif isLicenseAlreadyInUse and QBCore.Config.Server.CheckDuplicateLicense then
deferrals.done('Duplicate Rockstar License Found')
deferrals.done(Lang:t('error.duplicate_license'))
elseif isWhitelist and not whitelisted then
deferrals.done('You\'re not whitelisted for this server')
deferrals.done(Lang:t('error.not_whitelisted'))
else
deferrals.done()
if QBCore.Config.Server.UseConnectQueue then
@@ -128,14 +135,13 @@ end)
RegisterNetEvent('QBCore:Server:SetMetaData', function(meta, data)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
if meta == 'hunger' or meta == 'thirst' then
if data > 100 then
data = 100
end
end
if Player then
Player.Functions.SetMetaData(meta, data)
end
Player.Functions.SetMetaData(meta, data)
TriggerClientEvent('hud:client:UpdateNeeds', src, Player.PlayerData.metadata['hunger'], Player.PlayerData.metadata['thirst'])
end)
@@ -182,7 +188,7 @@ RegisterNetEvent('QBCore:CallCommand', function(command, args)
if not QBCore.Commands.List[command] then return end
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
local hasPerm = QBCore.Functions.HasPermission(src, QBCore.Commands.List[command].permission)
local hasPerm = QBCore.Functions.HasPermission(src, "command."..QBCore.Commands.List[command].name)
if hasPerm then
if QBCore.Commands.List[command].argsrequired and #QBCore.Commands.List[command].arguments ~= 0 and not args[#QBCore.Commands.List[command].arguments] then
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.missing_args2'), 'error')
@@ -200,52 +206,32 @@ QBCore.Functions.CreateCallback('QBCore:HasItem', function(source, cb, items, am
local retval = false
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return cb(false) end
if type(items) == 'table' then
local count = 0
local finalcount = 0
for k, v in pairs(items) do
if type(k) == 'string' then
finalcount = 0
for i, _ in pairs(items) do finalcount += 1 end
local item = Player.Functions.GetItemByName(k)
if item then
if item.amount >= v then
count += 1
if count == finalcount then
retval = true
end
end
end
else
finalcount = #items
local item = Player.Functions.GetItemByName(v)
if item then
if amount then
if item.amount >= amount then
count += 1
if count == finalcount then
retval = true
end
end
else
count += 1
if count == finalcount then
retval = true
end
end
end
local isTable = type(items) == 'table'
local isArray = isTable and table.type(items) == 'array' or false
local totalItems = #items
local count = 0
local kvIndex = 2
if isTable and not isArray then
totalItems = 0
for _ in pairs(items) do totalItems += 1 end
kvIndex = 1
end
if isTable then
for k, v in pairs(items) do
local itemKV = {k, v}
local item = Player.Functions.GetItemByName(itemKV[kvIndex])
if item and ((amount and item.amount >= amount) or (not amount and not isArray and item.amount >= v) or (not amount and isArray)) then
count += 1
end
end
else
local item = Player.Functions.GetItemByName(items)
if not item then return cb(false) end
if amount then
if item.amount >= amount then
retval = true
end
else
end
if count == totalItems then
retval = true
end
else -- Single item as string
local item = Player.Functions.GetItemByName(items)
if item and not amount or (amount and item.amount >= amount) then
retval = true
end
end
end
cb(retval)
end)
+32
View File
@@ -65,6 +65,22 @@ end
QBCore.Functions.AddItem = AddItem
exports('AddItem', AddItem)
-- Single update item
local function UpdateItem(itemName, item)
if type(itemName) ~= "string" then
return false, "invalid_item_name"
end
if not QBCore.Shared.Items[itemName] then
return false, "item_not_exists"
end
QBCore.Shared.Items[itemName] = item
TriggerClientEvent('QBCore:Client:OnSharedUpdate', -1, 'Items', itemName, item)
TriggerEvent('QBCore:Server:UpdateObject')
return true, "success"
end
QBCore.Functions.UpdateItem = UpdateItem
exports('UpdateItem', UpdateItem)
-- Multiple Add Items
local function AddItems(items)
local shouldContinue = true
@@ -152,3 +168,19 @@ local function GetCoreVersion(InvokingResource)
end
QBCore.Functions.GetCoreVersion = GetCoreVersion
exports('GetCoreVersion', GetCoreVersion)
local function ExploitBan(playerId, origin)
local name = GetPlayerName(playerId)
MySQL.insert('INSERT INTO bans (name, license, discord, ip, reason, expire, bannedby) VALUES (?, ?, ?, ?, ?, ?, ?)', {
name,
QBCore.Functions.GetIdentifier(playerId, 'license'),
QBCore.Functions.GetIdentifier(playerId, 'discord'),
QBCore.Functions.GetIdentifier(playerId, 'ip'),
origin,
2147483647,
'Anti Cheat'
})
DropPlayer(playerId, "You have been banned for cheating. Check our Discord for more information: " .. QBCore.Config.Server.Discord)
TriggerEvent("qb-log:server:CreateLog", "anticheat", "Anti-Cheat", "red", name.." has been banned for exploiting "..origin, true)
end
exports('ExploitBan', ExploitBan)
+8 -8
View File
@@ -63,7 +63,7 @@ end
function QBCore.Functions.GetPlayers()
local sources = {}
for k, v in pairs(QBCore.Players) do
for k, _ in pairs(QBCore.Players) do
sources[#sources+1] = k
end
return sources
@@ -137,7 +137,7 @@ end
function QBCore.Functions.GetPlayersInBucket(bucket --[[ int ]])
local curr_bucket_pool = {}
if QBCore.Player_Buckets and next(QBCore.Player_Buckets) then
for k, v in pairs(QBCore.Player_Buckets) do
for _, v in pairs(QBCore.Player_Buckets) do
if v.bucket == bucket then
curr_bucket_pool[#curr_bucket_pool + 1] = v.id
end
@@ -152,7 +152,7 @@ end
function QBCore.Functions.GetEntitiesInBucket(bucket --[[ int ]])
local curr_bucket_pool = {}
if QBCore.Entity_Buckets and next(QBCore.Entity_Buckets) then
for k, v in pairs(QBCore.Entity_Buckets) do
for _, v in pairs(QBCore.Entity_Buckets) do
if v.bucket == bucket then
curr_bucket_pool[#curr_bucket_pool + 1] = v.id
end
@@ -236,7 +236,7 @@ function QBCore.Functions.Kick(source, reason, setKickReason, deferrals)
if source then
DropPlayer(source, reason)
end
for i = 0, 4 do
for _ = 0, 4 do
while true do
if source then
if GetPlayerPing(source) >= 0 then
@@ -279,7 +279,7 @@ function QBCore.Functions.RemovePermission(source, permission)
QBCore.Commands.Refresh(src)
end
else
for k,v in pairs(QBCore.Config.Server.Permissions) do
for _, v in pairs(QBCore.Config.Server.Permissions) do
if IsPlayerAceAllowed(src, v) then
ExecuteCommand(('remove_principal identifier.%s qbcore.%s'):format(license, v))
QBCore.Commands.Refresh(src)
@@ -299,7 +299,7 @@ end
function QBCore.Functions.GetPermission(source)
local src = source
local perms = {}
for k,v in pairs (QBCore.Config.Server.Permissions) do
for _, v in pairs (QBCore.Config.Server.Permissions) do
if IsPlayerAceAllowed(src, v) then
perms[v] = true
end
@@ -328,13 +328,13 @@ end
function QBCore.Functions.IsPlayerBanned(source)
local plicense = QBCore.Functions.GetIdentifier(source, 'license')
local result = MySQL.Sync.fetchSingle('SELECT * FROM bans WHERE license = ?', { plicense })
local result = MySQL.single.await('SELECT * FROM bans WHERE license = ?', { plicense })
if not result then return false end
if os.time() < result.expire then
local timeTable = os.date('*t', tonumber(result.expire))
return true, 'You have been banned from the server:\n' .. result.reason .. '\nYour ban expires ' .. timeTable.day .. '/' .. timeTable.month .. '/' .. timeTable.year .. ' ' .. timeTable.hour .. ':' .. timeTable.min .. '\n'
else
MySQL.Async.execute('DELETE FROM bans WHERE id = ?', { result.id })
MySQL.query('DELETE FROM bans WHERE id = ?', { result.id })
end
return false
end
+1 -1
View File
@@ -10,4 +10,4 @@ end)
-- To use this export in a script instead of manifest method
-- Just put this line of code below at the very top of the script
-- local QBCore = exports['qb-core']:GetCoreObject()
-- local QBCore = exports['qb-core']:GetCoreObject()
+28 -29
View File
@@ -9,7 +9,7 @@ function QBCore.Player.Login(source, citizenid, newData)
if source and source ~= '' then
if citizenid then
local license = QBCore.Functions.GetIdentifier(source, 'license')
local PlayerData = MySQL.Sync.prepare('SELECT * FROM players where citizenid = ?', { citizenid })
local PlayerData = MySQL.prepare.await('SELECT * FROM players where citizenid = ?', { citizenid })
if PlayerData and license == PlayerData.license then
PlayerData.money = json.decode(PlayerData.money)
PlayerData.job = json.decode(PlayerData.job)
@@ -56,7 +56,7 @@ function QBCore.Player.CheckPlayerData(source, PlayerData)
PlayerData.charinfo.gender = PlayerData.charinfo.gender or 0
PlayerData.charinfo.backstory = PlayerData.charinfo.backstory or 'placeholder backstory'
PlayerData.charinfo.nationality = PlayerData.charinfo.nationality or 'USA'
PlayerData.charinfo.phone = PlayerData.charinfo.phone or QBCore.Functions.CreatePhoneNumber()
PlayerData.charinfo.phone = tonumber(PlayerData.charinfo.phone) or QBCore.Functions.CreatePhoneNumber()
PlayerData.charinfo.account = PlayerData.charinfo.account or QBCore.Functions.CreateAccountNumber()
-- Metadata
PlayerData.metadata = PlayerData.metadata or {}
@@ -240,9 +240,9 @@ function QBCore.Player.CreatePlayer(PlayerData)
self.PlayerData.money[moneytype] = self.PlayerData.money[moneytype] + amount
self.Functions.UpdatePlayerData()
if amount > 100000 then
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'AddMoney', 'lightgreen', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') added, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype], true)
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'AddMoney', 'lightgreen', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') added, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason, true)
else
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'AddMoney', 'lightgreen', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') added, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype])
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'AddMoney', 'lightgreen', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') added, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason)
end
TriggerClientEvent('hud:client:OnMoneyChange', self.PlayerData.source, moneytype, amount, false)
return true
@@ -264,9 +264,9 @@ function QBCore.Player.CreatePlayer(PlayerData)
self.PlayerData.money[moneytype] = self.PlayerData.money[moneytype] - amount
self.Functions.UpdatePlayerData()
if amount > 100000 then
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'RemoveMoney', 'red', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') removed, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype], true)
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'RemoveMoney', 'red', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') removed, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason, true)
else
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'RemoveMoney', 'red', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') removed, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype])
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'RemoveMoney', 'red', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') removed, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason)
end
TriggerClientEvent('hud:client:OnMoneyChange', self.PlayerData.source, moneytype, amount, true)
if moneytype == 'bank' then
@@ -283,7 +283,7 @@ function QBCore.Player.CreatePlayer(PlayerData)
if not self.PlayerData.money[moneytype] then return false end
self.PlayerData.money[moneytype] = amount
self.Functions.UpdatePlayerData()
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'SetMoney', 'green', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') set, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype])
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'SetMoney', 'green', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') set, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason)
return true
end
@@ -353,16 +353,16 @@ function QBCore.Player.CreatePlayer(PlayerData)
local slots = QBCore.Player.GetSlotsByItem(self.PlayerData.items, item)
local amountToRemove = amount
if slots then
for _, slot in pairs(slots) do
if self.PlayerData.items[slot].amount > amountToRemove then
self.PlayerData.items[slot].amount = self.PlayerData.items[slot].amount - amountToRemove
for _, _slot in pairs(slots) do
if self.PlayerData.items[_slot].amount > amountToRemove then
self.PlayerData.items[_slot].amount = self.PlayerData.items[_slot].amount - amountToRemove
self.Functions.UpdatePlayerData()
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** lost item: [slot:' .. slot .. '], itemname: ' .. self.PlayerData.items[slot].name .. ', removed amount: ' .. amount .. ', new total amount: ' .. self.PlayerData.items[slot].amount)
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** lost item: [slot:' .. _slot .. '], itemname: ' .. self.PlayerData.items[_slot].name .. ', removed amount: ' .. amount .. ', new total amount: ' .. self.PlayerData.items[_slot].amount)
return true
elseif self.PlayerData.items[slot].amount == amountToRemove then
self.PlayerData.items[slot] = nil
elseif self.PlayerData.items[_slot].amount == amountToRemove then
self.PlayerData.items[_slot] = nil
self.Functions.UpdatePlayerData()
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** lost item: [slot:' .. slot .. '], itemname: ' .. item .. ', removed amount: ' .. amount .. ', item removed')
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** lost item: [slot:' .. _slot .. '], itemname: ' .. item .. ', removed amount: ' .. amount .. ', item removed')
return true
end
end
@@ -447,7 +447,7 @@ function QBCore.Player.Save(source)
local pcoords = GetEntityCoords(ped)
local PlayerData = QBCore.Players[source].PlayerData
if PlayerData then
MySQL.Async.insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (:citizenid, :cid, :license, :name, :money, :charinfo, :job, :gang, :position, :metadata) ON DUPLICATE KEY UPDATE cid = :cid, name = :name, money = :money, charinfo = :charinfo, job = :job, gang = :gang, position = :position, metadata = :metadata', {
MySQL.insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (:citizenid, :cid, :license, :name, :money, :charinfo, :job, :gang, :position, :metadata) ON DUPLICATE KEY UPDATE cid = :cid, name = :name, money = :money, charinfo = :charinfo, job = :job, gang = :gang, position = :position, metadata = :metadata', {
citizenid = PlayerData.citizenid,
cid = tonumber(PlayerData.cid),
license = PlayerData.license,
@@ -476,7 +476,6 @@ local playertables = { -- Add tables as needed
{ table = 'phone_invoices' },
{ table = 'phone_messages' },
{ table = 'playerskins' },
{ table = 'player_boats' },
{ table = 'player_contacts' },
{ table = 'player_houses' },
{ table = 'player_mails' },
@@ -486,7 +485,7 @@ local playertables = { -- Add tables as needed
function QBCore.Player.DeleteCharacter(source, citizenid)
local license = QBCore.Functions.GetIdentifier(source, 'license')
local result = MySQL.Sync.fetchScalar('SELECT license FROM players where citizenid = ?', { citizenid })
local result = MySQL.scalar.await('SELECT license FROM players where citizenid = ?', { citizenid })
if license == result then
local query = "DELETE FROM %s WHERE citizenid = ?"
local tableCount = #playertables
@@ -497,8 +496,8 @@ function QBCore.Player.DeleteCharacter(source, citizenid)
queries[i] = {query = query:format(v.table), values = { citizenid }}
end
MySQL.Async.transaction(queries, function(result)
if result then
MySQL.transaction(queries, function(result2)
if result2 then
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Deleted', 'red', '**' .. GetPlayerName(source) .. '** ' .. license .. ' deleted **' .. citizenid .. '**..')
end
end)
@@ -512,7 +511,7 @@ end
function QBCore.Player.LoadInventory(PlayerData)
PlayerData.items = {}
local inventory = MySQL.Sync.prepare('SELECT inventory FROM players WHERE citizenid = ?', { PlayerData.citizenid })
local inventory = MySQL.prepare.await('SELECT inventory FROM players WHERE citizenid = ?', { PlayerData.citizenid })
local missingItems = {}
if inventory then
inventory = json.decode(inventory)
@@ -568,9 +567,9 @@ function QBCore.Player.SaveInventory(source)
}
end
end
MySQL.Async.prepare('UPDATE players SET inventory = ? WHERE citizenid = ?', { json.encode(ItemsJson), PlayerData.citizenid })
MySQL.prepare('UPDATE players SET inventory = ? WHERE citizenid = ?', { json.encode(ItemsJson), PlayerData.citizenid })
else
MySQL.Async.prepare('UPDATE players SET inventory = ? WHERE citizenid = ?', { '[]', PlayerData.citizenid })
MySQL.prepare('UPDATE players SET inventory = ? WHERE citizenid = ?', { '[]', PlayerData.citizenid })
end
end
@@ -611,7 +610,7 @@ function QBCore.Player.CreateCitizenId()
local CitizenId = nil
while not UniqueFound do
CitizenId = tostring(QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(5)):upper()
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE citizenid = ?', { CitizenId })
local result = MySQL.prepare.await('SELECT COUNT(*) as count FROM players WHERE citizenid = ?', { CitizenId })
if result == 0 then
UniqueFound = true
end
@@ -625,7 +624,7 @@ function QBCore.Functions.CreateAccountNumber()
while not UniqueFound do
AccountNumber = 'US0' .. math.random(1, 9) .. 'QBCore' .. math.random(1111, 9999) .. math.random(1111, 9999) .. math.random(11, 99)
local query = '%' .. AccountNumber .. '%'
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE charinfo LIKE ?', { query })
local result = MySQL.prepare.await('SELECT COUNT(*) as count FROM players WHERE charinfo LIKE ?', { query })
if result == 0 then
UniqueFound = true
end
@@ -637,9 +636,9 @@ function QBCore.Functions.CreatePhoneNumber()
local UniqueFound = false
local PhoneNumber = nil
while not UniqueFound do
PhoneNumber = math.random(100,999) .. math.random(1000000,9999999)
PhoneNumber = tonumber(math.random(100,999) .. math.random(1000000,9999999))
local query = '%' .. PhoneNumber .. '%'
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE charinfo LIKE ?', { query })
local result = MySQL.prepare.await('SELECT COUNT(*) as count FROM players WHERE charinfo LIKE ?', { query })
if result == 0 then
UniqueFound = true
end
@@ -653,7 +652,7 @@ function QBCore.Player.CreateFingerId()
while not UniqueFound do
FingerId = tostring(QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(1) .. QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(4))
local query = '%' .. FingerId .. '%'
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM `players` WHERE `metadata` LIKE ?', { query })
local result = MySQL.prepare.await('SELECT COUNT(*) as count FROM `players` WHERE `metadata` LIKE ?', { query })
if result == 0 then
UniqueFound = true
end
@@ -667,7 +666,7 @@ function QBCore.Player.CreateWalletId()
while not UniqueFound do
WalletId = 'QB-' .. math.random(11111111, 99999999)
local query = '%' .. WalletId .. '%'
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query })
local result = MySQL.prepare.await('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query })
if result == 0 then
UniqueFound = true
end
@@ -681,7 +680,7 @@ function QBCore.Player.CreateSerialNumber()
while not UniqueFound do
SerialNumber = math.random(11111111, 99999999)
local query = '%' .. SerialNumber .. '%'
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query })
local result = MySQL.prepare.await('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query })
if result == 0 then
UniqueFound = true
end