neonblack

State Animations v1.0

Aug 18th, 2013
118
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##-----------------------------------------------------------------------------
  2. ## Animated States v1.0
  3. ## Created by Neon Black
  4. ##
  5. ## For both commercial and non-commercial use as long as credit is given to
  6. ## Neon Black and any additional authors.  Licensed under Creative Commons
  7. ## CC BY 3.0 - http://creativecommons.org/licenses/by/3.0/.
  8. ##----------------------------------------------------------------------------##
  9.                                                                               ##
  10. ##----------------------------------------------------------------------------##
  11. ##    Revision Info:
  12. ## v1.0 - 8.18.2013
  13. ##  Wrote and debugged main script
  14. ##----------------------------------------------------------------------------##
  15.                                                                               ##
  16. $imported ||= {}                                                              ##
  17. $imported["Anim_States"] = 1.0                                                ##
  18.                                                                               ##
  19. ##----------------------------------------------------------------------------##
  20. ##    Instructions:
  21. ## Place this script in the script editor below "Materials" and above "Main".
  22. ## This allows tagged states to display battle animations on battlers with the
  23. ## state applied.  The animation will loop for as long as the state is applied
  24. ## and will stop once the state is removed.  The animation will stop while
  25. ## another animation is being played unless certain other scripts are used.
  26. ##
  27. ## state anim id[5]  -etc-
  28. ##  - This tag goes into the state's notebox.  As long as the state is applied
  29. ##    the animation will play on the battler applied with the state.
  30. ##----------------------------------------------------------------------------##
  31.                                                                               ##
  32.                                                                               ##
  33. ##----------------------------------------------------------------------------##
  34. ## The following lines are the actual core code of the script.  While you are
  35. ## certainly invited to look, modifying it may result in undesirable results.
  36. ## Modify at your own risk!
  37. ###----------------------------------------------------------------------------
  38.  
  39.  
  40. class Game_Battler < Game_BattlerBase
  41.   def state_animation  ## A collection of the state animations.
  42.     icons = states.collect {|state| state.animation_index }
  43.     icons.delete(0)
  44.     icons[0]
  45.   end
  46. end
  47.  
  48. ## To prevent an error that would prevent combat from continuing while state
  49. ## animations played, this method checks if animations are playing MINUS
  50. ## animations related to states.
  51. class Sprite_Battler < Sprite_Base
  52.   def animation_minus_state?
  53.     if ($imported["CP_BATTLEVIEW_2"] || 0) >= 1.3
  54.       return @ani_array.size > 1 || (@ani_array.size == 1 &&
  55.              @ani_array[0].animation.id != @battler.state_animation)
  56.     else
  57.       return @animation && @animation.id != @battler.state_animation
  58.     end
  59.   end
  60.  
  61.   ## Starts state animations playing again.
  62.   alias :cp_animation_states_setup :setup_new_animation
  63.   def setup_new_animation
  64.     cp_animation_states_setup
  65.     unless check_using_animation
  66.       animation = $data_animations[@battler.state_animation]
  67.       start_animation(animation)
  68.       update_animation
  69.     end
  70.   end
  71.  
  72.   def check_using_animation
  73.     return true if @battler.state_animation.nil? || !self.visible
  74.     return true unless @battler.use_sprite?
  75.     if ($imported["CP_BATTLEVIEW_2"] || 0) >= 1.3
  76.       return @ani_array.any? { |ani| ani.animation.id == @battler.state_animation }
  77.     else
  78.       return animation?
  79.     end
  80.   end
  81. end
  82.  
  83. class Spriteset_Battle
  84.   def animation?
  85.     battler_sprites.any? {|sprite| sprite.animation_minus_state? }
  86.   end
  87. end
  88.  
  89. class RPG::State < RPG::BaseItem
  90.   def animation_index
  91.     @animation_index || make_animation_state
  92.   end
  93.  
  94.   def make_animation_state
  95.     note.split(/[\r\n]+/).each do |line|
  96.       @animation_index = 0
  97.       case line
  98.       when /state anim id\[(\d+)\]/i
  99.         @animation_index = $1.to_i
  100.       end
  101.     end
  102.     return @animation_index
  103.   end
  104. end
  105.  
  106.  
  107. ##-----------------------------------------------------------------------------
  108. ## End of script.
  109. ##-----------------------------------------------------------------------------
RAW Paste Data