Szyu's Item Usage Redirection

Szyu's Item Usage Redirection​
 
Introduction
Redirects an items usage effect, when certain conditions are met.


Get it at Pastebin
 
 
How to Use

<usage_redirection> and </usage_redirection> mark the condition area in an Item's notes
In this block, you can add redirection with
 

id - conditionExample:

<usage_redirection>20 - class_id == 2</usage_redirection>In this example, the used item's effect is redirected to item[20], if the
target's class_id is 2
 
Possible conditions could be everything, that could be done with script call
or from Game_Battler as class (for example id for actor's id, or $game_variables[x])
 
 
Credits
Credits to Szyu if you plan to use this script.

Terms of Use
You are free to use this script for commercial and non-commercial projects. However I'd like you to inform me of the projects you are planning to use it in, so I can keep track of where my scripts are used. 
Again, it would be helpful to put your Terms of Use commercial/non commercial in the opening post.

This looks particularly interesting.  Nice idea.


Line 47 to 51,

def use_item(item)
old_item = item.clone
sz_iurd_use_item(item)
consume_item(old_item) if item.is_a?(RPG::Item) && old_item != item
end

Does anyone know what the above script is doing?

This script will cause the item to be consumed twice.
Did the author make a mistake?
Moderator note: I have merged your post into the thread for the script

If we have the thread here for the script, you can just post your questions/issues right there, rather than starting a new post. This could help get attention sooner, from the script creator, as they might be subscribed to the thread.

It doesn't seem like that to me. Have you actually added the script to your game and played it, and confirmed that it DOES consume the item twice? If so, please show a screenshot so we can see how you've set it up.
Does anyone know what the above script is doing?
Did you not understand the instructions?

Since the script allows you to redirect effects to a different item, the script is simply applying the affects of item x and then removing item y (item used).

But like Shaz said, you should test scripts before questioning if they work.
I would also ask that the next time you post code to use a code block, not paste it as plain text.
I understood how the code was actually written when looking at the script itself.
未命名.png

MuRWgz.gif


I don't understand why you guys think I'm asking this question without testing it.

Just build a new project and paste the script in the script editor,
Not even a <usage_redirection>......</usage_redirection> tag in any item's note box.
When there are two potions in the inventory, just using one potion will consume two potions.

To Shaz:
Sorry, because the author was last online in 2021,
So I thought it would be more efficient to solve my problem by opening a new thread.
I don't understand why you guys think I'm asking this question without testing it.

Just build a new project and paste the script in the script editor,
Not even a <usage_redirection>......</usage_redirection> tag in any item's note box.
When there are two potions in the inventory, just using one potion will consume two potions.
Apologies. Didn't expect this to actually be an issue since the script is so old, who would have thought this issue was not discovered until now.

I believe the issue can be corrected if the method in question was changed to this
Ruby:
  def use_item(item)
    old_item = item.clone
    sz_iurd_use_item(item)
    consume_item(old_item) if item.is_a?(RPG::Item) && old_item.id != item.id
  end

The bug is real because when the item is cloned it creates a new reference in memory and thus they are different so it removes the item since they are not the same.
Apologies. Didn't expect this to actually be an issue sine the script is so old, who would have thought this issue was not discovered until now.

I believe the issue can be corrected if the method in question was changed to this
Ruby:
  def use_item(item)
    old_item = item.clone
    sz_iurd_use_item(item)
    consume_item(old_item) if item.is_a?(RPG::Item) && old_item.id != item.id
  end

The bug is real because when the item is cloned it creates a new reference in memory and thus they are different so it removes the item since they are not the same.
I would like to ask, what is the rationale for this change?
In other words, when is "old_item.id" not equal to "item.id"?
"old_item.id" and "tem.id" will be same when I use <usage_redirection> tag or not.
In other words, when is "old_item.id" not equal to "item.id"?
"old_item.id" and "tem.id" will be same when I use <usage_redirection> tag or not.
You are entirely right. All that does is stop the bug, but really we can delete that method entirely.
I tested it and it works as expected without the use_item method.
You are entirely right. All that does is stop the bug, but really we can delete that method entirely.
I tested it and it works as expected without the use_item method.
Thank you for all the help today.
Hope it helps someone who has the same problem in the future.

Original thread: https://forums.rpgmakerweb.com/threads/szyus-item-usage-redirection.45686/