Skip to content

Commit

Permalink
Merge pull request #1514 from Kenshiin13/refactor-death-module
Browse files Browse the repository at this point in the history
refactor(es_extended/client/modules/death): replace gameEventTriggered
  • Loading branch information
Kenshiin13 authored Dec 3, 2024
2 parents 369a015 + 114c337 commit 50d736f
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions [core]/es_extended/client/modules/death.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Death:ByPlayer()
TriggerServerEvent("esx:onPlayerDeath", data)
end

function Death:Natual()
function Death:Natural()
local coords = GetEntityCoords(ESX.PlayerData.ped)

local data = {
Expand All @@ -43,25 +43,7 @@ function Death:Natual()
TriggerServerEvent("esx:onPlayerDeath", data)
end

function Death:Damaged(victim, victimDied)
if not victimDied then
return
end

if not IsEntityAPed(victim) then
return
end

if not IsPedAPlayer(victim) then
return
end

local victimId = NetworkGetPlayerIndexFromPed(victim)
local isDead = IsPedDeadOrDying(victim, true) or IsPedFatallyInjured(victim)
if victimId ~= ESX.playerId or not isDead then
return
end

function Death:Died()
self.killerEntity = GetPedSourceOfDeath(ESX.PlayerData.ped)
self.deathCause = GetPedCauseOfDeath(ESX.PlayerData.ped)
self.killerId = NetworkGetPlayerIndexFromPed(self.killerEntity)
Expand All @@ -72,15 +54,20 @@ function Death:Damaged(victim, victimDied)
if self.killerEntity ~= ESX.PlayerData.ped and self.killerId and isActive then
self:ByPlayer()
else
self:Natual()
self:Natural()
end

self:ResetValues()
end

AddEventHandler("gameEventTriggered", function(event, data)
if event ~= "CEventNetworkEntityDamage" then
return
end
Death:Damaged(data[1], data[4])
AddEventHandler("esx:onPlayerSpawn", function()
Citizen.CreateThreadNow(function()
while not ESX.PlayerData.dead do
if IsPedDeadOrDying(ESX.PlayerData.ped, true) or IsPedFatallyInjured(ESX.PlayerData.ped) then
Death:Died()
break
end
Citizen.Wait(250)
end
end)
end)

0 comments on commit 50d736f

Please sign in to comment.