Sorry, newbie developer here. I am struggling to understand how to get the amount of money a player has in cash and their bank account and deduct it so that they may purchase an item.
Please see the snippet of code I am struggling with below. When I trigger this block of code I receive a script error, attempt to call a nil value (field ‘GetPlayer’). Is someone able to please point me in the right direction?
local src = source
local Player = QBCore.Functions.GetPlayer(src)
BankAmount = Player.GetMoney('bank')
PlayerCashAm = Player.GetMoney('cash')
if PayWithBank == 1 then
XNLUserMoney = BankAmount
else
XNLUserMoney = PlayerCashAm
end
if XNLUserMoney < TicketPrice then
if UserBankIDi == 1 then -- Maze Bank
BankIcon = "CHAR_BANK_MAZE"
BankName = "Maze Bank"
end
if UserBankIDi == 2 then -- Bank Of Liberty
BankIcon = "CHAR_BANK_BOL"
BankName = "Bank Of Liberty"
end
if UserBankIDi == 3 then -- Fleeca (Default Fallback to!)
BankIcon = "CHAR_BANK_FLEECA"
BankName = "Fleeca Bank"
end
SMS_Message(BankIcon, BankName, Message[Language]['account_information'],
Message[Language]['account_nomoney'], true)
else
if PayWithBank == 1 then
-- Put YOUR code to deduct the amount from the players BANK account here
-- 'Basic Example': PlayerBankMoney = PlayerBankMoney - TicketPrice
Player.Functions.RemoveItem('bank', TicketPrice)
if Debug then print("FiveM-Trains: Ticket bought via bank.") end
else
-- Put YOUR code to deduct the amount from the players CASH money account here
-- 'Basic Example': PlayerCash = PlayerCash - TicketPrice
Player.Functions.RemoveItem('cash', TicketPrice)
if Debug then print("FiveM-Trains: Ticket bought via cash.") end
end
SMS_Message("CHAR_LS_TOURIST_BOARD", Message[Language]['los_santos_transit'],
Message[Language]['tourist_information'], Message[Language]['ticket_purchased'], true)
PlayerHasMetroTicket = true
end
IsPlayerUsingTicketMachine = false
end
else
ShowedBuyTicketHelper = false
end
system
Closed
2
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.