How do you get money to work? Cash and Bank

Hey everyone. Working on a custom game script and so far, it’s going very well! Until I had to give people money to buy things. Since this is GTA, you’d think money would be stupid, but… Money makes the world go round. I am not using Essential Mode, I am writing everything on my own from scratch.

I’m trying to call the player’s cash and bank based on the last known value in the MySQL Database. These values are being retrieved correctly, but I cannot get the game to hold them.

client_cash.lua

RegisterNetEvent('sp:load_cash')
AddEventHandler('sp:load_cash', function(cash, bank)
        -- I have verified that 'cash' and 'bank' are passing properly.
	SetPlayerCashChange(cash, bank)
end)

The money will flash correctly on the screen, “Cash $5000” and “Bank $50000”. However, when I hit ESC, it says my bank and cash values are $0. I also can’t get it to come back up again after it fades away. I have tried “DisplayCash(true)”, but putting it in a Citizen.CreateThread() just crashes the client. Putting it on the function, does nothing (it still fades).

I’ve also tried SetMultiplayerHudCash(cash, bank), which didn’t do anything worthwhile. I also used “SetMultiplayerBankCash()”, which has no arguments so I have no idea how that’s supposed to work.

I took a peek at Essential Mode, but their code makes no sense to me (InvokeNative with no explanation?). It looks like the writer of Essential Mode also figured it out from someone else (they credited them with it).

1 Like

I too have played around with this a little and found a simular issue when pressing escape, however to make the money amounts remain on the screen you need to call them using one of the following natives im not sure which, credit to Lobix300 and Essentialmode code:

Cash
        -- Found by FiveM forum user @Lobix300
	-- N_0xc2d15bef167e27bc()
	-- SetPlayerCashChange(1, 0)
	-- Citizen.InvokeNative(0x170F541E1CADD1DE, true)
	-- SetPlayerCashChange(cash, 0)

Bank
	-- Found by FiveM forum user @Lobix300
	-- SetMultiplayerBankCash()
	-- SetPlayerCashChange(0, 1)
	-- Citizen.InvokeNative(0x170F541E1CADD1DE, true)
	-- SetPlayerCashChange(0, bank)
1 Like

Thanks, Titch! I’ll play with those and see what comes up.

No problem, anytime! Anything else just ask.

No luck with those. Changed them out and reloaded, and they behaved differently based on circumstances… If I used one at a time, it practically did nothing (talking about the natives). If I gave myself cash and then used a native, it would stay up on the screen. One of them appears to wipe cash/bank clean. It’s too confusing to have a definitive answer on what they do.

okay, take a look into how essential mode uses them this might help as I don’t have very much time at the moment.

No worries, thanks again. I’m going to just code a “psuedo cash” system, where I’m just going to display the MySQL values of their cash/banks on a DrawText instead of trying to adapt into the native system (for now). If someone figures it out, I’ll try it again.

You should just set stats:

StatSetInt('BANK_BALANCE', 50000, true)
StatSetInt('MP0_WALLET_BALANCE', 50000, true)
4 Likes

I will test this when I get home, and give you best answer if it works. Thank you! Where did you find “StatSetInt”? Can’t find it on the native or documentation.

2 Likes

STAT_SET_INT.

Stat names are defined in mpstatssetup.xml and spstatssetup.xml in the game files.

1 Like

Thanks - I was forgetting to put the underscore in the search bar.

1 Like

Solved, Natrium’s suggestion worked flawlessly mixed in with the display options. Thank you!

@RhapidFyre so i should write your code first and then @natives code??? And also please tell me in which file should i write the both?.. and if i will make a single file for this only and business on other, will it work with them?

This code worked for what I was doing. You’ll have to figure it out for what you’re trying to do. Make sure you understand client vs server.

@RhapidFyre can you please tell me the difference?

No, you will need to learn some basic coding fundamentals and how client/server interactions work. I’m in University full time and have a family, so I can’t take on an apprentice.

How can i get cash or bank value?