dojwun / doj-casino

Casino pack for FiveM
GNU General Public License v3.0
146 stars 81 forks source link

Incorrect amount taken when purchasing chips #57

Open bakerzone opened 1 month ago

bakerzone commented 1 month ago

When you purchase chips, the amount taken is double what the actual price of the chip is set to, so if you buy 10 @ $100 each you will pay $2000 ... it doesn't matter what price you set the chips at, it is always doubled.

When you sell your winnings, or if you just sell straight back the correct calculations are used, set the chip price to $100 buy 10, you pay $2000, sell them straight back and you receive $1000.

I know it is a casino and all that .. but the logic appears wrong, somewhere, I have been through it all and cannot work out where it is failing.

bakerzone commented 1 month ago

If you replace the two scripts for selling with the below, you will get the correct amount back when selling:

RegisterNetEvent('doj:server:sellAllChips', function() local Player = qbx_core:GetPlayer(source) local item = ox_inventory:GetItem(source, Config.Casino.Item, nil, true) local price = item Config.Casino.ChipPrice if ox_inventory:RemoveItem(source, Config.Casino.Item, item) then Player.Functions.AddMoney(Config.Casino.Payment, price 2, "casino") ox_inventory:RemoveItem(source, Config.Casino.Item, item) TriggerClientEvent('doj:client:UpdateInteractSpeech', source, "exchange-menu", 'You sold '..item..' Casino Chips for $'..price..'.', 1250) else TriggerClientEvent('doj:client:UpdateInteractSpeech', source, "exchange-menu", 'You dont have any chips!', 750) end end)

RegisterNetEvent('doj:server:sellSelectedAmount', function(amount) local Player = qbx_core:GetPlayer(source) local item = ox_inventory:GetItem(source, Config.Casino.Item, nil, true) local price = amount Config.Casino.ChipPrice if item >= amount then Player.Functions.AddMoney(Config.Casino.Payment, price 2, "casino") ox_inventory:RemoveItem(source, Config.Casino.Item, amount) TriggerClientEvent('doj:client:UpdateInteractSpeech', source, "exchange-menu", 'You sold '..amount..' Casino Chip(s) for $'..price..'.', 1500) else TriggerClientEvent('doj:client:UpdateInteractSpeech', source, "exchange-menu", 'Not enough chips!', 500) end end)