mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-16 22:46:03 +01:00
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:
committed by
GitHub
parent
753d3eb025
commit
9fbf0222ad
55
resource/cache/client.lua
vendored
55
resource/cache/client.lua
vendored
@@ -29,40 +29,43 @@ local GetCurrentPedWeapon = GetCurrentPedWeapon
|
|||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while true do
|
while true do
|
||||||
local ped = PlayerPedId()
|
local ped = PlayerPedId()
|
||||||
cache:set('ped', ped)
|
|
||||||
|
|
||||||
local vehicle = GetVehiclePedIsIn(ped, false)
|
-- 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)
|
||||||
|
|
||||||
if vehicle > 0 then
|
local vehicle = GetVehiclePedIsIn(ped, false)
|
||||||
if vehicle ~= cache.vehicle then
|
|
||||||
|
if vehicle > 0 then
|
||||||
|
if vehicle ~= cache.vehicle then
|
||||||
|
cache:set('seat', false)
|
||||||
|
end
|
||||||
|
|
||||||
|
cache:set('vehicle', vehicle)
|
||||||
|
|
||||||
|
if not cache.seat or GetPedInVehicleSeat(vehicle, cache.seat) ~= ped then
|
||||||
|
for i = -1, GetVehicleMaxNumberOfPassengers(vehicle) - 1 do
|
||||||
|
if GetPedInVehicleSeat(vehicle, i) == ped then
|
||||||
|
cache:set('seat', i)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
cache:set('vehicle', false)
|
||||||
cache:set('seat', false)
|
cache:set('seat', false)
|
||||||
end
|
end
|
||||||
|
|
||||||
cache:set('vehicle', vehicle)
|
if cache.game == 'redm' then
|
||||||
|
local mount = GetMount(ped)
|
||||||
if not cache.seat or GetPedInVehicleSeat(vehicle, cache.seat) ~= ped then
|
local onMount = IsPedOnMount(ped)
|
||||||
for i = -1, GetVehicleMaxNumberOfPassengers(vehicle) - 1 do
|
cache:set('mount', onMount and mount or false)
|
||||||
if GetPedInVehicleSeat(vehicle, i) == ped then
|
|
||||||
cache:set('seat', i)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
|
||||||
cache:set('vehicle', false)
|
local hasWeapon, currentWeapon = GetCurrentPedWeapon(ped, true)
|
||||||
cache:set('seat', false)
|
cache:set('weapon', (hasWeapon and currentWeapon ~= 0) and currentWeapon or false)
|
||||||
end
|
end
|
||||||
|
|
||||||
if cache.game == 'redm' then
|
|
||||||
local mount = GetMount(ped)
|
|
||||||
local onMount = IsPedOnMount(ped)
|
|
||||||
cache:set('mount', onMount and mount or false)
|
|
||||||
end
|
|
||||||
|
|
||||||
local hasWeapon, currentWeapon = GetCurrentPedWeapon(ped, true)
|
|
||||||
|
|
||||||
cache:set('weapon', hasWeapon and currentWeapon or false)
|
|
||||||
|
|
||||||
Wait(100)
|
Wait(100)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user