Thread: [Tutorial] XSE Scripting Tutorial
View Single Post
Old 1st March 2018, 10:26 PM  
Avara
Mirage Of Tales Creator
 
Join Date: Nov 2013
Posts: 33
Avara
Default

Give, Take & Check For Money

To check if your player has a certain amount of money, we use the checkmoney command like so:
Quote:
Originally Posted by Avara View Post
checkmoney 0x[Amount In Hex] 0x0
compare LASTRESULT 0x1
if [More/Less/EqualTo] goto @pointer
For the [More/Less/EqualTo] part, remember this from the item section?
Quote:
Originally Posted by Avara View Post
0x0 = Lower Than
0x1 = Equal To
0x2 = Greater Than
0x3 = Lower Than or Equal To
0x4 = Greater Than or Equal To
These apply here too - meaning if the player has what we want them to have, we goto @pointer. What if we wanted to check if a player has less than the amount specified? Here's a fuller example:
Quote:
Originally Posted by Avara View Post
#org @start
lock
faceplayer
checkmoney 0x2710 0x0
compare LASTRESULT 0x1
if 0x0 goto @HasCorrectAmount
msgbox @IncorrectAmountMsg 0x6
release
end

#org @HasCorrectAmount
msgbox @HasCorrectAmountMsg 0x6
release
end

#org @HasCorrectAmountMsg
= Oh, you don't have very much\nmoney.

#org @IncorrectAmountMsg
= Wow, you have lots of money!
Let's pretend this is a script for an obnoxious rich kid NPC. If the player has more than or exactly $10,000 (0x2710), our rich kid will mention how rich. If the player has less than that (if 0x0, our rich kid will make a snarky comment about their perceived lack of money =P

-----------------------------------------------------------------------------------------------------------------------------------------------------

To give your player a certain amount of money, the givemoney command is extremely straightforward.
Quote:
Originally Posted by Avara
givemoney 0x[Amount In Hex] 0x0
Let's give our player $10,000 so he can be as well off as Obnoxious Rich Kid from earlier:
Quote:
Originally Posted by Avara
givemoney 0x2710 0x0
Okay, now your player is now pretty comfortable financially. Let's take it all away from them again using paymoney, which is set up just the same.
Quote:
Originally Posted by Avara
paymoney 0x[Amount In Hex] 0x0
As you can probably guess, this makes the player pay up the specified amount. Before you use this command in a script, I recommend you actually check if the player has the desired amount that you want to be taken from them in the first place.
Quote:
Originally Posted by Avara
#org @main
lock
faceplayer
checkmoney 0x2710 0x0
compare LASTRESULT 0x1
if 0x4 goto @MoneyCanBeTaken
[...]

#org @MoneyCanBeTaken
paymoney 0x2710 0x0
[...]
-----------------------------------------------------------------------------------------------------------------------------------------------------
Pokémarts, as we know, show the player's amount of money then update it when an item is purchased and money is taken, complete with a sound effect. What if we wanted to replicate that, minus the list of buyable items? I'll start by explaining how to show the player's money:
Quote:
Originally Posted by Avara
showmoney 0x[X-Co-ord] 0x[Y-Co-ord] 0x0
The X and Y co-ordinates pertain to the position of the box on the screen. Hiding the money box is also just a single line:
Quote:
Originally Posted by Avara
hidemoney 0x[X-Co-ord] 0x[Y-Co-ord]
The following is a script for a NPC who sells... eh, Heart Scales or something.
Quote:
Originally Posted by Avara
#org @main
lock
faceplayer
showmoney 0x0 0x0 0x0
msgbox @OfferMsg 0x5
compare 0x800D 0x1
if 0x1 goto @AcceptedOffer
msgbox @DeclinedMsg 0x6
hidemoney 0x0 0x0
release
end

#org @AcceptedOffer
checkmoney 0x1F4 0x0
compare LASTRESULT 0x1
if 0x4 goto @Transaction
msgbox @IncorrectAmountMsg 0x6
hidemoney 0x0 0x0
release
end

#org @NoRoom
msgbox @NoRoomMsg 0x6
hidemoney 0x0 0x0
release
end

#org @Transaction
checkitemroom 0x6F 0x1
compare LASTRESULT 0x0
if 0x1 goto @NoRoom
paymoney 0x1F4 0x0
sound 0x58
updatemoney 0x0 0x0 0x0
msgbox @TransactionMsg 0x6
additem 0x6F 0x1
hidemoney 0x0 0x0
release
end

#org @OfferMsg
= Hi! Would you like to buy a Heart\nScale for [$]500?

#org @IncorrectAmountMsg
= Oh, you can't afford one.

#org @DeclinedMsg
= Not interested?

#org @NoRoomMsg
= You don't have room for it.

#org @TransactionMsg
= Thank you!\nPlease come again!
First, we display their money in the top left-hand corner of the screen and ask the player whether or not they'd like to buy an incredibly useful Heart Scale. If the player decines this incredible offer the money display box closes, our script ends and they are free to go. If the player says "Yes", the script will goto @AcceptedOffer then check if they have $500 (0x1F4). If they can't afford it, the script will also close everything and end. Having the required amount of $$$ takes us to @Transaction, where as long as the player has enough space for the item in their bag, we can go ahead with the exchange - if their bag is full the script will close. sound 0x58 plays a mart transaction noise as the player's money updates. We use additem as opposed to giveitem here, as it adds the item to the player's bag silently.

-----------------------------------------------------------------------------------------------------------------------------------------------------
Coins

Coins are used mainly in the Game Corner of the canon games, but since we're ROM hacking, you could use them for anything. Coin commands are very similar to the ones for money, so they don't require too much explanation, hopefully! To show, update and hide the box which shows the player's coins:
Quote:
Originally Posted by Avara
showcoins 0x[X-Co-ord] 0x[Y-Co-ord]
Quote:
Originally Posted by Avara
updatecoins 0x[X-Co-ord] 0x[Y-Co-ord]
Quote:
Originally Posted by Avara
hidecoins 0x[X-Co-ord] 0x[Y-Co-ord]
If you want to add coins to the player's Coin Case, you only need one short line.
Quote:
Originally Posted by Avara
givecoins 0x[Amount In Hex]
Practically the same for taking coins away, just a different command name:
Quote:
Originally Posted by Avara
removecoins 0x[Amount In Hex]
-----------------------------------------------------------------------------------------------------------------------------------------------------
Pokémarts

So, we now know how to check, give and take amounts of money, plus coins. Since we referred to Marts earlier, why don't we cover those to tie up the money stuff?

Quote:
Originally Posted by Avara
#dynamic 0x800000

#org @main
lock
faceplayer
preparemsg @MartGreetingMsg
waitmsg
pokemart @MartItemsList
msgbox @MartLeavingMsg 0x6
release
end

#org @MartGreetingMsg
= Welcome!\pHow may I help you?

#org @MartLeavingMsg
= Please come again!

#org @MartItemsList
#raw word 0x4
#raw word 0xD
#raw word 0xE
#raw word 0x12
#raw word 0x11
#raw word 0x0
Alternatively, if you make use of the stdmart.rbh header file I made, you could have this instead:
Quote:
Originally Posted by Avara
#dynamic 0x800000
#include stdmart.rbh

#org @main
lock
faceplayer
preparemsg @MartGreetingMsg
waitmsg
pokemart @MartItemsList
msgbox @MartLeavingMsg 0x6
release
end

#org @MartGreetingMsg
= Welcome!\pHow may I help you?

#org @MartLeavingMsg
= Please come again!

#org @MartItemsList
#raw MART_POKEBALL
#raw MART_POTION
#raw MART_ANTIDOTE
#raw MART_PARLYZHEAL
#raw MART_AWAKENING
#raw MART_END
Avara is offline   Reply With Quote
Likes Lunos liked this post