Guest User

Graphic Equip VX

a guest
Aug 13th, 2012
412
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # ** Change Graphic by Equipment
  3. # by: Jeneeus Guruman
  4. #------------------------------------------------------------------------------
  5. #  This script allows to change sprite and face graphics depending on the
  6. # Equipment.
  7. #
  8. #   How to insert:
  9. #
  10. #     * Plug-n-play
  11. #     * Place this below default and non-aliased scripts.
  12. #  
  13. #   How to use:
  14. #
  15. #     To use this, you need to put the following notetags:
  16. #
  17. #       To change sprites:
  18. #
  19. #       <ge: actor_id, sprite_name, sprite_index>
  20. #
  21. #       actor_id: The ID of the actor to be change graphics.
  22. #       sprite_name: The filename of the sprite graphic to be placed.
  23. #       sprite_index: The index of the sprite graphic to be placed.
  24. #
  25. #       To change face:
  26. #
  27. #       <fe: actor_id, face_name, face_index>
  28. #
  29. #       actor_id: The ID of the actor to be change face.
  30. #       face_name: The filename of the face graphic to be placed.
  31. #       face_index: The index of the face graphic to be placed.
  32. #
  33. #       Notes:
  34. #       * If you use a single-sprite file (files with $ at the
  35. #       beginning), you may also add it but the index must be 0.
  36. #       * If the notetag is not fit in a single line, shorten the filename or
  37. #       use the other method below.
  38. #       * You may put many notetags for the different actors at the same
  39. #       equipment.
  40. #      
  41. #==============================================================================
  42.  
  43. module Jene
  44.   #--------------------------------------------------------------------------
  45.   # * CHANGE_DEFAULT_GRAPHIC
  46.   #     Change default graphic if changed using "Change Actor Graphic" command.
  47.   #--------------------------------------------------------------------------
  48.   CHANGE_DEFAULT_GRAPHIC = true
  49.   #--------------------------------------------------------------------------
  50.   # * CHANGE_DEFAULT_GRAPHIC_SWITCH
  51.   #     Switch used to change default graphic if changed using "Change Actor
  52.   #   Graphic" command. CHANGE_DEFAULT_GRAPHIC must be "true" (without quotes)
  53.   #   to enable this. Put "0" (without quotes) to disable using the switch and
  54.   #   always changing the default graphics.
  55.   #--------------------------------------------------------------------------
  56.   CHANGE_DEFAULT_GRAPHIC_SWITCH = 1
  57.   #--------------------------------------------------------------------------
  58.   # * PRIORITY_EQUIP
  59.   #     The priority of what equipment type will be the bases on changing
  60.   #   the sprites and faces. This is from the least to greatest priority.
  61.   #     0 = Weapon;         3 = Body Armor;
  62.   #     1 = Shield;         4 = Accessory;
  63.   #     2 = Headgear;
  64.   #--------------------------------------------------------------------------
  65.   PRIORITY_EQUIP = [0, 4, 1, 2, 3]
  66.   #--------------------------------------------------------------------------
  67.   # * graphic_equip
  68.   #     Used to change sprites.
  69.   #     when item_id
  70.   #       return [[actor_id, sprite_name, sprite_index]]
  71.   #
  72.   #     Add another bonus by adding a comma (,) and another parameter array
  73.   #   before the last bracket.
  74.   #
  75.   #     Example: when 20
  76.   #                return [[1, Actor2, 2], [2, Actor2, 3]]
  77.   #
  78.   #     In this example, if Actor 1 will equip the item with the ID 20
  79.   #   (Saint Robe in Default), that actor will change its sprite graphic to
  80.   #   the sprite in actor 2 at index 2 (Bennett's Sprite) and if Actor 2 will
  81.   #   equip the item with the ID 20 (Saint Robe in Default), that actor will
  82.   #   change its sprite graphic to the sprite in actor 2 at index 3
  83.   #   (the sprite at Bennett's Right).
  84.   #--------------------------------------------------------------------------
  85.   def self.graphic_equip(id)
  86.     case id
  87.     when 1
  88.       return [[0, nil, 0]]
  89.     end
  90.     return [[0, nil, 0]]
  91.   end
  92.   #--------------------------------------------------------------------------
  93.   # * face_equip
  94.   #     Used to change faces.
  95.   #     when item_id
  96.   #       return [[actor_id, sprite_name, sprite_index]]
  97.   #
  98.   #     Add another bonus by adding a comma (,) and another parameter array
  99.   #   before the last bracket.
  100.   #
  101.   #     Example: when 20
  102.   #                return [[1, Actor2, 2], [2, Actor2, 3]]
  103.   #
  104.   #     In this example, if Actor 1 will equip the item with the ID 20
  105.   #   (Saint Robe in Default), that actor will change its face graphic to
  106.   #   the face in actor 2 at index 2 (Bennett's Face) and if Actor 2 will
  107.   #   equip the item with the ID 20 (Saint Robe in Default), that actor will
  108.   #   change its face graphic to the face in actor 2 at index 3
  109.   #   (the face at Bennett's Right).
  110.   #--------------------------------------------------------------------------
  111.   def self.face_equip(id)
  112.     case id
  113.     when 1
  114.       return [[0, nil, 0]]
  115.     end
  116.     return [[0, nil, 0]]
  117.   end
  118.  
  119. #----------------------------------------------------------------------------
  120. # * Do not edit below here
  121. #----------------------------------------------------------------------------
  122.  
  123.   GRAPHIC_EQUIP = /<ge[:]?\s*(\d+)\s*[,]?\s*([$]*\w+)?\s*[,]?\s*(\d+)\s*>/i
  124.   FACE_EQUIP = /<fe[:]?\s*(\d+)\s*[,]?\s*(\w+)?\s*[,]?\s*(\d+)\s*>/i
  125. end
  126.  
  127. class RPG::Armor
  128.   #--------------------------------------------------------------------------
  129.   # * Graphic Equipment
  130.   #--------------------------------------------------------------------------
  131.   def graphic_equip(equip_arr = [])
  132.     self.note.split(/[\r\n]+/).each { |line|
  133.       case line
  134.       when Jene::GRAPHIC_EQUIP
  135.         equip_arr.push([$1.to_i, $2.to_s, $3.to_i])
  136.       end
  137.     }
  138.     equip_arr.concat(Jene.graphic_equip(@id))
  139.     return equip_arr
  140.   end
  141.   #--------------------------------------------------------------------------
  142.   # * Face Equipment
  143.   #--------------------------------------------------------------------------
  144.   def face_equip(equip_arr = [])
  145.     self.note.split(/[\r\n]+/).each { |line|
  146.       case line
  147.       when Jene::FACE_EQUIP
  148.         equip_arr.push([$1.to_i, $2.to_s, $3.to_i])
  149.       end
  150.     }
  151.     equip_arr.concat(Jene.face_equip(@id))
  152.     return equip_arr
  153.   end
  154. end
  155.  
  156. class RPG::Weapon
  157.   #--------------------------------------------------------------------------
  158.   # * Graphic Equipment
  159.   #--------------------------------------------------------------------------
  160.   def graphic_equip(equip_arr = [])
  161.     self.note.split(/[\r\n]+/).each { |line|
  162.       case line
  163.       when Jene::GRAPHIC_EQUIP
  164.         equip_arr.push([$1.to_i, $2.to_s, $3.to_i])
  165.       end
  166.     }
  167.     equip_arr.concat(Jene.graphic_equip(@id))
  168.     return equip_arr
  169.   end
  170.   #--------------------------------------------------------------------------
  171.   # * Face Equipment
  172.   #--------------------------------------------------------------------------
  173.   def face_equip(equip_arr = [])
  174.     self.note.split(/[\r\n]+/).each { |line|
  175.       case line
  176.       when Jene::FACE_EQUIP
  177.         equip_arr.push([$1.to_i, $2.to_s, $3.to_i])
  178.       end
  179.     }
  180.     equip_arr.concat(Jene.face_equip(@id))
  181.     return equip_arr
  182.   end
  183. end
  184.  
  185. #==============================================================================
  186. # ** Game_Actor
  187. #------------------------------------------------------------------------------
  188. #  This class handles actors. It's used within the Game_Actors class
  189. # ($game_actors) and referenced by the Game_Party class ($game_party).
  190. #==============================================================================
  191.  
  192. class Game_Actor < Game_Battler
  193.   #--------------------------------------------------------------------------
  194.   # * Public Instance Variables
  195.   #--------------------------------------------------------------------------
  196.   attr_reader   :default_character_name           # character graphic filename
  197.   attr_reader   :default_character_index          # character graphic index
  198.   attr_reader   :default_face_name                # face graphic filename
  199.   attr_reader   :default_face_index               # face graphic index
  200.   #--------------------------------------------------------------------------
  201.   # * Setup
  202.   #     actor_id : actor ID
  203.   #--------------------------------------------------------------------------
  204.   alias jene_setup setup
  205.   def setup(actor_id)
  206.     jene_setup(actor_id)
  207.     actor = $data_actors[actor_id]
  208.     @default_character_name = actor.character_name
  209.     @default_character_index = actor.character_index
  210.     @default_face_name = actor.face_name
  211.     @default_face_index = actor.face_index
  212.     refresh_graphic_equip
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # * Change Equipment (designate object)
  216.   #     equip_type : Equip region (0..4)
  217.   #     item       : Weapon or armor (nil is used to unequip)
  218.   #     test       : Test flag (for battle test or temporary equipment)
  219.   #--------------------------------------------------------------------------
  220.   alias jene_change_equip change_equip
  221.   def change_equip(equip_type, item, test = false)
  222.     jene_change_equip(equip_type, item, test)
  223.     refresh_graphic_equip
  224.     $game_player.refresh
  225.   end
  226.   #--------------------------------------------------------------------------
  227.   # * Graphic Equipment
  228.   #     item  : Weapon or Armor
  229.   #--------------------------------------------------------------------------
  230.   def graphic_equip(item)
  231.     return unless item.is_a?(RPG::Weapon) || item.is_a?(RPG::Armor)
  232.     id = item.id
  233.     for graphic in item.graphic_equip
  234.       if @actor_id == graphic[0]
  235.         set_graphic(graphic[1], graphic[2], @face_name, @face_index)
  236.         break
  237.       end
  238.     end
  239.   end
  240.   #--------------------------------------------------------------------------
  241.   # * Face Equipment
  242.   #     item  : Weapon or Armor
  243.   #--------------------------------------------------------------------------
  244.   def face_equip(item)
  245.     return unless item.is_a?(RPG::Weapon) || item.is_a?(RPG::Armor)
  246.     id = item.id
  247.     for graphic in item.face_equip
  248.       if @actor_id == graphic[0]
  249.         set_graphic(@character_name, @character_index, graphic[1], graphic[2])
  250.         break
  251.       end
  252.     end
  253.   end
  254.   #--------------------------------------------------------------------------
  255.   # * Refresh Graphic Equip
  256.   #--------------------------------------------------------------------------
  257.   def refresh_graphic_equip
  258.     set_graphic(@default_character_name, @default_character_index,
  259.       @default_face_name, @default_face_index)
  260.     for i in Jene::PRIORITY_EQUIP
  261.       graphic_code = 'graphic_equip($data_weapons[@weapon_id])'
  262.       face_code = 'face_equip($data_weapons[@weapon_id])'
  263.       if i > 0
  264.         graphic_code = 'graphic_equip($data_armors[@armor' + i.to_s + '_id])'
  265.         face_code = 'face_equip($data_armors[@armor' + i.to_s + '_id])'
  266.       end
  267.       eval(graphic_code)
  268.       eval(face_code)
  269.     end
  270.   end
  271.   #--------------------------------------------------------------------------
  272.   # * Change Default Graphics
  273.   #--------------------------------------------------------------------------
  274.   def set_default_graphic(character_name, character_index, face_name, face_index)
  275.     @default_character_name = character_name
  276.     @default_character_index = character_index
  277.     @default_face_name = face_name
  278.     @default_face_index = face_index
  279.   end
  280. end
  281.  
  282. #==============================================================================
  283. # ** Game_Party
  284. #------------------------------------------------------------------------------
  285. #  This class handles the party. It includes information on amount of gold
  286. # and items. The instance of this class is referenced by $game_party.
  287. #==============================================================================
  288.  
  289. class Game_Party < Game_Unit
  290.   #--------------------------------------------------------------------------
  291.   # * Object Initialization
  292.   #--------------------------------------------------------------------------
  293.   alias jene_initialize initialize
  294.   def initialize
  295.     jene_initialize
  296.     refresh_graphic_equip
  297.   end
  298.   #--------------------------------------------------------------------------
  299.   # * Refresh Graphic Equip
  300.   #--------------------------------------------------------------------------
  301.   def refresh_graphic_equip
  302.     for actor in members
  303.       actor.refresh_graphic_equip
  304.     end
  305.   end
  306. end
  307.  
  308. #==============================================================================
  309. # ** Game_Interpreter
  310. #------------------------------------------------------------------------------
  311. #  An interpreter for executing event commands. This class is used within the
  312. # Game_Map, Game_Troop, and Game_Event classes.
  313. #==============================================================================
  314.  
  315. class Game_Interpreter
  316.   #--------------------------------------------------------------------------
  317.   # * Change Actor Graphic
  318.   #--------------------------------------------------------------------------
  319.   alias jene_command_322 command_322
  320.   def command_322
  321.     actor = $game_actors[@params[0]]
  322.     if actor && Jene::CHANGE_DEFAULT_GRAPHIC &&
  323.       ($game_switches[Jene::CHANGE_DEFAULT_GRAPHIC_SWITCH] ||
  324.       Jene::CHANGE_DEFAULT_GRAPHIC_SWITCH == 0)
  325.       actor.set_default_graphic(@params[1], @params[2], @params[3], @params[4])
  326.     end
  327.     jene_command_322
  328.   end
  329. end
RAW Paste Data