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] Change Items By Name

0 Members and 1 Guest are viewing this topic.

*
The Hero of Rhyme
Rep:
Level 83
( ͡° ͜ʖ ͡°)
2014 Best RPG Maker User - StoryProject of the Year 20142014 Queen of RMRK2011 Best Newbie2014 Best RPG Maker User - Creativity2014 Kindest Member2013 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
Change Items By Name
Version: 1.0
Author: yuyu!
Date: September 13, 2016

Version History


  • <Version 1.0> 9-13-2016 - Original Release

Description


If there's one thing I really can't stand about the RPG Maker engines, it's the way IDs are handled for items, weapons, armor...and just about everything, for that matter. I can't tell you how many times I want to go back and tweak the order of my items - which means adjusting every time I've tried to add or remove that item in my events.

This plugin will allow you to add or remove items (items, weapons, armor) by name. That means you can change the order of the items as you please! Huzzah! ^_^

Note: You will have to update your plugin calls if you change the item's name, though.

Instructions

PLUGIN COMMAND
Code: [Select]
YUYU_ITEM add/remove type qty name inc


COMMAND LEGEND
    (1) Add/remove = "add" / "remove" (or "a" / "r")
    (2) Type = "item" / "weapon" / "armor" (or "i", "w", "a")
    (3) Qty = The # amount to add or remove (ex: 3)
    (4) Name = The item's name (ex: "Potion")
        *Note: Use "_" in place of spaces in the name. Ex: "Rusty_Sword"
        *Note: Name IS case sensitive!
    (5) Inc = "include" (or "inc"), to include equipped items
        *Note: Only use this when removing weapons or armor.
        *Note: That means you can leave this blank. :)

EXAMPLES
   YUYU_ITEM add item 10 Magic_Water
      *Will add 10 of "Magic Water" from the items category.
   YUYU_ITEM r a 2 Shield
      *Will remove 2 of "Shield" from the armor category.
   YUYU_ITEM remove weapon 1 Bronze_Sword inc
      *Will remove 1 "Bronze Sword" from weapons (including equipped)
 
ADDITIONAL NOTES
   I don't recommend using this plugin for items that have the same name in your database. If you have multiple items with the same name, the one with the LARGEST id will be added / removed.
      Ex: If item ID 1 and 15 are named "Potion", the plugin will choose #15.

Plugin


Code: [Select]
/*
#=============================================================================
# Change Items By Name
# Yuyu_ChangeItemsByName.js
# By yuyu!
# Version 1.00
#=============================================================================
/*:
 * @plugindesc Allows adding / removing items by name and type.
 * @author Yuyu
 * @version 1.0
 *
 * @help
 *
 * == PLUGIN COMMAND ==
 *
 *  YUYU_ITEM add/remove type qty name inc
 *
 *  COMMAND LEGEND:
 *   (1) Add/remove = "add" / "remove" (or "a" / "r")
 *   (2) Type = "item" / "weapon" / "armor" (or "i", "w", "a")
 *   (3) Qty = The # amount to add or remove (ex: 3)
 *   (4) Name = The item's name (ex: "Potion")
 *       *Note: Use "_" in place of spaces in the name. Ex: "Rusty_Sword"
 *       *Note: Name IS case sensitive!
 *   (5) Inc = "include" (or "inc"), to include equipped items
 *       *Note: Only use this when removing weapons or armor.
 *       *Note: That means you can leave this blank. :)
 *
 * == EXAMPLES ==
 *
 *  YUYU_ITEM add item 10 Magic_Water
 *     *Will add 10 of "Magic Water" from the items category.
 *  YUYU_ITEM r a 2 Shield
 *     *Will remove 2 of "Shield" from the armor category.
 *  YUYU_ITEM remove weapon 1 Bronze_Sword inc
 *     *Will remove 1 "Bronze Sword" from weapons (including equipped)
 *
 * == ADDITIONAL NOTES ==
 *
 *  I don't recommend using this plugin for items that have the same name in
 *  your database. If you have multiple items with the same name, the one with
 *  the LARGEST id will be added / removed.
 *     Ex: If item ID 1 and 15 are named "Potion", the plugin will choose #15.
 *
 * == TERMS OF USE ==
 *
 *  Free for non-commercial and commercial use (credit would be appreciated!).
 *
*/
//#=============================================================================

    //  ----------------------------
    //  PLUGIN COMMANDS CHECK
    //  ----------------------------

    var yuyu_ChangeItemByName_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        yuyu_ChangeItemByName_Game_Interpreter_pluginCommand.call(this, command, args);

        if (command.toLowerCase() === 'yuyu_item') {

            // Set Variables
            var command = args[0];
            var type = args[1];
            var qty = parseInt(args[2]);
            var name = args[3];
            var inc = args[4];

            this.yuyuItemMain(command, type, qty, name, inc);

        }

    };

    //  ----------------------------
    //  MAIN METHOD
    //  ----------------------------

    Game_Interpreter.prototype.yuyuItemMain = function(command, type, qty, name, inc) {

        // add/remove type qty name inc

        var newName = this.yuyuItemChangeSpaces(name);

    // If Item
    if (type.toLowerCase() == 'item' || type.toLowerCase() == 'i') {

            var id = this.yuyuItemGetItemId(newName);
            this.yuyuItemChangeItem(command, id, qty);

        }

        // If Weapon
        if (type.toLowerCase() == 'weapon' || type.toLowerCase() == 'w') {

            var id = this.yuyuItemGetWeaponId(newName);
            this.yuyuItemChangeWeapon(command, id, qty, inc);

        }

        // If Armor
        if (type.toLowerCase() == 'armor' || type.toLowerCase() == 'a') {

            var id = this.yuyuItemGetArmorId(newName);
            this.yuyuItemChangeArmor(command, id, qty, inc);

        }
       
    };

    //  ----------------------------
    //  CHANGE SPACES
    //  ----------------------------
    // Replaces underscores in the item's name with spaces.

    Game_Interpreter.prototype.yuyuItemChangeSpaces = function(name) {

        if (name.contains("_"))
            return name.replace(/_/g , " ");
        else
            return name;

    };

    //  ----------------------------
    //  GET ITEM ID
    //  ----------------------------

    Game_Interpreter.prototype.yuyuItemGetItemId = function(name) {

        // Get item ID from name (checks all items for a name match)
        for (var i = 0; i < $dataItems.length; i++) {
            if ( $dataItems[i] != null ) {
                if ( $dataItems[i].name == name )
                    return $dataItems[i].id;
            }
        }

    };

    //  ----------------------------
    //  GET WEAPON ID
    //  ----------------------------

    Game_Interpreter.prototype.yuyuItemGetWeaponId = function(name) {

        // Get weapon ID from name (checks all weapons for a name match)
        for (var i = 0; i < $dataWeapons.length; i++) {
            if ( $dataWeapons[i] != null ) {
                if ( $dataWeapons[i].name == name )
                    return $dataWeapons[i].id;
            }
        }

    };


    //  ----------------------------
    //  GET ARMOR ID
    //  ----------------------------

    Game_Interpreter.prototype.yuyuItemGetArmorId = function(name) {

        // Get armor ID from name (checks all armors for a name match)
        for (var i = 0; i < $dataArmors.length; i++) {
            if ( $dataArmors[i] != null ) {
                if ( $dataArmors[i].name == name )
                    return $dataArmors[i].id;
            }
        }

    };

    //  ----------------------------
    //  CHANGE ITEM
    //  ----------------------------

    Game_Interpreter.prototype.yuyuItemChangeItem = function(command, id, qty) {

        // Add item
        if (command.toLowerCase() == "add" || command.toLowerCase() == "a")
            $gameParty.gainItem($dataItems[id], qty);

        // Remove item
        if (command.toLowerCase() == "remove" || command.toLowerCase() == "r")
            $gameParty.gainItem($dataItems[id], -qty);

    };

    //  ----------------------------
    //  CHANGE WEAPON
    //  ----------------------------

    Game_Interpreter.prototype.yuyuItemChangeWeapon = function(command, id, qty, inc) {

        // Check for including equipment.
        if (inc != undefined) {
            if (inc.toLowerCase() == "include" || inc.toLowerCase() == "inc")
                var incE = true;
            else
                var incE = false;
        }

        // Add weapon
        if (command.toLowerCase() == "add" || command.toLowerCase() == "a")
            $gameParty.gainItem($dataWeapons[id], qty);

        // Remove weapon
        if (command.toLowerCase() == "remove" || command.toLowerCase() == "r")
            $gameParty.gainItem($dataWeapons[id], -qty, incE);

    };

    //  ----------------------------
    //  CHANGE ARMOR
    //  ----------------------------

    Game_Interpreter.prototype.yuyuItemChangeArmor = function(command, id, qty, inc) {

        // Check for including equipment.
        if (inc != undefined) {
            if (inc.toLowerCase() == "include" || inc.toLowerCase() == "inc")
                var incE = true;
            else
                var incE = false;
        }

        // Add armor
        if (command.toLowerCase() == "add" || command.toLowerCase() == "a")
            $gameParty.gainItem($dataArmors[id], qty);

        // Remove armor
        if (command.toLowerCase() == "remove" || command.toLowerCase() == "r")
            $gameParty.gainItem($dataArmors[id], -qty, incE);

    };


Thanks


  • SoulPour - His tutorials still save my butt from time to time
  • Whoever wrote the script call list - Seriously. That thing is amazing. ;o;
  • Modern Algebra - Because he's awesome and I sorta copied this post from his script posts :>
  • Pacman - So he doesn't get mad at me for not crediting him again :V (ilu pcmn)

Terms of Use


Free for commercial and non-commercial use. Credit always appreciated! ^o^
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]