Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- #
- # Shanghai Simple Script - Counterattack State
- # Last Date Updated: 2010.05.02
- # Level: Normal
- #
- # For a simple counterattack script with nothing fancy like skill counters,
- # this script will have battlers retaliate if they're alive and have a state
- # with the counterattack property. Compatibility with Battle Engine Melody.
- #===============================================================================
- # Instructions
- # -----------------------------------------------------------------------------
- # To install this script, open up your script editor and copy/paste this script
- # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
- #
- # <counterattack>
- # Just put this into your state's notebox and it will create a counterattack
- # when the battler takes damage. Cannot counterattack other counterattacks.
- #===============================================================================
- $imported = {} if $imported == nil
- $imported["CounterattackState"] = true
- #==============================================================================
- # RPG::State
- #==============================================================================
- class RPG::State
- #--------------------------------------------------------------------------
- # counterattack
- #--------------------------------------------------------------------------
- def counterattack
- return @counterattack if @counterattack != nil
- @counterattack = false
- self.note.split(/[\r\n]+/).each { |line|
- case line
- when /<(?:COUNTERATTACK|counter attack)>/i
- @counterattack = true
- end
- }
- return @counterattack
- end
- end
- #==============================================================================
- # ** Game_Battler
- #==============================================================================
- class Game_Battler
- attr_accessor :action
- attr_accessor :counterattack
- #--------------------------------------------------------------------------
- # * Damage Reflection
- #--------------------------------------------------------------------------
- alias execute_damage_sss_counterattack execute_damage unless $@
- def execute_damage(user)
- execute_damage_sss_counterattack(user)
- create_counterattack if @hp_damage > 0
- end
- #--------------------------------------------------------------------------
- # * create_counterattack
- #--------------------------------------------------------------------------
- def create_counterattack
- return if !$scene.is_a?(Scene_Battle)
- return if !exist?
- return if $scene.active_battler.actor? == self.actor?
- for state in states
- next if !state.counterattack
- @counterattack = true
- break
- end
- end
- end
- #==============================================================================
- # ** Scene_Battle
- #==============================================================================
- class Scene_Battle < Scene_Base
- attr_accessor :active_battler
- #--------------------------------------------------------------------------
- # * Execute Battle Actions
- #--------------------------------------------------------------------------
- alias execute_action_sss_counterattack execute_action unless $@
- def execute_action
- execute_action_sss_counterattack
- process_counterattack if !@process_counterattack
- end
- #--------------------------------------------------------------------------
- # * process_counterattack
- #--------------------------------------------------------------------------
- def process_counterattack
- @process_counterattack = true
- for member in ($game_party.existing_members + $game_troop.existing_members)
- break if !@active_battler.exist?
- next if member == nil
- next if !member.counterattack
- last_action = member.action.clone
- last_battler = @active_battler
- member.action.set_attack
- member.action.target_index = @active_battler.index
- @active_battler = member
- inside_performed_actors = false
- if @performed_actors != nil
- inside_performed_actors = true if @performed_actors.include?(member)
- end
- @message_window.clear
- execute_action
- if @performed_actors != nil and !inside_performed_actors
- @performed_actors.delete(@active_battler)
- end
- @active_battler = last_battler
- member.action = last_action
- member.counterattack = nil
- end
- @process_counterattack = false
- end
- end
- #===============================================================================
- #
- # END OF FILE
- #
- #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement