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

Feature/health armour #1164

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
18 changes: 17 additions & 1 deletion client/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,26 @@
-- if LocalPlayer.state['isLoggedIn'] then
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
ShutdownLoadingScreenNui()
local pid = PlayerPedId()
LocalPlayer.state:set('isLoggedIn', true, false)
if not QBCore.Config.Server.PVP then return end
SetCanAttackFriendly(PlayerPedId(), true, false)
SetCanAttackFriendly(pid, true, false)
NetworkSetFriendlyFireOption(true)

CreateThread(function ()
Wait(4000) -- Wait for the player to load in properly
local player = PlayerId()
SetEntityMaxHealth(pid, 200)
SetPlayerHealthRechargeMultiplier(player, 0.0)
SetPlayerHealthRechargeLimit(player, 0.0)
if QBConfig.Player.SaveArmor then
SetPedArmour(pid, QBCore.PlayerData.metadata['armor'])
end

if QBConfig.Player.SaveHealth then
SetEntityHealth(pid, QBCore.PlayerData.metadata['health'])
end
end)
end)

RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
Expand Down
3 changes: 3 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ QBConfig.Money.PayCheckTimeOut = 10 -- The time
QBConfig.Money.PayCheckSociety = false -- If true paycheck will come from the society account that the player is employed at, requires qb-management

QBConfig.Player = {}
QBConfig.Player.SaveHealth = true -- Save player health on respawn.
QBConfig.Player.SaveArmor = true -- Save player armor on respawn.
QBConfig.Player.HungerRate = 4.2 -- Rate at which hunger goes down.
QBConfig.Player.ThirstRate = 3.8 -- Rate at which thirst goes down.
QBConfig.Player.Bloodtypes = {
Expand Down Expand Up @@ -67,6 +69,7 @@ QBConfig.Player.PlayerDefaults = {
isdead = false,
inlaststand = false,
armor = 0,
health = 200,
ishandcuffed = false,
tracker = false,
injail = 0,
Expand Down
25 changes: 25 additions & 0 deletions server/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ AddEventHandler('playerDropped', function(reason)
local Player = QBCore.Players[src]
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Dropped', 'red', '**' .. GetPlayerName(src) .. '** (' .. Player.PlayerData.license .. ') left..' .. '\n **Reason:** ' .. reason)
TriggerEvent('QBCore:Server:PlayerDropped', Player)

local ped = GetPlayerPed(src)

if QBConfig.Player.SaveHealth and ped then
local health = GetEntityHealth(ped)
Player.Functions.SetMetaData('health', health)
end

if QBConfig.Player.SaveArmor and ped then
local armour = GetPedArmour(ped)
Player.Functions.SetMetaData('armor', armour)
end

Player.Functions.Save()
QBCore.Player_Buckets[Player.PlayerData.license] = nil
QBCore.Players[src] = nil
Expand Down Expand Up @@ -151,6 +164,7 @@ end)
RegisterNetEvent('QBCore:UpdatePlayer', function()
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local ped = GetPlayerPed(src)
if not Player then return end
local newHunger = Player.PlayerData.metadata['hunger'] - QBCore.Config.Player.HungerRate
local newThirst = Player.PlayerData.metadata['thirst'] - QBCore.Config.Player.ThirstRate
Expand All @@ -162,6 +176,17 @@ RegisterNetEvent('QBCore:UpdatePlayer', function()
end
Player.Functions.SetMetaData('thirst', newThirst)
Player.Functions.SetMetaData('hunger', newHunger)

if QBConfig.Player.SaveHealth and ped then
local health = GetEntityHealth(ped)
Player.Functions.SetMetaData('health', health)
end

if QBConfig.Player.SaveArmor and ped then
local armour = GetPedArmour(ped)
Player.Functions.SetMetaData('armor', armour)
end

TriggerClientEvent('hud:client:UpdateNeeds', src, newHunger, newThirst)
Player.Functions.Save()
end)
Expand Down
Loading