12-07-2008, 02:54 PM 
	
	
	Enemies Use Items
Version: 2.1
Version: 2.1
Introduction
I think this is self-explanatory.
Script
 Script
  			Code:
#==============================================================================
# ** Enemies Use Items
#------------------------------------------------------------------------------
#    by Fomar0153
#    updates by DerVVulfman
#    version 2.1
#       12-02-2007
#    Full SDK 2.3 Compatible (Does not need or require SDK 2.3)
#------------------------------------------------------------------------------
#
# INTRODUCTION:
#
# This system allows enemy battlers to use items during battle.  This is accom-
# plished by switching the skill used by an enemy to that of an item in a pre-
# defined list in the configuration section.
#
# By example, you could set up a Skeleton enemy to use a 'Tonic' in battle when
# it performs its 'Sleep' skill.   This 'skill-to-item' change would have to be
# defined in either the SWITCH_SKILL_ITEM hash,  or the SWITCH_ENEMY_SKILL_ITEM 
# hash (explained in the configuration section below).
#
# The enemies can either have infinite item usage, or can be limited to the no.
# of items used based on the SP points at their disposal.  This feature is con-
# trolled by the SWITCH_SP_LIMIT value. As long as it is false, enemies can use
# items without running out.   But if it is true, the enemies will use up their
# SP points as they use items.  The SP points used will be based on the SP Cost
# of the Skill it is switched from.
#
#------------------------------------------------------------------------------
#
# COMPATABILITY:
#
# This system is compatible  with the default battlesystem,  SDK 2.2,  the RTAB
# system,  Fomar's Action Cost,  ParaDog's  and XRXS's battle system in certain
# limits.
#
# Systems that  use AT bars  (everything except the 'default' and 'SDK default' 
# battlesystems) must have the SWITCH_SP_LIMIT value set to 'false'.  All other
# systems either use up the enemy sp  through repeated calls of the make_action
# def as their AT gauges are filled, or uses values other than sp_cost.
#
# In short,  the 'SWITCH_SP_LIMIT' value can only be 'true' if you're using the
# default or SDK default battlesystems.
#
#==============================================================================
   #========================================================================
   #  **  C  O  N  F  I  G  U  R  A  T  I  O  N      S  Y  S  T  E  M  **  #
   #========================================================================
   
# This constant holds the list of skills and items they are switched with.  It
# is in the following format:  { skill.id => item.id, skill.id => item.id,... }
# The sample currently switches the "Heal" skill with the "Sharp Stone" item, 
# and the "Greater Heal" with the "Potion" item.
  SWITCH_SKILL_ITEM       = {1 => 1, 2 => 1}
# This constant holds the lists of skills & items switched  for each enemy that
# uses them. The format to apply the switch mimics the design to the one above:
# { enemy.id => ( skill.id => item.id), enemy.id =>{ skill.id => item.id},... }
# The sample currently switches the "Mass Heal" skill with the "Tonic" item for
# the GHOST enemy,  and changes the "Heal" skill  with the "Barrier Stone" item
# for the BASILISK enemy.
  SWITCH_ENEMY_SKILL_ITEM = { 1 => {3 => 1}, 2 => {1 => 1}}
  
# This merely determines if you limit the items based on Skill SP cost. If this
# is true,  then the enemy must have enough SP to use the original skill before
# the item is used.  If it is false, then the enemy has an infinite supply.
  SWITCH_SP_LIMIT = false
  
#==============================================================================
# ** Game_Enemy
#------------------------------------------------------------------------------
#  This class handles enemies. It's used within the Game_Troop class
#  ($game_troop).
#==============================================================================
class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # * Make Action
  #--------------------------------------------------------------------------  
  alias item_make_action make_action
  def make_action
    item_make_action
    temp_hash = {}
    switch_id = self.current_action.skill_id  
    # Sets the Skill Limiting switch if the SWITCH_SP_LIMIT is true.
    # If true, this sets 'sp_limted' to true if SP is too low for item use.
    if SWITCH_SP_LIMIT
      if $data_skills[switch_id].sp_cost > self.sp
        sp_limited = true
      else
        sp_limited = nil
      end
    else
      sp_limited = nil
    end
    # Perform Skill/Item switch if 'sp_limited' switch isn't true.
    # It won't be true if there's enough SP, or if SWITCH_SP_LIMITED is false.
    if !sp_limited
      if SWITCH_SKILL_ITEM.include? switch_id
        self.current_action.kind = 2
        self.current_action.item_id = SWITCH_SKILL_ITEM[switch_id]      
        self.current_action.decide_random_target_for_enemy      
      end
      temp_hash = SWITCH_ENEMY_SKILL_ITEM[self.id] if SWITCH_ENEMY_SKILL_ITEM.include? self.id
      if temp_hash.include? switch_id
        self.current_action.kind = 2
        self.current_action.item_id = temp_hash[switch_id]      
        self.current_action.decide_random_target_for_enemy            
      end
    end
    # Use up SP (If SWITCH_SP_LIMIT is true)
    if SWITCH_SP_LIMIT
      self.sp =- $data_skills[switch_id].sp_cost
    end
  end
end
#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================
class Scene_Battle
  #--------------------------------------------------------------------------
  # * Make Item Action Results
  #--------------------------------------------------------------------------  
  alias e_make_item_action_result make_item_action_result
  def make_item_action_result(battler = @active_battler)
    @rtab = !@target_battlers
    if battler.is_a?(Game_Actor)
      @rtab ? e_make_item_action_result(battler) : e_make_item_action_result
    else
      # Get item
      @item = $data_items[battler.current_action.item_id]
      if @rtab
        # Setting animation ID
        battler.anime1 = @item.animation1_id
        battler.anime2 = @item.animation2_id
        # Setting common event ID
        battler.event = @item.common_event_id        
      else
        # Display item name on help window
        @help_window.set_text(@item.name, 1)
        # Set animation ID
        @animation1_id = @item.animation1_id
        @animation2_id = @item.animation2_id
        # Set common event ID
        @common_event_id = @item.common_event_id
      end
      # Deciding the object
      index = battler.current_action.target_index
      target = $game_party.smooth_target_actor(index)      
      if @rtab
        # Setting the object side battler
        set_target_battlers(@item.scope, battler)  
        # Applying the effect of the item
        for target in battler.target
          target.item_effect(@item, battler)
        end
      else
        # Set targeted battlers
        set_target_battlers(@item.scope)
        # Apply item effect
        for target in @target_battlers
          target.item_effect(@item)
        end
      end
    end
  end
endInstructions
Add the code and then read the comments DerVVulfman wrote.
FAQ
Is this RTAB compatable?
I haven't checked this version but I trust DerVVulfman and so should you.
Compatibility
Should be RTAB compatable and SDK 2.3 Compatible (Does not need or require SDK 2.3).
Credits and Thanks
Original Script: Fomar0153
Current Script: DerVVulfman (but you still have to credit me)
Author's Notes
The original version is still viewable at my site specifically:
http://fomar0153.awardspace.co.uk/index.ph...ripts&script=14
Terms and Conditions
Credit me and DerVVulfman. Other than that I don't care too much.

 
 
 Enemies Use Items
 Enemies Use Items