Increasing enemy weight in game

Hi all,

I'm trying to make a game where the player can manipulate enemy weight(troops map spawn rate basically).

The feature would basically work by having the map with a 0 weight/spawn rate of a certain enemy troop, like for example bat spawn rate, and the player can use gold to increase the weight/spawn rate by 5.

The issue is that the enemy weight is fixed on the map, and I can't figure out how to increase the enemy troop's weight cause I can't really use switches, since they're not really events, and I haven't found a plug in that allows me to do that(only found plugins that just add an inventory weight feature).

Anyone got some tips on how to make this feature, or a plugin?
Unless you find a plugin or have one made, I think the only thing you can do is to create a troop called "RANDOM" and have it's battle event call a common event. Write the common event to summon the troops with the chances you want using the "Battle Processing" option to summon the troop type.

You basically are creating a switch to bypass the maps selection of troop to the method in your common event.
I was going to say that you'd need to code that but @ZimXero has an idea for a workaround that might work -- my initial thought though is that it would start the battle process with the scene shift graphics and audio (and literal scene change in the js) before abandoning the battle -- could make it interesting for the player to wonder for a second whether this was a real battle or not, but if that isn't a good mechanic, then you'll probably have to code it as a plugin.
Spoiler: etc
Another approach could be to add the rare enemy to all applicable troops, but set it to Appear Midway (right-click it on the Troops tab). Then have the Turn 0 troop event check for the "increased encounter rate" condition (e.g. a state, or a variable) and use an Enemy Appear command to show the rare enemy if appropriate.

Turn 0 events run after the standard battle start messages (e.g. "Sheep emerged!"), so that may still look a bit off.

In case it helps, here's an untested plugin:
Spoiler: plugin code
JavaScript:
/*:
 * @target MV MZ
 * @plugindesc Enemy notetag: <appear chance: B, V>
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/threads/176790/
 * @help Implements the following Enemy notetag:
 *    <appear chance: B>
 *    <appear chance: B, V>
 * Replace:
 *   - B with the base chance (100 for 100%).
 *   - V with the ID of a variable; its value will be added to X.
 * E.g.
 *    <appear chance: 80>      chance to show: 80%
 *    <appear chance: 0, 12>   chance to show: value of variable 12
 *
 * Free to use and/or modify for any project, no credit required.
 */
;void (function() {
"use strict";
  /** Identifier for Enemy notetag. @type {string} */
  const TAG_NAME = "appear chance";

  /** String for splitting X and V tag values. @type {string} */
  const SPLITTER = ",";

  /**
   * @param {$dataEnemy} nme
   * Reference enemy database record.
   * @returns {?[number,number?]}
   * Base appear chance and optional variable ID.
   */
  const parseTag = function(nme) {
    const t = nme.meta[TAG_NAME];
    if (typeof t === "string") {
      const a = Array.from(t.split(SPLITTER), function(v) {
        return parseInt(v, 10);
      });
      if (a.length)
        return a;
    }
    return null;
  };

  /**
   * @param {$dataEnemy} nme
   * Reference enemy database record.
   * @returns {number}
   * Chance for this enemy to show up, based on tags (default 1, i.e. 100%).
   */
  const showChance = function(nme) {
    const a = parseTag(nme);
    if (a) {
      const b = a[0] || 0;
      const v = 1 in a ? $gameVariables.value(a[1]) : 0;
      return (b + v) / 100;
    }
    return 1;
  };

  /**
   * @param {$dataEnemy} nme
   * Reference enemy database record.
   * @returns {boolean}
   * `true` iff this enemy should hide due to this plugin's notetag.
   */
  const shouldHide = function(nme) {
    return Math.random() >= showChance(nme);
  };

  // Patch - temporarily edit hidden flags on troop setup.
  void (function(alias) {
    Game_Troop.prototype.setup = function() {
      const mem = [];
      // Mutate.
      for (const nme of this.troop().members)
        if (!nme.hidden && shouldHide(nme))
          nme.hidden = true, mem.push(nme);
      // Apply.
      alias.apply(this, arguments);
      // Reset.
      for (const nme of mem)
        nme.hidden = false;
    };
  })(Game_Troop.prototype.setup);

})();

Edit: never mind, I just realised you were asking about conditional troop appearances, not enemies. Maybe this plugin?
Unless you find a plugin or have one made, I think the only thing you can do is to create a troop called "RANDOM" and have it's battle event call a common event. Write the common event to summon the troops with the chances you want using the "Battle Processing" option to summon the troop type.

You basically are creating a switch to bypass the maps selection of troop to the method in your common event.
I tried to do something like that, but the issue is that I don't want an event battle, it's more like I want to increase the spawn rate by doing certain tasks, like paying gold for a certain enemy to spawn, kind of like a reward, the enemy never spawns in the map until you do that task, but it's a random encounter not scripted ones, it's kind of like the opposite of Pokemon's repel.
I updated my encounter rate plugin to handle troop weight changes.

It SHOULD be able to handle this request.
Maliki's Encounter Rate Options
I updated my encounter rate plugin to handle troop weight changes.

It SHOULD be able to handle this request.
Maliki's Encounter Rate Options
I'll test it out as soon as I can, thanks!
You're welcome. Let me know if you need help with the conditionals.
You're welcome. Let me know if you need help with the conditionals.
hmmm, maybe I just don't understand how it works, but is it possible with this plugin to modify the enemy weight by paying a certain NPC to do that?

Cause that's kind of what I'm trying to make, my game i very much based on grinding gold to buy stuff, and enemy spawnrates are kind of a a reward, like for example buying the chance of spawning a certain type of enemy you can't find normally, and increase the weight the more the player pays(from 0 it adds +5 weight the more the player pays)
Hmmm...
So as it is currently, you can only increase the weight of one troop at a time (per map)

So, let's say you want to increase the chance of meeting troop 10 from the database and you want to use an NPC to increase this chance.

First, we need to setup the troops on your map, so we have a baseline weight for the encounters.
Let's just say ALL encounters on the map have a weight of 5.

Since you want this to build each time, we'll have to use a variable.
Let's say we use variable 2.

Ok. So first we will setup the event, which I'm assuming you did, setting up that the variable 2 goes up by 1 every time you pay the NPC.

Now, to do this with my current plugin, you'd have to add a map notetag raising the weight value by a certain amount for each level the variable can reach.

Using the info above, we'd use the notetag:
JavaScript:
<malEncAdj: 10, 10, $gameVariables.value(2) > 0>>>

This will increase the weight of troop 10 (ONLY) by 10 if the variable 2 is higher than 0.
If you NPC is used once, it should set the variable to 1, which will raise the weight to 15 total, increasing the likelihood of the PC meeting them in a random battle ON THAT MAP.
You'd need to use copies of the notetag to account for higher variables.

So if the NPC was used again, the variable would change to 2 and you'd need the tag:
JavaScript:
<malEncAdj: 10, 10, $gameVariables.value(2) > 1>>>

Each tag would be counted, so the weight for troop 10 would rise to 25 since both +10 tags were activated.

This all said, I do think that in this edge case, evaling the amount of the rise might be a good idea.
So for example, you'd be able to do something like:
JavaScript:
<malEncAdj: 10, $gameVariables.value(2) * 10, $gameVariables.value(2) > 0>>>
(You'd only need the one tag per map to do what you wanted if I implemented this.

I'll leave that open for someone to second before I add it as it might increase slowdown if there are too many evals and it really seems like not too many people would need that functionality.

Let me know if you need me to assist further.

EDIT: Cancel pretty much all of this.
I just edited the plugin to allow the evals of weight values.
So now you CAN use the tag:
JavaScript:
<malEncAdj: 10, $gameVariables.value(2) * 10, $gameVariables.value(2) > 0>>>
and it will work.

But again, let me know if you need any further clarification.
Hmmm...
So as it is currently, you can only increase the weight of one troop at a time (per map)

So, let's say you want to increase the chance of meeting troop 10 from the database and you want to use an NPC to increase this chance.

First, we need to setup the troops on your map, so we have a baseline weight for the encounters.
Let's just say ALL encounters on the map have a weight of 5.

Since you want this to build each time, we'll have to use a variable.
Let's say we use variable 2.

Ok. So first we will setup the event, which I'm assuming you did, setting up that the variable 2 goes up by 1 every time you pay the NPC.

Now, to do this with my current plugin, you'd have to add a map notetag raising the weight value by a certain amount for each level the variable can reach.

Using the info above, we'd use the notetag:
JavaScript:
<malEncAdj: 10, 10, $gameVariables.value(2) > 0>>>

This will increase the weight of troop 10 (ONLY) by 10 if the variable 2 is higher than 0.
If you NPC is used once, it should set the variable to 1, which will raise the weight to 15 total, increasing the likelihood of the PC meeting them in a random battle ON THAT MAP.
You'd need to use copies of the notetag to account for higher variables.

So if the NPC was used again, the variable would change to 2 and you'd need the tag:
JavaScript:
<malEncAdj: 10, 10, $gameVariables.value(2) > 1>>>

Each tag would be counted, so the weight for troop 10 would rise to 25 since both +10 tags were activated.

This all said, I do think that in this edge case, evaling the amount of the rise might be a good idea.
So for example, you'd be able to do something like:
JavaScript:
<malEncAdj: 10, $gameVariables.value(2) * 10, $gameVariables.value(2) > 0>>>
(You'd only need the one tag per map to do what you wanted if I implemented this.

I'll leave that open for someone to second before I add it as it might increase slowdown if there are too many evals and it really seems like not too many people would need that functionality.

Let me know if you need me to assist further.

EDIT: Cancel pretty much all of this.
I just edited the plugin to allow the evals of weight values.
So now you CAN use the tag:
JavaScript:
<malEncAdj: 10, $gameVariables.value(2) * 10, $gameVariables.value(2) > 0>>>
and it will work.

But again, let me know if you need any further clarification.
I'm not the coder in my team, but I think I understand what you're telling me(very rusty, but I do remember some js from school).

Is it a problem if I show your script to my coder, and allow him some additional content or improvement?
Edits to my plugin is fine.
Depending on what exactly you want to change (enemy spawns and their weight) there is also the option to change the Region ID from specific tiles in your Maps using the

$dataMap.data.fill(TileID,StartPoint,EndPoint);

function to change them It is a One Liner if you fill the entire Map but will become a more liner if you need to fill specific areas only.

I use something similar in a Project of mine where the Average Player Level will make the enemies spawn in bigger and more dangerous troops. As for Region ID's you'd be stuck with about 255 variations per Tile but that could help for a good bit.
Edits to my plugin is fine.
Thank you very much!
Depending on what exactly you want to change (enemy spawns and their weight) there is also the option to change the Region ID from specific tiles in your Maps using the

$dataMap.data.fill(TileID,StartPoint,EndPoint);

function to change them It is a One Liner if you fill the entire Map but will become a more liner if you need to fill specific areas only.

I use something similar in a Project of mine where the Average Player Level will make the enemies spawn in bigger and more dangerous troops. As for Region ID's you'd be stuck with about 255 variations per Tile but that could help for a good bit.
thanks for the advice.

Original thread: https://forums.rpgmakerweb.com/threads/increasing-enemy-weight-in-game.176790/