WiggleLib - Variable Encounters & Random Encounter Formula

JumbocactuarX27

Veteran
Veteran
Joined
Jan 11, 2013
Messages
86
Reaction score
39
First Language
English
WiggleLib - Encounter Plugins
Author: JumbocactuarX27 (aka Wiggle)


*NOTE*
These are old scripts and were for the early versions of RPG Maker MV. I have not tested them on more recent versions!


Introduction
In creating my first RPG Maker MV game, I found myself looking for a few specific plugins. Not able to find them, I decided to create them myself. Now I am happy to offer them for download and use by the greater RPG Maker community. In this post I'll introduce two seperate, but related, plugins: Variable Encounter and Random Encounter Formula.

Features
Random Encounter Formula

This plugin allows you to customize the way that the number of steps until the next random encounter is triggered. By default, RPG Maker looks at the map's encoutnerStep property and does the following calculation:

Math.randomInt(encounterStep) + Math.randomInt(encounterStep) + 1But with this plugin, you can have access to that encounterStep variable and change it to whatever you want. For example, if you wanted to have the encounter length be no less than half the encounter step but no more than 1.5 times the encounter step, you could change it to:

Math.ceil(encounterStep / 2) + Math.randomInt(encounterStep)Variable Encounter

With this plugin, you can use plugin commands to alter the weight or regionSet of a troop on a map, the available troops for a map, or even the encounter step, changing how often battles occur on a map!



Using script or plugin commands with this plugin you can:

  • Add a troop to a map's encounter list
  • Remove a troop from a map's encounter list
  • Clear all troops from a map's encounter list
  • Set the regions a troop appears on in a map
  • Change the probability a given troop will appear on a map's random encounter
  • Change the encounterStep property for a given map.

How to Use
Install the plugins and turn them on. For the Random Encounter Formula, configure the formula you'd like by changing the Formula parameter. For the Variable Encounter plugin you can configure the Storage ID parameter which defines which game variable the encounter data will be stored in (this allows the changes in encounter lists to be persisted in the save file between play sessions). At this point you are ready to start using plugin commands.

Below is the variable encounter plugin help text inside a spoiler. The random encounter formula plugin has no help text.
Code:
// ============================================================================
 * Introduction
 * ============================================================================
 * No matter how much time you spend in an area killing monsters in an RPG
 * Maker game's random encounters, the enemies just keep coming. What if you
 * could alter the encounter list for maps though? What if your actions in a
 * dungeon caused the creatures you could encounter in that dungeon, or even
 * another dungeon, to change? What if you could hunt a monster to extinction?
 * If these ideas excite you, then the Variable Encounter plugin is for you.
 *
 * With this plugin, you can use plugin commands to alter the weight or
 * regionSet of a troop on a map, the available troops for a map, or even the
 * encounter step, changing how often battles occur on a map!
 *
 * ============================================================================
 * Important Information!
 * ============================================================================
 * If you try to perform an operation listed below on a map that your player
 * has not visited yet, generally nothing will happen. You will not be able
 * to modify their encounter list until the player has visited that map!
 * However, there is a workaround for this. If you wish to modify a map's
 * encounter list before it is visited by the player, you must use a script
 * command to create empty map data for that map.
 * The command for this is: WiggleLib.VariableEncounter._createMapEntry(mapId)
 *
 * For example, if you wanted to alter encounter data for map #8 and the
 * player has not visited map #8 yet, you would have to create a script event
 * and enter the following:
 * WiggleLib.VariableEncounter._createMapEntry(8);
 *
 * Perhaps your player may have visited map #8 already or perhaps they have
 * not. If they have, the command listed above will overwrite any encounter
 * data that already exists for map #8. In this case please check if the map
 * data exists first. The following code will only create map data if it
 * does not already exist:
 * if (WiggleLib.VariableEncounter._getMapData(8) === undefined) {
 *     WiggleLib.VariableEncounter._createMapEntry(8);
 * }
 * ============================================================================
 * Parameters
 * ============================================================================
 * Storage ID (Default: 1)
 * The Storage ID parameter is what lets the changes you make persist between
 * play sessions. This plugin keeps its data in a game variable and references
 * that data as the player travels through the game. Without being able to
 * store the altered encounter data in a variable, the changes you make would
 * be reset every time a player loads a game.
 * Do not overwrite the specified variable in the game events, or this plugin
 * will, at worst, crash or, at best, stop working.
 *
 * ============================================================================
 * Plugin Commands
 * ============================================================================
 *
 * All plugin commands begin with "VariableEncounter".
 *
 * Add <troopId> <weight> <mapId>
 * Adds a troop to a map's encounter list. You must specify the ID of the enemy
 * troop you want to add and you must specify a weight for that troop, just
 * like if you were adding them to the encounter list in the editor via map
 * properties. The mapId parameter is optional, and if omitted will add the
 * encounter to the map that is currently loaded when the command is run. No
 * regionSet data will be added with this command, meaning that the encounter
 * will be available everywhere on the map. If you want to add regionSet data
 * for an encounter, add it with this command and then run the Region
 * command (see below).
 * Example Use: VariableEncounter Add 1 5 8
 *     (Adds troop #1 to the encounter list of map #8 with a weight of 5)
 *
 * Remove <troopId> <mapId>
 * Removes a troop from a map's encounter list. You must specify the ID of the
 * enemy troop you want to remove. The mapId parameter is optional, and if
 * omitted will remove the troop from the map that is currently loaded when the
 * command is run. If the troop specified is not in the specified map's
 * encounter list, nothing will happen.
 * Example Use: VariableEncounter Remove 1 8
 *     (Removes troop #1 from the encounter list of map #8)
 *
 * Update <troopId> <weight> <mapId>
 * Updates the weight of a troop on a map's encounter list. You must specify
 * the ID of the enemy troop you want to update and you must specify a new
 * weight for them. If your weight is not a valid number, it will be set to 0.
 * The mapId parameter is optional, and if omitted will update the troop on
 * the map that is currently loaded when the command is run. If the troop
 * specified is not in the specified map's encounter list, nothing will
 * be updated.
 * Example Use: VariableEncounter Update 1 40 8
 *     (Updates the weight of troop #1 on map #8 to 40)
 *
 * Region <troopId> <regionSet> <mapId>
 * Sets the regions that an enemy troop can appear in on a map. You must
 * specify the ID of the enemy troop you want to set region data for. The
 * regionSet parameter must also be set, and must be an array of region IDs
 * seperated by commas without any spaces. The mapId parameter is optional,
 * and if omitted will set the region for the specified troop on the map that
 * is currently loaded when the command is run. If the troop specified is not
 * in the specified map's encounter list, nothing will happen.
 * Example Use: VariableEncounter Region 1 [1,2,3] 8
 *     (This command makes troop 1 appear only in regions 1, 2, and 3 on map 8)
 * Another Example: VariableEncounter Region 1 [] 8
 *     (This command makes troop 1 appear anywhere on map 8)
 * One More Example: VariableEncounter Region 1 [1, 2, 3] 8
 *     (This command will *not* work! You cannot have spaces in the array!)
 *
 * Clear <mapId>
 * Clears the encounter list for the specified map. The mapId parameter is
 * optional, and if omitted will set the region for the specified troop on the
 * map that is currently loaded when the command is run.
 * Example Use: VariableEncounter Clear 8
 *     (The encounter list for map #8 is empty and no random encounters will
 *      occur there until you use the Add command for that map (see above))
 *
 * Step <encounterStep> <mapId>
 * Sets the average number of steps that it will take to trigger a random
 * battle on the specified map. The mapId parameter is optional, and if
 * omitted will set the region for the specified troop on the map that
 * is currently loaded when the command is run.
 * If you would like to change the default method of calculating when to
 * trigger a random battle, please look for my Random Encounter Formula
 * plugin.
 * Example Use: VariableEncounter Step 60 8
 *     (Sets the encounter step parameter for map #8 to 60)
 *
 * ============================================================================
 * Script Commands
 * ============================================================================
 * I won't provide too much information here, but if you want to use scripts
 * commands instead of plugin commands, here is a quick table of equivalent
 * commands. If you'd like more detail, please look at the functions below or
 * feel free to ask me directly by PM-ing me at the rpgmakerweb forums. My
 * username is: JumbocactuarX27
 *
 * Plugin | Script Function
 * ======================================
 * Add    | WiggleLib.VariableEncounter.addEncounter(troopId, weight, mapId)
 * Remove | WiggleLib.VariableEncounter.removeEncounter(troopId, mapId)
 * Update | WiggleLib.VariableEncounter.updateEncounter(troopId, weight, mapId)
 * Region | WiggleLib.VariableEncounter.updateRegionSet(troopId, regionSet, mapId)
 * Clear  | WiggleLib.VariableEncounter.clearEncounterList(mapId)
 * Step   | WiggleLib.VariableEncounter.changeEncounterStep(encounterStep, mapId)
 */
 //=============================================================================

Demo
I don't have a demo that uses these plugins right now. I can put one together if there's demand.

Download
Both files are attached below.

Known Issues
I don't know of any bugs in this plugin, but if you find some report them here and I'll fix it.

Important development considerations for the Variable Encounter plugin

This can be found in the Variable Encounter help file as well with more information, but it's very important to consider this if you're getting really into using the plugin:

If you try to perform an operation listed below on a map that your player has not visited yet, generally nothing will happen. You will not be able to modify their encounter list until the player has visited that map!However, there is a workaround for this. If you wish to modify a map's encounter list before it is visited by the player, you must use a script command to create empty map data for that map. The command for this is:
Code:
WiggleLib.VariableEncounter._createMapEntry(mapId)

Terms of Use

Please feel free to use these scripts commercially or non-commercially. If you use it commercially please credit me in your game's credits and let me know about your game's release! I'd love to link to it here.
 

Attachments

Last edited:

Bicept

Jack of Most Trades
Veteran
Joined
Oct 22, 2015
Messages
34
Reaction score
25
First Language
English
Primarily Uses
RMMV
Very useful! Thanks!
 

Radis3D

Just a Devilz
Veteran
Joined
Nov 1, 2015
Messages
172
Reaction score
33
First Language
Indonesian
Primarily Uses
RMVXA
Your plugin in right monent.. //rmwforums.s3.amazonaws.com/emoticons/default_smile.gif  sankyu.. 
 

Harken_W

Veteran
Veteran
Joined
Oct 13, 2015
Messages
80
Reaction score
22
First Language
English
Primarily Uses
N/A
download link isn't working, any chance you could provide a new link, or if anyone else has this plugin available?
 

sb~

Villager
Member
Joined
Aug 2, 2016
Messages
17
Reaction score
6
First Language
English
Primarily Uses
Bump, the plugin would be really helpful. Hoping the download link can be updated.

Edit: I found it easier to directly edit the rpg_objects.js and replace the formula in there. If you Ctrl + F and search for "Game_Player.prototype.makeEncounterCount", replace it and the 2 lines below it with this:

Game_Player.prototype.makeEncounterCount = function() {
var n = $gameMap.encounterStep();
this._encounterCount = Math.ceil(n / 2) + Math.randomInt(n) + 1;
The result is that the random encounter range will be narrower than the default formula. For example, an area with an encounter rate every 20 steps will now have a range of 11 - 31 steps (= plus/minus half of 20, +1) instead of a wider range of 1 - 40.
 
Last edited:

Joy Diamond

Talkative
Veteran
Joined
Nov 12, 2017
Messages
135
Reaction score
173
First Language
English
Primarily Uses
RMMV
Greetings,
Edit: I found it easier to directly edit the rpg_objects.js.
Yes, short term this is way easier.

However, long term, this can lead to many problems, including lots of wasted time, ...
  • I strongly suggest against editing the original rpg_*.js files; but instead ...
  • Learning how to modify them from another *.js file.
  • There are many example plugins that do exactly that (modify them from another *.js file)
Joy Diamond.
 
  • Like
Reactions: sb~

sb~

Villager
Member
Joined
Aug 2, 2016
Messages
17
Reaction score
6
First Language
English
Primarily Uses
Thanks Joy Diamond. I'm a little late to reply but I took your advice and made my own plugin. Nothing fancy, but anyone is free to use it:

//=============================================================================
// EncounterCount.js
//=============================================================================

/*:
* Changes EncounterCount function in rpg_objects.js to smooth high fluctuation in encounter rates
- E.g. Currently if map encounter steps is set to 20...
- Each encounter rate would be = (random: 0-20) + (random: 0-20) + 1;
- Players would have a chance to encounter monsters every 1-40 steps even though the encounter rate is set to 20
- This plugin eliminates risk of frustration by changing the formula to = (20 / 2) + (random: 0-20) + 1
- Therefore the new encounter range would be every 11-31 steps
* @plugindesc Eliminates risk of back-to-back encounters and makes map encounter rate feel more consistent.
*/
(function() {
Game_Player.prototype.makeEncounterCount = function() {
var n = $gameMap.encounterStep();
this._encounterCount = Math.ceil(n / 2) + Math.randomInt(n) + 1;
};
})();
 

JumbocactuarX27

Veteran
Veteran
Joined
Jan 11, 2013
Messages
86
Reaction score
39
First Language
English
Sorry for not replying to this thread sooner; didn't see the replies until today. I've reformatted the first post and uploaded the scripts I wrote to this thread. If this is not acceptable, please let me know and I'll find another way to host them.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,018
Members
137,563
Latest member
MinyakaAeon
Top