Merge branch 'main' of https://github.com/JericoFX/community_bridge
This commit is contained in:
commit
0dff8bd7bd
3 files changed
+106
-29
No files matched your search
Vendored
+32
-5
@@ -1,15 +1,31 @@
|
|||||||
Cache = Require("lib/cache/shared/cache.lua")
|
Cache = Require("lib/cache/shared/cache.lua")
|
||||||
|
local PlayerPedId = PlayerPedId
|
||||||
|
local GetVehiclePedIsIn = GetVehiclePedIsIn
|
||||||
|
local GetVehicleMaxNumberOfPassengers = GetVehicleMaxNumberOfPassengers
|
||||||
|
local GetPedInVehicleSeat = GetPedInVehicleSeat
|
||||||
|
local GetPlayerServerId = GetPlayerServerId
|
||||||
|
local GetSelectedPedWeapon = GetSelectedPedWeapon
|
||||||
|
local PlayerId = PlayerId
|
||||||
|
|
||||||
|
|
||||||
-- Comparison functions for client-side state
|
-- Comparison functions for client-side state
|
||||||
|
|
||||||
|
--- Get the player's ped ID
|
||||||
|
---@return integer
|
||||||
local function GetPed()
|
local function GetPed()
|
||||||
return PlayerPedId()
|
return PlayerPedId()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Get the vehicle the player is in, if any
|
||||||
|
---@return integer | nil
|
||||||
local function GetVehicle()
|
local function GetVehicle()
|
||||||
local ped = Cache.Get("Ped") -- Use cached ped for efficiency
|
local ped = Cache.Get("Ped") -- Use cached ped for efficiency
|
||||||
if not ped then return end -- Or handle error/default case
|
if not ped then return end -- Or handle error/default case
|
||||||
return GetVehiclePedIsIn(ped, false)
|
return GetVehiclePedIsIn(ped, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Get the seat of the player in the vehicle if the vehicle is occupied
|
||||||
|
---@return integer | nil
|
||||||
local function GetVehicleSeat()
|
local function GetVehicleSeat()
|
||||||
local vehicle = Cache.Get("Vehicle")
|
local vehicle = Cache.Get("Vehicle")
|
||||||
if not vehicle then return end
|
if not vehicle then return end
|
||||||
@@ -22,15 +38,26 @@ local function GetVehicleSeat()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Get The Server ID of the player
|
||||||
|
---@return integer | nil
|
||||||
|
local function GetServerId()
|
||||||
|
local ped <const> = PlayerId()
|
||||||
|
if not ped then return end -- Return unarmed hash if no ped
|
||||||
|
return GetPlayerServerId(ped)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Get the current weapon of the player
|
||||||
|
--- @return integer | nil
|
||||||
local function GetWeapon()
|
local function GetWeapon()
|
||||||
local ped = Cache.Get("Ped")
|
local ped = Cache.Get("Ped")
|
||||||
if not ped then return end -- Return unarmed hash if no ped
|
if not ped then return end -- Return unarmed hash if no ped
|
||||||
return GetSelectedPedWeapon(ped)
|
return GetSelectedPedWeapon(ped)
|
||||||
end
|
end
|
||||||
|
|
||||||
Cache.Create("Ped", GetPed, 1000) -- Check ped every second (adjust as needed)
|
Cache.Create("Ped", GetPed, 1000) -- Check ped every second (adjust as needed)
|
||||||
Cache.Create("Vehicle", GetVehicle, 500) -- Check vehicle every 500ms
|
Cache.Create("Vehicle", GetVehicle, 500) -- Check vehicle every 500ms
|
||||||
Cache.Create("Seat", GetVehicleSeat, 500) -- Check if in vehicle every 500ms
|
Cache.Create("Seat", GetVehicleSeat, 500) -- Check if in vehicle every 500ms
|
||||||
Cache.Create("Weapon", GetWeapon, 250) -- Check weapon every 250ms
|
Cache.Create("Weapon", GetWeapon, 250) -- Check weapon every 250ms
|
||||||
|
Cache.Create("ServerId", GetServerId, 1000) -- Check server ID every second
|
||||||
|
|
||||||
return Cache
|
return Cache
|
||||||
Vendored
+63
-16
@@ -1,8 +1,20 @@
|
|||||||
local Cache = {}
|
local Cache = {}
|
||||||
|
local Config = require("lib/settings/clientConfig.lua")
|
||||||
|
local max = 5000
|
||||||
|
local CreateThread = CreateThread
|
||||||
|
local Wait = Wait
|
||||||
|
local GetGameTimer = GetGameTimer
|
||||||
|
|
||||||
|
|
||||||
Cache.Caches = Cache.Caches or {}
|
Cache.Caches = Cache.Caches or {}
|
||||||
Cache.LoopRunning = Cache.LoopRunning or false
|
Cache.LoopRunning = Cache.LoopRunning or false
|
||||||
|
|
||||||
local max = 5000
|
local function print(...)
|
||||||
|
if Config.Debug then
|
||||||
|
print("^2[Cache]^0", ...)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function StartLoop()
|
local function StartLoop()
|
||||||
if Cache.LoopRunning then return end
|
if Cache.LoopRunning then return end
|
||||||
Cache.LoopRunning = true
|
Cache.LoopRunning = true
|
||||||
@@ -44,30 +56,65 @@ local function StartLoop()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Cache.Create(name, compare, waitTime)
|
function Cache.Create(name, compare, waitTime)
|
||||||
Cache.Caches[name] = Cache.Caches[name] or {}
|
assert(name, "Cache name is required.")
|
||||||
Cache.Caches[name].WaitTime = waitTime or max
|
assert(compare, "Comparison function is required.")
|
||||||
Cache.Caches[name].Compare = compare
|
assert(type(compare) == "function", "Comparison function must be a function.")
|
||||||
Cache.Caches[name].OnChange = Cache.Caches[name].OnChange or {}
|
local _name = tostring(name) -- Ensure name is a string
|
||||||
Cache.Caches[name].Value = compare()
|
local cache = Cache.Caches[_name]
|
||||||
print("Cache created: " .. name .. " with initial value: " .. tostring(Cache.Caches[name].Value))
|
if cache and cache.Compare == compare then
|
||||||
for _, onChange in pairs(Cache.Caches[name].OnChange) do
|
print(name .. " already exists with the same comparison function.")
|
||||||
onChange(Cache.Caches[name].Value, nil)
|
return cache
|
||||||
end
|
end
|
||||||
print("Cache created: " .. name .. " with initial value: " .. tostring(Cache.Caches[name].Value))
|
cache = nil -- clean variable, so we can use the same name for the new cache
|
||||||
|
local s, r = pcall(function() -- Try to create the cache and catch any errors
|
||||||
|
local _cache <const> = {
|
||||||
|
Name = _name,
|
||||||
|
Compare = compare,
|
||||||
|
WaitTime = waitTime or max,
|
||||||
|
LastChecked = nil,
|
||||||
|
OnChange = {},
|
||||||
|
Value = compare()
|
||||||
|
}
|
||||||
|
Cache.Caches[_name] = _cache
|
||||||
|
print(_name .. " created with initial value: " .. tostring(Cache.Caches[_name].Value))
|
||||||
|
for _, onChange in pairs(_cache.OnChange) do
|
||||||
|
onChange(_cache.Value, nil)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
if not s then
|
||||||
|
print("Error creating cache '" .. _name .. "': " .. tostring(r))
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
return StartLoop()
|
return StartLoop()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Cache.Get(name)
|
function Cache.Get(name)
|
||||||
local cache = Cache.Caches[name]
|
assert(name, "Cache name is required.")
|
||||||
|
local _name = tostring(name)
|
||||||
|
local cache = Cache.Caches[_name]
|
||||||
return cache and cache.Value or nil
|
return cache and cache.Value or nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function Cache.OnChange(name, onChange)
|
function Cache.OnChange(name, onChange)
|
||||||
local cache = Cache.Caches[name]
|
assert(name, "Cache name is required.")
|
||||||
assert(cache, "Cache with name '" .. name .. "' does not exist.")
|
local _name = tostring(name) -- Ensure name is a string
|
||||||
table.insert(cache.OnChange, onChange)
|
local cache = Cache.Caches[_name]
|
||||||
|
assert(cache, "Cache with name '" .. _name .. "' does not exist.")
|
||||||
|
cache.OnChange[#cache.OnChange + 1] = onChange
|
||||||
|
end
|
||||||
|
|
||||||
|
function Cache.Remove(name)
|
||||||
|
assert(name, "Cache name is required.")
|
||||||
|
local _name = tostring(name) -- Ensure name is a string
|
||||||
|
local cache = Cache.Caches[_name]
|
||||||
|
if cache then
|
||||||
|
Cache.Caches[_name] = nil
|
||||||
|
print(_name .. " removed from cache.")
|
||||||
|
if next(Cache.Caches) == nil then
|
||||||
|
Cache.LoopRunning = false -- Stop the loop if no caches are left
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return Cache
|
return Cache
|
||||||
|
|
||||||
|
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
BridgeClientConfig = {}
|
BridgeClientConfig = {}
|
||||||
BridgeClientConfig.InputSystem = "auto" -- [ auto | ox_lib | qb-input ]
|
BridgeClientConfig.InputSystem = "auto" -- [ auto | ox_lib | qb-input ]
|
||||||
BridgeClientConfig.MenuSystem = "auto" -- [ auto | ox_lib | qb-menu ]
|
BridgeClientConfig.MenuSystem = "auto" -- [ auto | ox_lib | qb-menu ]
|
||||||
BridgeClientConfig.ProgressBarSystem = "auto" -- [ auto | ox_lib | progressbar ]
|
BridgeClientConfig.ProgressBarSystem = "auto" -- [ auto | ox_lib | progressbar ]
|
||||||
BridgeClientConfig.VehicleKey = "auto" -- [ auto | qb-vehiclekeys | MrNewbVehicleKeys | jaksams_VehiclesKeys | wasabi_carlock | mk_vehiclekeys | qbx_vehiclekeys | qs-vehiclekeys | t1ger_keys | Renewed-Vehiclekeys | mono_carkeys| cd_garage | okokGarage | F_RealCarKeysSystem
|
BridgeClientConfig.VehicleKey =
|
||||||
BridgeClientConfig.Fuel = "auto" -- [ auto | LegacyFuel | ox_fuel | ps-fuel | qs-fuelstations | Renewed-Fuel | ti_fuel | lc_fuel | x-fuel | cdn-fuel | esx-sna-fuel | BigDaddy-Fuel | okokGasStation ]
|
"auto" -- [ auto | qb-vehiclekeys | MrNewbVehicleKeys | jaksams_VehiclesKeys | wasabi_carlock | mk_vehiclekeys | qbx_vehiclekeys | qs-vehiclekeys | t1ger_keys | Renewed-Vehiclekeys | mono_carkeys| cd_garage | okokGarage | F_RealCarKeysSystem
|
||||||
BridgeClientConfig.TargetSystem = "auto" -- [ auto | ox_target | qb-target | sleepless_interact ] -- sleepless is only partially supported and would need another system in place
|
BridgeClientConfig.Fuel =
|
||||||
|
"auto" -- [ auto | LegacyFuel | ox_fuel | ps-fuel | qs-fuelstations | Renewed-Fuel | ti_fuel | lc_fuel | x-fuel | cdn-fuel | esx-sna-fuel | BigDaddy-Fuel | okokGasStation ]
|
||||||
|
BridgeClientConfig.TargetSystem =
|
||||||
|
"auto" -- [ auto | ox_target | qb-target | sleepless_interact ] -- sleepless is only partially supported and would need another system in place
|
||||||
|
BridgeClientConfig.Debug = false
|
||||||
return BridgeClientConfig
|
return BridgeClientConfig
|
||||||
Reference in new issue
Block a user