Changing an Event’s Behavior Suddenly – Remote Self-Switch! (RPG Maker Ace, MV) 

 April 23, 2018

By  kokororeflections

Let’s say you’re in the middle of a cutscene and you need to change an event’s behavior. Maybe you want to make a bad guy suddenly turn and chase the player instead of standing still. Maybe you want to make a door lead to a new location after something happens. Or, maybe you want to set up a cutscene on another map from your existing cutscene.

You can have each of these behaviors set up on their own event pages, but…how do you change an event’s behavior from inside a running script?  You can’t make a self-switch for another event activate immediately in the middle of a script…or can you?

How to Change an Event’s Behavior Suddenly

change an event's behavior
You need a “remote control” to change these events. Let’s use my example from above, a scenario with a bad guy chasing the player character. Our concept here is this:
The player walks in,
the door locks,
the villain chases the player,
the player activates a lever to stop the villain,
the door unlocks.

Let’s start!

The Lair

change an event's behavior Tutorial 2

Need to make a home for our lovely lil villain to live in. Lair, sweet lair.

Put the actors on the stage

change an event's behavior

Everyone’s in place…

Next are the villain’s event pages.  The default page is the villain’s normal, non-attacking state.  It’s the state he will have when you first enter the room, and after you stop him.  The second page is the attack mode, which we’ll selectively activate later.

change an event's behavior

As my toddler niece would say, “look at that scary thing.”

And let’s add a lockable door, too. We don’t want our hero to go all chicken on us.

change an event's behavior

The Setup

Speaking of chickens, we’ve decided that our villain was voted “most likely to eat chicken” in high school, and you’re the chicken! Can you survive?

change an event's behavior

(Sorry, Eric. Some days you’re the hero, and some days you’re the chicken.)
*BGM “turkeyinthestraw.ogg”*

Now let’s throw in that lever to stop the villain for no apparent reason whatsoever.

change an event's behavior

The Main “Event”

Now we just need one more thing – the event that starts our death match!

change an event's behavior

And here’s what it looks like. When The Chicken steps on this event, suddenly the villain will attack! Well, sort of.

Let’s take a closer look at this event. This is where the good stuff starts to happen. Obviously, we don’t want the player to get close to start the chase sequence; that wouldn’t make much sense. We need to start it from a distance so the player has time to get out of the way. This is how we do it.

change an event's behavior

Here’s what we did. We’re going to use a Ruby (Ace) or Javascript (MV) code to remotely trigger the villain to attack. The moment the Chicken crosses through the door…bam! The door locks and the fun begins!

The Self-Switch Code

#set villain to chase (ACE VERSION ONLY)
$game_self_switches[[1, 1, ‘A’]] = true
//set villain to chase (MV VERSION ONLY)
$gameSelfSwitches.setValue([1, 1, ‘A’], true);

We need two copies of the code for your version, one for the door and one for the villain. Each code takes two numbers and a letter, then true/false.

The first number is the ID of the map and the second is the ID of the event. You can get both of these at any time by clicking the event on the map when in event mode.

change an event's behavior

The letter is the self-switch you want to activate…then, after that, true or false. Oh yes, and the comment. ALWAYS write a reminder of what each one does so you aren’t struggling to remember if you come back to it later.

Okay, now we have our sticky predicament set up! Let’s see what happens. But wait! We have no way of making sure the Chicken can escape. We need to look at the lever event.

change an event's behavior

Following our logic before, all we have to do is set the A self-switches back to false, and the villain stops, plus the door opens, because their event pages “A” are no longer being used. Easy, right?

Let’s see if it works.

The End!

change an event's behavior

Yay! The Chicken can escape. Not bad for a guy who has no hands and can’t actually pull a lever.

Why use plugins when you can use script calls to change an event’s behavior?  Give it a try!

New Items In:

  • Tilesets

Shopping cart
There are no products in the cart!
Continue shopping