PG_EventItemExtra - "Choose Items" for Weapons or Armour

Piyan Glupak

Veteran
Veteran
Joined
Nov 14, 2016
Messages
128
Reaction score
66
First Language
English
Here is a short plugin that lets you choose weapons or armour using a similar window to the "Choose Items" editor command. There are two plugin commands, one for weapons and the other for armour. The argument of both the plugin commands is the number of the variable that returns the database id number of the weapon or article of armour chosen.

Why might you want this plugin? I want to try re-usable treasure chests where you can store gold, an item, a weapon or a piece of armour. I didn't want to create huge "Show Choices" events with a lot of hidden choices, and then have to rewrite the choices whenever I added a new item to the game. Obviously, Yanfly's message core plugin and one of the self-variable plugins will be of great help as well in naming what comes out and storing the database id of the number or weapon.

If anyone has any comment about my writing style, I would be interested to read it, as I have a lot to learn.

[ISPOILER]

JavaScript:
//=============================================================================
// PG_EventItemExtra.js
//=============================================================================
/*:
 * @plugindesc Allows plugin commands to use the "Select Item" window to select
 * weapons or armour.
 *
 * @author Piyan Glupak (Richard Lee)
 *
 * @help
 *******************************************************************************
 * Plugin Commands
 *******************************************************************************
 * selectweapon VAR
 *
 * selectarmour VAR
 *
 * 'VAR' is the number of the variable the chosen weapon or armour is stored in.
 *******************************************************************************
 *Script Calls
 *******************************************************************************
 * If preferred, the following script calls can be used:
 *
 * $gameMessage.setItemChoice(VAR, 5);   for weapons
 * $gameMessage.setItemChoice(VAR, 6);   for armour
 *
 * 'VAR' is the variable to store the chosen weapon or armour.
 *
 * I recommend that you include the following in the same script box, immediately
 * after either of the above script calls:
 *
 * this.setWaitMode('message');
 ********************************************************************************
 * TERMS OF USE
 * Free to use for commercial or non-commercial games.  Crediting me would be a
 * nice gesture.
 *
 * COMPATIBILITY
 * No issues known at time of writing.
 */

 Window_EventItem.prototype.includes = function(item) {
    var itypeId = $gameMessage.itemChoiceItypeId();
    switch (itypeId) {
       case 6:
          return DataManager.isArmor(item);
       case 5:
          return DataManager.isWeapon(item);
          break;
       default :
          return DataManager.isItem(item) && item.itypeId === itypeId;
          }
};

const Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
   Game_Interpreter_pluginCommand.call(this, command, args);
};

Game_Interpreter.prototype.pluginCommand = function (command, args) {
   Game_Interpreter_pluginCommand.call(this, command, args);
   // If the plugin command is ours
   if (command.toLowerCase() === "selectweapon") {
      // Grab the arguments
      const weaponChoice = (parseInt(args[0]));
      $gameMessage.setItemChoice(weaponChoice, 5);
      this.setWaitMode('message');
   }
   if (command.toLowerCase() === "selectarmour") {
      // Grab the arguments
      const armourChoice = (parseInt(args[0]));
      $gameMessage.setItemChoice(armourChoice, 6);
      this.setWaitMode('message');
   }
};

[/ISPOILER]

EDIT: Had found a nasty bug between origin posting and being able to edit. It should work as planned now. I have also included a script call in case people prefer script to plugins.

Details of the bug were that it worked fine in events where it was followed immediately by text (such as in the events that I used to develop it), but gave unpredictable results if it was followed by things like controlling variables (as in creating treasure chests that you can store items in).

Yes, you can use it in commercial games free of charge.

Credit me either as "Piyan Glupak" or under my real name, which is "Richard Lee".

I know that I can't stop people passing it around, but I would much prefer people to link back to this account because if I ever need to do an update, I only have to worry about one publicly available version.
 
Last edited:

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,647
Reaction score
15,742
First Language
English
Primarily Uses
RMMV
Please add terms of use.

Can it be used in commercial games?
Can it be shared/reposted or would you prefer people to link back to your post?
How do you want to be credited?
 

Latest Threads

Latest Profile Posts

I honestly haven't ever been really active in this community, even though this year will mark my 4th year of having an account and 5th or 6th of using RPG maker. I didn't do anything with RM for most of 2020 and 2021 for personal reasons, but I'm excited to get back into game making!
Editing my old work, I thought the black border made the characters stand out.
Yes, I should have done it from the start. 010.PNG
Took a while, but finally released an update to my game. Now to see if anyone buys it :')
Doing RPG Maker News for this week (January 21st - 27th, 2022)
practice drawing start with duck :guffaw: 64*64010.PNG

Forum statistics

Threads
118,769
Messages
1,118,583
Members
155,924
Latest member
radoink
Top