Skip to content
Closed
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
15 changes: 15 additions & 0 deletions client/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
ShutdownLoadingScreenNui()
LocalPlayer.state:set('isLoggedIn', true, false)

-- Restore saved health and armor after ped is ready
CreateThread(function()
Wait(1000) -- Wait for ped to be fully spawned
local ped = PlayerPedId()
Comment on lines 4 to +11
local health = QBCore.PlayerData.metadata['health']
local armor = QBCore.PlayerData.metadata['armor']
if health and health > 0 then
SetEntityHealth(ped, health)
Comment on lines +14 to +15
end
if armor and armor > 0 then
SetPedArmour(ped, armor)
end
end)

if not QBCore.Config.Server.PVP then return end
SetCanAttackFriendly(PlayerPedId(), true, false)
NetworkSetFriendlyFireOption(true)
Expand Down
5 changes: 4 additions & 1 deletion client/loops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ CreateThread(function()
local sleep = 1000
if LocalPlayer.state.isLoggedIn then
sleep = (1000 * 60) * QBCore.Config.UpdateInterval
TriggerServerEvent('QBCore:UpdatePlayer')
local ped = PlayerPedId()
local health = GetEntityHealth(ped)
local armor = GetPedArmour(ped)
TriggerServerEvent('QBCore:UpdatePlayer', health, armor)
end
Wait(sleep)
end
Expand Down
1 change: 1 addition & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ QBConfig.Player.PlayerDefaults = {
isdead = false,
inlaststand = false,
armor = 0,
health = 200,
ishandcuffed = false,
tracker = false,
injail = 0,
Expand Down
13 changes: 12 additions & 1 deletion server/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ AddEventHandler('playerDropped', function(reason)
local src = source
if not QBCore.Players[src] then return end
local Player = QBCore.Players[src]
local ped = GetPlayerPed(src)
if ped and DoesEntityExist(ped) then
Player.Functions.SetMetaData('health', GetEntityHealth(ped))
Player.Functions.SetMetaData('armor', GetPedArmour(ped))
end
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()
Expand Down Expand Up @@ -149,7 +154,7 @@ end)

-- Player

RegisterNetEvent('QBCore:UpdatePlayer', function()
RegisterNetEvent('QBCore:UpdatePlayer', function(health, armor)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
Comment on lines +157 to 160
Expand All @@ -163,6 +168,12 @@ RegisterNetEvent('QBCore:UpdatePlayer', function()
end
Player.Functions.SetMetaData('thirst', newThirst)
Player.Functions.SetMetaData('hunger', newHunger)
if health then
Player.Functions.SetMetaData('health', health)
end
if armor then
Player.Functions.SetMetaData('armor', armor)
end
Comment on lines +171 to +176
TriggerClientEvent('hud:client:UpdateNeeds', src, newHunger, newThirst)
Player.Functions.Save()
end)
Expand Down
Loading