Element Immunities
Version: 1.0
Author: modern algebra
Date: October 10, 2008
Version History
- <Version 1.0> 10.10.2008 Original Release
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
- Allows you to restrict what weapons, etc... can be used to target an enemy
- Easy customizability by setting element vulnerabilites in the Notes section of the Enemy
Instructions
See inside the header of the script.
Script
#==============================================================================
# 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
- Razielboy, for the request
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
This script by
modern algebra is licensed under a
Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.