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

Mayor bug. #21

Open
Duqino opened this issue Sep 1, 2019 · 5 comments
Open

Mayor bug. #21

Duqino opened this issue Sep 1, 2019 · 5 comments

Comments

@Duqino
Copy link

Duqino commented Sep 1, 2019

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
Copy link

madalton commented Oct 1, 2019

Hi,

do you have solved this issues ?

@Duqino
Copy link
Author

Duqino commented Oct 1, 2019

No i have not :(

@z00t
Copy link

z00t commented Nov 10, 2019

-- 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
Copy link

this fixed mine thanks

@RuisSoftware
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants