esx-kr-advanced-shops icon indicating copy to clipboard operation
esx-kr-advanced-shops copied to clipboard

Mayor bug.

Open Duqino opened this issue 5 years ago • 5 comments

When players try to by more then one item, you pay for all of it. But the shop owner get only paid for 1 item

Just both 150 cocacola and 100 wine. He only got the money from the wine and cocacola is gone.

Duqino avatar Sep 01 '19 15:09 Duqino

Hi,

do you have solved this issues ?

madalton avatar Oct 01 '19 15:10 madalton

No i have not :(

Duqino avatar Oct 01 '19 16:10 Duqino

-- BUYING PRODUCT
RegisterServerEvent('esx_kr_shops:Buy')
AddEventHandler('esx_kr_shops:Buy', function(id, Item, ItemCount)
  local src = source
  local identifier = ESX.GetPlayerFromId(src).identifier
  local xPlayer = ESX.GetPlayerFromId(src)

        local ItemCount = tonumber(ItemCount)

        MySQL.Async.fetchAll(
        'SELECT * FROM shops WHERE ShopNumber = @Number AND item = @item',
        {
            ['@Number'] = id,
            ['@item'] = Item,
        }, function(result)

    
        MySQL.Async.fetchAll(
        'SELECT * FROM owned_shops WHERE ShopNumber = @Number',
        {
            ['@Number'] = id,
        }, function(result2)

            if xPlayer.getMoney() < ItemCount * result[1].price then
                TriggerClientEvent('esx:showNotification', src, '~r~You don\'t have enough money.')
            elseif ItemCount <= 0 then
                TriggerClientEvent('esx:showNotification', src, '~r~invalid quantity.')
            else
                xPlayer.removeMoney(ItemCount * result[1].price)
                TriggerClientEvent('esx:showNotification', xPlayer.source, '~g~You bought ' .. ItemCount .. 'x ' .. Item .. ' for $' .. ItemCount * result[1].price)
                xPlayer.addInventoryItem(result[1].item, ItemCount)
		local result3 = (ItemCount * result[1].price)
                MySQL.Async.execute("UPDATE owned_shops SET money = money + @money WHERE ShopNumber = @Number",
                {
                    --['@money']      = result2[1].money + (result[1].price * ItemCount),
		    ['@money']      = result3,
                    ['@Number']     = id,
                })
    

                if result[1].count ~= ItemCount then
                    MySQL.Async.execute("UPDATE shops SET count = @count WHERE item = @name AND ShopNumber = @Number",
                    {
                        ['@name'] = Item,
                        ['@Number'] = id,
                        ['@count'] = result[1].count - ItemCount
                    })
                elseif result[1].count == ItemCount then
                    MySQL.Async.fetchAll("DELETE FROM shops WHERE item = @name AND ShopNumber = @Number",
                    {
                        ['@Number'] = id,
                        ['@name'] = result[1].item
                    })
                end
            end
        end)
    end)
end)

Fix provided by z00t @ God's Plan RP

z00t avatar Nov 10 '19 00:11 z00t

this fixed mine thanks

Danny9865 avatar Apr 26 '20 02:04 Danny9865

Thank you!

RuisSoftware avatar May 06 '20 18:05 RuisSoftware