mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-30 01:38:52 +00:00
Death module: fixed killer sometimes not getting found, changed native. Fixes #417
This commit is contained in:
+16
-17
@@ -3,7 +3,6 @@ Citizen.CreateThread(function()
|
||||
|
||||
while true do
|
||||
Citizen.Wait(0)
|
||||
|
||||
local player = PlayerId()
|
||||
|
||||
if NetworkIsPlayerActive(player) then
|
||||
@@ -12,13 +11,13 @@ Citizen.CreateThread(function()
|
||||
if IsPedFatallyInjured(playerPed) and not isDead then
|
||||
isDead = true
|
||||
|
||||
local killer, killerWeapon = NetworkGetEntityKillerOfPlayer(player)
|
||||
local killerServerId = NetworkGetPlayerIndexFromPed(killer)
|
||||
|
||||
if killer ~= playerPed and killerServerId ~= nil and NetworkIsPlayerActive(killerServerId) then
|
||||
PlayerKilledByPlayer(GetPlayerServerId(killerServerId), killerServerId, killerWeapon)
|
||||
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()
|
||||
PlayerKilled(deathCause)
|
||||
end
|
||||
|
||||
elseif not IsPedFatallyInjured(playerPed) then
|
||||
@@ -28,18 +27,18 @@ Citizen.CreateThread(function()
|
||||
end
|
||||
end)
|
||||
|
||||
function PlayerKilledByPlayer(killerServerId, killerClientId, killerWeapon)
|
||||
function PlayerKilledByPlayer(killerServerId, killerClientId, deathCause)
|
||||
local victimCoords = GetEntityCoords(PlayerPedId())
|
||||
local killerCoords = GetEntityCoords(GetPlayerPed(killerClientId))
|
||||
local distance = GetDistanceBetweenCoords(victimCoords, killerCoords, true)
|
||||
local distance = #(victimCoords - killerCoords)
|
||||
|
||||
local data = {
|
||||
victimCoords = { x = ESX.Math.Round(victimCoords.x, 1), y = ESX.Math.Round(victimCoords.y, 1), z = ESX.Math.Round(victimCoords.z, 1) },
|
||||
killerCoords = { x = ESX.Math.Round(killerCoords.x, 1), y = ESX.Math.Round(killerCoords.y, 1), z = ESX.Math.Round(killerCoords.z, 1) },
|
||||
victimCoords = {x = ESX.Math.Round(victimCoords.x, 1), y = ESX.Math.Round(victimCoords.y, 1), z = ESX.Math.Round(victimCoords.z, 1)},
|
||||
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 = killerWeapon,
|
||||
distance = ESX.Math.Round(distance, 1),
|
||||
deathCause = deathCause,
|
||||
distance = ESX.Math.Round(distance, 1),
|
||||
|
||||
killerServerId = killerServerId,
|
||||
killerClientId = killerClientId
|
||||
@@ -49,15 +48,15 @@ function PlayerKilledByPlayer(killerServerId, killerClientId, killerWeapon)
|
||||
TriggerServerEvent('esx:onPlayerDeath', data)
|
||||
end
|
||||
|
||||
function PlayerKilled()
|
||||
function PlayerKilled(deathCause)
|
||||
local playerPed = PlayerPedId()
|
||||
local victimCoords = GetEntityCoords(PlayerPedId())
|
||||
local victimCoords = GetEntityCoords(playerPed)
|
||||
|
||||
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(victimCoords.x, 1), y = ESX.Math.Round(victimCoords.y, 1), z = ESX.Math.Round(victimCoords.z, 1)},
|
||||
|
||||
killedByPlayer = false,
|
||||
deathCause = GetPedCauseOfDeath(playerPed)
|
||||
deathCause = deathCause
|
||||
}
|
||||
|
||||
TriggerEvent('esx:onPlayerDeath', data)
|
||||
|
||||
Reference in New Issue
Block a user