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//=============================================================================
// 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
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.