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

refactor: combined inLaststand & isDead into a DeathState enum #49

Merged
merged 1 commit into from
Nov 22, 2023
Merged
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
2 changes: 1 addition & 1 deletion client/damage/damage-effects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ end
---applies disabling status effects based on injuries to specific body parts
function ApplyDamageEffects()
local ped = cache.ped
if IsDead or InLaststand then return end
if DeathState ~= Config.DeathState.ALIVE then return end
for bodyPartKey, severity in pairs(Injuries) do
if isLegDamaged(bodyPartKey, severity) then
if legCount >= Config.LegInjuryTimer then
Expand Down
2 changes: 1 addition & 1 deletion client/damage/damage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ local function checkDamage(ped, boneId, weapon, damageDone)
if not weapon then return end

local bodyPartKey = Config.Bones[boneId]
if not bodyPartKey or IsDead or InLaststand then return end
if not bodyPartKey or DeathState ~= Config.DeathState.ALIVE then return end

applyImmediateEffects(ped, bodyPartKey, weapon, damageDone)
injureBodyPart(bodyPartKey)
Expand Down
10 changes: 5 additions & 5 deletions client/dead.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ exports('playDeadAnimation', playDeadAnimation)

---put player in death animation and make invincible
function OnDeath()
if IsDead then return end
IsDead = true
if DeathState == Config.DeathState.DEAD then return end
DeathState = Config.DeathState.DEAD
TriggerServerEvent('qbx_medical:server:playerDied')
TriggerServerEvent("InteractSound_SV:PlayOnSource", "demo", 0.1)
local player = cache.ped
Expand Down Expand Up @@ -51,7 +51,7 @@ end
function AllowRespawn()
allowRespawn = true
RespawnHoldTime = 5
while IsDead do
while DeathState == Config.DeathState.DEAD do
Wait(1000)
DeathTime -= 1
if DeathTime <= 0 then
Expand Down Expand Up @@ -98,9 +98,9 @@ AddEventHandler('gameEventTriggered', function(event, data)
if event ~= "CEventNetworkEntityDamage" then return end
local victim, attacker, victimDied, weapon = data[1], data[2], data[4], data[7]
if not IsEntityAPed(victim) or not victimDied or NetworkGetPlayerIndexFromPed(victim) ~= cache.playerId or not IsEntityDead(cache.ped) then return end
if not InLaststand then
if DeathState ~= Config.DeathState.LAST_STAND then
StartLastStand()
elseif not IsDead then
elseif DeathState ~= Config.DeathState.DEAD then
EndLastStand()
logDeath(victim, attacker, weapon)
DeathTime = 0
Expand Down
5 changes: 2 additions & 3 deletions client/laststand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ end
function EndLastStand()
local ped = cache.ped
TaskPlayAnim(ped, LastStandDict, "exit", 1.0, 8.0, -1, 1, -1, false, false, false)
InLaststand = false
LaststandTime = 0
TriggerServerEvent('qbx_medical:server:onPlayerLaststandEnd')
end
Expand Down Expand Up @@ -75,10 +74,10 @@ function StartLastStand()
ResurrectPlayer()
SetEntityHealth(ped, 150)
PlayUnescortedLastStandAnimation()
InLaststand = true
DeathState = Config.DeathState.LAST_STAND
TriggerServerEvent('qbx_medical:server:onPlayerLaststand')
CreateThread(function()
while InLaststand do
while DeathState == Config.DeathState.LAST_STAND do
countdownLastStand()
end
end)
Expand Down
20 changes: 10 additions & 10 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ FadeOutTimer, BlackoutTimer = 0, 0
---@type number
Hp = nil

IsDead = false
InLaststand = false
DeathState = Config.DeathState.ALIVE

DeathTime = 0
LaststandTime = 0
RespawnHoldTime = 5
Expand All @@ -59,19 +59,19 @@ exports('setHp', function(hp)
end)

exports('isDead', function()
return IsDead
return DeathState == Config.DeathState.DEAD
end)

exports('setIsDeadDeprecated', function(isDead)
IsDead = isDead
DeathState = isDead and Config.DeathState.DEAD or Config.DeathState.ALIVE
end)

exports('getLaststand', function()
return InLaststand
return DeathState == Config.DeathState.LAST_STAND
end)

exports('setLaststand', function(inLaststand)
InLaststand = inLaststand
DeathState = inLaststand and Config.DeathState.LAST_STAND or Config.DeathState.ALIVE
end)

exports('getDeathTime', function()
Expand Down Expand Up @@ -110,7 +110,7 @@ end

---notify the player of damage to their body.
local function doLimbAlert()
if IsDead or InLaststand or NumInjuries == 0 then return end
if DeathState ~= Config.DeathState.ALIVE or NumInjuries == 0 then return end

local limbDamageMsg = ''
if NumInjuries <= Config.AlertShowInfo then
Expand Down Expand Up @@ -182,7 +182,7 @@ end

---notify the player of bleeding to their body.
function SendBleedAlert()
if IsDead or BleedLevel == 0 then return end
if DeathState == Config.DeathState.DEAD or BleedLevel == 0 then return end
exports.qbx_core:Notify(Lang:t('info.bleed_alert', {bleedstate = Config.BleedingStates[BleedLevel]}), 'inform')
end

Expand Down Expand Up @@ -241,10 +241,10 @@ RegisterNetEvent('qbx_medical:client:playerRevived', function()
if source then return end
local ped = cache.ped

if IsDead or InLaststand then
if DeathState ~= Config.DeathState.ALIVE then
local pos = GetEntityCoords(ped, true)
NetworkResurrectLocalPlayer(pos.x, pos.y, pos.z, GetEntityHeading(ped), true, false)
IsDead = false
DeathState = Config.DeathState.ALIVE
SetEntityInvincible(ped, false)
EndLastStand()
end
Expand Down
2 changes: 1 addition & 1 deletion client/wounding.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ end
exports('removeBleed', removeBleed)

local function handleBleeding()
if IsDead or InLaststand or BleedLevel <= 0 then return end
if DeathState ~= Config.DeathState.ALIVE or BleedLevel <= 0 then return end
if FadeOutTimer + 1 == Config.FadeOutTimer then
if BlackoutTimer + 1 == Config.BlackoutTimer then
makePlayerBlackout()
Expand Down
9 changes: 8 additions & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,11 @@ Config.Weapons = { -- Correspond weapon names to their class number
[`WEAPON_EXHAUSTION`] = Config.WeaponClasses.SUFFOCATING, -- Exhaust
[`WEAPON_BZGAS`] = Config.WeaponClasses.SUFFOCATING,
[`WEAPON_SMOKEGRENADE`] = Config.WeaponClasses.SUFFOCATING,
}
}

---@enum DeathState
Config.DeathState = {
ALIVE = 1,
LAST_STAND = 2,
DEAD = 3,
}
Loading