Files
community_bridge/lib/cache/client/cache.lua
T

43 lines
1.4 KiB
Lua
Raw Normal View History

2025-05-02 03:11:06 -05:00
Cache = Require("lib/cache/shared/cache.lua")
2025-05-04 19:21:50 -03:00
local PlayerPedId = PlayerPedId
local GetVehiclePedIsIn = GetVehiclePedIsIn
local GetVehicleMaxNumberOfPassengers = GetVehicleMaxNumberOfPassengers
local GetPedInVehicleSeat = GetPedInVehicleSeat
local GetSelectedPedWeapon = GetSelectedPedWeapon
2025-04-23 14:10:19 -05:00
2025-05-04 19:21:50 -03:00
--- Get the vehicle the player is in, if any
---@return integer | nil
2025-05-15 01:48:02 -05:00
function GetVehicle()
2025-08-18 18:32:38 -05:00
local ped = PlayerPedId()
if not ped then return end
2025-04-23 14:10:19 -05:00
return GetVehiclePedIsIn(ped, false)
end
2025-05-04 19:21:50 -03:00
--- Get the seat of the player in the vehicle if the vehicle is occupied
---@return integer | nil
2025-05-15 01:48:02 -05:00
function GetVehicleSeat()
2025-08-18 18:32:38 -05:00
local vehicle = GetVehicle()
2025-04-23 14:10:19 -05:00
if not vehicle then return end
2025-08-18 18:32:38 -05:00
local ped = PlayerPedId()
2025-04-23 14:10:19 -05:00
if not ped then return end
for i = -1, GetVehicleMaxNumberOfPassengers(vehicle) - 1 do
if ped == GetPedInVehicleSeat(vehicle, i) then
return i
end
end
end
2025-05-04 19:21:50 -03:00
--- Get the current weapon of the player
--- @return integer | nil
2025-05-15 01:48:02 -05:00
function GetWeapon()
2025-08-18 18:32:38 -05:00
local ped = PlayerPedId()
2025-04-23 14:10:19 -05:00
if not ped then return end -- Return unarmed hash if no ped
return GetSelectedPedWeapon(ped)
end
2025-08-18 18:32:38 -05:00
Cache.Create("Ped", PlayerPedId, 1000) -- Check ped every second (adjust as needed)
Cache.Create("Vehicle", GetVehicle, 500) -- Check vehicle every 500ms
Cache.Create("Seat", GetVehicleSeat, 500) -- Check if in vehicle every 500ms
2025-05-15 01:48:02 -05:00
Cache.Create("Weapon", GetWeapon , 250) -- Check weapon every 250ms
2025-04-23 14:10:19 -05:00
2025-05-04 19:21:50 -03:00
return Cache