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

How to pay shops in cash then bank #1632

Open
Rogue38 opened this issue Feb 28, 2024 · 1 comment
Open

How to pay shops in cash then bank #1632

Rogue38 opened this issue Feb 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Rogue38
Copy link

Rogue38 commented Feb 28, 2024

Trying to get ox inventory shops to accept cash then if the player does not have enough cash to take it from the players bank.

I suspect its around this part of code-

local function canAffordItem(inv, currency, price) 
 	local canAfford = price >= 0 and Inventory.GetItem(inv, currency, false, true) >= price 
  
 	return canAfford or { 
 		type = 'error', 
 		description = locale('cannot_afford', ('%s%s'):format((currency == 'money' and locale('$') or comma_value(price)), (currency == 'money' and comma_value(price) or ' '..Items(currency).label))) 
 	} 
 end 
  
 local function removeCurrency(inv, currency, price) 
 	Inventory.RemoveItem(inv, currency, price)
@Rogue38 Rogue38 added the bug Something isn't working label Feb 28, 2024
@dorlevy1
Copy link

dorlevy1 commented Mar 25, 2024

if you want to load the bank account and charge from the bank , you should load the player first
QBCore.Functions.GetPlayer(source)
and then you can do some if statement
if Player.Functions.RemoveMoney('bank',price) then
and do your stuff

something like that

`
local Player =QBCore.Functions.GetPlayer(source)
local canAfford = price >= 0 and Inventory.GetItem(inv, currency, false, true) >= price
if not canAfford then
if not Player.Functions.RemoveMoney('bank',price) then
return {
type = 'error',
description = locale('cannot_afford', ('%s%s'):format((currency == 'money' and locale('$') or comma_value(price)), (currency == 'money' and comma_value(price) or ' '..Items(currency).label)))
}
end
#do your stuff if you indeed have any money in bank
end

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants