Advertisement
Talonos

Shanghai's Counterattack

Apr 25th, 2011
1,303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.72 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Shanghai Simple Script - Counterattack State
  4. # Last Date Updated: 2010.05.02
  5. # Level: Normal
  6. #
  7. # For a simple counterattack script with nothing fancy like skill counters,
  8. # this script will have battlers retaliate if they're alive and have a state
  9. # with the counterattack property. Compatibility with Battle Engine Melody.
  10. #===============================================================================
  11. # Instructions
  12. # -----------------------------------------------------------------------------
  13. # To install this script, open up your script editor and copy/paste this script
  14. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  15. #
  16. # <counterattack>
  17. # Just put this into your state's notebox and it will create a counterattack
  18. # when the battler takes damage. Cannot counterattack other counterattacks.
  19. #===============================================================================
  20.  
  21. $imported = {} if $imported == nil
  22. $imported["CounterattackState"] = true
  23.  
  24. #==============================================================================
  25. # RPG::State
  26. #==============================================================================
  27.  
  28. class RPG::State
  29.   #--------------------------------------------------------------------------
  30.   # counterattack
  31.   #--------------------------------------------------------------------------
  32.   def counterattack
  33.     return @counterattack if @counterattack != nil
  34.     @counterattack = false
  35.     self.note.split(/[\r\n]+/).each { |line|
  36.       case line
  37.       when /<(?:COUNTERATTACK|counter attack)>/i
  38.         @counterattack = true
  39.       end
  40.     }
  41.     return @counterattack
  42.   end
  43. end
  44.  
  45. #==============================================================================
  46. # ** Game_Battler
  47. #==============================================================================
  48.  
  49. class Game_Battler
  50.   attr_accessor :action
  51.   attr_accessor :counterattack
  52.   #--------------------------------------------------------------------------
  53.   # * Damage Reflection
  54.   #--------------------------------------------------------------------------
  55.   alias execute_damage_sss_counterattack execute_damage unless $@
  56.   def execute_damage(user)
  57.     execute_damage_sss_counterattack(user)
  58.     create_counterattack if @hp_damage > 0
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # * create_counterattack
  62.   #--------------------------------------------------------------------------
  63.   def create_counterattack
  64.     return if !$scene.is_a?(Scene_Battle)
  65.     return if !exist?
  66.     return if $scene.active_battler.actor? == self.actor?
  67.     for state in states
  68.       next if !state.counterattack
  69.       @counterattack = true
  70.       break
  71.     end
  72.   end
  73. end
  74.  
  75. #==============================================================================
  76. # ** Scene_Battle
  77. #==============================================================================
  78.  
  79. class Scene_Battle < Scene_Base
  80.   attr_accessor :active_battler
  81.   #--------------------------------------------------------------------------
  82.   # * Execute Battle Actions
  83.   #--------------------------------------------------------------------------
  84.   alias execute_action_sss_counterattack execute_action unless $@
  85.   def execute_action
  86.     execute_action_sss_counterattack
  87.     process_counterattack if !@process_counterattack
  88.   end
  89.   #--------------------------------------------------------------------------
  90.   # * process_counterattack
  91.   #--------------------------------------------------------------------------
  92.   def process_counterattack
  93.     @process_counterattack = true
  94.     for member in ($game_party.existing_members + $game_troop.existing_members)
  95.       break if !@active_battler.exist?
  96.       next if member == nil
  97.       next if !member.counterattack
  98.       last_action = member.action.clone
  99.       last_battler = @active_battler
  100.       member.action.set_attack
  101.       member.action.target_index = @active_battler.index
  102.       @active_battler = member
  103.       inside_performed_actors = false
  104.       if @performed_actors != nil
  105.         inside_performed_actors = true if @performed_actors.include?(member)
  106.       end
  107.       @message_window.clear
  108.       execute_action
  109.       if @performed_actors != nil and !inside_performed_actors
  110.         @performed_actors.delete(@active_battler)
  111.       end
  112.       @active_battler = last_battler
  113.       member.action = last_action
  114.       member.counterattack = nil
  115.     end
  116.     @process_counterattack = false
  117.   end
  118. end
  119.  
  120. #===============================================================================
  121. #
  122. # END OF FILE
  123. #
  124. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement