Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # Szyu's Item Usage Redirection
- # Version 1.0
- # By Szyu
- #
- # About:
- # If an item is used, and a condition of the target fits to the notes, the effect
- # is redirected to another items usage effect
- #
- # Instructions:
- # - Place below "▼ Materials" but above "▼ Main Process".
- #
- # How to Use:
- # <usage_redirection> and </usage_redirection> mark the condition area
- # in this block, you can add redirection with
- # "id - condition"
- #
- # Example:
- # <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])
- #
- #
- # Requires:
- # - RPG Maker VX Ace
- #
- # Terms of Use:
- # - Free for commercal and non-commercial use. Please list me
- # in the credits to support my work.
- #
- # Pastebin:
- # http://adf.ly/4920670/item-usage-redirection
- #
- #
- #==============================================================
- # * Game_Battler
- #==============================================================
- class Game_Battler < Game_BattlerBase
- alias sz_iurd_use_item use_item
- alias sz_iurd_item_apply item_apply
- 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
- def item_apply(user, item)
- if item.is_a?(RPG::Item) && item.usage_redirection.size > 0
- item.usage_redirection.each_pair do |cond, nid|
- if evaluate_redir_condition(cond)
- item = $data_items[nid]
- break
- end
- end
- end
- sz_iurd_item_apply(user, item)
- end
- def evaluate_redir_condition(cond)
- return eval(cond)
- end
- end
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- #==============================================================
- # * Initialize BaseItems
- #==============================================================
- module DataManager
- class << self
- alias load_db_iurd_sz load_database
- end
- def self.load_database
- load_db_iurd_sz
- load_iurd_items
- end
- def self.load_iurd_items
- groups = [$data_items]
- for group in groups
- for obj in group
- next if obj.nil?
- obj.load_iurd_notetags_sz
- end
- end
- end
- end
- #==============================================================
- # * Content of Recycling Items
- #==============================================================
- class RPG::UsableItem < RPG::BaseItem
- attr_reader :usage_redirection
- def load_iurd_notetags_sz
- @usage_redirection = {}
- @redir = false
- self.note.split(/[\r\n]+/).each do |line|
- case line
- when /<usage_redirection>/i
- @redir = true
- when /<\/usage_redirection>/i
- @redir = false
- else
- scan_sz_redir_notetag_line(line) if @redir
- end
- end
- end
- def scan_sz_redir_notetag_line(line)
- return unless line =~ /(\d+)\s*-(.+)/i ? true : false
- usage_redirection[$2.to_s] = $1.to_i
- end
- end
Add Comment
Please, Sign In to add comment