Skip to content

Commit

Permalink
fix(bridge/qb/client): make functions strictly backwards compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
D4isDAVID committed Jan 29, 2024
1 parent 8f253e0 commit 57eb42c
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions bridge/qb/client/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,32 +143,18 @@ local function getEntities(pool, ignoreList) -- luacheck: ignore
end

---@deprecated use the GetGamePool('CVehicle') native directly
functions.GetVehicles = function(ignoreList)
return getEntities('CVehicle', ignoreList)
functions.GetVehicles = function()
return GetGamePool('CVehicle')
end

---@deprecated use the GetGamePool('CObject') native directly
functions.GetObjects = function(ignoreList)
return getEntities('CObject', ignoreList)
functions.GetObjects = function()
return GetGamePool('CObject')
end

---@deprecated use the GetActivePlayers native directly
functions.GetPlayers = function(ignoreList)
ignoreList = ignoreList or {}
local plys = GetActivePlayers()
local players = {}
local ignoreMap = {}
for i = 1, #ignoreList do
ignoreMap[ignoreList[i]] = true
end

for i = 1, #plys do
local player = plys[i]
if not ignoreMap[player] then
players[#players + 1] = player
end
end
return players
functions.GetPlayers = function()
return GetActivePlayers()
end

---@deprecated use the GetGamePool('CPed') native directly
Expand Down Expand Up @@ -205,11 +191,22 @@ end
---@deprecated use qbx.isWearingGloves from modules/lib.lua
functions.IsWearingGloves = qbx.isWearingGloves

functions.GetClosestPlayer = function(coords, maxDistance) -- luacheck: ignore
---@deprecated use lib.getClosestPlayer from ox_lib
functions.GetClosestPlayer = function(coords) -- luacheck: ignore
coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords or GetEntityCoords(cache.ped)
local playerId, _, playerCoords = lib.getClosestPlayer(coords, maxDistance or 50, false)
local closestDistance = playerCoords and #(playerCoords - coords) or nil
return playerId, closestDistance
local players = GetActivePlayers()
local closestDistance = -1
local closestPlayer = -1
for i = 1, #players do
local player = players[i]
local playerCoords = GetEntityCoords(GetPlayerPed(player))
local distance = #(playerCoords - coords)
if closestDistance == -1 or closestDistance > distance then
closestPlayer = player
closestDistance = distance
end
end
return closestPlayer, closestDistance
end

---@deprecated use lib.getNearbyPlayers from ox_lib
Expand All @@ -226,13 +223,13 @@ functions.GetPlayersFromCoords = function(coords, radius)
end

---@deprecated use lib.getClosestVehicle from ox_lib
functions.GetClosestVehicle = function(coords, ignoreList)
return getClosestEntity(getEntities('CVehicle', ignoreList), coords)
functions.GetClosestVehicle = function(coords)
return getClosestEntity(GetGamePool('CVehicle'), coords)
end

---@deprecated use lib.getClosestObject from ox_lib
functions.GetClosestObject = function(coords, ignoreList)
return getClosestEntity(getEntities('CObject', ignoreList), coords)
functions.GetClosestObject = function(coords)
return getClosestEntity(GetGamePool('CObject'), coords)
end

---@deprecated use the GetWorldPositionOfEntityBone native and calculate distance directly
Expand Down

0 comments on commit 57eb42c

Please sign in to comment.