Skip to content

Commit 13962c9

Browse files
committed
fix(peds): correct issue with non-target use of peds and no items to sell/buy
In cases where there are no items to buy from or sell to a ped an error was unhandled. Now two guard conditions prevent possible steps into this code path.
1 parent 023d735 commit 13962c9

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

client/peds.lua

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ local function inputBox(action, shopName, item, maxAmount)
2020
end
2121
end
2222

23-
local function openSellMenu(shopName)
23+
local function openItemsToSellMenu(shopName)
2424
local itemsForSale = lib.callback.await('red40_mining:server:getSellableItems', false, shopName)
2525
local sellOptions = {}
26+
if not itemsForSale or #itemsForSale == 0 then
27+
return Notify(locale('error.no_items_to_sell'), 'error')
28+
end
2629
for i = 1, #itemsForSale do
2730
local item = itemsForSale[i]
2831
sellOptions[#sellOptions + 1] = {
@@ -42,11 +45,14 @@ local function openSellMenu(shopName)
4245
lib.showContext('red40_mining_sell_menu')
4346
end
4447

45-
local function openBuyMenu(shopName)
46-
local itemsForSale = lib.callback.await('red40_mining:server:getShopItems', false, shopName)
48+
local function openItemsToBuyMenu(shopName)
49+
local itemsToBuy = lib.callback.await('red40_mining:server:getShopItems', false, shopName)
4750
local buyOptions = {}
48-
for i = 1, #itemsForSale do
49-
local item = itemsForSale[i]
51+
if not itemsToBuy or #itemsToBuy == 0 then
52+
return Notify(locale('error.no_items_to_buy'), 'error')
53+
end
54+
for i = 1, #itemsToBuy do
55+
local item = itemsToBuy[i]
5056
local label = Items[item.name] and Items[item.name].label or item.name
5157
buyOptions[#buyOptions + 1] = {
5258
title = locale('menu.buy_item', label),
@@ -95,7 +101,7 @@ local function createPedPoint(point)
95101
label = locale('target.buy'),
96102
icon = 'fa-solid fa-box',
97103
onSelect = function()
98-
openBuyMenu(point.shopName)
104+
openItemsToBuyMenu(point.shopName)
99105
end,
100106
}
101107
end
@@ -105,7 +111,7 @@ local function createPedPoint(point)
105111
label = locale('target.sell'),
106112
icon = 'fa-solid fa-hand-holding-dollar',
107113
onSelect = function()
108-
openSellMenu(point.shopName)
114+
openItemsToSellMenu(point.shopName)
109115
end,
110116
}
111117
end
@@ -189,11 +195,11 @@ local function createPedPoint(point)
189195
lib.showTextUI(textLocale)
190196
end
191197
end
192-
if IsControlJustReleased(0, config.useKey) then
193-
openSellMenu(point.shopName)
198+
if IsControlJustReleased(0, config.useKey) and point.pedBuys then
199+
openItemsToSellMenu(point.shopName)
194200
end
195-
if IsControlJustReleased(0, config.useKey2) then
196-
openBuyMenu(point.shopName)
201+
if IsControlJustReleased(0, config.useKey2) and point.pedSells then
202+
openItemsToBuyMenu(point.shopName)
197203
end
198204
else
199205
local textOpen, text = lib.isTextUIOpen()

locales/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
"not_enough_items": "You don't have enough items",
2323
"not_carry": "You cannot carry that much",
2424
"tool_level_too_low": "Your %s level is too low to use this tool",
25-
"invalid_activity": "Invalid activity"
25+
"invalid_activity": "Invalid activity",
26+
"no_items_to_sell": "You have no items to sell",
27+
"no_items_to_buy": "There are no items available for purchase"
2628
},
2729
"activity": {
2830
"mining": "Mining",

0 commit comments

Comments
 (0)