Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for double remove item #10

Merged
merged 1 commit into from Oct 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 29 additions & 18 deletions server/main.lua
Expand Up @@ -86,27 +86,38 @@ RegisterServerEvent('esx_truck_inventory:removeInventoryItem')
AddEventHandler('esx_truck_inventory:removeInventoryItem', function(plate, item, itemType, count)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
MySQL.Async.execute( 'UPDATE `truck_inventory` SET `count`= `count` - @qty WHERE `plate` = @plate AND `item`= @item AND `itemt`= @itemt',
{
['@plate'] = plate,
['@qty'] = count,
['@item'] = item,
['@itemt'] = itemType
})
if xPlayer ~= nil then
if itemType == 'item_standard' then
xPlayer.addInventoryItem(item, count)
end
MySQL.Async.fetchScalar('SELECT `count` FROM truck_inventory WHERE `plate` = @plate AND `item`= @item AND `itemt`= @itemt',
{
['@plate'] = plate,
['@item'] = item,
['@itemt'] = itemType
}, function(countincar)
if countincar >= count then
MySQL.Async.execute( 'UPDATE `truck_inventory` SET `count`= `count` - @qty WHERE `plate` = @plate AND `item`= @item AND `itemt`= @itemt',
{
['@plate'] = plate,
['@qty'] = count,
['@item'] = item,
['@itemt'] = itemType
})
if xPlayer ~= nil then
if itemType == 'item_standard' then
xPlayer.addInventoryItem(item, count)
end

if itemType == 'item_account' then
xPlayer.addAccountMoney(item, count)
end

if itemType == 'item_weapon' then
xPlayer.addWeapon(item, count)
end
end
else

if itemType == 'item_account' then
xPlayer.addAccountMoney(item, count)
end

if itemType == 'item_weapon' then
xPlayer.addWeapon(item, count)
end
end
end)
end)


RegisterServerEvent('esx_truck_inventory:addInventoryItem')
Expand Down