Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create and save metadata "Health" and "Armor" when disconnecting. #1025

Closed
wants to merge 3 commits into from
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
5 changes: 5 additions & 0 deletions server/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ end)

AddEventHandler('playerDropped', function(reason)
local src = source
local ped = GetPlayerPed(src)
local armor = GetPedArmour(ped)
local health = GetEntityHealth(ped)
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..' ..'\n **Reason:** ' .. reason)
Player.Functions.SetMetaData('health', health)
Player.Functions.SetMetaData('armor', armor)
Player.Functions.Save()
QBCore.Player_Buckets[Player.PlayerData.license] = nil
QBCore.Players[src] = nil
Expand Down
3 changes: 2 additions & 1 deletion server/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ function QBCore.Player.CheckPlayerData(source, PlayerData)
PlayerData.charinfo.account = PlayerData.charinfo.account or QBCore.Functions.CreateAccountNumber()
-- Metadata
PlayerData.metadata = PlayerData.metadata or {}
PlayerData.metadata['health'] = PlayerData.metadata['health'] or 200
PlayerData.metadata['armor'] = PlayerData.metadata['armor'] or 0
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
Expand Down
Loading