refactor: Optimize death module

This commit is contained in:
MiddleSkillz
2021-05-06 02:21:31 -06:00
parent 7f4f4d14e0
commit 4cd90dc1d8
2 changed files with 16 additions and 12 deletions
+8 -10
View File
@@ -405,17 +405,15 @@ function StartServerSyncLoops()
end)
end
Citizen.CreateThread(function()
while Config.EnableDefaultInventory do
Citizen.Wait(9)
if IsControlJustReleased(0, 289) then
if IsInputDisabled(0) and not isDead and not ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then
ESX.ShowInventory()
end
if Config.EnableDefaultInventory then
RegisterCommand('showinv', function()
if not isDead and not ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then
ESX.ShowInventory()
end
end
end)
end)
RegisterKeyMapping('showinv', _U('keymap_showinventory'), 'keyboard', 'F2')
end
Citizen.CreateThread(function()
while true do
+8 -2
View File
@@ -2,13 +2,15 @@ Citizen.CreateThread(function()
local isDead = false
while true do
Citizen.Wait(150)
Citizen.Wait(0)
local letSleep = 0
local player = PlayerId()
if NetworkIsPlayerActive(player) then
local playerPed = PlayerPedId()
if IsPedFatallyInjured(playerPed) and not isDead then
letSleep = false
isDead = true
local killerEntity, deathCause = GetPedSourceOfDeath(playerPed), GetPedCauseOfDeath(playerPed)
@@ -20,10 +22,14 @@ Citizen.CreateThread(function()
PlayerKilled(deathCause)
end
elseif not IsPedFatallyInjured(playerPed) then
elseif not IsPedFatallyInjured(playerPed) and isDead then
letSleep = false
isDead = false
end
end
if letSleep then
Citizen.Wait(500)
end
end
end)