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.
本贴来自国际rpgmaker官方论坛作者:Piyan Glupak处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:
https://forums.rpgmakerweb.com/threads/pg_eventitemextra-choose-items-for-weapons-or-armour.141076/