#Armor Saving through player quits and restarts
11 messages · Page 1 of 1 (latest)
Actually qbcore can save armor across quits an restarts without need of another resource.
Just have to add it to metadata
why a json lmao
1.) qb-core/server/player.lua
add this line below PlayerData.metadata = PlayerData.metadata or {}
PlayerData.metadata['health'] = PlayerData.metadata['health'] or 200
2.) qb-core/server/events.lua
search AddEventHandler('playerDropped', function()
`and replace with this
AddEventHandler('playerDropped', function()
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..')
Player.Functions.SetMetaData('health', health)
Player.Functions.SetMetaData('armor', armor)
Player.Functions.Save()
QBCore.Player_Buckets[Player.PlayerData.license] = nil
QBCore.Players[src] = nil
end)`
3.) qb-ambulancejob/client/job.lua
search RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
`and replace with this
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
exports.spawnmanager:setAutoSpawn(false)
local ped = PlayerPedId()
TriggerServerEvent("hospital:server:SetDoctor")
CreateThread(function()
Wait(5000)
-- SetEntityMaxHealth(ped, 200)
-- SetEntityHealth(ped, 200)
SetPlayerHealthRechargeMultiplier(ped, 0.0)
SetPlayerHealthRechargeLimit(ped, 0.0)
end)
CreateThread(function()
Wait(1000)
QBCore.Functions.GetPlayerData(function(PlayerData)
PlayerJob = PlayerData.job
onDuty = PlayerData.job.onduty
SetEntityHealth(PlayerPedId(), PlayerData.metadata["health"])
SetPedArmour(PlayerPedId(), PlayerData.metadata["armor"])
if (not PlayerData.metadata["inlaststand"] and PlayerData.metadata["isdead"]) then
deathTime = Laststand.ReviveInterval
OnDeath()
DeathTimer()
elseif (PlayerData.metadata["inlaststand"] and not PlayerData.metadata["isdead"]) then
SetLaststand(true)
else
TriggerServerEvent("hospital:server:SetDeathStatus", false)
TriggerServerEvent("hospital:server:SetLaststandStatus", false)
end
if PlayerJob.name == 'ambulance' and onDuty then
TriggerServerEvent("hospital:server:AddDoctor", PlayerJob.name)
end
end)
end)
end)`
4.) qb-ambulancejob/server/main.lua
search RegisterNetEvent('hospital:server:SetArmor', function(amount)
and replace with this RegisterNetEvent('hospital:server:SetArmor', function(amount) local src = source local Player = QBCore.Functions.GetPlayer(src) if not Player then return end if amount <= 0 then amount = 0 end Player.Functions.SetMetaData('armor', amount) Player.Functions.Save() end)
Add the following
5.) qb-ambulancejob/server/main.lua
RegisterNetEvent('hospital:server:SetHealth', function(amount) local src = source local Player = QBCore.Functions.GetPlayer(src) if not Player then return end if amount <= 0 then amount = 0 end Player.Functions.SetMetaData('health', amount) Player.Functions.Save() end)
6.) qb-ambulancejob/client/main.lua
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function() local ped = PlayerPedId() TriggerServerEvent("hospital:server:SetDeathStatus", false) TriggerServerEvent('hospital:server:SetLaststandStatus', false) TriggerServerEvent("hospital:server:SetHealth", GetEntityHealth(ped)) TriggerServerEvent("hospital:server:SetArmor", GetPedArmour(ped)) if bedOccupying then TriggerServerEvent("hospital:server:LeaveBed", bedOccupying) end isDead = false deathTime = 0 SetEntityInvincible(ped, false) SetPedArmour(ped, 0) ResetAll() end)
This is not my code, Holiday wrote and published it
im on the new qb and it saves
new qb saves with this or saves anyways?
saves without this
ill just delete my msg since there is a better option here