MV (SOLVED) How to Permanently Remove Instance Actors

Firstly, my apologies if this is in the wrong place. Not sure if this was suppose to be here or game mechanics.

I am trying to create a beast tamer/capture game for my son who is big into Pokemon at the moment. For those who do not know, a beast tamer style came means the player can capture many of the same type of enemies as long as they have room in a storage or stable of some type.

I'm most familiar with MV, which is why I am building it in the engine. So far, I have found plenty of plugins to capture enemies, such as through DreamX Enemy Capture plugin. And using another plugin, I can store them in a box. My problem comes here, after capturing a bunch of monsters and adding them to the party --How do I remove them permanently? In Pokemon game terms, that would be releasing them back into the wild. Or if we look at it as hired merc help, firing the help.

As far as I can tell, some of these Enemy Capture plugins, or Instance Actors by Hime, or Copy Actors by SRD, store these duplicate enemy and/or actors as variables. How can I call these variable actors later to permanently remove them?

Not sure if this is a specific plugin issue, if I just need some code to call in a script, or if I need one of these plugins modified.

Currently using the following plugins for this:
DreamX's Enemy Capture
Jeremy Cannady's Monster Storage Box
Well, the general code is

Code:
$gameParty.removeActor(1)
to remove actor with ID 1. I think the plugins you mentioned also support this code for their cloned actors.
If you have problems getting those IDs (for example if an actor is not currently in the party where you could get it with control variable)), then it depends completely on the plugin used to see what IDs it uses for instance actors.
You would have to link the specific plugin you've chosen to use to get help there.
Also, note that removing them from the party won't delete their data unless the plugin is coded to do that. If you just want to remove them, then no worries! Otherwise you'll need a plugin-specific answer...

Spoiler: deleting actor data
It doesn't look like any of the plugins you mentioned actually implement actor deletion. In fact, Hime's plugin specifically notes:
Deleting Actors

This plugin does not provide support for deleting actors, because that actor might be in use by other objects. It is safer to simply not use the actor.
I'll make some suggestions here (all untested) based on a quick look at each plugin's code; if they don't work (and I haven't made a mistake) then you might need either an alternative plugin that explicitly supports deleting instances, or a patch for the plugin of your choice.
  1. DreamX Capture Enemies:
    JavaScript:
    var copiedActorId = $gameVariables.value(1);
    $gameParty.removeActor(copiedActorId);
    for (var n = $gameSystem.capturedActors; n--;) {
      var capture = $gameSystem.capturedActors[n];
      if (capture.id === copiedActorId) {
        $gameSystem.capturedActors.splice(n, 1);
        var a = $dataActors.indexOf(capture);
        if (a >= 0)
          $dataActors.splice(a, 1);
        break;
      }
    }

  2. Hime's Instance Actors:
    JavaScript:
    var copiedActorId = $gameVariables.value(1);
    $gameParty.removeActor(copiedActorId);
    delete $dataActors[copiedActorId];

  3. SRD's Copy Actors:
    JavaScript:
    var copiedActorId = $gameVariables.value(1);
    $gameParty.removeActor(copiedActorId);
    delete $dataActors[copiedActorId];
    delete $gameSystem.copyStorage[copiedActorId];
In theory these will greatly reduce (but not eliminate) save bloat over time, particularly if actors get deleted a lot.

These all assume you've put the copied actor's ID into variable 1 in advance. If they cause an error then you could try splitting the single Script command into 2 commands separated by a 1-frame wait: remove the actor, wait for next frame, then delete the persistent data. E.g. for Hime's plugin:
  • Script: $gameParty.removeActor($gameVariables.value(1));
  • Wait: 1 frame
  • Script: delete $dataActors[$gameVariables.value(1)];
Thank you everyone for responding. Currently I am using DreamX's Capture Enemies plugin. After reviewing the help file, it states that the default duplicate actors are held at Actor ID 3000 and upwards. I am also using Monster Storage Box by Jeremy Cannady to store the duplicate actors in when not in the party.

@Aerosys - Thank you for the script code but I am not sure how I would go about using it. For example, if the duplicate actors are in the Monster Storage Box, I have no way of selecting them to permanently remove them. Or, say, if I set up a separate NPC event to speak to to remove the duplicate actors from the current party permanently, how do I know to target the specific duplicate actor? The same would go if they are in my party. There simply is no selection window within the menu to select a party member with the option to permanently delete them from the game.

@Andar - Linked the plugins I am currently using here and in the main thread.

@caethyril - That! I have no problem removing them from the party using Monster Storage Box or Party Switching plugins, but my concern comes when there is simply too many to deal with or the Monster Storage Box fills up. I would need a way that I can delete the duplicate actor entirely from the game. For example, if the duplicate actors are sitting in the Monster Storage Box, I would love for there to be an option to select the actor from that Box. When they are selected, then one of the options would be to Release/Fire/Etc. (permanently delete from game data).

Edit: I just realized that you posted suggestions for each plugin. I am very appreciative for your help and dedication. Where would I test using DreamX's JavaScript edit?
Ah, OK! For the snippets I provided I was thinking you could use them in a Script command, in an event. But if you want it to be part of an existing menu, that'll need to be written up as part of a plugin.

I am also using Monster Storage Box by Jeremy Cannady to store the duplicate actors in when not in the party.
...
For example, if the duplicate actors are sitting in the Monster Storage Box, I would love for there to be an option to select the actor from that Box. When they are selected, then one of the options would be to Release/Fire/Etc. (permanently delete from game data).
Maybe something like this would work (untested!):
[Edit: this one's broken, see follow-up post for a working version.]
Spoiler: plugin code
JavaScript:
/*:
 * @target MV
 * @plugindesc v1 - "Delete" command for MonsterStorageBox + DreamX_CaptureEnemies.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/posts/1523177/
 * @base DreamX_CaptureEnemies
 * @base MonsterStorageBox
 * @orderAfter MonsterStorageBox
 * @help Written for use with these plugins:
 *   - MonsterStorageBox by Jeremy Cannady:
 *      https://forums.rpgmakerweb.com/threads/51591/
 *   - DreamX_CaptureEnemies by DreamX:
 *      https://forums.rpgmakerweb.com/threads/57771/
 *
 * Free to use and/or modify for any project, no credit required.
 */
;void (function() {
"use strict";

  /**
   * `true` = try to fully delete the actor's data (e.g. instanced actors);
   * `false` = simply remove them from the deposit/party.
   */
  const FULL_DELETE = true;

  /** User-facing text for delete command. */
  const DELETE = "Release";

  /** User-facing text for cancelling deletion. */
  const CANCEL = "Cancel";

  /** Internal constructor name for new "confirm delete" window. */
  const C = "Window_ConfirmDelete";

  /** Internal scene property name for "confirm delete" window instance. */
  const W = "_confirmDeleteWindow";

  // Define new "confirm delete" window.
  COLD.BREED[C] = function() { this.initialize.apply(this, arguments); };
  COLD.BREED[C].prototype = Object.create(Window_Command.prototype);
  COLD.BREED[C].constructor = COLD.BREED[C];

  // Start closed and deactivated.
  COLD.BREED[C].prototype.initialize = function() {
    Window_Command.prototype.initialize.apply(this, arguments);
    this.openness = 0;
    this.deactivate();
  };

  // Delete Y/N.
  COLD.BREED[C].prototype.makeCommandList = function() {
    this.addCommand(CANCEL, "cancel");
    this.addCommand(DELETE, "ok");
  };

  // Add "confirm delete" window to scene.
  COLD.BREED.Scene_Breed_Select.prototype.createConfirmDeleteWindow = function() {
    this[W] = new COLD.BREED[C](0, 0);
    // Move to screen centre.
    this[W].x = Graphics.boxWidth - this[W].width >> 1;
    this[W].y = Graphics.boxHeight - this[W].height >> 1;
    // Bind response handlers.
    this[W].setHandler("ok", this.onDeleteOk.bind(this));
    this[W].setHandler("cancel", this.onDeleteCancel.bind(this));
    // Add to display.
    this.addWindow(this[W]);
  };
  void (function(alias) {
    COLD.BREED.Scene_Breed_Select.prototype.createAllWindows = function() {
      alias.apply(this, arguments);
      this.createConfirmDeleteWindow();
    };
  })(COLD.BREED.Scene_Breed_Select.prototype.createAllWindows);

  // Called when "delete" is chosen from details menu.
  COLD.BREED.Scene_Breed_Select.prototype.choseDelete = function() {
    const w0 = this._detailsMenu;
    const w1 = this[W];  // transfer control to confirmation window
    w0.deactivate();
    w1.open();
    w1.activate();
  };

  // Called when "delete" is confirmed.
  COLD.BREED.Scene_Breed_Select.prototype.onDeleteOk = function() {
    // Get ID of selected actor.
    const mode = this._menuWindow.currentSymbol();
    const actorId = (function() {
      switch (mode) {
        case "deposit":
          return $gameParty.members()[this._actorWindow.index()].actorId();
        case "withdraw":
          return $gameSystem.depositedActors[this._depositedWindow.index()];
      }
      return 0;
    })();
    // Remove from source.
    switch (mode) {
      case "deposit":
        $gameParty.removeActor(actorId);
        break;
      case "withdraw":
        $gameSystem.depositedActors.splice(this._depositedWindow.index(), 1);
        break;
    }
    // Remove from instanced actor list if appropriate.
    if (FULL_DELETE) {
      for (let n = $gameSystem.capturedActors; n--;) {
        const capture = $gameSystem.capturedActors[n];
        if (capture.id === actorId) {
          $gameSystem.capturedActors.splice(n, 1);
          const a = $dataActors.indexOf(capture);
          if (a >= 0)
            $dataActors.splice(a, 1);
          delete $gameActors._data[actorId];
          break;
        }
      }
    }
    // Test message! Remove this if/when it seems to be working.
    alert(TEXT + " complete for actor ID " + actorId ".");
    // Transfer control back to details.
    this.deleteCancel();
    // Refresh actor/deposit windows jic.
    this._actorWindow.refresh();
    this._depositedWindow.refresh();
  };

  // Called when "delete" is cancelled.
  COLD.BREED.Scene_Breed_Select.prototype.onDeleteCancel = function() {
    const w0 = this[W];  // transfer control from confirm window
    const w1 = this._detailsWindow;
    w0.deactivate();
    w0.close();
    w1.activate();
  };

  // Add "delete" command to details menu.
  ;void (function(alias) {
    COLD.BREED.detailsMenu.prototype.addMainCommands = function() {
      alias.apply(this, arguments);
      this.addCommand(DELETE, "delete", $gameSystem.depositedActors.length > 0);
      const L = this._list.length;
      this._list.splice(L - 2, 0, this._list.splice(L - 1, 1)[0]);  // penultimate command
    };
  })(COLD.BREED.detailsMenu.prototype.addMainCommands);

  // Bind response function for new "delete" command.
  ;void (function(alias) {
    COLD.BREED.Scene_Breed_Select.prototype.createDetailsMenu = function() {
      alias.apply(this, arguments);
      this.setHandler("delete", this.choseDelete.bind(this));
    };
  })(COLD.BREED.Scene_Breed_Select.prototype.createDetailsMenu);

})();
In theory this should add a "Release" command to the window that appears when you select an actor. You should have to confirm removal via a separate "Release"/"Cancel" window before it actually does anything.

I'd be amazed if all that works, untested as it is, but hopefully it's close to what you want. If you do encounter problems, you could try turning off FULL_DELETE in its code, i.e.
JavaScript:
  const FULL_DELETE = false;
Might help if that's the part that's causing problems.

Also, there's an alert line in the code for debug purposes; if you get this stuff working then that line can be removed~
Once again, thank you very kindly Caethryil for all your help. I just got the chance to test out the plugin addon and it does not appear to be working. I am not sure if it is user error on my part or it just does not work. I know that sometimes plugins will not work if they are not named correctly. As I had to copy/paste the code into a .js I wasn't sure what it was suppose to be called. Perhaps it wouldn't work for that reason? If that is not the case, the command for 'Release' did not appear in the command window for Monster Storage Box at all.
You're welcome! This monster box plugin is quite neatly written, so it's fairly easy to work with. 👋

I just got the chance to test out the plugin addon and it does not appear to be working. I am not sure if it is user error on my part or it just does not work. I know that sometimes plugins will not work if they are not named correctly.
Oh well, it was worth a try. No, you're OK: the filename can be pretty much whatever, since this one has no parameters (though to be safe it should follow the usual rules like no spaces etc). It sounds like my plugin is being ignored, meaning it probably has a syntax error somewhere. I'll look into testing it at some point...

Actually, I'll do that now. *muffled thuds, crashes, and cursing* 👋

OK, so I was right, there were several errors: a syntax error in the debug message (of all places!), a scope error, and a bunch of typos. Here's version 2!
Spoiler: plugin code v2
JavaScript:
/*:
 * @target MV
 * @plugindesc v2 - "Delete" command for MonsterStorageBox + DreamX_CaptureEnemies.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/posts/1523338/
 * @base MonsterStorageBox
 * @orderAfter MonsterStorageBox
 * @help Written for use with these plugins:
 *   - (REQUIRED) MonsterStorageBox by Jeremy Cannady:
 *      https://forums.rpgmakerweb.com/threads/51591/
 *   - (OPTIONAL) DreamX_CaptureEnemies by DreamX:
 *      https://forums.rpgmakerweb.com/threads/57771/
 * To fully delete instanced actors from DreamX's plugin, set:
 *     const FULL_DELETE = true;
 * ...in the plugin code.
 *
 * Free to use and/or modify for any project, no credit required.
 */
;void (function() {
"use strict";

  /**
   * For DreamX_CaptureEnemies compatibility.
   * - `true` = try to fully delete the actor's data, if they're instanced;
   * - `false` = simply remove the actor from the deposit/party.
   */
  const FULL_DELETE = false;

  /** User-facing text for delete command. */
  const DELETE = "Release";

  /** User-facing text for cancelling deletion. */
  const CANCEL = "Cancel";

  /** Internal constructor name for new "confirm delete" window. */
  const C = "Window_ConfirmDelete";

  /** Internal scene property name for "confirm delete" window instance. */
  const W = "_confirmDeleteWindow";

  // Define new "confirm delete" window.
  COLD.BREED[C] = function() { this.initialize.apply(this, arguments); };
  COLD.BREED[C].prototype = Object.create(Window_Command.prototype);
  COLD.BREED[C].constructor = COLD.BREED[C];

  // Start closed and deactivated.
  COLD.BREED[C].prototype.initialize = function() {
    Window_Command.prototype.initialize.apply(this, arguments);
    this.openness = 0;
    this.deactivate();
  };

  // Delete Y/N.
  COLD.BREED[C].prototype.makeCommandList = function() {
    this.addCommand(DELETE, "ok");
    this.addCommand(CANCEL, "cancel");
  };

  // Add "confirm delete" window to scene.
  COLD.BREED.Scene_Breed_Select.prototype.createConfirmDeleteWindow = function() {
    this[W] = new COLD.BREED[C](0, 0);
    // Move to screen centre.
    this[W].x = Graphics.boxWidth - this[W].width >> 1;
    this[W].y = Graphics.boxHeight - this[W].height >> 1;
    // Bind response handlers.
    this[W].setHandler("ok", this.onDeleteOk.bind(this));
    this[W].setHandler("cancel", this.onDeleteCancel.bind(this));
    // Add to display.
    this.addWindow(this[W]);
  };
  void (function(alias) {
    COLD.BREED.Scene_Breed_Select.prototype.createAllWindows = function() {
      alias.apply(this, arguments);
      this.createConfirmDeleteWindow();
    };
  })(COLD.BREED.Scene_Breed_Select.prototype.createAllWindows);

  // Called when "delete" is chosen from details menu.
  COLD.BREED.Scene_Breed_Select.prototype.choseDelete = function() {
    const w0 = this._detailsMenu;
    const w1 = this[W];  // transfer control to confirmation window
    w0.deactivate();
    w1.select(1);   // initialise to Cancel
    w1.open();
    w1.activate();
  };

  // Called when "delete" is confirmed.
  COLD.BREED.Scene_Breed_Select.prototype.onDeleteOk = function() {
    // Get ID of selected actor.
    const mode = this._menuWindow.currentSymbol();
    const actorId =
        mode === "deposit" ? $gameParty.members()[this._actorWindow.index()].actorId() :
        mode === "withdraw" ? $gameSystem.depositedActors[this._depositedWindow.index()] :
        0;
    // Remove from source.
    switch (mode) {
      case "deposit":
        $gameParty.removeActor(actorId);
        break;
      case "withdraw":
        $gameSystem.depositedActors.splice(this._depositedWindow.index(), 1);
        break;
    }
    // Remove from instanced actor list if appropriate.
    if (FULL_DELETE) {
      for (let n = $gameSystem.capturedActors; n--;) {
        const capture = $gameSystem.capturedActors[n];
        if (capture.id === actorId) {
          $gameSystem.capturedActors.splice(n, 1);
          const a = $dataActors.indexOf(capture);
          if (a >= 0)
            $dataActors.splice(a, 1);
          delete $gameActors._data[actorId];
          break;
        }
      }
    }
    // Test message! Remove this if/when it seems to be working.
    alert(DELETE + " complete for actor ID " + actorId + ".");
    // Refresh actor/deposit windows jic.
    this._actorWindow.refresh();
    this._depositedWindow.refresh();
    // Transfer control back to details.
    this.onDeleteCancel();
  };

  // Called when "delete" is cancelled.
  COLD.BREED.Scene_Breed_Select.prototype.onDeleteCancel = function() {
    const w0 = this[W];  // transfer control from confirm window
    const w1 = this._detailsMenu;
    w0.deactivate();
    w0.close();
    w1.activate();
  };

  // Add "delete" command to details menu.
  ;void (function(alias) {
    COLD.BREED.detailsMenu.prototype.addMainCommands = function() {
      alias.apply(this, arguments);
      this.addCommand(DELETE, "delete", $gameSystem.depositedActors.length > 0);
      const L = this._list.length;
      this._list.splice(L - 2, 0, this._list.splice(L - 1, 1)[0]);  // penultimate command
    };
  })(COLD.BREED.detailsMenu.prototype.addMainCommands);

  // Bind response function for new "delete" command.
  ;void (function(alias) {
    COLD.BREED.Scene_Breed_Select.prototype.createDetailsMenu = function() {
      alias.apply(this, arguments);
      this._detailsMenu.setHandler("delete", this.choseDelete.bind(this));
    };
  })(COLD.BREED.Scene_Breed_Select.prototype.createDetailsMenu);

})();
I briefly tested this version with MonsterStorageBox, but not with DreamX's Capture Enemies. Note that this version has FULL_DELETE = false by default.
Actually, I'll do that now. *muffled thuds, crashes, and cursing* 👋
Oh no! Caethryil! Is everything alright? I heard a crash!

😂Lol! In all seriousness, thank you so much! The new version of the plugin is working. The release function appears in the command box and the monster is released back into the wild. The only issue that there seems to be is this window box appearing to confirm that the Actor has been released. Can that be removed or, if not, changed to the in-game windowskin alerting it has been 'Successfully released into the wild'?


Capture.PNG
They wrote in the plugin code that:

// Test message! Remove this if/when it seems to be working.
alert(DELETE + " complete for actor ID " + actorId + ".");

Anyway, where's her medal for all the work she's done here?
Oh! I wasn't aware of that. I'll go in and remove it then.

@caethyril -Thank you so much for everything! My son and I really appreciate this. He had the biggest grin on his face when I told him this morning that there was now a release function on the storage box. With it we have the base mechanics down to proceed with his beast capture game. So again, thank you so much! You've made my eight year olds day.

If you don't mind, I think it would be wonderful to place a link in Jeremy Cannady's Storage Box thread back to this thread. That way other people will know there is an addon for it. I'm sure plenty of other people will be excited for that.
Great! 😂 And yes, feel free to mention this in the Monster Box plugin thread~

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-how-to-permanently-remove-instance-actors.179016/