-
Notifications
You must be signed in to change notification settings - Fork 56
Overworld Scripting ‐ Script Events
Click to return to the main scripting page
Sometimes, you want an event to occur when a player steps on a specific location, instead of when they interact with a person/object/signpost. These are called "script events" or just "scripts" for short. They're the green-looking events. These are often used for things like rival encounters, or to make a player 'step back' if they go somewhere they shouldn't.
The 3 green cells in Cerulean City show that script events can trigger when the player enters those cells. However "can" doesn't mean that they "will": scripts will only run if the trigger variable has the correct index. In the example above, the scripts will only run if variable 0x4052
is set to 0
. However, if the trigger variable has the correct index, the script will always run when the player is in that cell. That means that somewhere in the script, you want to either move the player off the script or change the value in the variable so that the trigger won't happen again. Otherwise you'll get stuck in an infinite loop!
In the example in Cerulean City, the only way the script can end is either the player losing the rival battle and warping away, or the player winning the battle and the script updating the value stored in the trigger variable.
Besides the trigger/index, the script is also only run if the elevation matches the player. This only matters if you're making some kind of bridge, where the player can pass over or under. Otherwise, it's safe just to leave the script's elevation at 0
(always active) or 3
(player default elevation).
Here's a simple event where an NPC asks you not to step on some flowers. The trigger variable doesn't matter, except that you want it to be a variable that will always have value 0. This is a good time to use a temporary variable (0x4000
through 0x400F
) since those get reset every time you change maps.
section0:
lockall
move.npc 4 <auto>
{
face_left
emote_exclamation_mark
}
msgbox.default <auto>
{
Hey! Those are my favorite flowers!
Don't step on them!
}
closeonkeypress
move.player <auto>
{
walk_up
}
releaseall
end
- Remember that by using
<auto>
for the movement and text, HMA will pick addresses near the script for that data and you won't have to worry about it yourself. - We're using
move.npc 4 <auto>
because the npc that we want to move has the ID 4. - We're using
lockall
andreleaseall
instead oflock
andrelease
becauselock
/release
only effect the OW that owns the script. This script is running from a script event, solock
andrelease
won't do what we need.