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

Load metadata "Health" and "Armor" when connecting. #316

Closed
wants to merge 1 commit 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: 2 additions & 3 deletions client/job.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
local player = PlayerId()
CreateThread(function()
Wait(5000)
SetEntityMaxHealth(ped, 200)
SetEntityHealth(ped, 200)
SetPlayerHealthRechargeMultiplier(player, 0.0)
SetPlayerHealthRechargeLimit(player, 0.0)
end)
Expand All @@ -108,7 +106,8 @@ RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
QBCore.Functions.GetPlayerData(function(PlayerData)
PlayerJob = PlayerData.job
onDuty = PlayerData.job.onduty
SetPedArmour(PlayerPedId(), PlayerData.metadata["armor"])
SetEntityHealth(ped, PlayerData.metadata["health"])
SetPedArmour(ped, PlayerData.metadata["armor"])
if (not PlayerData.metadata["inlaststand"] and PlayerData.metadata["isdead"]) then
deathTime = Config.ReviveInterval
OnDeath()
Expand Down
1 change: 1 addition & 0 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ 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)
Expand Down
20 changes: 17 additions & 3 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,23 @@ end)
RegisterNetEvent('hospital:server:SetArmor', function(amount)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if Player then
Player.Functions.SetMetaData("armor", amount)
end
if not Player then return end
if amount <= 0 then
amount = 0
end
Player.Functions.SetMetaData('armor', amount)
Player.Functions.Save()
end)

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)

RegisterNetEvent('hospital:server:TreatWounds', function(playerId)
Expand Down
Loading