Evented and tested in RM2K. Should work in other RPGMakers when tweaked.
This is a tutorial that will let you create "touch encounters" that are smarter than the normal "Run Towards Hero" -> "Touch" -> "Battle" archetype. What the monsters in this tutorial will do is:
- They will follow a route defined by the developer (this can be a random route if so desired).
- They will scan an area 6 tiles in front and 1 tile either side (6x3) of themselves for the hero.
- If they spot the hero them they will chase them and initiate combat by touching them.
- They can be attacked from behind if the hero has not yet been detected. This initiates "pre-emptive strikes".
- If the hero escapes from battle, they are given a chance to escape before the monster continues to chase them.Setting Up:
What you need to create such a monster is the following:Three Switches:
"<Monster Name> Gets You", "Running Away Active", "<Monster Name> Dead". The "Running Away Active" switch is a common switch shared between all monster events. The other two switches are unique to each monster event (i.e. you need to create new ones for every single monster event you have on a map).Two Variables:
"<Monster Name> X" and "<Monster Name> Y". These are unique to each monster event (i.e. you need to create new ones for every single monster event you have on a map).Eventing - Page 1:
The first page of the monster event is very much the main page. This page will control the monster's "normal" movements, it will determine if the monster has detected the hero, it will determine if the hero has managed to sneak up behind the enemy and it will initiate a "pre-emptive strike" battle if they have managed to do so.
First, you need to set the monster graphic as normal. The event should be a parallel process (as it needs to loop) and the event should be set to "Same Level As Hero". The movement type can be anything you want, but it is generally best to set up the route manually ("By Its Route").
Second, we need to check the monsters field-of-vision for the hero. We do this by setting the X and Y variables to the monster's X and Y co-ordinates and then subtracting the respective hero co-ordinates from them. Then, based on the way the monster is facing, we can use these two differences to work out if the hero is in the monster's field-of-view or not. If the hero is in the monster's field-of-vision then we turn on a switch that allows the monster to chase the hero.
Lastly, if the hero is not in the monster's field-of-view then we check if the hero is directly behind the monster. If this is the case then we initiate a "pre-emptive attack". If this isn't the case, then we do nothing and let the calculation cycle through again.
Here is how the event should look (don't be overwhelmed by the length: A lot of it is just repeating the same thing with different values):
The important thing is understanding how those variable checks work. What we have done, as I said before, is subtract the hero's X and Y co-ordinates from the monster's X and Y co-ordinates. How does this relate to map position?
Well, RM2K measures co-ordinates from the top-left of the screen. Therefore, because we are subtracting the hero's values from the monster's values:
If the difference in X is negative, the hero has a higher X value and is to the right of the monster.
If the difference in X is positive, the hero has a lower X value and is to the right of the monster.
If the difference in Y is negative, the hero has a higher Y value and is below the monster.
If the difference in Y is positive, the hero has a lower Y value and is above the monster.
So, when the monster is facing up, the hero is in front of the monster when the difference in Y is positive and the hero is close enough to the monster to be seen when Y is between 0 and 6.
Don't worry, all the other pages are a lot simpler.Eventing - Page 2:
Page 2 is the page that is activated if the monster "sees" the hero. As such, you're going to want to set this page's movement to "Walk Towards Hero" as you want the monster to be chasing the hero relentlessly. Set the event to be "Below Hero" (this prevents the monster from being able to attack the hero from an adjacent tile even when that adjacent tile is off the edge of a cliff or something equally ridiculous) and to be "On Touch (Event, Hero)" so that the hero doesn't have to actively walk into the monster to trigger the event. I would set the speed to be slower than the hero's walk speed so that the player has a chance to avoid combat should they so wish, but that is entirely up to you. You could argue that they had a chance to avoid battle by avoiding falling into the enemy's line of site!
Here is how the event should look:
All it does it trigger the battle if the hero catches the monster. The switch that activates this page is the one that is turned on by page 1 when the hero is in the monster's field-of-vision - see how it links together?Eventing - Page 3:
This is the page that gives the hero a break should they escape a battle. See how all the escape clauses have this "Change Switch: "Running Away Active": ON" command? This is why.
This page is really simple and should look like this:
See how the switch that turns on the monster chasing you is turned on here? This is to make sure that a pre-emptive strike that is ran away from doesn't result in the monster just tottering off as if nothing happened. Fits together nicely, huh?Eventing - Page 4:
Basically just a blank page. This is what you show when the enemy is killed:Other Notes?
If you want the enemies to re-spawn when the hero returns to a map, then you're going to want to turn all these switches off when the hero is teleporting onto the map and reset all the variables to 0. If you don't want the enemies to re-spawn then only turn off the "<Monster Name> Gets You" switch and reset all the variables to 0 when the hero teleports onto the map.
Happy hunting, heroes!Images reduced due to excess size causing page stretching
Use spoilers where possible.