Item Charges

Selchar

Veteran
Veteran
Joined
Dec 28, 2012
Messages
299
Reaction score
81
First Language
English
Primarily Uses
Item Charges
Selchar
Introduction
This script allows for giving items multiple uses before they are consumed. It is to be used alongside Tsukihime's Instance Items.

Features
- Adds Item Charges
- Items can transform into other items when their charge reaches 0
- Items can be preserved with 0 charges(but unusable) if desired for some reason.

How to Use
Place the script below ▼ Materials, below Tsukihime's Instance Items, but above ▼ Main Process. Use the provided notetags to set individual item charge settings. Be sure to set Tsukihime's Instance Item's Enable Items to true.

Script
>Required<
Item Charges
Recharge Item Scene

FAQ
Q: What are the terms of use?
A: My terms are, anything goes, while the terms for Tsukihime's scripts can be found here

Q: Are there compatibility problems with any scripts?
A: None known at this time except for Kread's Actor Inventories, to which I have a patch for down below.

Credit and Thanks
- Selchar
- Tsukihime for the Instance Items Base

Compatibility Patches
Kread's Actor Inventory
Code:
#===============================================================================
# Selchar's Item Charges Compatibility Patch with Kread's Actor Inventory
#===============================================================================
class Game_Battler < Game_BattlerBase
  alias :kread_actor_inventory_sel_item_charge_consume  :consume_equip_item
  def consume_equip_item(item)
    return if self.enemy?
    return unless item.consumable
    item.current_charge -= 1
    item.refresh_name
    item.refresh_price
    if item.current_charge.zero?
      kread_actor_inventory_sel_item_charge_consume(item) unless item.no_charge_keep
      $game_party.gain_item(InstanceManager.get_instance($data_items[item.no_charge_transform]), 1) if item.no_charge_transform
    end
  end
end

class Game_Party < Game_Unit
  alias :kread_actor_inventory_sel_item_charge_consume :consume_item
  def consume_item(item)
    if $imported['KRX-ActorInventory'] && SceneManager.scene.is_a?(Scene_Battle)
      item_charge_consume_item(item)
    else
      kread_actor_inventory_sel_item_charge_consume(item)
    end
  end
end

class Window_ActorItem < Window_EquipSlot
  def enable?(index)
    item = @actor.equips[index]
    return false if item.is_a?(RPG::Item) && item.current_charge.zero?
    item.is_a?(RPG::Item) && item.battle_ok?
  end
end
 
Last edited:

Bonkers

Get ready to be Wowed!
Restaff
Joined
May 26, 2013
Messages
2,941
Reaction score
2,897
First Language
English
Primarily Uses
RMMV
How nice!  I had done something similar myself with Common events, and have a few questions.

For equipped weapons/armor/accessories, does the expended item automatically reequip itself to the actor it was attached too while it had charges, or is this only for items like potions etc? 

Do the new items stack with themselves normally?  It looks like the empty bottles in your screen shots are unique to one another for some reason.

If an actor could be tagged to be the only one to use an item, would this script still allow that to carry over without expending a charge when used by another actor?
 

Selchar

Veteran
Veteran
Joined
Dec 28, 2012
Messages
299
Reaction score
81
First Language
English
Primarily Uses
1: it's only for items like potions and the like.

2: There is no item stacking with Tsukihime's Item Instance script

3: The numbers following items names work as follow.

  a: non-consumable items will show no text(empty bottles shown in the screenshot)

  b: Items with only 1 charge will appear as (1), or (0) if they have no charge but you tag them to keep them.

  c: Items with more than 1 charge will appear as (x/y) where x is the current charge, and y is the maximum charge.

4: How do you mean?  The charge count is handled by the item itself, so when used by anyone it decreases.  I suppose it could be possible to make a tag that prevents charge reduction based on various circumstances, but it would probably be better to code a tag that makes it so that it can't be selected in battle unless the current actor has a specific tag.
 

Bonkers

Get ready to be Wowed!
Restaff
Joined
May 26, 2013
Messages
2,941
Reaction score
2,897
First Language
English
Primarily Uses
RMMV
4: How do you mean?  The charge count is handled by the item itself, so when used by anyone it decreases.  I suppose it could be possible to make a tag that prevents charge reduction based on various circumstances, but it would probably be better to code a tag that makes it so that it can't be selected in battle unless the current actor has a specific tag.
Actor 1 is a mage, Actor 2 is a cleric.  The consumable item grants an effect\skill only intended for mage class, and is tagged--> <tag: Mage> in it's note box.

Understood.  I am just seeing if Hime's tag script would be enough to control those circumstances.

Could I tag a class or actor to have the following circumstance?  Actor 3 is an alchemist class.  No charges for items are used when they use an item on themselves or others, while all other classes expend a charge from items.
 

Selchar

Veteran
Veteran
Joined
Dec 28, 2012
Messages
299
Reaction score
81
First Language
English
Primarily Uses
1: I haven't really used Tsukihime's Tag Manager, but I suppose now is as good of a time as any for me to check it out.  If you could block item use with regular items before, then that "should" carry over to the Instance item.

2: I could try to put together a notetag that will block charge use without blocking item use if it's on an actor/class/state/equipment/etc... that an actor is using.  It shouldn't be too hard at all.  Probably easier to do that than to add support to the tag manager just for that.

Edit:

I went and finished up an update of the script for an <ignore item charge> notetag when I had a bit of a brainwave, item charges tie into item consumption, and consumption is only done to consumable items, and you want your alchemist to treat consumable items as non-consumable meaning for your alchemist alone he'd have unlimited item use

If that sounds like what you want, then I can pull it out of the update and put it into it's own script for you.  The way I worked it out I can do so and it can be used both with and without this item charge script.

Note: The update mentioned isn't live of course since I'm considering it being a separate script on it's own.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Actor 1 is a mage, Actor 2 is a cleric.  The consumable item grants an effect\skill only intended for mage class, and is tagged--> <tag: Mage> in it's note box.


Understood.  I am just seeing if Hime's tag script would be enough to control those circumstances.
Use the "Use Condition Tags" add-on which prevents you from attempting to use an item if you're not allowed to (via tags).


If you want to have a special case where you can actually USE the item, but it has no effect, AND therefore charges should not be expended (doesn't seem very logical, but I guess you might want that), Selchar will have to add extra logic to check whether tag conditions are met.
 

Selchar

Veteran
Veteran
Joined
Dec 28, 2012
Messages
299
Reaction score
81
First Language
English
Primarily Uses
Finally managed to make a Item Recharge scene, tho I still don't fully understand how scenes/windows work, there doesn't seem to be any problems.
 

Feldherren

Veteran
Veteran
Joined
Mar 15, 2012
Messages
33
Reaction score
11
First Language
English
Is there a way of recharging a specified item, or must all recharging be done through the Recharge Item scene or semi-creative eventing?
 

Selchar

Veteran
Veteran
Joined
Dec 28, 2012
Messages
299
Reaction score
81
First Language
English
Primarily Uses
As far as I can think, it can only be done via the Recharge Item Scene provided, or some semi creative eventing as you called it. If eventing, you need to be able to grab the specific item and use it's individual recharge method. The scene does it automatically, but when eventing... *thinks*


If eventing, you would need to be able to grab the specific item, or item's id to be used. Normally to do that you'd need a select item menu(since it requires instance items, the actual ids may not be the same every play-through). You do have the option of "removing" a specific item, then re-adding it using the default event commands I think.


It all really depends on what specifically you want to do.
 

Feldherren

Veteran
Veteran
Joined
Mar 15, 2012
Messages
33
Reaction score
11
First Language
English
Let's say I had a specific item I wanted to recharge for free when the player does a certain action. For not-entirely-random example, imagine a DnD item with X uses a day. Could I recharge all instances of that item without player intervention?

Removing and replacing the items did seem like the simplest way, but I also plan on using Actor Inventory (...if it doesn't turn out to be utterly and completely incompatible with Item Instances, because they do just seem to toss up a lot of errors when put together). In that case I might have issues returning the new items to the correct inventories.
 

Selchar

Veteran
Veteran
Joined
Dec 28, 2012
Messages
299
Reaction score
81
First Language
English
Primarily Uses
I can't test it at the moment, but I thinking... place the following into your scripts.

Code:
class Game_Interpreter  def recharge_all_of(template_id)    $data_items.each do |item|      next unless item      next if item.is_template?      item.recharge if item.template_id == template_id    end  endend
Then you use the scriptcall recharge_all_of(template_id) where template_id is the id in the database of the item you wish to recharge.
 
Last edited by a moderator:

Nalathni

Villager
Member
Joined
Mar 22, 2014
Messages
7
Reaction score
0
First Language
English
Primarily Uses
I'm currently running into an issue of compatibility with this mod and skill conditions 1.1b by neonblack here is the link .http://forums.rpgmak...45-skill-costs/    What I'm trying to do is require skills to need the use of an item for instance I want a medic to be able to use the ability administer pills, which would require 1 bottle of pills, but I'd like to have it so a single bottle of pills can be used 5 times before consumed.  What I'm currently running into is that I can't use the skill without pills in my inventory and when they are in inventory as a useable item the charge counter counts down the way it's supposed to.  However when i trigger a skill to use the pills it consumes all the charges with one use.  Any assistance with this would be awesome.
 

ShadowLurk

Tanoshii~
Veteran
Joined
Feb 14, 2014
Messages
226
Reaction score
53
Primarily Uses
I'm currently running into an issue of compatibility with this mod
Try this.

Code:
class Game_BattlerBase    def item_cost_pay(skill)    return if enemy?  ## Prevents enemies from using the party's inventory.    return if skill.item_cost.empty?    skill.item_cost.each do |item|      case item.kind      when 1        req = $data_items[item.id]      when 2        req = $data_weapons[item.id]      when 3        req = $data_armors[item.id]      end      #$game_party.lose_item(req, item.cost)  ## Removes the items.      item.cost.times { $game_party.consume_item(req) }    end  end  end
 

Nalathni

Villager
Member
Joined
Mar 22, 2014
Messages
7
Reaction score
0
First Language
English
Primarily Uses
Try this.

class Game_BattlerBase def item_cost_pay(skill) return if enemy? ## Prevents enemies from using the party's inventory. return if skill.item_cost.empty? skill.item_cost.each do |item| case item.kind when 1 req = $data_items[item.id] when 2 req = $data_weapons[item.id] when 3 req = $data_armors[item.id] end #$game_party.lose_item(req, item.cost) ## Removes the items. item.cost.times { $game_party.consume_item(req) } end end endSo I ended up dropping this script and switching back to Kread-EX's item charge script, then I used this little ditty here you supplied me with and everything goes off without a hitch, you're a genius Shadow Lurk ty so much!!!
 

Mawichan

Veteran
Veteran
Joined
Jan 24, 2018
Messages
55
Reaction score
6
First Language
Spanish
Primarily Uses
RMVXA
Hello, I'm testing the script on a "dummy" project to see how it works and it gives me a NoMethodError.
In line 47 of the scrip "undefined method '-' for nil:NilClass.

upload_2018-1-23_21-38-17.png

It happens everytime I try to use a tagged item on an actor. (It's tested on a new game everytime, so the problem is not an outdated savefile)
Additionally, the current charges/max charges ratio doesn't show up in the menu.

What should I do?
 

Selchar

Veteran
Veteran
Joined
Dec 28, 2012
Messages
299
Reaction score
81
First Language
English
Primarily Uses
In Tsukihime's Instance Items script, line 198 you will see the line - Enable_Items = false, change that false to True
 

Mawichan

Veteran
Veteran
Joined
Jan 24, 2018
Messages
55
Reaction score
6
First Language
Spanish
Primarily Uses
RMVXA
It works perfectly now. Thank you so much! This the best script for item charges!
 

Mawichan

Veteran
Veteran
Joined
Jan 24, 2018
Messages
55
Reaction score
6
First Language
Spanish
Primarily Uses
RMVXA
Hello again! Sorry for the dumb question I made last time, and thank you again for helping me with it.
However there's something I want to do with Item Charges, but don't know how, maybe you could shine some light onto this.
I'm using Yanfly's Skill Cost Manager and I'd like to use item charges as a custom cost. In the skill notes I need to put the following tags:

This one would be to check if the item has some charges left
<custom cost requirement>
string
string
</custom cost requirement>

And this one would be to decrease the charges of the item by one.
<custom cost perform>
string
string
</custom cost perform>

That's really all I want to know. If this cannot really be done, then I understand. I'd rather not have returned to this thread and bothered you like this, but several days have gone by without a response on a separate thread I made and it's an important feature I wanted to add. Either way thank you very much for your time.
 

Selchar

Veteran
Veteran
Joined
Dec 28, 2012
Messages
299
Reaction score
81
First Language
English
Primarily Uses
*reads other thread as well* Under the assumption that the item(quiver) would simply be in your invenory the following should work.

Code:
<custom cost requirement>
$game_party.find_instance_item($data_items[X])
</custom cost requirement>

<custom cost perform>
$game_party.consume_item($game_party.find_instance_item($data_items[X]))
</custom cost perform>
The above of course doesn't work properly(negative charge o.o) if you use the <no charge keep> notetag but in the event that you do use it then add the following to the bottom of my script.

Code:
class Game_Party < Game_Unit
  def find_instance_item_wc(template_item)
    container_list = item_container_list(template_item)
    return container_list.find {|obj| obj.template_id == template_item.template_id && obj.current_charge > 0 }
  end
end
Then use...

Code:
<custom cost requirement>
$game_party.find_instance_item_wc($data_items[X])
</custom cost requirement>

<custom cost perform>
$game_party.consume_item($game_party.find_instance_item_wc($data_items[X]))
</custom cost perform>
In both cases X would be the ID of your item who's charge you wish to consume.
 
Last edited:

Mawichan

Veteran
Veteran
Joined
Jan 24, 2018
Messages
55
Reaction score
6
First Language
Spanish
Primarily Uses
RMVXA
*squeals*
God yess! It's a nice detail that you also took into consideration the <no charge keep> tag.
Thank you very much for taking the time for even taking a look at the other thread. I just got the notetags tested and it's working well.
You don't know how happy I'm right now. Pretty much made my whole week so far!
I'll paste your post onto the separate thread I had made to get it closed as solved. So it can stay there as reference for future users as well).
Thank you very much! Gosh this is so neat~
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,085
Members
137,583
Latest member
write2dgray
Top