Thread: [Tutorial] XSE Scripting Tutorial
View Single Post
Old 2nd March 2018, 02:03 PM  
Avara
Mirage Of Tales Creator
 
Join Date: Nov 2013
Posts: 33
Avara
Default

Changing Map Tiles

The "setmaptile" command, as you could probably guess, allows you to change a map's tiles. This is commonly used in the canon games for puzzles - such as Cinnabar's mansion where you interact with statues to open doors - but it can be used for anything, really.
Quote:
Originally Posted by Avara
setmaptile 0x[X-Coordinate] 0x[Y-Coordinate] 0x[Block Number] 0x[Passable? - 0x0 = Passable, 0x1 = Not Passable]
Your map editor should show the X and Y co-ordinates of the tile you want to change when you hover over it, same with the block number when selecting from the block palette. If you're using AdvanceMap, this data is shown at the bottom of the screen.
In this example, I'm just going to make some flowers appear when you talk to someone in an unedited Emerald ROM. Nothing too fancy!
Quote:
Originally Posted by Avara
#org @main
lock
faceplayer
checkflag 0x250
if 0x1 goto @done
msgbox @msg1 0x6
setmaptile 0x08 0x08 0x04 0x0
setmaptile 0x09 0x08 0x04 0x0
setmaptile 0x0A 0x08 0x04 0x0
setmaptile 0x0B 0x08 0x04 0x0
special 0x91
setflag 0x250
release
end

#org @done
msgbox @msg2 0x6
release
end

#org @msg1
= Bellsprout, use Growth!

#org @msg2
= Aren't Grass-type Pokémon great?
These X and Y co-ordinates are for the tiles between Brendan & May's homes in Littleroot Town. In vanilla Emerald, block number 0x04 is the one containing default flowers. I used 0x0 for the last bit, so that the flowers don't block the player's path. What's the special 0x91 for? This refreshes the map so that we can see the changes we've made. If you're hacking FR, you'll need special 0x8E to refresh the map instead of 0x91. I've also setflag 0x250 so that the script doesn't repeat itself - although you could use a var instead if you wanted.


Yay, it works! But what about when we exit the map? The flowers are gone! We used a flag, so the player can't talk to the NPC to make the flowers grow again. How do we make this a permanent change? We need a second script for the map header.
Quote:
Originally Posted by Avara
#org @start
checkflag 0x250
if 0x1 call @pointer
end

#org @pointer
setmaptile 0x08 0x08 0x04 0x0
setmaptile 0x09 0x08 0x04 0x0
setmaptile 0x0A 0x08 0x04 0x0
setmaptile 0x0B 0x08 0x04 0x0
return
All this does is call @pointer which shows our flower tiles if flag 0x250 is set. We want to add this to the map's header so that the script runs immediately upon entering the map.
To do this, first compile a similar script to the one above and take a note of its offset. Add a "setmaptile" script as shown then paste your offset in the "Script Offset" box if you're using AdvanceMap:


Test again, and this time when you talk to the NPC to make the flowers grow, the map will be changed permanently.

Avara is offline   Reply With Quote
Likes Lunos liked this post