Community Feedback on cache
serverid in cache is pointless and will never change unit tests are not actually unit tests so i renamed to examples.
This commit is contained in:
1 parent
fd28d9a1a6
commit
cdeba0652d
8 files changed
+9
-28
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Vendored
+6
-26
@@ -3,33 +3,22 @@ local PlayerPedId = PlayerPedId
|
|||||||
local GetVehiclePedIsIn = GetVehiclePedIsIn
|
local GetVehiclePedIsIn = GetVehiclePedIsIn
|
||||||
local GetVehicleMaxNumberOfPassengers = GetVehicleMaxNumberOfPassengers
|
local GetVehicleMaxNumberOfPassengers = GetVehicleMaxNumberOfPassengers
|
||||||
local GetPedInVehicleSeat = GetPedInVehicleSeat
|
local GetPedInVehicleSeat = GetPedInVehicleSeat
|
||||||
local GetPlayerServerId = GetPlayerServerId
|
|
||||||
local GetSelectedPedWeapon = GetSelectedPedWeapon
|
local GetSelectedPedWeapon = GetSelectedPedWeapon
|
||||||
local PlayerId = PlayerId
|
|
||||||
|
|
||||||
|
|
||||||
-- Comparison functions for client-side state
|
|
||||||
|
|
||||||
--- Get the player's ped ID
|
|
||||||
---@return integer
|
|
||||||
function GetPed()
|
|
||||||
return PlayerPedId()
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Get the vehicle the player is in, if any
|
--- Get the vehicle the player is in, if any
|
||||||
---@return integer | nil
|
---@return integer | nil
|
||||||
function GetVehicle()
|
function GetVehicle()
|
||||||
local ped = Cache.Get("Ped") -- Use cached ped for efficiency
|
local ped = PlayerPedId()
|
||||||
if not ped then return end -- Or handle error/default case
|
if not ped then return end
|
||||||
return GetVehiclePedIsIn(ped, false)
|
return GetVehiclePedIsIn(ped, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get the seat of the player in the vehicle if the vehicle is occupied
|
--- Get the seat of the player in the vehicle if the vehicle is occupied
|
||||||
---@return integer | nil
|
---@return integer | nil
|
||||||
function GetVehicleSeat()
|
function GetVehicleSeat()
|
||||||
local vehicle = Cache.Get("Vehicle")
|
local vehicle = GetVehicle()
|
||||||
if not vehicle then return end
|
if not vehicle then return end
|
||||||
local ped = Cache.Get("Ped")
|
local ped = PlayerPedId()
|
||||||
if not ped then return end
|
if not ped then return end
|
||||||
for i = -1, GetVehicleMaxNumberOfPassengers(vehicle) - 1 do
|
for i = -1, GetVehicleMaxNumberOfPassengers(vehicle) - 1 do
|
||||||
if ped == GetPedInVehicleSeat(vehicle, i) then
|
if ped == GetPedInVehicleSeat(vehicle, i) then
|
||||||
@@ -38,26 +27,17 @@ function GetVehicleSeat()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Get The Server ID of the player
|
|
||||||
---@return integer | nil
|
|
||||||
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
|
--- Get the current weapon of the player
|
||||||
--- @return integer | nil
|
--- @return integer | nil
|
||||||
function GetWeapon()
|
function GetWeapon()
|
||||||
local ped = Cache.Get("Ped")
|
local ped = PlayerPedId()
|
||||||
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", PlayerPedId, 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
|
||||||
@@ -3,6 +3,7 @@ local blipIDs = {}
|
|||||||
local spawnedPeds = {}
|
local spawnedPeds = {}
|
||||||
|
|
||||||
Locales = Locales or Require('modules/locales/shared.lua')
|
Locales = Locales or Require('modules/locales/shared.lua')
|
||||||
|
Point = Point or Require('lib/points/client/pointsv2.lua')
|
||||||
|
|
||||||
---Get the hash of a model (string or number)
|
---Get the hash of a model (string or number)
|
||||||
---@param model string|number
|
---@param model string|number
|
||||||
@@ -410,8 +411,8 @@ function Utility.GetClosestVehicle(coords, distanceScope, includePlayerVeh)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Deprecated point functions (no changes)
|
-- Deprecated point functions (no changes)
|
||||||
function Utility.RegisterPoint(pointID, pointCoords, pointDistance, _onEnter, _onExit, _nearby)
|
function Utility.RegisterPoint(pointID, pointCoords, pointDistance, _onEnter, _onExit)
|
||||||
return Point.Register(pointID, pointCoords, pointDistance, nil, _onEnter, _onExit, _nearby)
|
return Point.Register(pointID, pointCoords, pointDistance, nil, _onEnter, _onExit)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Utility.GetPointById(pointID)
|
function Utility.GetPointById(pointID)
|
||||||
|
|||||||
Reference in new issue
Block a user