⚠️ Major Update ⚠️

- Major cleanup of all files including reformatting & notations
- Added an optional export to add to scripts as an alternative to import.lua
- Added player state to OnPlayerLoaded so no more need for isLoggedIn inside scripts
- Updated all events to the new RegisterNetEvent and got rid of unneeded handlers
- Added the ability for ACE permissions with commands
- Added two new config options for player update interval and status update
- Changed players table to use citizenid column as primary key <-- very important
- Overall sloppy code cleanup, removal of unused code, got rid of nil checks
This commit is contained in:
Kakarot
2021-09-24 22:46:20 -06:00
parent e683b991c6
commit 923f3d3a31
16 changed files with 5283 additions and 5580 deletions
+240 -240
View File
@@ -1,142 +1,157 @@
QBCore.Players = {}
QBCore.Player = {}
QBCore.Player.Login = function(source, citizenid, newData)
if source ~= nil then
-- On player login get their data or set defaults
-- Don't touch any of this unless you know what you are doing
-- Will cause major issues!
function QBCore.Player.Login(source, citizenid, newData)
local src = source
if src then
if citizenid then
local result = exports.oxmysql:fetchSync('SELECT * FROM players WHERE citizenid = ?', { citizenid })
local PlayerData = result[1]
if PlayerData ~= nil then
if PlayerData then
PlayerData.money = json.decode(PlayerData.money)
PlayerData.job = json.decode(PlayerData.job)
PlayerData.position = json.decode(PlayerData.position)
PlayerData.metadata = json.decode(PlayerData.metadata)
PlayerData.charinfo = json.decode(PlayerData.charinfo)
if PlayerData.gang ~= nil then
if PlayerData.gang then
PlayerData.gang = json.decode(PlayerData.gang)
else
PlayerData.gang = {}
end
end
QBCore.Player.CheckPlayerData(source, PlayerData)
QBCore.Player.CheckPlayerData(src, PlayerData)
else
QBCore.Player.CheckPlayerData(source, newData)
QBCore.Player.CheckPlayerData(src, newData)
end
return true
else
QBCore.ShowError(GetCurrentResourceName(), "ERROR QBCORE.PLAYER.LOGIN - NO SOURCE GIVEN!")
QBCore.ShowError(GetCurrentResourceName(), 'ERROR QBCORE.PLAYER.LOGIN - NO SOURCE GIVEN!')
return false
end
end
QBCore.Player.CheckPlayerData = function(source, PlayerData)
PlayerData = PlayerData ~= nil and PlayerData or {}
PlayerData.source = source
PlayerData.citizenid = PlayerData.citizenid ~= nil and PlayerData.citizenid or QBCore.Player.CreateCitizenId()
PlayerData.license = PlayerData.license ~= nil and PlayerData.license or QBCore.Functions.GetIdentifier(source, 'license')
PlayerData.name = GetPlayerName(source)
PlayerData.cid = PlayerData.cid ~= nil and PlayerData.cid or 1
PlayerData.money = PlayerData.money ~= nil and PlayerData.money or {}
function QBCore.Player.CheckPlayerData(source, PlayerData)
local src = source
PlayerData = PlayerData or {}
PlayerData.source = src
PlayerData.citizenid = PlayerData.citizenid or QBCore.Player.CreateCitizenId()
PlayerData.license = PlayerData.license or QBCore.Functions.GetIdentifier(src, 'license')
PlayerData.name = GetPlayerName(src)
PlayerData.cid = PlayerData.cid or 1
PlayerData.money = PlayerData.money or {}
for moneytype, startamount in pairs(QBCore.Config.Money.MoneyTypes) do
PlayerData.money[moneytype] = PlayerData.money[moneytype] ~= nil and PlayerData.money[moneytype] or startamount
PlayerData.money[moneytype] = PlayerData.money[moneytype] or startamount
end
PlayerData.charinfo = PlayerData.charinfo ~= nil and PlayerData.charinfo or {}
PlayerData.charinfo.firstname = PlayerData.charinfo.firstname ~= nil and PlayerData.charinfo.firstname or "Firstname"
PlayerData.charinfo.lastname = PlayerData.charinfo.lastname ~= nil and PlayerData.charinfo.lastname or "Lastname"
PlayerData.charinfo.birthdate = PlayerData.charinfo.birthdate ~= nil and PlayerData.charinfo.birthdate or "00-00-0000"
PlayerData.charinfo.gender = PlayerData.charinfo.gender ~= nil and PlayerData.charinfo.gender or 0
PlayerData.charinfo.backstory = PlayerData.charinfo.backstory ~= nil and PlayerData.charinfo.backstory or "placeholder backstory"
PlayerData.charinfo.nationality = PlayerData.charinfo.nationality ~= nil and PlayerData.charinfo.nationality or "USA"
PlayerData.charinfo.phone = PlayerData.charinfo.phone ~= nil and PlayerData.charinfo.phone or "1"..math.random(111111111, 999999999)
PlayerData.charinfo.account = PlayerData.charinfo.account ~= nil and PlayerData.charinfo.account or "US0"..math.random(1,9).."QBCore"..math.random(1111,9999)..math.random(1111,9999)..math.random(11,99)
PlayerData.metadata = PlayerData.metadata ~= nil and PlayerData.metadata or {}
PlayerData.metadata["hunger"] = PlayerData.metadata["hunger"] ~= nil and PlayerData.metadata["hunger"] or 100
PlayerData.metadata["thirst"] = PlayerData.metadata["thirst"] ~= nil and PlayerData.metadata["thirst"] or 100
PlayerData.metadata["stress"] = PlayerData.metadata["stress"] ~= nil and PlayerData.metadata["stress"] or 0
PlayerData.metadata["isdead"] = PlayerData.metadata["isdead"] ~= nil and PlayerData.metadata["isdead"] or false
PlayerData.metadata["inlaststand"] = PlayerData.metadata["inlaststand"] ~= nil and PlayerData.metadata["inlaststand"] or false
PlayerData.metadata["armor"] = PlayerData.metadata["armor"] ~= nil and PlayerData.metadata["armor"] or 0
PlayerData.metadata["ishandcuffed"] = PlayerData.metadata["ishandcuffed"] ~= nil and PlayerData.metadata["ishandcuffed"] or false
PlayerData.metadata["tracker"] = PlayerData.metadata["tracker"] ~= nil and PlayerData.metadata["tracker"] or false
PlayerData.metadata["injail"] = PlayerData.metadata["injail"] ~= nil and PlayerData.metadata["injail"] or 0
PlayerData.metadata["jailitems"] = PlayerData.metadata["jailitems"] ~= nil and PlayerData.metadata["jailitems"] or {}
PlayerData.metadata["status"] = PlayerData.metadata["status"] ~= nil and PlayerData.metadata["status"] or {}
PlayerData.metadata["phone"] = PlayerData.metadata["phone"] ~= nil and PlayerData.metadata["phone"] or {}
PlayerData.metadata["fitbit"] = PlayerData.metadata["fitbit"] ~= nil and PlayerData.metadata["fitbit"] or {}
PlayerData.metadata["commandbinds"] = PlayerData.metadata["commandbinds"] ~= nil and PlayerData.metadata["commandbinds"] or {}
PlayerData.metadata["bloodtype"] = PlayerData.metadata["bloodtype"] ~= nil and PlayerData.metadata["bloodtype"] or QBCore.Config.Player.Bloodtypes[math.random(1, #QBCore.Config.Player.Bloodtypes)]
PlayerData.metadata["dealerrep"] = PlayerData.metadata["dealerrep"] ~= nil and PlayerData.metadata["dealerrep"] or 0
PlayerData.metadata["craftingrep"] = PlayerData.metadata["craftingrep"] ~= nil and PlayerData.metadata["craftingrep"] or 0
PlayerData.metadata["attachmentcraftingrep"] = PlayerData.metadata["attachmentcraftingrep"] ~= nil and PlayerData.metadata["attachmentcraftingrep"] or 0
PlayerData.metadata["currentapartment"] = PlayerData.metadata["currentapartment"] ~= nil and PlayerData.metadata["currentapartment"] or nil
PlayerData.metadata["jobrep"] = PlayerData.metadata["jobrep"] ~= nil and PlayerData.metadata["jobrep"] or {
["tow"] = 0,
["trucker"] = 0,
["taxi"] = 0,
["hotdog"] = 0,
-- Charinfo
PlayerData.charinfo = PlayerData.charinfo or {}
PlayerData.charinfo.firstname = PlayerData.charinfo.firstname or 'Firstname'
PlayerData.charinfo.lastname = PlayerData.charinfo.lastname or 'Lastname'
PlayerData.charinfo.birthdate = PlayerData.charinfo.birthdate or '00-00-0000'
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 ~= nil and PlayerData.charinfo.phone or '1'..math.random(111111111, 999999999)
PlayerData.charinfo.account = PlayerData.charinfo.account ~= nil and PlayerData.charinfo.account or 'US0'..math.random(1,9)..'QBCore'..math.random(1111,9999)..math.random(1111,9999)..math.random(11,99)
-- Metadata
PlayerData.metadata = PlayerData.metadata or {}
PlayerData.metadata['hunger'] = PlayerData.metadata['hunger'] or 100
PlayerData.metadata['thirst'] = PlayerData.metadata['thirst'] or 100
PlayerData.metadata['stress'] = PlayerData.metadata['stress'] or 0
PlayerData.metadata['isdead'] = PlayerData.metadata['isdead'] or false
PlayerData.metadata['inlaststand'] = PlayerData.metadata['inlaststand'] or false
PlayerData.metadata['armor'] = PlayerData.metadata['armor'] or 0
PlayerData.metadata['ishandcuffed'] = PlayerData.metadata['ishandcuffed'] or false
PlayerData.metadata['tracker'] = PlayerData.metadata['tracker'] or false
PlayerData.metadata['injail'] = PlayerData.metadata['injail'] or 0
PlayerData.metadata['jailitems'] = PlayerData.metadata['jailitems'] or {}
PlayerData.metadata['status'] = PlayerData.metadata['status'] or {}
PlayerData.metadata['phone'] = PlayerData.metadata['phone'] or {}
PlayerData.metadata['fitbit'] = PlayerData.metadata['fitbit'] or {}
PlayerData.metadata['commandbinds'] = PlayerData.metadata['commandbinds'] or {}
PlayerData.metadata['bloodtype'] = PlayerData.metadata['bloodtype'] or QBCore.Config.Player.Bloodtypes[math.random(1, #QBCore.Config.Player.Bloodtypes)]
PlayerData.metadata['dealerrep'] = PlayerData.metadata['dealerrep'] or 0
PlayerData.metadata['craftingrep'] = PlayerData.metadata['craftingrep'] or 0
PlayerData.metadata['attachmentcraftingrep'] = PlayerData.metadata['attachmentcraftingrep'] or 0
PlayerData.metadata['currentapartment'] = PlayerData.metadata['currentapartment'] or nil
PlayerData.metadata['jobrep'] = PlayerData.metadata['jobrep'] or {
['tow'] = 0,
['trucker'] = 0,
['taxi'] = 0,
['hotdog'] = 0,
}
PlayerData.metadata["callsign"] = PlayerData.metadata["callsign"] ~= nil and PlayerData.metadata["callsign"] or "NO CALLSIGN"
PlayerData.metadata["fingerprint"] = PlayerData.metadata["fingerprint"] ~= nil and PlayerData.metadata["fingerprint"] or QBCore.Player.CreateFingerId()
PlayerData.metadata["walletid"] = PlayerData.metadata["walletid"] ~= nil and PlayerData.metadata["walletid"] or QBCore.Player.CreateWalletId()
PlayerData.metadata["criminalrecord"] = PlayerData.metadata["criminalrecord"] ~= nil and PlayerData.metadata["criminalrecord"] or {
["hasRecord"] = false,
["date"] = nil
PlayerData.metadata['callsign'] = PlayerData.metadata['callsign'] or 'NO CALLSIGN'
PlayerData.metadata['fingerprint'] = PlayerData.metadata['fingerprint'] or QBCore.Player.CreateFingerId()
PlayerData.metadata['walletid'] = PlayerData.metadata['walletid'] or QBCore.Player.CreateWalletId()
PlayerData.metadata['criminalrecord'] = PlayerData.metadata['criminalrecord'] or {
['hasRecord'] = false,
['date'] = nil
}
PlayerData.metadata["licences"] = PlayerData.metadata["licences"] ~= nil and PlayerData.metadata["licences"] or {
["driver"] = true,
["business"] = false,
["weapon"] = false
PlayerData.metadata['licences'] = PlayerData.metadata['licences'] or {
['driver'] = true,
['business'] = false,
['weapon'] = false
}
PlayerData.metadata["inside"] = PlayerData.metadata["inside"] ~= nil and PlayerData.metadata["inside"] or {
PlayerData.metadata['inside'] = PlayerData.metadata['inside'] or {
house = nil,
apartment = {
apartmentType = nil,
apartmentId = nil,
}
}
PlayerData.metadata["phonedata"] = PlayerData.metadata["phonedata"] ~= nil and PlayerData.metadata["phonedata"] or {
PlayerData.metadata['phonedata'] = PlayerData.metadata['phonedata'] or {
SerialNumber = QBCore.Player.CreateSerialNumber(),
InstalledApps = {},
}
PlayerData.job = PlayerData.job ~= nil and PlayerData.job or {}
PlayerData.job.name = PlayerData.job.name ~= nil and PlayerData.job.name or "unemployed"
PlayerData.job.label = PlayerData.job.label ~= nil and PlayerData.job.label or "Civilian"
PlayerData.job.payment = PlayerData.job.payment ~= nil and PlayerData.job.payment or 10
PlayerData.job.onduty = PlayerData.job.onduty ~= nil and PlayerData.job.onduty or true
-- Added for grade system
PlayerData.job.isboss = PlayerData.job.isboss ~= nil and PlayerData.job.isboss or false
PlayerData.job.grade = PlayerData.job.grade ~= nil and PlayerData.job.grade or {}
PlayerData.job.grade.name = PlayerData.job.grade.name ~= nil and PlayerData.job.grade.name or "Freelancer"
PlayerData.job.grade.level = PlayerData.job.grade.level ~= nil and PlayerData.job.grade.level or 0
PlayerData.gang = PlayerData.gang ~= nil and PlayerData.gang or {}
PlayerData.gang.name = PlayerData.gang.name ~= nil and PlayerData.gang.name or "none"
PlayerData.gang.label = PlayerData.gang.label ~= nil and PlayerData.gang.label or "No Gang Affiliaton"
-- Added for grade system
PlayerData.gang.isboss = PlayerData.gang.isboss ~= nil and PlayerData.gang.isboss or false
PlayerData.gang.grade = PlayerData.gang.grade ~= nil and PlayerData.gang.grade or {}
PlayerData.gang.grade.name = PlayerData.gang.grade.name ~= nil and PlayerData.gang.grade.name or "none"
PlayerData.gang.grade.level = PlayerData.gang.grade.level ~= nil and PlayerData.gang.grade.level or 0
PlayerData.position = PlayerData.position ~= nil and PlayerData.position or QBConfig.DefaultSpawn
-- Job
PlayerData.job = PlayerData.job or {}
PlayerData.job.name = PlayerData.job.name or 'unemployed'
PlayerData.job.label = PlayerData.job.label or 'Civilian'
PlayerData.job.payment = PlayerData.job.payment or 10
PlayerData.job.onduty = PlayerData.job.onduty or true
PlayerData.job.isboss = PlayerData.job.isboss or false
PlayerData.job.grade = PlayerData.job.grade or {}
PlayerData.job.grade.name = PlayerData.job.grade.name or 'Freelancer'
PlayerData.job.grade.level = PlayerData.job.grade.level or 0
-- Gang
PlayerData.gang = PlayerData.gang or {}
PlayerData.gang.name = PlayerData.gang.name or 'none'
PlayerData.gang.label = PlayerData.gang.label or 'No Gang Affiliaton'
PlayerData.gang.isboss = PlayerData.gang.isboss or false
PlayerData.gang.grade = PlayerData.gang.grade or {}
PlayerData.gang.grade.name = PlayerData.gang.grade.name or 'none'
PlayerData.gang.grade.level = PlayerData.gang.grade.level or 0
-- Other
PlayerData.position = PlayerData.position or QBConfig.DefaultSpawn
PlayerData.LoggedIn = true
PlayerData = QBCore.Player.LoadInventory(PlayerData)
QBCore.Player.CreatePlayer(PlayerData)
end
QBCore.Player.CreatePlayer = function(PlayerData)
-- On player logout
function QBCore.Player.Logout(source)
local src = source
TriggerClientEvent('QBCore:Client:OnPlayerUnload', src)
TriggerClientEvent('QBCore:Player:UpdatePlayerData', src)
Citizen.Wait(200)
QBCore.Players[src] = nil
end
-- Create a new character
-- Don't touch any of this unless you know what you are doing
-- Will cause major issues!
function QBCore.Player.CreatePlayer(PlayerData)
local self = {}
self.Functions = {}
self.PlayerData = PlayerData
self.Functions.UpdatePlayerData = function(dontUpdateChat)
TriggerClientEvent("QBCore:Player:SetPlayerData", self.PlayerData.source, self.PlayerData)
TriggerClientEvent('QBCore:Player:SetPlayerData', self.PlayerData.source, self.PlayerData)
if dontUpdateChat == nil then
QBCore.Commands.Refresh(self.PlayerData.source)
end
@@ -144,20 +159,20 @@ QBCore.Player.CreatePlayer = function(PlayerData)
self.Functions.SetJob = function(job, grade)
local job = job:lower()
local grade = tostring(grade) ~= nil and tostring(grade) or '0'
local grade = tostring(grade) or '0'
if QBCore.Shared.Jobs[job] ~= nil then
if QBCore.Shared.Jobs[job] then
self.PlayerData.job.name = job
self.PlayerData.job.label = QBCore.Shared.Jobs[job].label
self.PlayerData.job.onduty = QBCore.Shared.Jobs[job].defaultDuty
if QBCore.Shared.Jobs[job].grades[grade] then
local jobgrade = QBCore.Shared.Jobs[job].grades[grade]
self.PlayerData.job.grade = {}
self.PlayerData.job.grade.name = jobgrade.name
self.PlayerData.job.grade.level = tonumber(grade)
self.PlayerData.job.payment = jobgrade.payment ~= nil and jobgrade.payment or 30
self.PlayerData.job.isboss = jobgrade.isboss ~= nil and jobgrade.isboss or false
self.PlayerData.job.payment = jobgrade.payment or 30
self.PlayerData.job.isboss = jobgrade.isboss or false
else
self.PlayerData.job.grade = {}
self.PlayerData.job.grade.name = 'No Grades'
@@ -167,7 +182,7 @@ QBCore.Player.CreatePlayer = function(PlayerData)
end
self.Functions.UpdatePlayerData()
TriggerClientEvent("QBCore:Client:OnJobUpdate", self.PlayerData.source, self.PlayerData.job)
TriggerClientEvent('QBCore:Client:OnJobUpdate', self.PlayerData.source, self.PlayerData.job)
return true
end
@@ -176,9 +191,9 @@ QBCore.Player.CreatePlayer = function(PlayerData)
self.Functions.SetGang = function(gang, grade)
local gang = gang:lower()
local grade = tostring(grade) ~= nil and tostring(grade) or '0'
local grade = tostring(grade) or '0'
if QBCore.Shared.Gangs[gang] ~= nil then
if QBCore.Shared.Gangs[gang] then
self.PlayerData.gang.name = gang
self.PlayerData.gang.label = QBCore.Shared.Gangs[gang].label
if QBCore.Shared.Gangs[gang].grades[grade] then
@@ -186,7 +201,7 @@ QBCore.Player.CreatePlayer = function(PlayerData)
self.PlayerData.gang.grade = {}
self.PlayerData.gang.grade.name = ganggrade.name
self.PlayerData.gang.grade.level = tonumber(grade)
self.PlayerData.gang.isboss = ganggrade.isboss ~= nil and ganggrade.isboss or false
self.PlayerData.gang.isboss = ganggrade.isboss or false
else
self.PlayerData.gang.grade = {}
self.PlayerData.gang.grade.name = 'No Grades'
@@ -195,7 +210,7 @@ QBCore.Player.CreatePlayer = function(PlayerData)
end
self.Functions.UpdatePlayerData()
TriggerClientEvent("QBCore:Client:OnGangUpdate", self.PlayerData.source, self.PlayerData.gang)
TriggerClientEvent('QBCore:Client:OnGangUpdate', self.PlayerData.source, self.PlayerData.gang)
return true
end
return false
@@ -216,35 +231,35 @@ QBCore.Player.CreatePlayer = function(PlayerData)
self.Functions.AddJobReputation = function(amount)
local amount = tonumber(amount)
self.PlayerData.metadata["jobrep"][self.PlayerData.job.name] = self.PlayerData.metadata["jobrep"][self.PlayerData.job.name] + amount
self.PlayerData.metadata['jobrep'][self.PlayerData.job.name] = self.PlayerData.metadata['jobrep'][self.PlayerData.job.name] + amount
self.Functions.UpdatePlayerData()
end
self.Functions.AddMoney = function(moneytype, amount, reason)
reason = reason ~= nil and reason or "unkown"
reason = reason or 'unknown'
local moneytype = moneytype:lower()
local amount = tonumber(amount)
if amount < 0 then return end
if self.PlayerData.money[moneytype] ~= nil then
if self.PlayerData.money[moneytype] then
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], 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])
end
TriggerClientEvent("hud:client:OnMoneyChange", self.PlayerData.source, moneytype, amount, false)
TriggerClientEvent('hud:client:OnMoneyChange', self.PlayerData.source, moneytype, amount, false)
return true
end
return false
end
self.Functions.RemoveMoney = function(moneytype, amount, reason)
reason = reason ~= nil and reason or "unkown"
reason = reason or 'unknown'
local moneytype = moneytype:lower()
local amount = tonumber(amount)
if amount < 0 then return end
if self.PlayerData.money[moneytype] ~= nil then
if self.PlayerData.money[moneytype] then
for _, mtype in pairs(QBCore.Config.Money.DontAllowMinus) do
if mtype == moneytype then
if self.PlayerData.money[moneytype] - amount < 0 then return false end
@@ -253,12 +268,12 @@ QBCore.Player.CreatePlayer = function(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], 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])
end
TriggerClientEvent("hud:client:OnMoneyChange", self.PlayerData.source, moneytype, amount, true)
if moneytype == "bank" then
TriggerClientEvent('hud:client:OnMoneyChange', self.PlayerData.source, moneytype, amount, true)
if moneytype == 'bank' then
TriggerClientEvent('qb-phone:client:RemoveBankMoney', self.PlayerData.source, amount)
end
return true
@@ -267,21 +282,21 @@ QBCore.Player.CreatePlayer = function(PlayerData)
end
self.Functions.SetMoney = function(moneytype, amount, reason)
reason = reason ~= nil and reason or "unkown"
reason = reason or 'unknown'
local moneytype = moneytype:lower()
local amount = tonumber(amount)
if amount < 0 then return end
if self.PlayerData.money[moneytype] ~= nil then
if self.PlayerData.money[moneytype] then
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])
return true
end
return false
end
self.Functions.GetMoney = function(moneytype)
if moneytype ~= nil then
if moneytype then
local moneytype = moneytype:lower()
return self.PlayerData.money[moneytype]
end
@@ -291,72 +306,71 @@ QBCore.Player.CreatePlayer = function(PlayerData)
self.Functions.AddItem = function(item, amount, slot, info)
local totalWeight = QBCore.Player.GetTotalWeight(self.PlayerData.items)
local itemInfo = QBCore.Shared.Items[item:lower()]
if itemInfo == nil then TriggerClientEvent('QBCore:Notify', source, "Item Does Not Exist", "error") return end
if itemInfo == nil then TriggerClientEvent('QBCore:Notify', source, 'Item Does Not Exist', 'error') return end
local amount = tonumber(amount)
local slot = tonumber(slot) ~= nil and tonumber(slot) or QBCore.Player.GetFirstSlotByItem(self.PlayerData.items, item)
if itemInfo["type"] == "weapon" and info == nil then
local slot = tonumber(slot) or QBCore.Player.GetFirstSlotByItem(self.PlayerData.items, item)
if itemInfo['type'] == 'weapon' and info == nil then
info = {
serie = tostring(QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(1) .. QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(4)),
}
end
if (totalWeight + (itemInfo["weight"] * amount)) <= QBCore.Config.Player.MaxWeight then
if (slot ~= nil and self.PlayerData.items[slot] ~= nil) and (self.PlayerData.items[slot].name:lower() == item:lower()) and (itemInfo["type"] == "item" and not itemInfo["unique"]) then
if (totalWeight + (itemInfo['weight'] * amount)) <= QBCore.Config.Player.MaxWeight then
if (slot and self.PlayerData.items[slot]) and (self.PlayerData.items[slot].name:lower() == item:lower()) and (itemInfo['type'] == 'item' and not itemInfo['unique']) then
self.PlayerData.items[slot].amount = self.PlayerData.items[slot].amount + amount
self.Functions.UpdatePlayerData()
TriggerEvent("qb-log:server:CreateLog", "playerinventory", "AddItem", "green", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** got item: [slot:" ..slot.."], itemname: " .. self.PlayerData.items[slot].name .. ", added amount: " .. amount ..", new total amount: ".. self.PlayerData.items[slot].amount)
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**'..GetPlayerName(self.PlayerData.source) .. ' (citizenid: '..self.PlayerData.citizenid..' | id: '..self.PlayerData.source..')** got item: [slot:' ..slot..'], itemname: ' .. self.PlayerData.items[slot].name .. ', added amount: ' .. amount ..', new total amount: '.. self.PlayerData.items[slot].amount)
return true
elseif (not itemInfo["unique"] and slot or slot ~= nil and self.PlayerData.items[slot] == nil) then
self.PlayerData.items[slot] = {name = itemInfo["name"], amount = amount, info = info ~= nil and info or "", label = itemInfo["label"], description = itemInfo["description"] ~= nil and itemInfo["description"] or "", weight = itemInfo["weight"], type = itemInfo["type"], unique = itemInfo["unique"], useable = itemInfo["useable"], image = itemInfo["image"], shouldClose = itemInfo["shouldClose"], slot = slot, combinable = itemInfo["combinable"]}
elseif (not itemInfo['unique'] and slot or slot and self.PlayerData.items[slot] == nil) then
self.PlayerData.items[slot] = {name = itemInfo['name'], amount = amount, info = info or '', label = itemInfo['label'], description = itemInfo['description'] or '', weight = itemInfo['weight'], type = itemInfo['type'], unique = itemInfo['unique'], useable = itemInfo['useable'], image = itemInfo['image'], shouldClose = itemInfo['shouldClose'], slot = slot, combinable = itemInfo['combinable']}
self.Functions.UpdatePlayerData()
TriggerEvent("qb-log:server:CreateLog", "playerinventory", "AddItem", "green", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** got item: [slot:" ..slot.."], itemname: " .. self.PlayerData.items[slot].name .. ", added amount: " .. amount ..", new total amount: ".. self.PlayerData.items[slot].amount)
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**'..GetPlayerName(self.PlayerData.source) .. ' (citizenid: '..self.PlayerData.citizenid..' | id: '..self.PlayerData.source..')** got item: [slot:' ..slot..'], itemname: ' .. self.PlayerData.items[slot].name .. ', added amount: ' .. amount ..', new total amount: '.. self.PlayerData.items[slot].amount)
return true
elseif (itemInfo["unique"]) or (not slot or slot == nil) or (itemInfo["type"] == "weapon") then
elseif (itemInfo['unique']) or (not slot or slot == nil) or (itemInfo['type'] == 'weapon') then
for i = 1, QBConfig.Player.MaxInvSlots, 1 do
if self.PlayerData.items[i] == nil then
self.PlayerData.items[i] = {name = itemInfo["name"], amount = amount, info = info ~= nil and info or "", label = itemInfo["label"], description = itemInfo["description"] ~= nil and itemInfo["description"] or "", weight = itemInfo["weight"], type = itemInfo["type"], unique = itemInfo["unique"], useable = itemInfo["useable"], image = itemInfo["image"], shouldClose = itemInfo["shouldClose"], slot = i, combinable = itemInfo["combinable"]}
self.PlayerData.items[i] = {name = itemInfo['name'], amount = amount, info = info or '', label = itemInfo['label'], description = itemInfo['description'] or '', weight = itemInfo['weight'], type = itemInfo['type'], unique = itemInfo['unique'], useable = itemInfo['useable'], image = itemInfo['image'], shouldClose = itemInfo['shouldClose'], slot = i, combinable = itemInfo['combinable']}
self.Functions.UpdatePlayerData()
TriggerEvent("qb-log:server:CreateLog", "playerinventory", "AddItem", "green", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** got item: [slot:" ..i.."], itemname: " .. self.PlayerData.items[i].name .. ", added amount: " .. amount ..", new total amount: ".. self.PlayerData.items[i].amount)
--TriggerClientEvent('QBCore:Notify', self.PlayerData.source, itemInfo["label"].. " toegevoegd!", "success")
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**'..GetPlayerName(self.PlayerData.source) .. ' (citizenid: '..self.PlayerData.citizenid..' | id: '..self.PlayerData.source..')** got item: [slot:' ..i..'], itemname: ' .. self.PlayerData.items[i].name .. ', added amount: ' .. amount ..', new total amount: '.. self.PlayerData.items[i].amount)
--TriggerClientEvent('QBCore:Notify', self.PlayerData.source, itemInfo['label'].. ' toegevoegd!', 'success')
return true
end
end
end
else
TriggerClientEvent('QBCore:Notify', self.PlayerData.source, "Your inventory is too heavy!", "error")
TriggerClientEvent('QBCore:Notify', self.PlayerData.source, 'Your inventory is too heavy!', 'error')
end
return false
end
self.Functions.RemoveItem = function(item, amount, slot)
local itemInfo = QBCore.Shared.Items[item:lower()]
local amount = tonumber(amount)
local slot = tonumber(slot)
if slot ~= nil then
if slot then
if self.PlayerData.items[slot].amount > amount then
self.PlayerData.items[slot].amount = self.PlayerData.items[slot].amount - amount
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
else
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
else
local slots = QBCore.Player.GetSlotsByItem(self.PlayerData.items, item)
local amountToRemove = amount
if slots ~= nil then
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
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
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
@@ -368,19 +382,19 @@ QBCore.Player.CreatePlayer = function(PlayerData)
self.Functions.SetInventory = function(items, dontUpdateChat)
self.PlayerData.items = items
self.Functions.UpdatePlayerData(dontUpdateChat)
TriggerEvent("qb-log:server:CreateLog", "playerinventory", "SetInventory", "blue", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** items set: " .. json.encode(items))
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'SetInventory', 'blue', '**'..GetPlayerName(self.PlayerData.source) .. ' (citizenid: '..self.PlayerData.citizenid..' | id: '..self.PlayerData.source..')** items set: ' .. json.encode(items))
end
self.Functions.ClearInventory = function()
self.PlayerData.items = {}
self.Functions.UpdatePlayerData()
TriggerEvent("qb-log:server:CreateLog", "playerinventory", "ClearInventory", "red", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** inventory cleared")
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'ClearInventory', 'red', '**'..GetPlayerName(self.PlayerData.source) .. ' (citizenid: '..self.PlayerData.citizenid..' | id: '..self.PlayerData.source..')** inventory cleared')
end
self.Functions.GetItemByName = function(item)
local item = tostring(item):lower()
local slot = QBCore.Player.GetFirstSlotByItem(self.PlayerData.items, item)
if slot ~= nil then
if slot then
return self.PlayerData.items[slot]
end
return nil
@@ -391,7 +405,7 @@ QBCore.Player.CreatePlayer = function(PlayerData)
local items = {}
local slots = QBCore.Player.GetSlotsByItem(self.PlayerData.items, item)
for _, slot in pairs(slots) do
if slot ~= nil then
if slot then
table.insert(items, self.PlayerData.items[slot])
end
end
@@ -407,7 +421,7 @@ QBCore.Player.CreatePlayer = function(PlayerData)
local item = tostring(cardType):lower()
local slots = QBCore.Player.GetSlotsByItem(self.PlayerData.items, item)
for _, slot in pairs(slots) do
if slot ~= nil then
if slot then
if self.PlayerData.items[slot].info.cardNumber == cardNumber then
return slot
end
@@ -418,7 +432,7 @@ QBCore.Player.CreatePlayer = function(PlayerData)
self.Functions.GetItemBySlot = function(slot)
local slot = tonumber(slot)
if self.PlayerData.items[slot] ~= nil then
if self.PlayerData.items[slot] then
return self.PlayerData.items[slot]
end
return nil
@@ -436,106 +450,91 @@ QBCore.Player.CreatePlayer = function(PlayerData)
self.Functions.UpdatePlayerData()
end
QBCore.Player.Save = function(source)
local PlayerData = QBCore.Players[source].PlayerData
if PlayerData ~= nil then
-- TODO: Merge these 3 queries into 1 with an on duplicate (citizenid isn't primary so https://stackoverflow.com/a/33495408/3200040 might need to be used)
local result = exports.oxmysql:fetchSync('SELECT * FROM players WHERE citizenid = ?', { PlayerData.citizenid })
if result[1] == nil then
exports.oxmysql:insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', {
PlayerData.citizenid,
tonumber(PlayerData.cid),
PlayerData.license,
PlayerData.name,
json.encode(PlayerData.money),
json.encode(PlayerData.charinfo),
json.encode(PlayerData.job),
json.encode(PlayerData.gang),
json.encode(PlayerData.position),
json.encode(PlayerData.metadata)
})
else
exports.oxmysql:execute('UPDATE players SET license = ?, name = ?, money = ?, charinfo = ?, job = ?, gang = ?, position = ?, metadata = ? WHERE citizenid = ?', {
PlayerData.license,
PlayerData.name,
json.encode(PlayerData.money),
json.encode(PlayerData.charinfo),
json.encode(PlayerData.job),
json.encode(PlayerData.gang),
json.encode(PlayerData.position),
json.encode(PlayerData.metadata),
PlayerData.citizenid
})
end
QBCore.Player.SaveInventory(source)
QBCore.ShowSuccess(GetCurrentResourceName(), PlayerData.name .." PLAYER SAVED!")
-- Save player info to database (make sure citizenid is the primary key in your database)
function QBCore.Player.Save(source)
local src = source
local PlayerData = QBCore.Players[src].PlayerData
if PlayerData then
exports.oxmysql: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,
name = PlayerData.name,
money = json.encode(PlayerData.money),
charinfo = json.encode(PlayerData.charinfo),
job = json.encode(PlayerData.job),
gang = json.encode(PlayerData.gang),
position = json.encode(PlayerData.position),
metadata = json.encode(PlayerData.metadata)
})
QBCore.Player.SaveInventory(src)
QBCore.ShowSuccess(GetCurrentResourceName(), PlayerData.name ..' PLAYER SAVED!')
else
QBCore.ShowError(GetCurrentResourceName(), "ERROR QBCORE.PLAYER.SAVE - PLAYERDATA IS EMPTY!")
QBCore.ShowError(GetCurrentResourceName(), 'ERROR QBCORE.PLAYER.SAVE - PLAYERDATA IS EMPTY!')
end
end
QBCore.Player.Logout = function(source)
TriggerClientEvent('QBCore:Client:OnPlayerUnload', source)
TriggerClientEvent("QBCore:Player:UpdatePlayerData", source)
Citizen.Wait(200)
QBCore.Players[source] = nil
end
-- Delete character
local playertables = {
{table = "players"},
{table = "apartments"},
{table = "bank_accounts"},
{table = "crypto_transactions"},
{table = "phone_invoices"},
{table = "phone_messages"},
{table = "playerskins"},
{table = "player_boats"},
{table = "player_contacts"},
{table = "player_houses"},
{table = "player_mails"},
{table = "player_outfits"},
{table = "player_vehicles"}
local playertables = { -- Add tables as needed
{table = 'players'},
{table = 'apartments'},
{table = 'bank_accounts'},
{table = 'crypto_transactions'},
{table = 'phone_invoices'},
{table = 'phone_messages'},
{table = 'playerskins'},
{table = 'player_boats'},
{table = 'player_contacts'},
{table = 'player_houses'},
{table = 'player_mails'},
{table = 'player_outfits'},
{table = 'player_vehicles'}
}
QBCore.Player.DeleteCharacter = function(source, citizenid)
local license = QBCore.Functions.GetIdentifier(source, 'license')
function QBCore.Player.DeleteCharacter(source, citizenid)
local src = source
local license = QBCore.Functions.GetIdentifier(src, 'license')
local result = exports.oxmysql:scalarSync('SELECT license FROM players where citizenid = ?', { citizenid })
if license == result then
for k,v in pairs(playertables) do
exports.oxmysql:execute('DELETE FROM '..v.table..' WHERE citizenid = ?', { citizenid })
end
TriggerEvent("qb-log:server:CreateLog", "joinleave", "Character Deleted", "red", "**".. GetPlayerName(source) .. "** ("..QBCore.Functions.GetIdentifier(source, 'license')..") deleted **"..citizenid.."**..")
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Deleted', 'red', '**'.. GetPlayerName(src) .. '** '..license..' deleted **'..citizenid..'**..')
else
DropPlayer(source, 'You Have Been Kicked For Exploitation')
TriggerEvent("qb-log:server:CreateLog", "anticheat", "Anti-Cheat", "white", GetPlayerName(source).." Has Been Dropped For Character Deletion Exploit", false)
DropPlayer(src, 'You Have Been Kicked For Exploitation')
TriggerEvent('qb-log:server:CreateLog', 'anticheat', 'Anti-Cheat', 'white', GetPlayerName(src)..' Has Been Dropped For Character Deletion Exploit', false)
end
end
-- Inventory
QBCore.Player.LoadInventory = function(PlayerData)
PlayerData.items = {}
local result = exports.oxmysql:fetchSync('SELECT * FROM players WHERE citizenid = ?', { PlayerData.citizenid })
if result[1] ~= nil then
if result[1].inventory ~= nil then
local result = exports.oxmysql:fetchSync('SELECT * FROM players WHERE citizenid = ?', {PlayerData.citizenid})
if result[1] then
if result[1].inventory then
plyInventory = json.decode(result[1].inventory)
if next(plyInventory) ~= nil then
if next(plyInventory) then
for _, item in pairs(plyInventory) do
if item ~= nil then
if item then
local itemInfo = QBCore.Shared.Items[item.name:lower()]
if itemInfo ~= nil then
if itemInfo then
PlayerData.items[item.slot] = {
name = itemInfo["name"],
amount = item.amount,
info = item.info ~= nil and item.info or "",
label = itemInfo["label"],
description = itemInfo["description"] ~= nil and itemInfo["description"] or "",
weight = itemInfo["weight"],
type = itemInfo["type"],
unique = itemInfo["unique"],
useable = itemInfo["useable"],
image = itemInfo["image"],
shouldClose = itemInfo["shouldClose"],
slot = item.slot,
combinable = itemInfo["combinable"]
name = itemInfo['name'],
amount = item.amount,
info = item.info or '',
label = itemInfo['label'],
description = itemInfo['description'] or '',
weight = itemInfo['weight'],
type = itemInfo['type'],
unique = itemInfo['unique'],
useable = itemInfo['useable'],
image = itemInfo['image'],
shouldClose = itemInfo['shouldClose'],
slot = item.slot,
combinable = itemInfo['combinable']
}
end
end
@@ -547,13 +546,14 @@ QBCore.Player.LoadInventory = function(PlayerData)
end
QBCore.Player.SaveInventory = function(source)
if QBCore.Players[source] ~= nil then
local PlayerData = QBCore.Players[source].PlayerData
local src = source
if QBCore.Players[src] then
local PlayerData = QBCore.Players[src].PlayerData
local items = PlayerData.items
local ItemsJson = {}
if items ~= nil and next(items) ~= nil then
if items and next(items) then
for slot, item in pairs(items) do
if items[slot] ~= nil then
if items[slot] then
table.insert(ItemsJson, {
name = item.name,
amount = item.amount,
@@ -570,9 +570,11 @@ QBCore.Player.SaveInventory = function(source)
end
end
QBCore.Player.GetTotalWeight = function(items)
-- Util Functions
function QBCore.Player.GetTotalWeight(items)
local weight = 0
if items ~= nil then
if items then
for slot, item in pairs(items) do
weight = weight + (item.weight * item.amount)
end
@@ -580,9 +582,9 @@ QBCore.Player.GetTotalWeight = function(items)
return tonumber(weight)
end
QBCore.Player.GetSlotsByItem = function(items, itemName)
function QBCore.Player.GetSlotsByItem(items, itemName)
local slotsFound = {}
if items ~= nil then
if items then
for slot, item in pairs(items) do
if item.name:lower() == itemName:lower() then
table.insert(slotsFound, slot)
@@ -592,8 +594,8 @@ QBCore.Player.GetSlotsByItem = function(items, itemName)
return slotsFound
end
QBCore.Player.GetFirstSlotByItem = function(items, itemName)
if items ~= nil then
function QBCore.Player.GetFirstSlotByItem(items, itemName)
if items then
for slot, item in pairs(items) do
if item.name:lower() == itemName:lower() then
return tonumber(slot)
@@ -603,10 +605,9 @@ QBCore.Player.GetFirstSlotByItem = function(items, itemName)
return nil
end
QBCore.Player.CreateCitizenId = function()
function QBCore.Player.CreateCitizenId()
local UniqueFound = false
local CitizenId = nil
while not UniqueFound do
CitizenId = tostring(QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(5)):upper()
local result = exports.oxmysql:fetchSync('SELECT COUNT(*) as count FROM players WHERE citizenid = ?', { CitizenId })
@@ -617,7 +618,7 @@ QBCore.Player.CreateCitizenId = function()
return CitizenId
end
QBCore.Player.CreateFingerId = function()
function QBCore.Player.CreateFingerId()
local UniqueFound = false
local FingerId = nil
while not UniqueFound do
@@ -631,11 +632,11 @@ QBCore.Player.CreateFingerId = function()
return FingerId
end
QBCore.Player.CreateWalletId = function()
function QBCore.Player.CreateWalletId()
local UniqueFound = false
local WalletId = nil
while not UniqueFound do
WalletId = "QB-"..math.random(11111111, 99999999)
WalletId = 'QB-'..math.random(11111111, 99999999)
local query = '%'..WalletId..'%'
local result = exports.oxmysql:fetchSync('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query })
if result[1].count == 0 then
@@ -645,10 +646,9 @@ QBCore.Player.CreateWalletId = function()
return WalletId
end
QBCore.Player.CreateSerialNumber = function()
function QBCore.Player.CreateSerialNumber()
local UniqueFound = false
local SerialNumber = nil
while not UniqueFound do
SerialNumber = math.random(11111111, 99999999)
local query = '%'..SerialNumber..'%'
@@ -660,4 +660,4 @@ QBCore.Player.CreateSerialNumber = function()
return SerialNumber
end
PaycheckLoop()
PaycheckLoop() -- This just starts the paycheck system