The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on October 11, 2008, 12:09:51 AM

Title: Element Immunities
Post by: modern algebra on October 11, 2008, 12:09:51 AM
Element Immunities
Version: 1.0
Author: modern algebra
Date: October 10, 2008

Version History



Description


This script allows you to make it so that only weapons, skills, or items with a certain element can target an enemy, as denoted by you. So, if you want to make a flying enemy that can only be hit by ranged weapons, then you can set it so that only weapons with the element 'Ranged' can hit that enemy.

Features


Instructions

See inside the header of the script.

Script


Code: [Select]
#==============================================================================
#  Element Immunities
#  Version: 1.0
#  Author: modern algebra (rmrk.net)
#  Date: October 9, 2008
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#    Place this script above Main and below Materials in the Script Editor.
#
#    To restrict what elements can harm the enemy, place into the notes section
#   of the Enemy this code:
#
#     \ELEM_VULN[element_ID]
#   
#    You can put as many of them as you like, and that will mean that only
#   those elements can harm the enemy. If you do not put any, then it will
#   assume that the monster is vulnerable to all elements.
#
#    EXAMPLE:
#     If this were in the Notes Box of a given enemy:
#
#      \ELEM_VULN[4]
#      \ELEM_VULN[5]
#
#    Then any item, weapon, or skill without either element 4 or 5 will not be
#   able to hurt this enemy.
#==============================================================================
# ** Game_Temp
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new accessor instance variable - active_battler
#==============================================================================

class Game_Temp
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Public Instance Variable
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  attr_accessor :active_battler # Holds current battler
end

#==============================================================================
# ** Game_Enemy
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - element_vulnerable?
#==============================================================================

class Game_Enemy
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Element Vulnerable?
  #    attack_array : an array of the objects used to attack the enemy
  #``````````````````````````````````````````````````````````````````````````
  #  Checks if the actor can hurt the enemy with the elements being used
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def element_vulnerable? (attack_array)
    # Retrieve note
    note = $data_enemies[@enemy_id].note.dup
    test = false
    while note.slice! (/\\ELEM_VULN\[(\d+)\]/i) != nil
      attack_array.each { |i| return true if i.element_set.include? ($1.to_i) }
      test = true
    end
    return !test
  end
end

#==============================================================================
# ** Window_TargetEnemy
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    overwritten super method - refresh
#==============================================================================

class Window_TargetEnemy < Window_Command
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Refresh
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def refresh
    self.contents.clear
    # Initialize enabled array
    @enabled_commands = [] if @enabled_commands.nil?
    @enabled_commands.clear
    for i in 0...@item_max
      # Get what is being used to attack the enemy
      tools = case $game_temp.active_battler.action.kind
      when 0 then $game_temp.active_battler.weapons # Basic; Target => Attack
      when 1 then [$data_skills[$game_temp.active_battler.action.skill_id]] # Skill
      when 2 then [$data_items[$game_temp.active_battler.action.item_id]]   # Item
      end
      enabled = @enemies[i].element_vulnerable? (tools.compact)
      @enabled_commands.push (enabled)
      draw_item(i, enabled)
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Enabled?
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def enabled?
    return @enabled_commands[self.index]
  end
end

#==============================================================================
# ** Scene_Battle
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased methods - start_target_enemy_selection,
#                    update_target_enemy_selection
#==============================================================================

class Scene_Battle
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Start Target Enemy Selection
  #``````````````````````````````````````````````````````````````````````````
  #  This saves the active battler into $game_temp for use in Target Window
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modalg_strt_enmy_slect_dnte_actor_83b5 start_target_enemy_selection
  def start_target_enemy_selection
    $game_temp.active_battler = @active_battler
    # Run Original Method
    modalg_strt_enmy_slect_dnte_actor_83b5
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Update Target Enemy Selection
  #``````````````````````````````````````````````````````````````````````````
  #  This method forbids a disabled enemy from being targeted
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias ma_enmy_elmnt_invuln_test_update_trgt update_target_enemy_selection
  def update_target_enemy_selection
    # If selected, then check if disabled
    if Input.trigger?(Input::C) && !@target_enemy_window.enabled?
      Sound.play_buzzer
      return
    end
    # Run original method
    ma_enmy_elmnt_invuln_test_update_trgt
  end
end

Credit



Thanks


Support


Just post here with any concerns.

Known Compatibility Issues

<If you know of any compatibility issues (like will not work with RTAB), post them here. Also, if you've done some compatibility fixes>

Demo


No Demo necessary


Creative Commons License
This script by modern algebra is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.
Title: Re: Element Immunities
Post by: Razielboy on October 11, 2008, 05:14:09 AM
Wow thanks for making this for me.
Title: Re: Element Immunities
Post by: Craze on October 11, 2008, 09:52:58 AM
This is pretty useful for people who haven't rewritten the stupid ONLY MOST EFFECTIVE ELEMENT WORKS part of Game_Battler. Good work!
Title: Re: Element Immunities
Post by: modern algebra on October 11, 2008, 11:29:46 PM
I'm glad you guys like it, though I'm not entirely sure what you're talking about Craze :P

And no problem Razielboy - it was fun enough to make.
Title: Re: Element Immunities
Post by: Countdown on August 26, 2009, 02:09:50 AM
Would this work with Vlad's Requiem ABS?
Title: Re: Element Immunities
Post by: modern algebra on August 26, 2009, 02:21:43 AM
No.
Title: Re: Element Immunities
Post by: Wiimeiser on July 06, 2010, 10:29:49 AM
Problem:
When I attempt to just attack an enemy the game crashes because normal attacks don't have any element. is there a fix for this, or do I need to rewrite the standard attacks system somehow?

Taking it Elsewhere!
Title: Re: Element Immunities
Post by: modern algebra on July 06, 2010, 11:46:05 AM
Normal attacks do have elements though, because weapons have elements :/

There might be an error if there is nothing equipped though, which might be what you meant?

Try changing this line:
Code: [Select]

      enabled = @enemies[i].element_vulnerable? (tools)

to:

Code: [Select]

      enabled = @enemies[i].element_vulnerable? (tools.compact)
Title: Re: Element Immunities
Post by: Wiimeiser on July 07, 2010, 08:01:21 AM
Yes, that's what I meant.