From 4efea53b37479be788886a7d6dff5d29a9c9c478 Mon Sep 17 00:00:00 2001 From: Poggu <45881722+Poggicek@users.noreply.github.com> Date: Sat, 19 Oct 2019 19:35:54 +0200 Subject: [PATCH] Added weight support (#65) * Added weight support --- client/main.lua | 8 ++------ server/main.lua | 15 +++++---------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/client/main.lua b/client/main.lua index 7e039a26..c07ad686 100644 --- a/client/main.lua +++ b/client/main.lua @@ -25,10 +25,6 @@ function OpenShopMenu(zone) for i=1, #Config.Zones[zone].Items, 1 do local item = Config.Zones[zone].Items[i] - if item.limit == -1 then - item.limit = 100 - end - table.insert(elements, { label = ('%s - %s'):format(item.label, _U('shop_item', ESX.Math.GroupDigits(item.price))), label_real = item.label, @@ -39,7 +35,7 @@ function OpenShopMenu(zone) value = 1, type = 'slider', min = 1, - max = item.limit + max = 100 }) end @@ -166,4 +162,4 @@ Citizen.CreateThread(function() Citizen.Wait(500) end end -end) +end) \ No newline at end of file diff --git a/server/main.lua b/server/main.lua index 8c1ec5f5..dfb052b0 100644 --- a/server/main.lua +++ b/server/main.lua @@ -11,15 +11,10 @@ MySQL.ready(function() ShopItems[shopResult[i].store] = {} end - if shopResult[i].limit == -1 then - shopResult[i].limit = 30 - end - table.insert(ShopItems[shopResult[i].store], { label = shopResult[i].label, item = shopResult[i].item, price = shopResult[i].price, - limit = shopResult[i].limit }) else print(('esx_shops: invalid item "%s" found!'):format(shopResult[i].item)) @@ -63,15 +58,15 @@ AddEventHandler('esx_shops:buyItem', function(itemName, amount, zone) -- can the player afford this item? if xPlayer.getMoney() >= price then -- can the player carry the said amount of x item? - if sourceItem.limit ~= -1 and (sourceItem.count + amount) > sourceItem.limit then - TriggerClientEvent('esx:showNotification', _source, _U('player_cannot_hold')) - else + if xPlayer.canCarryItem(itemName, amount) then xPlayer.removeMoney(price) xPlayer.addInventoryItem(itemName, amount) - TriggerClientEvent('esx:showNotification', _source, _U('bought', amount, itemLabel, ESX.Math.GroupDigits(price))) + xPlayer.showNotification(_U('bought', amount, itemLabel, ESX.Math.GroupDigits(price)) + else + xPlayer.showNotification(_U('player_cannot_hold')) end else local missingMoney = price - xPlayer.getMoney() - TriggerClientEvent('esx:showNotification', _source, _U('not_enough', ESX.Math.GroupDigits(missingMoney))) + xPlayer.showNotification(_U('not_enough', ESX.Math.GroupDigits(missingMoney)) end end)