Item Charges

As Ravenith suggested, here’s the Item Charges script! What does it do? Well, simply assign a number of charges to consumable items. They will only be really consumed once all their charges are used up. If I recall correctly, this feature existed in RM2k3 so I guess I could have put it within the RM2k3 Goodness release, if I hadn’t forgotten at that time.

Inventory screen

For simplicity purposes, the number of charges is displayed just after the name.

Download!

Instructions
The ever-so-glorious notetags are used once again to determine the maximum number of charges. Just put <item_charges: x> into them. Don’t forget: it only works for normal items. Not weapons. Not armors. Not your mom. At least I don’t think so.

Secondly, in the config module, you can change the color of the text used to display charges. Look out for this:
CHARGES_DISPLAY_COLOR = Color.new(40, 255, 120, 255)
And alter it however you want. The format is Color.new(red, green, blue, alpha).

DISABLE_CHARGE_TEXT = false
This will allow you to turn on or off the text to display the charges amount.

MAX_ITEMS = 99
And this is for setting a maximum amount of items (normal method, not with unique items).

If you are using Actor Inventory, things are gonna get real now.
Due to how the Actor Inventory script works, it is very possible to use charges from two different copies of a same item! Which is impossible with the normal way RPG Maker handles item possession. Look at this screen:

Actor Inventory example

If you find the 7 anomalies, you'll win a Yanfly inflatable doll! Limited edition!

As you can see, one of the Thunder Fûda has 3 charges and the other only 2. Normally, if you were to use one, the other would also lose one charge. So, how to do it? That’s simple. Use the config module!
DISABLE_ITEM_STACKING = false
This line. Set it to true. And items with charges will never stack with each other and be treated as completely different items. And this causes several problems:

  • If you modify the item database, your save file will never notice the changes. You will have to start a new game.
  • Scripts using the item ID will most likely be very confused. For instance, try to assign charges on a Grathnode and Install it: oh boy, this will be weird.
  • The Remove Item event command will not work on those items. They can still be sold though.

Unfortunately, as for now, I’m not really sure of how I can fix them. If I find out these will be the first issues to be addressed.

  1. When I set this:
    DISABLE_ITEM_STACKING = false
    to true, the game crash…it says

    Script ‘Kread EX – Item Charges’ line 226: NoMethodError ocurred.
    undefined method ‘max_charges’ for #
    –> Why? <–
    by the way…I use tankentai(Nah)…
    I use Actor Inventory and Ace Equip Engine…

    • I need more info. For instance, this line: undefined method ‘max_charges’ for #
      What was after the “#” symbol?

      • (OMG, that was really fast)Well…Nope…(There is no comment mark in the text)
        I should paste the method…Sorry for long text, the error is in the marked line
        #————————————————————————–
        # ● Trade items between an actor and the inventory (no stack version)
        #————————————————————————–
        def trade_item_with_party_wo_stack(new_item, old_item)
        return false if new_item && !$game_party.has_item?(new_item)
        if old_item != nil && old_item.max_charges != nil #marked line
        $game_party.temp_container_extract(old_item)
        else
        $game_party.gain_item(old_item, 1)
        end
        if new_item != nil && new_item.max_charges != nil
        $game_party.temp_container_add(new_item)
        else
        $game_party.lose_item(new_item, 1)
        end
        return true
        end
        end

        The error happens when I start a new game. o_O

      • Got it. It should work now. Try to download it again.

        It’s fast because I’ve got a computer at work and instant mail notification is win.

  2. Just dropping by, I wanted to say that your scripts are awesome; I’m using this along with Actor Inventory for a dungeon crawler I’m working on, and I really appreciate your work… your scripts are very handy!

    You rock, KreadEX!

    • Thanks, but remember that the stack disabler is experimental and might be extremely incompatible.
      I’ll update it one of those days…

      • I wouldn’t worry too much about about that; I’m keeping this project pretty simple.

        Other than the things you pointed out, what should I watch out for? General incompatibility with other item-based scripts?

  3. When disabling stacking, items are listed in the order they’re obtained.

    Is it possible to create a “Sort” option for the non-stackable item inventory? It’d be really neat.

    • Not with this (crappy) implementation. I’ll make a better one with Fomar’s base (like for Runic Enchantment) to fix the issue. You’ll have to wait for a bit because I’m extremely busy currently.

  4. hi i keep getting this error when using items that do not have charges

    Script ‘Item Charges’ line 316: NoMethodError occurred.

    undefined method ‘-‘ for nil:NilClass

    • This has already been reported and fixed. Try to download the script again.

      • Perhaps I’m just being dumb, but I keep getting an error when I attempt to use an item that doesn’t have a charge as well. With stacking disabled I get:
        “Script ‘Item Charges’ line 325: NoMethodError occurred.
        undefined method ‘[]’ for nil:NilClass”

        I believe I have the newest version of the script, so it would be wonderful if you could help me out.. Thanks in advance!

  5. I see you have this script with charges per item and you have an ammo requirement script, but neither quite matches what I am looking for. I was wondering if you might accept a request or perhaps already have a plan for the following.

    The idea is this. You equip a gun in your Weapon slot and a “clip”/”battery” (an item with say 20 charges) into an ammunition slot. Each use of the attack command would consume 1 charge of the “clip”/”battery”, and skills could potentially consume more, like a burst fire skill that would consume 3 shots and do a different attack. In this way, I was hoping to use Yanfly’s Command_Equip script to force players to “reload” be equipping a new “clip”/”battery” when the current one is used up, simulating the need to pay attention to your ammunition and to have to take time to reload.

    If this is not a possibility, or an interest of yours, I understand and will not press the issue, but I figured, “What’s the harm in asking?” Thanks for your time and consideration!

    –Steele

  6. When I use it along with Exp Bag it gives me an error:
    “script ‘Game_Battler’ line 707: NoMethodError occurred.
    Undefined method ‘tp’ for Nil:NilClass…
    Can Somebody help me with that?

  7. Is there any way to get rid of the charge amount next to the name? I prefer to add effects and that kind of information in the description, especially as I’m using icons for items instead of actual text.

  8. Added the option to remove charges display text and the option to set the max number of items (both are requests).

  9. This is a strange request, but is there any way to use a script call to replenish the charges of an item?

  10. Ah bugger actually, nevermind, there’s another problem with the above request. I’m trying to recreate the estus system from Dark Souls, whereby you have one item with ten charges. Using up all ten charges will result in you not being able to use the item anymore, obviously, but the item remains uncharged in your inventory. Interacting with a bonfire will replenish the charges you have.

    The problems I’ve encountered with doing this are the above one that I mentioned, and also the fact that setting an item to not be consumed results in the charges looping from the number set in . So when I use up all five charges, and the item is set to not be consumed, when I use the final charge the number goes to five again. Any ideas on how to overcome this?

    • That’s currently not implemented. I’ll try to add it soon (have a lot of things to do).

    • Dark Horseman

      I actually really wanted this too. If you ever work on this project again, could you make the charges changeable by a variable too? So you could upgrade an item you’ll be carrying with you throughout the entire game with common events.

  11. First of all, when it works, it looks nothing like the screen shots. Instead of the charges/uses being listed after the name of the item, It’s listed before the description of the item
    (i.e. 2/3 uses. description blah blah blah….)

    Here is the main problem. When I add items to be multiusable::

    Multiusable_Items= (4=>25, etc for about 12 items)

    I get “Syntax error line 47 ‘multiusable_items”

    Is there a maximum of items I can make to use charges? Is there a maximum amount of charges I can assign to an item?

    In D&D, brand new wands have 50 charges of a spell. That’s what I’m trying to accomplish.

    -Daniel (AKA Tiamat5774)

    • I have no Idea what Im doing. Let me apologize cause the script I was talking about above is not the same script you are offering. Having trouble figuring this one out period. I’m no good at scripting or editing scripts to my purpose so I’ll be taking this one out.

  12. This script prevented me from using the battle test feature on ace. I didn’t know if this was a known issue or not.

  13. So, I’m able to continue to use items in battle even if the charges are zero, or even negative!

    I’m using Actor Inventory, YEA Equip, YEA Battle, (pretty much every YEA script…)

  14. What about a fix so that you can have individual charges but eventing with items works as well? You see, my idea is that let’s say each Potion has 3 uses.
    If you have 3 potions, that’s 9 charges, or a (9) next to the name.
    When the number changes and lowers to 6, then you are automatically reduced one Potion.
    (It would use some sort of multiplication-whatever system to determine)

    So that way, you aren’t bound by the charge of just one potion, and there is no individual items aspect that breaks the game

  15. DarkClaymore

    Line 325 is throwing an exception for not having a method for nil:
    return if @item_charges[item.id].nil?

    My personal fix for that is adding the following check above that one line:
    return if @item_charges.nil?

    I haven’t encountered the same problem in line 312, but considering it has the same format, I’d suggest looking into it as well (I personally just threw my own primitive fix in there as well, just to make sure).

  16. DarkClaymore

    I have also now encountered a compatibility issue with Yanfly’s “JP Manager” script.
    If I equip an item (using the “Actor Inventory”) and then try to use the same type of item from Items menu, it throws an exception.

    The exception is thrown in line 402 of Yanfly’s “JP Manager” script:
    n *= equip.jp_rate

    I bypassed the error with an extra nil checking above that line, but I’m not confident that it’s an optimal solution:
    next if equip.jp_rate.nil?

  17. This script is so cool and beauty (i love rpgmaker 2k3) Is possible to add this feature to weapon and armor – limited ? This should always lost one point when attack succesfull with weapon or damage taken when armor is in equip – That could be something like weapons/armor endurance. Please make this possible 😀 Possibility of upgrade/repair could be cool too.That was in Silent Hill 4 .

  18. Hiya! First of all: Amazing script! Thank you so much!
    Secondly: I’m having trouble understanding what “MAX_ITEMS = 9” does. Could you clarify a bit? 😀

  19. The link is dead

Leave a comment