Coelocanth

Veteran
Veteran
Joined
Oct 10, 2018
Messages
41
Reaction score
67
First Language
English
Primarily Uses
RMMV
Do you like random encounters, but want to do more than just immediately launch a battle scene when one occurs?

This script changes random encounters on the map so that instead of immediately starting a battle, an event (common or map) is called.
This puts control of random encounters back in your hands, to build an evasion system, allow the player to lose random battles without game over, spawn a map encounter near the player or anything else you can do with events.

The troop ID which would have been used for the battle is stored in a variable, so you can still use the map / region settings to choose an encounter.

Also, you can change the formula used to calculate steps until the next random encounter using a plugin parameter.

This plugin was developed for MV, but is MZ compatible.

Download here: https://rpgmaker.net/scripts/787/

Eventing:
When your common event is called, the variable that was set in the plugin parameters will have its value set to the troop ID of the random encounter that would have been started normally.
If your map has no valid encounters for the region the player is in, the variable will be set to 0.
This allows you to completely make the encounter system using the common event instead of setting up troops on the map if you want to.

Otherwise, the simplest event code would be:


Code:
Conditional Branch: variable (random encounter troop) > 0:
    Battle Processing: variable (random encounter troop), can escape
End


That event would have exactly the same effect as the built in encounter system - starting a battle immediately.

A slightly less trivial example:

Code:
Conditional Branch: variable (random encounter troop) == 0:
    Exit Event Processing
End
Show Text: "Monsters Are Near..."
Show Choices: "Fight!", "Hide"
  When "Fight!":
    Battle Processing: variable (random encounter troop), can escape
  When "Hide":
     Show Text: "You got away.. this time."
End

This example gives the player a choice to fight the encounter or avoid it.
Try adding a random dice roll to make hiding not always work, or give the player advantage when choosing to fight.

With events, you can easily get creative and trigger a minigame using parallel events, or have a chasing map event appear near the player and vanish if the player manages to take enough steps without touching it.
It's all up to your own creativity.

For an example of use, you can see @Touchfuzzy build an encounter cancelling minigame out of events, triggered by this plugin in this stream:

Terms of Use:
Please credit as Coelocanth
This script is open source (ISC license)
 
Last edited:

Zaven

Veteran
Veteran
Joined
Aug 22, 2020
Messages
37
Reaction score
15
First Language
German
Primarily Uses
RMMZ
Thank you very much. That's exactly what I needed. I use visible enemies in dungeons, and now the fighting outside can finally be better controlled. But can you please tell the TOS of this?
 

Coelocanth

Veteran
Veteran
Joined
Oct 10, 2018
Messages
41
Reaction score
67
First Language
English
Primarily Uses
RMMV
Thank you very much. That's exactly what I needed. I use visible enemies in dungeons, and now the fighting outside can finally be better controlled. But can you please tell the TOS of this?
Apologies - for this plugin, just credit me.
I've attached a permissive open source license to it now.
 

Iqus

Veteran
Veteran
Joined
Oct 17, 2013
Messages
48
Reaction score
55
First Language
Spanish
Primarily Uses
RMMZ
Your plugin seems to disable preventive and surprise attack battles since it probably is skipping BattleManager.onEncounter(). Yoy might want to look into that.

Since you're triggering the battle through an event command, I'd suggest adding it into the code run by the command, like this:

Code:
// Battle Processing
Game_Interpreter.prototype.command301 = function(params) {
    if (!$gameParty.inBattle()) {
        let troopId;
        if (params[0] === 0) {
            // Direct designation
            troopId = params[1];
        } else if (params[0] === 1) {
            // Designation with a variable
            troopId = $gameVariables.value(params[1]);
        } else {
            // Same as Random Encounters
            troopId = $gamePlayer.makeEncounterTroopId();
        }
        if ($dataTroops[troopId]) {
            BattleManager.setup(troopId, params[2], params[3]);
            BattleManager.onEncounter();
            BattleManager.setEventCallback(n => {
                this._branch[this._indent] = n;
            });
            $gamePlayer.makeEncounterCount();
            SceneManager.push(Scene_Battle);
        }
    }
    return true;
};

It works for me!
 
Last edited:

Bean_Angel

Villager
Member
Joined
Apr 27, 2021
Messages
10
Reaction score
0
First Language
English
Primarily Uses
RMMZ
I can't seem to get it to work!
Could anyone explain this in less technical terms to me please?
 

Coelocanth

Veteran
Veteran
Joined
Oct 10, 2018
Messages
41
Reaction score
67
First Language
English
Primarily Uses
RMMV
What are you getting stuck with?

I guess you've got as far as installing and activating the plugin.
If you open the plugin parameters you'll see something like this:
ccre_snap.png

For basic use, you should set up a common event in the database.
Each common event has an ID number beside it, enter that for "Common Event" here.

In your event, create a "show text" command, and enter "Random encounter \v[7]"
(you can use any variable ID - just put the same ID in the plugin's "Variable for Troop ID". Variable 7 matches my screenshot)

Run around the map for a bit and you should get a popup message "Random encounter 0" after a while, depending on your map's encounter steps setting.
If you've set any random encounter troops on the map, the variable would be set to the matching troop ID instead of 0.

Once that's working, you can remove the "show text" command, and replace it with a minigame or some other event that fits your game.
 

Bean_Angel

Villager
Member
Joined
Apr 27, 2021
Messages
10
Reaction score
0
First Language
English
Primarily Uses
RMMZ
What are you getting stuck with?

I guess you've got as far as installing and activating the plugin.
If you open the plugin parameters you'll see something like this:
View attachment 192406

For basic use, you should set up a common event in the database.
Each common event has an ID number beside it, enter that for "Common Event" here.

In your event, create a "show text" command, and enter "Random encounter \v[7]"
(you can use any variable ID - just put the same ID in the plugin's "Variable for Troop ID". Variable 7 matches my screenshot)

Run around the map for a bit and you should get a popup message "Random encounter 0" after a while, depending on your map's encounter steps setting.
If you've set any random encounter troops on the map, the variable would be set to the matching troop ID instead of 0.

Once that's working, you can remove the "show text" command, and replace it with a minigame or some other event that fits your game.
It was my first day of trying to use plugins so I was pretty overwhelmed lol
Though I've got much better at understanding how they work now.
My main idea is so that instead of a game over you get sent to the closest inn (or a house you have purchased) when you lose. Only losing your money, not the entire game.
 

Coelocanth

Veteran
Veteran
Joined
Oct 10, 2018
Messages
41
Reaction score
67
First Language
English
Primarily Uses
RMMV
No worries, everyone starts as a beginner. In no time at all you'll level up!

So - if you look at the "Control Variables" event command, some of the options under Game Data are:
Map ID
Character: Player: Map X
Character: Player: Map Y

If you save these three values into three different variables, you have created a warp point. Use the "Transfer Player" command with variables to send the player back there.

You could set that warp point whenever the player sleeps at their house or an inn.

Or you could use the Map ID of the map where the battle happened to send the player back to the nearest town. Lots of options you can use.

And of course, use the "can lose" option on your battle so the warping only happens when the player lost.
 

Latest Threads

Latest Profile Posts

I realized a while ago my game was toooo big in scope. even now I wonder am I trying to do too much by myself. and that's after completely changing the format of the game.
Last week at SLC. Cali awaits. TBH I love SLC more than SF.
Back home now. I had a good time, but I had a checkup this morning so I had to come home for that. Now I'm just waiting for my therapist meeting tomorrow...
Decided to work on Wishful Wanda today. Since it's a BFB spinoff game, I decided to make the Huang brothers
Easter eggs! I'm actually pitching this to the BFDI team, btw.
I'm a bit perturbed that my two week project in a different engine is already shaping up to be far better than anything I've done in this one. It really calls into question my future plans. :kaoswt:

I guess I'll release whatever patches I made for Poppet Quest, then abandon it for my new project. I mean unless it somehow wins (I doubt it but hey sure). I'm not sure about And Remember Tomorrow.
It's really not fun burning 4 hours looking at code and trying certain things and getting no where.

Forum statistics

Threads
113,932
Messages
1,078,493
Members
148,038
Latest member
PunkyBlooze
Top