RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[MV] Select Item Categories 1.0.0

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
Select Item Categories
Version: 1.0.0
Author: modern algebra
Date: 31 October 2015

Version History


  • <Version 1.0.0> 2015-10-31 - Original Release

Description


Create additional categories for the Select Item event command, so that you are no longer restricted to just regular, key, or hidden items.

Features

  • You can now ask the player to choose from only a subset of their regular or key items, instead of showing them all their items of the same type every time
  • Can set items into as many categories as you like
  • Can make the categories include items of any type, so you can mix regular items with key items and hidden items

Instructions

Save the script in your plugins folder and import it through the Plugin Manager.

To set this script up, you first need to assign items to categories. To do that, enter the following code into the notebox of an item:

      \select[x]
          x : Category ID (must be an integer greater than 0)

You can also set an item to more than one category by putting a space and adding more category IDs.

Examples:

      \select[1]  // This item will show up in category 1.
      \select[3]  // This item will show up in category 3.
      \select[1 2 14]   // This item shows up in categories 1, 2, and 14

To select an item from one of these categories that you create, you need to use the following plugin command

      MASelectItem x y
          x : Variable ID - integer
          y : Category ID - integer

It will then work the same way as the regular Select Item command, and the ID of the item that the player selects will be assigned to the chosen variable.

Examples:

      MASelectItem 4 1
          // Items from Category 1 will be shown, and Variable 4 will be set
          // to the ID of the item that the player selects.

Plugin


You can download the .js file from Pastebin: http://pastebin.com/fE7hgf08

Code: [Select]
//=============================================================================
//  SelectItemCategories.js
//=============================================================================
//  Version: 1.0.0
//  Date: 31 October 2015
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*:
 * @plugindesc Create additional categories for the Select Item event command
 * @author Modern Algebra (rmrk.net)
 * @help To set this script up, you first need to assign items to categories.
 * To do that, enter the following code into the notebox of an item:
 *
 *      \select[x]
 *          x : Category ID (must be an integer greater than 0)
 *
 * You can also set an item to more than one category by putting a space and
 * adding more category IDs.
 *
 * Examples:
 *
 *      \select[1]  // This item will show up in category 1.
 *      \select[3]  // This item will show up in category 3.
 *      \select[1 2 14]   // This item shows up in categories 1, 2, and 14
 *
 * To select an item from one of these categories that you create, you need to
 * use the following plugin command
 *
 *      MASelectItem x y
 *          x : Variable ID - integer
 *          y : Category ID - integer
 *
 * It will then work the same way as the regular Select Item command, and the
 * ID of the item that the player selects will be assigned to the chosen
 * variable.
 *
 * Examples:
 *
 *      MASelectItem 4 1
 *          // Items from Category 1 will be shown, and Variable 4 will be set
 *          // to the ID of the item that the player selects.
 */
//=============================================================================

(function() {

    // Plugin Command : MASelectItem x y
    //      x : ID of the variable to set selection to (integer)
    //      y : ID of the category to select from (integer)
    var _ma_Game_Interpreter_pluginCommand =
            Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        _ma_Game_Interpreter_pluginCommand.call(this, command, args);
        if (command.toLowerCase() === 'maselectitem') {
            return this.maCommandSelectItemByCategory(+args[0], +args[1]);
        }
    };
   
    // Setup Select Item by Category
    Game_Interpreter.prototype.maCommandSelectItemByCategory = function(variableId, itemCategoryId) {
        if (!$gameMessage.isBusy()) {
            $gameMessage.maSelectItemByCategory(variableId, itemCategoryId)
            this.setWaitMode('message');
        }
        return false
    };
   
    // Clear - Initialize Item Category ID
    var _ma_Game_Message_clear =
            Game_Message.prototype.clear;
    Game_Message.prototype.clear = function() {
        _ma_Game_Message_clear.apply(this, arguments);
        this._maSelectItemCategoryId = 0; // Defauult is 0
    };
   
    // maSelectItemCategoryId - make category ID publicly accessible
    Game_Message.prototype.maSelectItemCategoryId = function() {
        return this._maSelectItemCategoryId;
    };
   
    // Game_Message - Setup Item by Category Selection
    Game_Message.prototype.maSelectItemByCategory = function(variableId, itemCategoryId) {
        this._itemChoiceVariableId = variableId;
        this._maSelectItemCategoryId = itemCategoryId;
    };

    // Window_EventItem includes - Include if category right and selecting by category
    var _ma_Window_EventItem_includes =
            Window_EventItem.prototype.includes;
    Window_EventItem.prototype.includes = function(item) {
        var categoryId = $gameMessage.maSelectItemCategoryId();
        if (categoryId > 0) { // If Category ID is setup (>0)
            return (DataManager.isItem(item) && this.masicCategoryIds(item).contains(categoryId));
        } else { // Default includes method if not using category ID
            return _ma_Window_EventItem_includes.apply(this, arguments);
        }
    };
   
    // Window_EventItem masicCategoryIds - Get all categories for an item
    Window_EventItem.prototype.masicCategoryIds = function(item) {
        var arr = [];
        var match = item.note.match(/\\SELECT\s*\[((?:\s*\d+[\s,;:]*)+)\]/i); // \select[x1 x2 x3 ... xn]
        if (match) { arr = match[1].match(/\d+/g).map(Number); } // Map strings to integers
        return arr;
    }

})();

Credit


  • modern algebra


Thanks

  • Yuyu - For requesting the script

Support


Post in this thread if you have any comments or questions. It is perfectly fine to post here even if this topic has not been posted in for a very long time.

Please do not message me privately, as any concerns you have are likely shared by others and they will benefit from our correspondence being public. Additionally, I am often absent, and posting publicly will allow other members to assist you when I am unable to do so quickly.

Terms of Use


You are welcome to use this script in any project of yours, whether it is commercial or non-commercial. There is no need to credit me, and please feel free to modify the plugin in whatever ways suit your project.

Basically, my plugin is your plugin, but please do not re-post this plugin or any modified version of it on another forum or website.
« Last Edit: October 31, 2015, 08:48:42 PM by modern algebra »

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Queen of RMRKProject of the Year 20142014 Best RPG Maker User - Story2011 Best Newbie2014 Kindest Member2014 Best RPG Maker User - Creativity2013 Queen of RMRKBronze SS AuthorBronze Writing ReviewerSecret Santa 2013 ParticipantFor taking arms in the name of your breakfast.GOOD!For frequently finding and reporting spam and spam bots2012 Best Yuyubabe Smiley2012 Best RPG Maker User (Creativity);o
Just tried it out... Ahhh, this plugin is perfect!! :gracie: Thanks again, modern! You're the best! ^_^
Spoiler for My Games and Art:
ℒℴѵℯ❤


My Artwork Thread

The Lhuvia Tales [Current]

Ambassador [Complete]

The Postman [Complete]

The Wyvern [Complete]

Phoenix Wright: Haunted Turnabout [Complete]

Major Arcana [Cancelled]


*
Rep: +0/-0Level 19
RMRK Junior
Hello. When i'm using native MVs Select Item function, i can put message before it and it will be displayed during selecting. When i'm using this plugin message closes before selecting starts, is there a way to keep showing it? Thanks.