Introduction:
This tutorial shows a method to control random encounters using a common event, so you can customize the results of the battles, for example, transfer the player to the respawn point.
What do you need?
1. a parallel common event
2. a switch to turn on/off this common event
Here's a screenshot and text of the common event. You can use it directly, or read on.
Explain:
This common event should work both on MV and MZ. So I only use MV for example, because they are pretty much the same.
The engine uses several classes to control its random encounters.
1. System settings. There's a event command you can turn random encounters on/off.
2. Game player. The player has a count down value _encounterCount, that decreases over time, to check if a random encounter needs to occur.
3. Game party. There are two traits, half encounter and no encounter.
4. Game map. There are several properties, like encounter list(troops, weight, regions, etc), encounter steps, the later is used to generate game player's _encounterCount.
5. Scene map. Here's the control center, there are several update functions check random encounters and execute them.
So we only need to simulate the steps, and 'intercept' the encounter before scene map triggers it.
Fortunately, the common event runs before the scene's encounter update function, so we have this solution.
Check the source code of the engine, we can find those conditions:
rpg_scenes.js
line 715:
line 590:
rpg_objects.js
line 7599:
After the condtions are checked, we need to reset $gamePlayer._encounterCount,
so we use the code from line 7600:
After that we just need to start the battle. There's already an event command battle processing, so we use it.
Make sure to check those options, and you are done.
Notice: If there're no random encounters on the map, nothing will happen but the event command will still continue, so be careful if you put any commands after the battle.
This tutorial shows a method to control random encounters using a common event, so you can customize the results of the battles, for example, transfer the player to the respawn point.
What do you need?
1. a parallel common event
2. a switch to turn on/off this common event
Here's a screenshot and text of the common event. You can use it directly, or read on.
◆If:Script:SceneManager._scene.isSceneChangeOk() && !SceneManager.isSceneChanging() && !$gameMap.isEventRunning() && $gamePlayer._encounterCount <= 0 ◆Script:$gamePlayer.makeEncounterCount(); ◆Battle Processing:Same as Random Encounter :If Win ◆Comment:Insert commands here ◆ :If Escape ◆Comment:Insert commands here ◆ :If Lose ◆Comment:Insert commands here, simple gameover or not. ◆ :End ◆:EndExplain:
This common event should work both on MV and MZ. So I only use MV for example, because they are pretty much the same.
The engine uses several classes to control its random encounters.
1. System settings. There's a event command you can turn random encounters on/off.
2. Game player. The player has a count down value _encounterCount, that decreases over time, to check if a random encounter needs to occur.
3. Game party. There are two traits, half encounter and no encounter.
4. Game map. There are several properties, like encounter list(troops, weight, regions, etc), encounter steps, the later is used to generate game player's _encounterCount.
5. Scene map. Here's the control center, there are several update functions check random encounters and execute them.
So we only need to simulate the steps, and 'intercept' the encounter before scene map triggers it.
Fortunately, the common event runs before the scene's encounter update function, so we have this solution.
Check the source code of the engine, we can find those conditions:
rpg_scenes.js
line 715:
!SceneManager.isSceneChanging()line 590:
SceneManager._scene.isSceneChangeOk()rpg_objects.js
line 7599:
!$gameMap.isEventRunning() && $gamePlayer._encounterCount <= 0After the condtions are checked, we need to reset $gamePlayer._encounterCount,
so we use the code from line 7600:
$gamePlayer.makeEncounterCount()After that we just need to start the battle. There's already an event command battle processing, so we use it.
Make sure to check those options, and you are done.
Notice: If there're no random encounters on the map, nothing will happen but the event command will still continue, so be careful if you put any commands after the battle.