mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
refactor(es_extended/client): rewrite death module
This commit is contained in:
@@ -1,27 +1,16 @@
|
||||
AddEventHandler("gameEventTriggered", function(event, data)
|
||||
if event ~= "CEventNetworkEntityDamage" then
|
||||
return
|
||||
end
|
||||
local victim, victimDied = data[1], data[4]
|
||||
if not IsPedAPlayer(victim) then
|
||||
return
|
||||
end
|
||||
local player = ESX.playerId
|
||||
local playerPed = PlayerPedId()
|
||||
if victimDied and NetworkGetPlayerIndexFromPed(victim) == player and (IsPedDeadOrDying(victim, true) or IsPedFatallyInjured(victim)) then
|
||||
local killerEntity, deathCause = GetPedSourceOfDeath(playerPed), GetPedCauseOfDeath(playerPed)
|
||||
local killerClientId = NetworkGetPlayerIndexFromPed(killerEntity)
|
||||
if killerEntity ~= playerPed and killerClientId and NetworkIsPlayerActive(killerClientId) then
|
||||
PlayerKilledByPlayer(GetPlayerServerId(killerClientId), killerClientId, deathCause)
|
||||
else
|
||||
PlayerKilled(deathCause)
|
||||
end
|
||||
end
|
||||
end)
|
||||
Death = {}
|
||||
Death._index = Death
|
||||
|
||||
function PlayerKilledByPlayer(killerServerId, killerClientId, deathCause)
|
||||
local victimCoords = GetEntityCoords(PlayerPedId())
|
||||
local killerCoords = GetEntityCoords(GetPlayerPed(killerClientId))
|
||||
function Death:ResetValues()
|
||||
self.killerEntity = nil
|
||||
self.deathCause = nil
|
||||
self.killerId = nil
|
||||
self.killerServerId = nil
|
||||
end
|
||||
|
||||
function Death:ByPlayer()
|
||||
local victimCoords = GetEntityCoords(ESX.PlayerData.ped)
|
||||
local killerCoords = GetEntityCoords(self.killerEntity)
|
||||
local distance = #(victimCoords - killerCoords)
|
||||
|
||||
local data = {
|
||||
@@ -29,28 +18,61 @@ function PlayerKilledByPlayer(killerServerId, killerClientId, deathCause)
|
||||
killerCoords = { x = ESX.Math.Round(killerCoords.x, 1), y = ESX.Math.Round(killerCoords.y, 1), z = ESX.Math.Round(killerCoords.z, 1) },
|
||||
|
||||
killedByPlayer = true,
|
||||
deathCause = deathCause,
|
||||
deathCause = self.deathCause,
|
||||
distance = ESX.Math.Round(distance, 1),
|
||||
|
||||
killerServerId = killerServerId,
|
||||
killerClientId = killerClientId,
|
||||
killerServerId = self.killerServerId,
|
||||
killerClientId = self.killerId,
|
||||
}
|
||||
|
||||
self:ResetValues()
|
||||
TriggerEvent("esx:onPlayerDeath", data)
|
||||
TriggerServerEvent("esx:onPlayerDeath", data)
|
||||
end
|
||||
|
||||
function PlayerKilled(deathCause)
|
||||
local playerPed = PlayerPedId()
|
||||
local victimCoords = GetEntityCoords(playerPed)
|
||||
function Death:Natual()
|
||||
local coords = GetEntityCoords(ESX.PlayerData.ped)
|
||||
|
||||
local data = {
|
||||
victimCoords = { x = ESX.Math.Round(victimCoords.x, 1), y = ESX.Math.Round(victimCoords.y, 1), z = ESX.Math.Round(victimCoords.z, 1) },
|
||||
victimCoords = { x = ESX.Math.Round(coords.x, 1), y = ESX.Math.Round(coords.y, 1), z = ESX.Math.Round(coords.z, 1) },
|
||||
|
||||
killedByPlayer = false,
|
||||
deathCause = deathCause,
|
||||
deathCause = self.deathCause,
|
||||
}
|
||||
|
||||
self:ResetValues()
|
||||
TriggerEvent("esx:onPlayerDeath", data)
|
||||
TriggerServerEvent("esx:onPlayerDeath", data)
|
||||
end
|
||||
|
||||
function Death:Damaged(victim, victimDied)
|
||||
if not IsPedAPlayer(victim) then
|
||||
return
|
||||
end
|
||||
|
||||
local victimId = NetworkGetPlayerIndexFromPed(victim)
|
||||
local isDead = IsPedDeadOrDying(victim, true) or IsPedFatallyInjured(victim)
|
||||
if not victimDied or victimId ~= ESX.playerId or not isDead then
|
||||
return
|
||||
end
|
||||
|
||||
self.killerEntity = GetPedSourceOfDeath(ESX.PlayerData.ped)
|
||||
self.deathCause = GetPedCauseOfDeath(ESX.PlayerData.ped)
|
||||
self.killerId = NetworkGetPlayerIndexFromPed(self.killerEntity)
|
||||
self.killerServerId = GetPlayerServerId(self.killerId)
|
||||
|
||||
local isActive = NetworkIsPlayerActive(self.killerId)
|
||||
|
||||
if self.killerEntity ~= ESX.PlayerData.ped and self.killerId and isActive then
|
||||
self:ByPlayer()
|
||||
else
|
||||
self:Natual()
|
||||
end
|
||||
end
|
||||
|
||||
AddEventHandler("gameEventTriggered", function(event, data)
|
||||
if event ~= "CEventNetworkEntityDamage" then
|
||||
return
|
||||
end
|
||||
Death:Damaged(data[3], data[4])
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user