KRILLE123 / esx-kr-advanced-shops

29 stars 34 forks source link

Mayor bug. #21

Open Duqino opened 5 years ago

Duqino commented 5 years ago

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.

madalton commented 5 years ago

Hi,

do you have solved this issues ?

Duqino commented 5 years ago

No i have not :(

z00t commented 4 years ago
-- 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

Danny9865 commented 4 years ago

this fixed mine thanks

RuisSoftware commented 4 years ago

Thank you!