The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on August 23, 2010, 04:07:28 PM

Title: Actor Specific Item Effects
Post by: modern algebra on August 23, 2010, 04:07:28 PM
Actor Specific Item Effects
Version: 1.0
Author: modern algebra
Date: August 23, 2010

Version History




Description



This script allows you to set items that have different effects based on who the item is used on. Thus, if you want to make apples give 50 HP generally but 100 HP to a particular actor who loves apples, you can do it. Similarly, if you want it to give only 25 HP to an actor who hates apples, you may do so. (Note that if you are using a script which predicts the effect of an item before using, it will not predict special effects correctly unless you ask me to write a patch). To add a graphical component to this script, please see the Graphical Favourite Items (http://rmrk.net/index.php/topic,39955.0.html) complementary script.

Features


Instructions

Place this script below the default scripts and above Main. If using Graphical Favourite Items, please ensure that this script is above that one.

Script




#==============================================================================
#    Actor Specific Item Effects
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: August 23, 2010
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#   
#    This script allows you to set items that have different effects based on
#   who the item is used on. Thus, if you want to make apples give 50 HP
#   generally but 100 HP to a particular actor who loves apples, you can do it.
#   Similarly, if you want it to give only 25 HP to an actor who hates apples,
#   you may do so. (Note that if you are using a script which predicts the
#   effect of an item before using, it will not predict special effects
#   correctly unless you ask me to write a patch).
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Place this script above Main and below the default scripts in the Script
#   Editor (F11).
#
#    The script works by replacing the item with another item when used on a
#   particular actor. This means that for each item that you want to have a
#   special effect, you need to create a dummy item. After that, it is pretty
#   simple. All you need to do is place the following code in the note field
#   of the item:
#     \favourite[actor_id, dummy_item_id]
#
#    So, when this item is used on that actor, then the item will have the
#   the effect of the dummy_item. So, for instance, if you put the following
#   code in the notebox of Item 1 (Potion):
#     \favourite[2, 2]
#   then the potion would have its normal effect when used on other actors, but
#   when used on Actor 2 (Ulrika), then it would have the effect of Item 2 (High
#   Potion). Please note that the dummy item must be usable under the same
#   conditions as the original item; otherwise it will not be used.
#
#    Note that this script is independent from its complement script: Graphical
#   Favourite Items. Therefore, setting items up in this script does not set
#   them up for that script and vice versa. Also, while this script will allow
#   you to make it so more than one item can have special effects on a single
#   actor, that script will only allow display for one item per actor.
#==============================================================================

#==============================================================================
# ** RPG::Item
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new methods - setup_actor_favourites; actor_favourites
#==============================================================================

class RPG::Item
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Actor Favourites
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def actor_favourites (actor_id = 0)
    setup_actor_favourites if @actor_favourites.nil?
    return @actor_favourites[actor_id].nil? ? 0 : @actor_favourites[actor_id]
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Retrieve Actor Favourites
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def setup_actor_favourites
    @actor_favourites = []
    self.note.gsub (/\\FAVOU?RITE\[(\d+)[,;\s]\s*(\d+)\]/i) {
      @actor_favourites[$1.to_i] = $2.to_i
    }
    return @actor_favourites
  end
end

#==============================================================================
# ** Game_Actor
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - item_effect
#==============================================================================

class Game_Actor
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Apply Item Effect
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mdrna_fvfd_itmefct_6yh2 item_effect
  def item_effect (user, item, *args)
    if item != nil && item.actor_favourites (@actor_id) != 0
      # Run method with the favourite item replacement.
      item_2 = $data_items[item.actor_favourites (@actor_id)]
      if item_effective? (user, item_2, *args)
        mdrna_fvfd_itmefct_6yh2 (user, item_2, *args)
      else
        mdrna_fvfd_itmefct_6yh2 (user, item, *args) # Run Original Method
      end
    else
      mdrna_fvfd_itmefct_6yh2 (user, item, *args) # Run Original Method
    end
  end
end


Credit




Thanks


Support



Please post in this topic at RMRK for support, no matter how old the thread is. Do not PM me.

Known Compatibility Issues

No currently known compatibility issues. If you are using the Graphical Favourite Items (http://rmrk.net/index.php/topic,39955.0.html) script, then that will need to be placed below this one.
Title: Re: Actor Specific Item Effects
Post by: hikomarukun on August 23, 2010, 07:59:52 PM
Thank you so much Modern Algebra! I can't wait to implement this in my game! You're are SUCH a champion!

-ps, you misspelled my name in the 'thanks' section (-o, +u) - not a big deal tho ^_^
Title: Re: Actor Specific Item Effects
Post by: IpickZero on September 23, 2011, 02:04:06 AM
I just found this Script today & was wondering If it Could also be used on weapons etc. I was looking for something like that.   :lol: