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.
Spoiler: Disclaimers
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:
Spoiler: Youtube Tutorial Version
Basic Notes:
Spoiler: Some Basic JavaScript notation
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
Spoiler: Position Script 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.
Spoiler: Proximity Event Example
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
Spoiler: Switch and Variable Script 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.
Spoiler: Boulder Puzzle Event Example
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.
Spoiler: Chase Event Example
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!
本贴来自国际rpgmaker官方论坛作者:Rubescen处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:
https://forums.rpgmakerweb.com/threads/doing-more-with-script-calls-proximity-chase-and-puzzle-events-mz-tutorial.126943/