fix(resource/cache): skip cache updates during ped transitions (#28)

also fixes an issue with cache not being set correctly when weapon hash is a negative number
This commit is contained in:
Mustafa Burak Güneş
2025-07-09 19:59:19 +03:00
committed by GitHub
parent 753d3eb025
commit 9fbf0222ad

View File

@@ -29,6 +29,9 @@ local GetCurrentPedWeapon = GetCurrentPedWeapon
CreateThread(function() CreateThread(function()
while true do while true do
local ped = PlayerPedId() local ped = PlayerPedId()
-- If the player's ped is changed, the ped value may return 0 during the transition. If the value is 0, skip all checks.
if ped ~= 0 then
cache:set('ped', ped) cache:set('ped', ped)
local vehicle = GetVehiclePedIsIn(ped, false) local vehicle = GetVehiclePedIsIn(ped, false)
@@ -60,8 +63,8 @@ CreateThread(function()
end end
local hasWeapon, currentWeapon = GetCurrentPedWeapon(ped, true) local hasWeapon, currentWeapon = GetCurrentPedWeapon(ped, true)
cache:set('weapon', (hasWeapon and currentWeapon ~= 0) and currentWeapon or false)
cache:set('weapon', hasWeapon and currentWeapon or false) end
Wait(100) Wait(100)
end end