Skip to content

Commit

Permalink
fix(server): check stash distance in getClosestStashCoordss
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Nov 18, 2024
1 parent 51099d4 commit 8b502d4
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ exports('setPlayerInventory', server.setPlayerInventory)
AddEventHandler('ox_inventory:setPlayerInventory', server.setPlayerInventory)

---@param playerPed number
---@param coordinates vector3|vector3[]
---@param distance? number
---@return vector3|false
local function getClosestStashCoords(playerPed, coordinates, distance)
---@param stash OxInventory
---@return vector3?
local function getClosestStashCoords(playerPed, stash)
local playerCoords = GetEntityCoords(playerPed)
local distance = stash.distance or 10
local coordinates = stash.coords

if not distance then distance = 10 end
if not coordinates then return end

if type(coordinates) == 'table' then
for i = 1, #coordinates do
Expand All @@ -85,10 +86,10 @@ local function getClosestStashCoords(playerPed, coordinates, distance)
end
end

return false
return
end

return #(coordinates - playerCoords) < distance and coordinates
return #(coordinates - playerCoords) < distance and coordinates or nil
end

---@param source number
Expand Down Expand Up @@ -217,7 +218,7 @@ local function openInventory(source, invType, data, ignoreSecurityChecks)
end

if not ignoreSecurityChecks and right.coords then
closestCoords = getClosestStashCoords(playerPed, right.coords)
closestCoords = getClosestStashCoords(playerPed, right)

if not closestCoords then return end
end
Expand Down

0 comments on commit 8b502d4

Please sign in to comment.