oh yeah… thank you
here is the fix in the server/main.lua
(replace the ServerEvent-esx-kr-bag:PutItem)
RegisterServerEvent('esx-kr-bag:PutItem')
AddEventHandler('esx-kr-bag:PutItem', function(id, item, label, count, type)
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
local identifier = ESX.GetPlayerFromId(src).identifier
local update
local count2 = count
local insert
local xItem = xPlayer.getInventoryItem(item)
MySQL.Async.fetchAll('SELECT * FROM owned_bags WHERE identifier = @identifier ',{["@identifier"] = identifier}, function(bag)
if xItem.count >= count then
if bag[1].itemcount < Config.MaxItemCount then
if count2 <= Config.MaxPerItem then
if type == 'weapon' then
xPlayer.removeWeapon(item, count)
MySQL.Async.execute('UPDATE owned_bags SET itemcount = @itemcount WHERE identifier = @identifier', {['@identifier'] = identifier, ['@itemcount'] = bag[1].itemcount + 1})
MySQL.Async.execute('INSERT INTO owned_bag_inventory (id, label, item, count) VALUES (@id, @label, @item, @count)', {['@id'] = id,['@item'] = item, ['@label'] = label, ['@count'] = count})
elseif type == 'item' then
MySQL.Async.fetchAll('SELECT * FROM owned_bag_inventory WHERE id = @id ',{["@id"] = id}, function(result)
if result[1] ~= nil then
for i=1, #result, 1 do
if result[i].item == item then
count = count + result[i].count
update = 1
elseif result[i].item ~= item then
insert = 1
end
end
if update == 1 then
if count <= Config.MaxPerItem then
MySQL.Async.execute('UPDATE owned_bag_inventory SET count = @count WHERE item = @item', {['@item'] = item, ['@count'] = count})
xPlayer.removeInventoryItem(item, count2)
else
TriggerClientEvent('esx:showNotification', src, _U('too_much', Config.MaxPerItem))
return
end
elseif insert == 1 then
if count2 <= Config.MaxPerItem then
MySQL.Async.execute('UPDATE owned_bags SET itemcount = @itemcount WHERE identifier = @identifier', {['@identifier'] = identifier, ['@itemcount'] = bag[1].itemcount + 1})
MySQL.Async.execute('INSERT INTO owned_bag_inventory (id, label, item, count) VALUES (@id, @label, @item, @count)', {['@id'] = id,['@item'] = item, ['@label'] = label, ['@count'] = count})
xPlayer.removeInventoryItem(item, count2)
else
TriggerClientEvent('esx:showNotification', src, _U('too_much', Config.MaxPerItem))
return
end
end
else
MySQL.Async.execute('UPDATE owned_bags SET itemcount = @itemcount WHERE identifier = @identifier', {['@identifier'] = identifier, ['@itemcount'] = bag[1].itemcount + 1})
MySQL.Async.execute('INSERT INTO owned_bag_inventory (id, label, item, count) VALUES (@id, @label, @item, @count)', {['@id'] = id,['@item'] = item, ['@label'] = label, ['@count'] = count})
xPlayer.removeInventoryItem(item, count2)
end
end)
end
else
TriggerClientEvent('esx:showNotification', src, _U('too_much', Config.MaxPerItem))
end
else
TriggerClientEvent('esx:showNotification', src, _U('bag_maxitem',Config.MaxItemCount))
end
else
TriggerClientEvent('esx:showNotification', src, _U('pick_toomuch'))
end
end)
end)
//EDIT:
optimized code (removed the canBeStored-variable)
a second doublecation-fix