Doing More With Script Calls (Proximity, Chase, and Puzzle Events) - MZ tutorial

Rubescen

Veteran
Veteran
Joined
Jan 4, 2016
Messages
173
Reaction score
186
First Language
English
Primarily Uses
RMMZ
INTRODUCTION
This tutorial describes and models uses for a range of simple script calls within events, which can be used to great effect in lieu of plugins or bulky event process. Using script calls you can make chase events, proximity triggers and create a range of puzzles. You don't need to know JavaScript, but you should have familiarity with the basic functions of the engine and an understanding of switches and variables, parallel processing, etc.

If you're still new to the engine/game development you should first look at this thread: RPG Maker MZ The Basics Tutorial Series and come back here later.

I am not a coder, and you don't need to be to use script calls. I've improved my understanding of JS over time, but I'm still just a hobbyist developer, taking advantage of whatever tricks I can to make more interesting mechanics.

Below are a number of simple script calls with explanation of what they do. You will find examples of Proximity Events, Chase Events, Puzzle Events and more using script calls for added/simpler functionality. I will add more as I implement them in MZ (although in general calls from MV work in MZ the same). I've also put together a video demoing and explaining some of these examples, if you prefer watching to reading:

Video Version:

Basic Notes:
Code:
=== //Equals
!== //Does not Equal
> < //Greater and less than
>= <= //Greater/equal and less/equal than
a &&  b // a and b must be true
a ||  b //a or b must be true
Remember JavaScript is case sensitive. So $gamePlayer.x !== $gameplayer.x
Also it is a good practice to add a wait in parallel events to prevent lag.

POSITION RELATED CALLS
Code:
$gamePlayer.x //Gives the Player's current X location value.
$gamePlayer.y //Gives the Players current Y location value.
$gameMap.regionId(x, y) //Gives the region ID of the x,y coordinates)
$gameMap.regionId($gamePlayer.x, $gamePlayer.y) //Gives the region ID of the x, y coordinates, in this case the Player's.
$gameMap.terrainTag($gamePlayer.x, $gamePlayer.y) //Gives the terrain tag of the x,y coordinates, in this case the Player's.
$gameMap.event(n).x //Gives the x of event n
$gameMap.event(n).y //Gives the y of event n
$gameMap.event(this._eventId).x //Gives the x of the current event
$gameMap.event(this._eventId).y//Gives the y of the current event

Examples of Position Data Use:

Proximity Event: Checking if the player is next to an event in a cross pattern.
1599501237780.png
Set up event in Parallel with a conditional check and the following in the script box (on one line):
Code:
$gameMap.event(this._eventId).x - 1 === $gamePlayer.x && $gameMap.event(this._eventId).y === $gamePlayer.y 
|| $gameMap.event(this._eventId).x + 1 === $gamePlayer.x && $gameMap.event(this._eventId).y === $gamePlayer.y 
|| $gameMap.event(this._eventId).x === $gamePlayer.x && $gameMap.event(this._eventId).y + 1 === $gamePlayer.y 
|| $gameMap.event(this._eventId).x === $gamePlayer.x && $gameMap.event(this._eventId).y - 1 === $gamePlayer.y
By modifying the x and y value checks as well as the && and || statements, you can change this to be a line, a square, two boxes from the player. Etc. Lots of possibilities with this.

SWITCH AND VARIABLE RELATED CALLS
Code:
$gameSwitches.value(n) //check value of switch n (true or false)
$gameVariables.value(n) === 1 //checks value of variable n === 1 (or any number)
$gameSwitches.setValue(n, true) //Sets Switch n to true.
$gameSwitches.setValue(n, false) //Sets Switch n to false.
$gameVariables.setValue(n, 1) //Sets Variable n to 1 (or any number)
$gameSelfSwitches.setValue([this._mapId, $gameMap.event(this._eventId), 'A'], true) //Sets Self Switch A on, for the current event on the current map.
$gameSelfSwitches.setValue([n, e, 'A'], true) //Sets Self Switch A on for event e on map n.
$gameSelfSwitches.value([this._mapId, $gameMap.event(this._eventId), 'A']) === true //checks if the self switch A is on for current event
$gameSelfSwitches.value([n, e, 'A']) === true //Checks if self switch A is on for event e on map n.


Examples of Switch control use:
Puzzle Event: Push a boulder onto a space to trigger another event with parallel.
1599775692930.png
Two Events: First a simple boulder that moves on player touch (skip). Second a parallel that checks in a conditional if that boulder event is at a certain x,y and if so flips a switch (making the witch appear in this case when switch is on.). You can also add an else to flip the switch off if the boulder is moved off the location.
Code:
$gameMap.event(3).x === 12 && $gameMap.event(3).y === 6 // use in conditional check.

$gameSwitches.setValue(1, true) // optional script call for switch/off(false),
//In this case though, you could just use the built in switch flip just as easily.

Chase Event: Check a player's current region and flipping a switch so an event chases.
1599502018912.png
Set up a parallel event checking RegionId of player in conditional, and flip self switch of an event to chase player when in certain regions. Flip off if outside of region (use in else condition). You could also use a regular switch flip instead of the self switch, as in n the puzzle event.
Code:
$gameMap.regionId($gamePlayer.x, $gamePlayer.y) === 3 // checks if Player is on Region 3
$gameSelfSwitches.setValue([this._mapId, 2, 'A'], true) //flips self switch A on event 2.

$gameSelfSwitches.setValue([this._mapId, 2, 'A'], false) //flips self switch A off event 2

I'll be updating this with more examples as I go.

Questions and suggestions are welcome. I'd especially love to see examples of what you make with script calls! Good luck!
 
Last edited:

Rubescen

Veteran
Veteran
Joined
Jan 4, 2016
Messages
173
Reaction score
186
First Language
English
Primarily Uses
RMMZ
Ok, now that this is out of review and live, I've added the written description of the Puzzle example from the video. I've also added spoiler tags to help make it easier to skim sections. Plan to add some more examples soon.
 

ulosbal

Shamach
Veteran
Joined
Sep 4, 2018
Messages
30
Reaction score
4
First Language
french
Primarily Uses
RMMZ
@Rubescen Thank you! for this tutorial,

do you know how to write the following condition:
if an event / player cannot move down/right/left/up
 

Rubescen

Veteran
Veteran
Joined
Jan 4, 2016
Messages
173
Reaction score
186
First Language
English
Primarily Uses
RMMZ
@Rubescen Thank you! for this tutorial,

do you know how to write the following condition:
if an event / player cannot move down/right/left/up
Thanks!

The basic setup for something like this could use the following script call with a conditional:
!$gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 2)

This will check the if the tile below the player's current location is impassable (remove the ! if you want to see if it is passable).
Change the 2 to a 4, 6, or 8 for left, right and up respectively.
Change $gamePlayer to an event to check that instead.
 

ulosbal

Shamach
Veteran
Joined
Sep 4, 2018
Messages
30
Reaction score
4
First Language
french
Primarily Uses
RMMZ
@Rubescen, Thank you so much! it took a little while to apply, but I got there in the end.

!$gameMap.event(x).canPass($gameMap.event(x).x, $gameMap.event(x).y, 2)

Is there a way "he" can find the event number, if the script is in the event? $gameMap.event(???)

I found!: this._eventId $gameMap.event(this._eventId)
 
Last edited:

Latest Threads

Latest Posts

Latest Profile Posts

Anyone going to talk about Chris Pratt Mario?
My friend just gave me chocolate milk at lunch today! My day is now 1000x better. Yay, choco milky!! :kaojoy:
RivalRamen_Games wrote on jacobv1014's profile.
I really like your profile picture! Who is that in it? is she an OC?
Making his first game

Forum statistics

Threads
115,332
Messages
1,089,080
Members
150,000
Latest member
dopeboy01
Top