mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 10:18:54 +00:00
Fixed having more than you can carry, closes #9
- Translation improvements with formatting - General improvements
This commit is contained in:
+18
-18
@@ -12,7 +12,7 @@ AddEventHandler('onMySQLReady', function()
|
||||
|
||||
for i=1, #result, 1 do
|
||||
ItemsLabels[result[i].name] = result[i].label
|
||||
end--
|
||||
end
|
||||
|
||||
end
|
||||
)
|
||||
@@ -25,25 +25,19 @@ ESX.RegisterServerCallback('esx_shop:requestDBItems', function(source, cb)
|
||||
'SELECT * FROM shops',
|
||||
{},
|
||||
function(result)
|
||||
|
||||
local shopItems = {}
|
||||
|
||||
for i=1, #result, 1 do
|
||||
|
||||
if shopItems[result[i].name] == nil then
|
||||
shopItems[result[i].name] = {}
|
||||
end
|
||||
|
||||
|
||||
table.insert(shopItems[result[i].name], {
|
||||
name = result[i].item,
|
||||
price = result[i].price,
|
||||
label = ItemsLabels[result[i].item]
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
cb(shopItems)
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
@@ -53,17 +47,23 @@ RegisterServerEvent('esx_shop:buyItem')
|
||||
AddEventHandler('esx_shop:buyItem', function(itemName, price)
|
||||
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
if xPlayer.get('money') >= price then
|
||||
|
||||
xPlayer.removeMoney(price)
|
||||
xPlayer.addInventoryItem(itemName, 1)
|
||||
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('bought') .. ItemsLabels[itemName])
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
local sourceItem = xPlayer.getInventoryItem(itemName)
|
||||
|
||||
-- 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 + 1) > sourceItem.limit then
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('player_cannot_hold'))
|
||||
else
|
||||
xPlayer.removeMoney(price)
|
||||
xPlayer.addInventoryItem(itemName, 1)
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('bought', ItemsLabels[itemName], price))
|
||||
end
|
||||
else
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('not_enough'))
|
||||
local missingMoney = price - xPlayer.getMoney()
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('not_enough', missingMoney))
|
||||
end
|
||||
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user