This is a tutorial on how I set up event trigger to move an actor to the player’s location upon entering a room or activating some other trigger. Its a useful event for a variety of game encounters, some of which I’ll explore.
So you’ve been developing your own game and you decide you want to be able to have the player enter a building or a room in a dungeon and upon doing so trigger an encounter with an actor of some type. Perhaps its a monster that rushes towards them and attacks, or a villain who make a speech before making their escape, or perhaps its an NPC who will approach and great them. How do you set this up?
Below is a small dungeon with just two rooms. On the left I’ve place a single event to create an actor, in this case a young girl, that the player will interact with in some way. We want her to wait in the room until the player first enters and then approach the player.
We can’t set the event up with just her event alone, we need to add a second event to act as a trigger, we’ll also need to set up a control switch as well. The girl is located at A, our trigger will be located at B.
There is no graphic for it, the event is invisible. Think of it as an invisible pressure plate on the floor that activates another event when stepped on. Make sure the Priority is set to Below Characters (this actually does put it on the floor so that the player may walk over it) and Trigger is set to Player Touch. When the player enters the room and stands on top of the event, it will trigger.
In the event script we need to add a control switch, which I named Trigger Encounter, but you can call anything you wish, and it must be set to ON. That’s it for the first event tab.
Add a second event tab, but this one has not scripting. However, we set tab 2 to have the Condition that our Trigger from the first tab is set to ON. The reason we do this is to effectively remove or turn off this event trigger once its been activated once. This prevents the same event from being repeated every time you enter the room. In some case you may want the event to be repeatable, in which case you can skip the second tab. Otherwise, add it with no scripting and we’re ready to set up the girl’s event.
Our event trigger at B is just a trigger to activate a control switch. Most of our scripting will be done in multiple event tabs for the girl at A. Her first tab should be very simple as shown below.
This creates the girl actor in the room. She won’t be doing anything and it is important that her movement be set to FIXED, otherwise this event won’t work properly. You could have her doing a simple looped animation in place if you wished.
Now add as 2nd event tab and set it up as shown below.
Two important aspects of this event tab. The Conditions switch must be set so that our trigger (from our other event) is set to ON. This is what activates the rest of the script. Also, the Trigger must be set to Autorun. This will “freeze” the player once the event is triggered so that they cannot move and may only react to things we set up in our script, until the scripted events end and we go back to normal play.
For the actual event, I started with a Show Balloon Icon. This isn’t necessary but I think it adds a nice touch, you can use it or skip it if you like. You could also add other events, like Show Text at this point to have your actor give a speech for example. Next we set up the Move script. On the map, the girl is 3 tiles up and 3 tiles to the left of the trigger B location. So we will need to script the girl to move down 3 and over 3 to the right (or she could go right and then down 3, or you could have her run in a circle first and then move down, or do 4 laps around the room, or any other movement you care to script) as show below.
When you set the movement, have it set to Wait til the script is finished, this will prevent anything else from happening until the actor has moved into the correct position. Also, I like to include the option to Skip if it cannot move. This prevents the script from “locking up” in the event something blocks the actors path. Say you added a dog wandering around the room later, if it happened to randomly move into the way of the script, it could cause problems.
Once the movement script finishes, I have the girl set to simply say Hi! to the player and the script ends. I end the script by setting another Control Switch, Met Girl, to ON. This triggers the third event tab which we’ll set up next. You could script a number of other options here which I’ll discuss further on.
Set up the third event tab as show below.
The important settings here are the Condition, the Met Girl switch is ON. I’ve also set her Autonomous movement to Random so that she will now move about the room on her own. This finishes our basic event script.
If you were to test the script at this point, the girl would be standing still in the room. Once the player enters, the girl will activate, move to stand in front of the player, say Hi and then will move around randomly. The event will not repeat even if you leave the dungeon and come back.
But wait, there’s another entrance to the room at the top, what if the player entered from there instead? Well, right now nothing would happen and that might present a problem. Fortunately this is easily fixed. Just add another trigger at the second opening like we did at B. However, name the trigger switch something else, like Trigger 2, or something. Also, add a 3rd event Tab to both triggers and have the Condition set to Trigger 2 is ON. This means triggering either of them will remove both event triggers so that the event cannot be triggered again.
For the girl, add 1 new event tab inserted betyween Tab 2 & 3 (so that Tab 3 becomes Tab 4).
On the new Tab 3, set the everything the same as Tab 2, except the Condition switch should be Trigger 2. You will also have to adjust the Move script to move her up and over to the 2nd event trigger. In this example, she would need to move up 5 tiles and then over 3 tiles. The scripting should otherwise be identical to Tab 2.
Note, the last tab must be the event we originally set up as Tab 3 (and should now be Tab 4). If this is not the LAST tab in our events, the script will not work properly and can result in an endless loop. The last tab must be the one with the Condition Met Girl is ON.
Now if the player enters from the 2nd entrance, the girl will move up and over, say Hi, then wander around randomly. The event can only be triggered once regardless of which entrance the player uses and will not repeat.
There are many possible uses for this type of event script.
You could use it to initiate a battle with a special monster or level boss. For example, the actor might first give some sort of speech, make a dire threat, etc. Then move to the player, and you simply use the battle processing script to start the fight. You could even use an animation inserted after the movement and before the battle processing to have the actor hit the player, just for a little extra visual.
This script is also handy if the player must rescue someone, perhaps this was a prison cell the player had to break into. Once the player enters, the princess runs to her rescuer and again you could script various speeches, animations, etc.
Or maybe it someone who joins the player’s party, or gives them an item, or provides important information.
As I mentioned above, rather than move directly to the player you could have the actor jump up and down, run around in a circle or do a variety of other things first before moving to the player to make the encounter more entertaining. Use your imagination and have fun with it.