Added exception handler when invalid item is found, closes #32

This commit is contained in:
ElPumpo
2018-11-19 18:47:26 +01:00
parent 652f8f31fd
commit 25071dfe33
2 changed files with 20 additions and 16 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ function OpenShopMenu(zone)
end
table.insert(elements, {
label = item.label .. ' - <span style="color: green;">$' .. item.price .. '</span>',
label = item.label .. ' - <span style="color: green;">$' .. ESX.Math.GroupDigits(item.price) .. '</span>',
label_real = item.label,
item = item.item,
price = item.price,
+19 -15
View File
@@ -20,20 +20,24 @@ MySQL.ready(function()
end
for i=1, #shopResult, 1 do
if ShopItems[shopResult[i].store] == nil then
ShopItems[shopResult[i].store] = {}
end
if itemInformation[shopResult[i].item] then
if ShopItems[shopResult[i].store] == nil then
ShopItems[shopResult[i].store] = {}
end
if itemInformation[shopResult[i].item].limit == -1 then
itemInformation[shopResult[i].item].limit = 30
end
if itemInformation[shopResult[i].item].limit == -1 then
itemInformation[shopResult[i].item].limit = 30
end
table.insert(ShopItems[shopResult[i].store], {
label = itemInformation[shopResult[i].item].label,
item = shopResult[i].item,
price = shopResult[i].price,
limit = itemInformation[shopResult[i].item].limit
})
table.insert(ShopItems[shopResult[i].store], {
label = itemInformation[shopResult[i].item].label,
item = shopResult[i].item,
price = shopResult[i].price,
limit = itemInformation[shopResult[i].item].limit
})
else
print(('esx_shops: invalid item "%s" found!'):format(shopResult[i].item))
end
end
end)
@@ -47,7 +51,7 @@ AddEventHandler('esx_shops:buyItem', function(itemName, amount, zone)
local xPlayer = ESX.GetPlayerFromId(_source)
local sourceItem = xPlayer.getInventoryItem(itemName)
amount = ESX.Round(amount)
amount = ESX.Math.Round(amount)
-- is the player trying to exploit?
if amount < 0 then
@@ -77,10 +81,10 @@ AddEventHandler('esx_shops:buyItem', function(itemName, amount, zone)
else
xPlayer.removeMoney(price)
xPlayer.addInventoryItem(itemName, amount)
TriggerClientEvent('esx:showNotification', _source, _U('bought', amount, itemLabel, price))
TriggerClientEvent('esx:showNotification', _source, _U('bought', amount, itemLabel, ESX.Math.GroupDigits(price)))
end
else
local missingMoney = price - xPlayer.getMoney()
TriggerClientEvent('esx:showNotification', _source, _U('not_enough', missingMoney))
TriggerClientEvent('esx:showNotification', _source, _U('not_enough', ESX.Math.GroupDigits(missingMoney)))
end
end)