Cache fix on initial load up of server
Issue with cache where it didnt load the default cache (ped, vehicle, seat and weapon) on initial loadup of server This is a pretty critical bug and should be tested and pushed asap
This commit is contained in:
1 parent
01d2f4e1f6
commit
df0dedd46c
2 files changed
+9
-13
No files matched your search
Vendored
+5
-9
@@ -1,5 +1,4 @@
|
|||||||
Cache = Cache or Require("lib/cache/shared/cache.lua")
|
Cache = Require("lib/cache/shared/cache.lua")
|
||||||
|
|
||||||
-- Comparison functions for client-side state
|
-- Comparison functions for client-side state
|
||||||
local function GetPed()
|
local function GetPed()
|
||||||
return PlayerPedId()
|
return PlayerPedId()
|
||||||
@@ -29,12 +28,9 @@ local function GetWeapon()
|
|||||||
return GetSelectedPedWeapon(ped)
|
return GetSelectedPedWeapon(ped)
|
||||||
end
|
end
|
||||||
|
|
||||||
AddEventHandler('onResourceStart', function(resource)
|
Cache.Create("Ped", GetPed, 1000) -- Check ped every second (adjust as needed)
|
||||||
if resource ~= GetCurrentResourceName() then return end
|
Cache.Create("Vehicle", GetVehicle, 500) -- Check vehicle every 500ms
|
||||||
Cache.Create("Ped", GetPed, 1000) -- Check ped every second (adjust as needed)
|
Cache.Create("Seat", GetVehicleSeat, 500) -- Check if in vehicle every 500ms
|
||||||
Cache.Create("Vehicle", GetVehicle, 500) -- Check vehicle every 500ms
|
Cache.Create("Weapon", GetWeapon, 250) -- Check weapon every 250ms
|
||||||
Cache.Create("Seat", GetVehicleSeat, 500) -- Check if in vehicle every 500ms
|
|
||||||
Cache.Create("Weapon", GetWeapon, 250) -- Check weapon every 250ms
|
|
||||||
end)
|
|
||||||
|
|
||||||
return Cache
|
return Cache
|
||||||
Vendored
+4
-4
@@ -1,7 +1,6 @@
|
|||||||
Cache = {}
|
local Cache = {}
|
||||||
Cache.Caches = {}
|
Cache.Caches = Cache.Caches or {}
|
||||||
|
Cache.LoopRunning = Cache.LoopRunning or false
|
||||||
Cache.LoopRunning = false
|
|
||||||
|
|
||||||
local max = 5000
|
local max = 5000
|
||||||
local function StartLoop()
|
local function StartLoop()
|
||||||
@@ -54,6 +53,7 @@ function Cache.Create(name, compare, waitTime)
|
|||||||
for _, onChange in pairs(Cache.Caches[name].OnChange) do
|
for _, onChange in pairs(Cache.Caches[name].OnChange) do
|
||||||
onChange(Cache.Caches[name].Value, nil)
|
onChange(Cache.Caches[name].Value, nil)
|
||||||
end
|
end
|
||||||
|
print("Cache created: " .. name .. " with initial value: " .. tostring(Cache.Caches[name].Value))
|
||||||
return StartLoop()
|
return StartLoop()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user