WiggleLib - Variable Encounters & Random Encounter Formula

Discussion in 'JS Plugin Releases (RMMV)' started by JumbocactuarX27, Nov 8, 2015.

  1. JumbocactuarX27

    JumbocactuarX27 Veteran Veteran

    Messages:
    86
    Likes Received:
    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.
     

    Attached Files:

    Last edited: Apr 24, 2018
    #1
    eluukkanen, Valnorein, sb~ and 5 others like this.
  2. Bicept

    Bicept Jack of Most Trades Veteran

    Messages:
    34
    Likes Received:
    25
    Location:
    Canada
    First Language:
    English
    Primarily Uses:
    RMMV
    Very useful! Thanks!
     
    #2
  3. Radis3D

    Radis3D Just a Devilz Veteran

    Messages:
    172
    Likes Received:
    33
    Location:
    Surabaya, East Java, Indonesia
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    Your plugin in right monent.. //rmwforums.s3.amazonaws.com/emoticons/default_smile.gif  sankyu.. 
     
    #3
  4. Harken_W

    Harken_W Veteran Veteran

    Messages:
    80
    Likes Received:
    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?
     
    #4
  5. sb~

    sb~ Villager Member

    Messages:
    17
    Likes Received:
    6
    First Language:
    English
    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:

    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: Nov 29, 2017
    #5
  6. Joy Diamond

    Joy Diamond Talkative Veteran

    Messages:
    135
    Likes Received:
    172
    First Language:
    English
    Primarily Uses:
    RMMV
    Greetings,
    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.
     
    #6
    sb~ likes this.
  7. sb~

    sb~ Villager Member

    Messages:
    17
    Likes Received:
    6
    First Language:
    English
    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:

     
    #7
    JumbocactuarX27 likes this.
  8. JumbocactuarX27

    JumbocactuarX27 Veteran Veteran

    Messages:
    86
    Likes Received:
    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.
     
    #8

Share This Page