Friday Script – Tsukihime’s Tile Swap 3.0

Hime's script allows lakes to appear anywhere you want!

Hime’s script allows lakes to appear anywhere you want!

If you want to get the most out of RPG Maker, learn Ruby. In the meantime, lots of talented scripters have done the work for you. Every Friday, The Iron Shoe features a fun script and goes into detail about how to use it. It also covers a little bit of Ruby each time so you can make even more out of the script.

Tile swapping is an incredibly powerful feature. With it, you can dynamically change a map based on player actions, based on variables, based on anything you want. Tsukihime (Hime) has not only built an incredibly powerful script to handle tile swapping, he’s written a great tutorial on how to use it. In this post, will explore some more intricate uses. Download it, and install it, and away we go!

Understanding Tile IDs

The key to using Hime’s script is figuring out tile IDs. Each is a combination of a letter and a number. The letter is easy – you get it from the tab at the bottom of your tileset.

The number is a little trickier. Hime has provided a little cheat-sheet to help you out. 

The way to calculate here is to count the number of rows down until you find your tile, subtract 1, multiply by 8, and add the column number (in Hime’s diagram, the yellow 1-8 on the top). That is, (row-1 * 8) + column. Or you can just count.

Be very careful with page A. Often times, in tileset A, you won’t use all of the available slots for tiles. To use this script, you must use all available slots. Even if those tiles never make their way into the map, add them to the tileset sheet, otherwise your numbering will be off.

Types of Swapping

With Hime’s script, you can use three different methods to tell the game what we want to swap out:

1) The old tile ID. That is, replace all dark dirt tiles with water. Helpful if a large map suddenly has a lake that gets filled.

2) The region ID. That is, replace these squares with rocks. Helpful if there’s been a sudden avalanche.

3) The exact map x and map y. That is, replace whatever is at 40,16 with a giant crack in the wall. Helpful if your player just blew up a secret entrance with a bomb.

We use script calls to call them all the same way.

tile_swap("oldtileid", "newtileid", mapid)

Replace oldtileid with the thing you want to get rid of, and newtileid with what you want to use in its place. So something like tile_swap(“A11”, “A25”). Remember the quote marks.

region_swap(regionid, "newtileid", layerid, mapid)

Replace region id with the number of the region in your map editor, and newtileid and mapid are as above. A note about layers: there are three layers in RPG Maker. I’ll refer to them as the ground layer, the structure layer, and the embellishment layer. Take a look at this shot from inside a house in Vidar:

"Base" tiles like wood floor, walls, stairs get layer 0. "Intermediate" layers like the table get 1. And props like the railing, washtub, or steel bars get 2.

“Base” tiles like wood floor, walls, stairs get layer 0. “Intermediate” layers like the table get 1. And props like the railing, washtub, or steel bars get 2.

The ground layer is the floor, the structure layer is the table, and the embellishment layer is the potion on top of the table. These get the numbers 0, 1, and 2, respectively. For “layerid” in the script call above, use either 0, 1, or 2 depending on where you want the tile to go. Confused? Experiment with it and you’ll get it right quick.

pos_swap(x,y,"newtileid", layerid, mapid)

newtileid, layerid and mapid are as above, x and y are the map x and map y you want to change (not screen x or screen y!).

As Hime notes, you can use this method to build a bridge! You can use this method to drain a lake! You can use this method to open up hidden passages! All of that just with using these three simple script calls.

But we can also replace the components of the script calls with variables. And that’s pretty awesome.

Intermediate Challenge

Brunhilde the Bruiser has a ground pound ability. When she activates it, she jumps into the air and lands with such shattering force, the very earth beneath her trembles and cracks. How can we make the ground itself split under Brunhilde’s might?

Expert Challenge

Brunhilde has come to a puzzle involving 2 switches and 2 tiles that have arrows. Every time she flips a switch, a corresponding arrow rotates 90 degrees. Brunhilde’s very confused by this, but jumping doesn’t seem to help. How can we program a tile which changes to a tile dependent on what the current tile is?

We’ll answer the intermediate challenge in a few weeks. The expert challenge is actually something Vidar tackles, so we’ll cover it in a dev blog post!

Advertisements

4 thoughts on “Friday Script – Tsukihime’s Tile Swap 3.0

  1. Pingback: Dev Blog / Challenge Solution – Using Hime’s Script to Rotate Direction Arrows | The Iron Shoe
  2. This Script Looks Amazing, but for me one of the Core Features is broken, the Tile Revert isnt Working properly and i read that he cant provide a Solution for this. I hope he trys and finds a Way to Fix it. Than this Script would be worth Donating in my Eyes.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s