Files
ox_lib/resource/cache/client.lua
T

73 lines
1.7 KiB
Lua
Raw Normal View History

2025-03-18 18:46:09 +11:00
--[[
https://github.com/overextended/ox_lib
This file is licensed under LGPL-3.0 or higher <https://www.gnu.org/licenses/lgpl-3.0.en.html>
2025-03-29 21:44:03 +11:00
Copyright © 2025 Linden <https://github.com/thelindat>
2025-03-18 18:46:09 +11:00
]]
2022-09-14 00:50:27 +10:00
local cache = _ENV.cache
cache.playerId = PlayerId()
cache.serverId = GetPlayerServerId(cache.playerId)
2022-03-01 12:28:04 +00:00
function cache:set(key, value)
if value ~= self[key] then
TriggerEvent(('ox_lib:cache:%s'):format(key), value, self[key])
2022-03-01 12:28:04 +00:00
self[key] = value
2022-03-01 12:28:04 +00:00
return true
end
end
2022-10-28 00:32:18 +11:00
local GetVehiclePedIsIn = GetVehiclePedIsIn
local GetPedInVehicleSeat = GetPedInVehicleSeat
local GetVehicleMaxNumberOfPassengers = GetVehicleMaxNumberOfPassengers
2022-11-25 18:05:55 -08:00
local GetMount = GetMount
local IsPedOnMount = IsPedOnMount
2022-11-08 21:49:51 +01:00
local GetCurrentPedWeapon = GetCurrentPedWeapon
CreateThread(function()
while true do
local ped = PlayerPedId()
cache:set('ped', ped)
2022-10-28 00:32:18 +11:00
local vehicle = GetVehiclePedIsIn(ped, false)
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)
end
2022-11-25 18:05:55 -08:00
if cache.game == 'redm' then
local mount = GetMount(ped)
local onMount = IsPedOnMount(ped)
cache:set('mount', onMount and mount or false)
end
2022-11-08 21:49:51 +01:00
local hasWeapon, currentWeapon = GetCurrentPedWeapon(ped, true)
cache:set('weapon', hasWeapon and currentWeapon or false)
Wait(100)
end
end)
2022-03-01 12:28:04 +00:00
function lib.cache(key)
return cache[key]
end