refactor: remove endless death check loop

This commit is contained in:
wasabirobby
2022-10-27 00:48:52 -07:00
committed by GitHub
parent a74e470a55
commit 0f458dbd9b
+5 -20
View File
@@ -1,32 +1,17 @@
CreateThread(function() AddEventHandler('gameEventTriggered', function(event, data)
local isDead = false if event ~= 'CEventNetworkEntityDamage' then return end
local victim, victimDied = data[1], data[4]
while true do if not IsPedAPlayer(victim) then return end
local sleep = 1500
local player = PlayerId() local player = PlayerId()
if NetworkIsPlayerActive(player) then
local playerPed = PlayerPedId() local playerPed = PlayerPedId()
if victimDied and NetworkGetPlayerIndexFromPed(victim) == player and IsPedDeadOrDying(victim, true) then
if IsPedFatallyInjured(playerPed) and not isDead then
sleep = 0
isDead = true
local killerEntity, deathCause = GetPedSourceOfDeath(playerPed), GetPedCauseOfDeath(playerPed) local killerEntity, deathCause = GetPedSourceOfDeath(playerPed), GetPedCauseOfDeath(playerPed)
local killerClientId = NetworkGetPlayerIndexFromPed(killerEntity) local killerClientId = NetworkGetPlayerIndexFromPed(killerEntity)
if killerEntity ~= playerPed and killerClientId and NetworkIsPlayerActive(killerClientId) then if killerEntity ~= playerPed and killerClientId and NetworkIsPlayerActive(killerClientId) then
PlayerKilledByPlayer(GetPlayerServerId(killerClientId), killerClientId, deathCause) PlayerKilledByPlayer(GetPlayerServerId(killerClientId), killerClientId, deathCause)
else else
PlayerKilled(deathCause) PlayerKilled(deathCause)
end end
elseif not IsPedFatallyInjured(playerPed) and isDead then
sleep = 0
isDead = false
end
end
Wait(sleep)
end end
end) end)