Advertisement
neonblack

State Graphics v1.3

Jun 15th, 2013
3,449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.83 KB | None | 0 0
  1. ##-----------------------------------------------------------------------------
  2. ## State Graphics v1.3
  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.3 - 8.17.2013
  13. ##  Fixed an issue with character sprite changing
  14. ## v1.2 - 3.16.2013
  15. ##  Added stacking states functions
  16. ## v1.1 - 3.15.2013
  17. ##  Fixed bug related to death transitions
  18. ## v1.0 - 3.15.2013
  19. ##  Wrote and debugged main script
  20. ##----------------------------------------------------------------------------##
  21.                                                                               ##
  22. $imported ||= {}                                                              ##
  23. $imported["Graphics_States"] = 1.3                                            ##
  24.                                                                               ##
  25. ##----------------------------------------------------------------------------##
  26. ##    Instructions:
  27. ## Place this script in the script editor below "Materials" and above "Main".
  28. ## This script allows states to change an actor or enemy's graphics.  This
  29. ## change remains active as long as the battler is afflicted with the state.
  30. ## If multiple states change graphics, the state with the highest priority
  31. ## determines the graphic.  These changes are applied using script calls:
  32. ##
  33. ## battler gfx["name" 0]  -or-  enemy battler gfx["name" 0 1, 2, 3]  -or-
  34. ## actor battler gfx["name" 0 1, 2, 3]
  35. ##  - Sets a battlers graphic name and hue while the state is applied.  "name"
  36. ##    is the file name and must be surrounded by quotes while 0 can be a number
  37. ##    from 0-255 for the hue.  If this tag is prefixed with "actor" or "enemy"
  38. ##    it must also include actor or enemy IDs at the end each separated by
  39. ##    commas (such as the 1, 2, 3 in this example).  Note that actor/enemy tags
  40. ##    take priority over the short tag, but higher priority states will always
  41. ##    be applied first.
  42. ## character gfx["name" 5]  -or-  face gfx["name" 5]  -or-
  43. ## actor face gfx["name" 5 1, 2, 3]  -etc-
  44. ##  - Changes the face or character walking sprites of the battler with this
  45. ##    state.  Either of these can be prefixed with actor or enemy and work
  46. ##    pretty much the same way as the battler gfx tags.  The only difference is
  47. ##    that the number behind the name changes the index (from 0-7).  This has
  48. ##    no effect on enemies without alternate scripts.
  49. ## name change["name"]  -or-  enemy name change["name" 1, 2, 3]
  50. ##  - Changes the name of the battler the that is applied to.  Works exactly
  51. ##    like all the other tags except it does not have a second argument.
  52. ##
  53. ## This script can also function with CP's Stacking States.  States can have
  54. ## different graphics for certain levels of stacks by adding a tag to the line
  55. ## you want to only occur on that stack.  This tag is as follows:
  56. ##
  57. ## stack gfx[1]
  58. ##  - Causes the line graphic to only occur when the stack condition is met.
  59. ##    To use this tag, simply place the tag after any other tag in this script.
  60. ##    You can use any number from 1 on up.  If this tag is not behind another
  61. ##    tag, the tag is assumed to work on all levels.  Note that this tag takes
  62. ##    priority over similar untagged lines.
  63. ##----------------------------------------------------------------------------##
  64.                                                                               ##
  65. ##----------------------------------------------------------------------------##
  66. ##    Compatibility:
  67. ## This script assumes that enemies cannot have faces and characters by default
  68. ## so if it happens to interfere with another script, try placing this script
  69. ## ABOVE the other script.  If that does not work, copy lines 111 to 142 and
  70. ## overwrite lines 152 to 178 with them.
  71. ##----------------------------------------------------------------------------##
  72.                                                                               ##
  73.                                                                               ##
  74. ##----------------------------------------------------------------------------##
  75. ## The following lines are the actual core code of the script.  While you are
  76. ## certainly invited to look, modifying it may result in undesirable results.
  77. ## Modify at your own risk!
  78. ###----------------------------------------------------------------------------
  79.  
  80.  
  81. class Game_BattlerBase
  82.   def state_graphic_bit(bit)  ## Gets the info from an array using the ID.
  83.     states.each do |state|
  84.       stack_pos = get_stack(state.id); ary = nil
  85.       id = enemy? ? -@enemy_id : @actor_id
  86.       if state.graphics_change.include?(id) &&
  87.          state.graphics_change[id].include?(bit)
  88.         ary = state.graphics_change[id][bit]
  89.       end
  90.       if state.graphics_change.include?(0) &&
  91.          state.graphics_change[0].include?(bit)
  92.         ary = state.graphics_change[0][bit] if ary.nil?
  93.       end
  94.      
  95.       if ary
  96.         return ary[stack_pos] if ary[stack_pos]
  97.         return ary[0] if ary[0]
  98.       end
  99.     end
  100.     return nil
  101.   end
  102.  
  103.   def get_stack(state) ## Gets the ID from the hash if Stack_States is used.
  104.     if ($imported["Stack_States"] || 0) >= 1.0
  105.       return state_stack(state)
  106.     else
  107.       return 1
  108.     end
  109.   end
  110. end
  111.  
  112. class Game_Battler < Game_BattlerBase
  113.   alias :cpgfxc_item_apply :item_apply
  114.   def item_apply(*args)
  115.     cpgfxc_item_apply(*args)
  116.     $game_player.refresh
  117.   end
  118. end
  119.  
  120. class Game_Actor < Game_Battler  ## If no replacement is found, use the old one.
  121.   alias :cpgfxc_state_face_name :face_name
  122.   alias :cpgfxc_state_face_index :face_index
  123.   alias :cpgfxc_state_character_name :character_name
  124.   alias :cpgfxc_state_character_index :character_index
  125.   alias :cpgfxc_state_battler_name :battler_name
  126.   alias :cpgfxc_state_battler_hue :battler_hue
  127.   alias :cpgfxc_state_name :name
  128.  
  129.   def face_name
  130.     state_graphic_bit(:face) || cpgfxc_state_face_name
  131.   end
  132.  
  133.   def face_index
  134.     state_graphic_bit(:face_ind) || cpgfxc_state_face_index
  135.   end
  136.  
  137.   def character_name
  138.     state_graphic_bit(:chara) || cpgfxc_state_character_name
  139.   end
  140.  
  141.   def character_index
  142.     state_graphic_bit(:chara_ind) || cpgfxc_state_character_index
  143.   end
  144.  
  145.   def battler_name
  146.     @held_battler_name = state_graphic_bit(:battler) if alive?
  147.     @held_battler_name || cpgfxc_state_battler_name
  148.   end
  149.  
  150.   def battler_hue
  151.     state_graphic_bit(:battler_hue) || cpgfxc_state_battler_hue
  152.   end
  153.  
  154.   def name
  155.     state_graphic_bit(:name) || cpgfxc_state_name
  156.   end
  157. end
  158.  
  159.  
  160. class Game_Enemy < Game_Battler
  161.   alias :cpgfxc_state_original_name :original_name
  162.   alias :cpgfxc_state_battler_name :battler_name
  163.   alias :cpgfxc_state_battler_hue :battler_hue
  164.  
  165.   def face_name
  166.     state_graphic_bit(:face)
  167.   end
  168.  
  169.   def face_index
  170.     state_graphic_bit(:face_ind)
  171.   end
  172.  
  173.   def character_name
  174.     state_graphic_bit(:chara)
  175.   end
  176.  
  177.   def character_index
  178.     state_graphic_bit(:chara_ind)
  179.   end
  180.  
  181.   def battler_name
  182.     @held_battler_name = state_graphic_bit(:battler) if alive?
  183.     @held_battler_name || cpgfxc_state_battler_name
  184.   end
  185.  
  186.   def battler_hue
  187.     state_graphic_bit(:battler_hue) || cpgfxc_state_battler_hue
  188.   end
  189.  
  190.   def original_name
  191.     state_graphic_bit(:name) || cpgfxc_state_original_name
  192.   end
  193.  
  194.   def name
  195.     get_name = state_graphic_bit(:name)
  196.     (get_name ? get_name : @original_name) + (@plural ? letter : "")
  197.   end
  198. end
  199.  
  200. class Game_Interpreter
  201.   alias :cpgfxc_command_313 :command_313
  202.   def command_313
  203.     cpgfxc_command_313
  204.     $game_player.refresh
  205.   end
  206. end
  207.  
  208. class Sprite_Battler < Sprite_Base
  209.   alias :cpgfxc_state_init_visibility :init_visibility
  210.   alias :cpgfxc_state_initialize :initialize
  211.  
  212.   def initialize(*args)
  213.     @first_run = true
  214.     cpgfxc_state_initialize(*args)
  215.   end
  216.  
  217.   def init_visibility
  218.     if @first_run
  219.       cpgfxc_state_init_visibility
  220.       @first_run = false
  221.     else
  222.       cpgfxc_state_init_visibility unless !@battler_visible && @battler.alive?
  223.     end
  224.   end
  225. end
  226.  
  227. module CP
  228. module STATEGFX
  229.  
  230. ACTOR  = /actor (battler|character|face) gfx\["(.+)" (\d+) ([\d, ]+)\]/i
  231. ENEMY  = /enemy (battler|character|face) gfx\["(.+)" (\d+) ([\d, ]+)\]/i
  232. COMMON = /(battler|character|face) gfx\["(.+)" (\d+)\]/i
  233. NAME   = /(actor |enemy )?name change\["(.+)"([\d, ]*)\]/i
  234. STACK  = /stack gfx\[(\d+)\]/i
  235.  
  236. end
  237. end
  238.  
  239. class RPG::State < RPG::BaseItem  ## REGEXPs and a few time savers.
  240.   def graphics_change
  241.     create_state_graphic_list if @graphics_change_hash.nil?
  242.     @graphics_change_hash
  243.   end
  244.  
  245.   def create_state_graphic_list
  246.     @graphics_change_hash = {}
  247.     note.split(/[\r\n]+/).each do |line|
  248.       if line =~ CP::STATEGFX::STACK
  249.         stack_pos = $1.to_i
  250.       else stack_pos = 0 end
  251.       case line
  252.       when CP::STATEGFX::ACTOR
  253.         bit, num = get_bit_num_61513($1.to_s.downcase)
  254.         package_61513($2.to_s, $3.to_i, to_a_61513($4.to_s), bit, num, stack_pos)
  255.       when CP::STATEGFX::ENEMY
  256.         bit, num = get_bit_num_61513($1.to_s.downcase)
  257.         package_61513($2.to_s, $3.to_i, to_a_61513($4.to_s), bit, num, stack_pos, true)
  258.       when CP::STATEGFX::COMMON
  259.         bit, num = get_bit_num_61513($1.to_s.downcase)
  260.         package_61513($2.to_s, $3.to_i, [0], bit, num, stack_pos)
  261.       when CP::STATEGFX::NAME
  262.         case $1.to_s.downcase
  263.         when "actor "; ary, invert = to_a_61513($3.to_s), false
  264.         when "enemy "; ary, invert = to_a_61513($3.to_s), true
  265.         else; ary, invert = [0], false
  266.         end
  267.         package_61513($2.to_s, 0, ary, :name, nil, stack_pos, invert)
  268.       end
  269.     end
  270.   end
  271.  
  272.   def get_bit_num_61513(state)
  273.     case state
  274.     when "battler";   bit, num = :battler, :battler_hue
  275.     when "character"; bit, num = :chara,   :chara_ind
  276.     when "face";      bit, num = :face,    :face_ind
  277.     else;             bit, num = nil,      nil
  278.     end
  279.     return [bit, num]
  280.   end
  281.  
  282.   def package_61513(string, int, array, bit, num, pos = 0, inverse = false)
  283.     array.each do |id|
  284.       id = inverse ? -id.to_i : id.to_i
  285.       @graphics_change_hash[id] ||= {}
  286.       @graphics_change_hash[id][bit] ||= {}
  287.       @graphics_change_hash[id][bit][pos] = string
  288.       @graphics_change_hash[id][num] ||= {}
  289.       @graphics_change_hash[id][num][pos] = int
  290.     end
  291.   end
  292.  
  293.   def to_a_61513(string)
  294.     string.split(/,/)
  295.   end
  296. end
  297.  
  298.  
  299. ##-----------------------------------------------------------------------------
  300. ## End of script.
  301. ##-----------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement