Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions client/events.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local lastStatsLoaded = false

-- Player load and unload handling
-- New method for checking if logged in across all scripts (optional)
-- if LocalPlayer.state['isLoggedIn'] then
Expand All @@ -10,7 +12,18 @@ RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
end)

RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
if not LocalPlayer.state.isLoggedIn then return end
LocalPlayer.state:set('isLoggedIn', false, false)
lastStatsLoaded = false
end)

RegisterNetEvent('QBCore:Client:LoadLastStats', function(data)
if not QBConfig.Player.KeepLastHealthArmor then return end
if lastStatsLoaded then return end -- Prevents loading multiple times (We are making this event more secure for cheaters)
local ped = PlayerPedId()
SetEntityHealth(ped, data.health)
SetPedArmour(ped, data.armor)
lastStatsLoaded = true
end)

RegisterNetEvent('QBCore:Client:PvpHasToggled', function(pvp_state)
Expand Down
4 changes: 3 additions & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ QBConfig.StatusInterval = 5000 -- how often to check hu
QBConfig.Money = {}
QBConfig.Money.MoneyTypes = { cash = 500, bank = 5000, crypto = 0 } -- type = startamount - Add or remove money types for your server (for ex. blackmoney = 0), remember once added it will not be removed from the database!
QBConfig.Money.DontAllowMinus = { 'cash', 'crypto' } -- Money that is not allowed going in minus
QBConfig.Money.MinusLimit = -5000 -- The maximum amount you can be negative
QBConfig.Money.MinusLimit = -5000 -- The maximum amount you can be negative
QBConfig.Money.PayCheckTimeOut = 10 -- The time in minutes that it will give the paycheck
QBConfig.Money.PayCheckSociety = false -- If true paycheck will come from the society account that the player is employed at, requires qb-management

Expand All @@ -18,6 +18,7 @@ QBConfig.Player.ThirstRate = 3.8 -- Rate at which thirst goes down.
QBConfig.Player.Bloodtypes = {
'A+', 'A-', 'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-',
}
QBConfig.Player.KeepLastHealthArmor = true -- If true, restores the player's last saved health and armor values when they join the game.

QBConfig.Player.PlayerDefaults = {
citizenid = function() return QBCore.Player.CreateCitizenId() end,
Expand Down Expand Up @@ -67,6 +68,7 @@ QBConfig.Player.PlayerDefaults = {
isdead = false,
inlaststand = false,
armor = 0,
health = 200,
ishandcuffed = false,
tracker = false,
injail = 0,
Expand Down
13 changes: 11 additions & 2 deletions server/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@ end)
AddEventHandler('playerDropped', function(reason)
local src = source
if not QBCore.Players[src] then return end

local Player = QBCore.Players[src]
local playerPed = GetPlayerPed(src)
local playerCoords = GetEntityCoords(playerPed)

QBCore.Players[src].metadata.armor = GetPedArmour(playerPed)
QBCore.Players[src].metadata.health = GetEntityHealth(playerPed)
QBCore.Players[src].position = vector4(playerCoords.x, playerCoords.y, playerCoords.z, GetEntityHeading(playerPed))

TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Dropped', 'red', '**' .. GetPlayerName(src) .. '** (' .. Player.PlayerData.license .. ') left..' .. '\n **Reason:** ' .. reason)
TriggerEvent('QBCore:Server:PlayerDropped', Player)

Player.Functions.Save()
QBCore.Player_Buckets[Player.PlayerData.license] = nil
QBCore.Players[src] = nil
end)

AddEventHandler("onResourceStop", function(resName)
for i,v in pairs(QBCore.UsableItems) do
for i, v in pairs(QBCore.UsableItems) do
if v.resource == resName then
QBCore.UsableItems[i] = nil
end
Expand All @@ -36,7 +45,7 @@ if readyFunction ~= nil then
local DatabaseInfo = QBCore.Functions.GetDatabaseInfo()
if not DatabaseInfo or not DatabaseInfo.exists then return end

local result = MySQL.query.await('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME = "bans";', {DatabaseInfo.database})
local result = MySQL.query.await('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME = "bans";', { DatabaseInfo.database })
if result and result[1] then
bansTableExists = true
end
Expand Down
10 changes: 7 additions & 3 deletions server/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ function QBCore.Player.CreatePlayer(PlayerData, Offline)
QBCore.Players[self.PlayerData.source] = self
QBCore.Player.Save(self.PlayerData.source)
TriggerEvent('QBCore:Server:PlayerLoaded', self)
if QBConfig.Player.KeepLastHealthArmor then
TriggerClientEvent('QBCore:Client:LoadLastStats', self.PlayerData.source, {
health = self.PlayerData.metadata.health,
armor = self.PlayerData.metadata.armor
})
end
self.Functions.UpdatePlayerData()
end
end
Expand Down Expand Up @@ -483,8 +489,6 @@ end
-- Save player info to database (make sure citizenid is the primary key in your database)

function QBCore.Player.Save(source)
local ped = GetPlayerPed(source)
local pcoords = GetEntityCoords(ped)
local PlayerData = QBCore.Players[source].PlayerData
if PlayerData then
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', {
Expand All @@ -496,7 +500,7 @@ function QBCore.Player.Save(source)
charinfo = json.encode(PlayerData.charinfo),
job = json.encode(PlayerData.job),
gang = json.encode(PlayerData.gang),
position = json.encode(pcoords),
position = json.encode(PlayerData.position),
metadata = json.encode(PlayerData.metadata)
})
if GetResourceState('qb-inventory') ~= 'missing' then exports['qb-inventory']:SaveInventory(source) end
Expand Down