Advertisement
Guest User

Graphic Equip Ace

a guest
Jul 6th, 2012
2,341
0
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.   # * PRIORITY_EQUIP
  46.   #     The priority of what equipment type will be the bases on changing
  47.   #   the sprites and faces. This is from the least to greatest priority.
  48.   #     0 = Weapon;         3 = Body Armor;
  49.   #     1 = Shield;         4 = Accessory;
  50.   #     2 = Headgear;
  51.   #--------------------------------------------------------------------------
  52.   PRIORITY_EQUIP = [0, 4, 1, 2, 3]
  53.   #--------------------------------------------------------------------------
  54.   # * graphic_equip
  55.   #     Used to change sprites.
  56.   #     when item_id
  57.   #       return [[actor_id, sprite_name, sprite_index]]
  58.   #
  59.   #     Add another bonus by adding a comma (,) and another parameter array
  60.   #   before the last bracket.
  61.   #
  62.   #     Example: when 20
  63.   #                return [[1, Actor2, 2], [2, Actor2, 3]]
  64.   #
  65.   #     In this example, if Actor 1 will equip the item with the ID 20
  66.   #   (Saint Robe in Default), that actor will change its sprite graphic to
  67.   #   the sprite in actor 2 at index 2 (Bennett's Sprite) and if Actor 2 will
  68.   #   equip the item with the ID 20 (Saint Robe in Default), that actor will
  69.   #   change its sprite graphic to the sprite in actor 2 at index 3
  70.   #   (the sprite at Bennett's Right).
  71.   #--------------------------------------------------------------------------
  72.   def self.graphic_equip(id)
  73.     case id
  74.     when 1
  75.       return [[0, nil, 0]]
  76.     end
  77.     return [[0, nil, 0]]
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # * face_equip
  81.   #     Used to change faces.
  82.   #     when item_id
  83.   #       return [[actor_id, sprite_name, sprite_index]]
  84.   #
  85.   #     Add another bonus by adding a comma (,) and another parameter array
  86.   #   before the last bracket.
  87.   #
  88.   #     Example: when 20
  89.   #                return [[1, Actor2, 2], [2, Actor2, 3]]
  90.   #
  91.   #     In this example, if Actor 1 will equip the item with the ID 20
  92.   #   (Saint Robe in Default), that actor will change its face graphic to
  93.   #   the face in actor 2 at index 2 (Bennett's Face) and if Actor 2 will
  94.   #   equip the item with the ID 20 (Saint Robe in Default), that actor will
  95.   #   change its face graphic to the face in actor 2 at index 3
  96.   #   (the face at Bennett's Right).
  97.   #--------------------------------------------------------------------------
  98.   def self.face_equip(id)
  99.     case id
  100.     when 1
  101.       return [[0, nil, 0]]
  102.     end
  103.     return [[0, nil, 0]]
  104.   end
  105.  
  106. #----------------------------------------------------------------------------
  107. # * Do not edit below here
  108. #----------------------------------------------------------------------------
  109.  
  110.   GRAPHIC_EQUIP = /<ge[:]?\s*(\d+)\s*[,]?\s*([$]*\w+)?\s*[,]?\s*(\d+)\s*>/i
  111.   FACE_EQUIP = /<fe[:]?\s*(\d+)\s*[,]?\s*(\w+)?\s*[,]?\s*(\d+)\s*>/i
  112. end
  113.  
  114. class RPG::Armor
  115.   #--------------------------------------------------------------------------
  116.   # * Graphic Equipment
  117.   #--------------------------------------------------------------------------
  118.   def graphic_equip(equip_arr = [])
  119.     self.note.split(/[\r\n]+/).each { |line|
  120.       case line
  121.       when Jene::GRAPHIC_EQUIP
  122.         equip_arr.push([$1.to_i, $2.to_s, $3.to_i])
  123.       end
  124.     }
  125.     equip_arr.concat(Jene.graphic_equip(@id))
  126.     return equip_arr
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # * Face Equipment
  130.   #--------------------------------------------------------------------------
  131.   def face_equip(equip_arr = [])
  132.     self.note.split(/[\r\n]+/).each { |line|
  133.       case line
  134.       when Jene::FACE_EQUIP
  135.         equip_arr.push([$1.to_i, $2.to_s, $3.to_i])
  136.       end
  137.     }
  138.     equip_arr.concat(Jene.face_equip(@id))
  139.     return equip_arr
  140.   end
  141. end
  142.  
  143. class RPG::Weapon
  144.   #--------------------------------------------------------------------------
  145.   # * Graphic Equipment
  146.   #--------------------------------------------------------------------------
  147.   def graphic_equip(equip_arr = [])
  148.     self.note.split(/[\r\n]+/).each { |line|
  149.       case line
  150.       when Jene::GRAPHIC_EQUIP
  151.         equip_arr.push([$1.to_i, $2.to_s, $3.to_i])
  152.       end
  153.     }
  154.     equip_arr.concat(Jene.graphic_equip(@id))
  155.     return equip_arr
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # * Face Equipment
  159.   #--------------------------------------------------------------------------
  160.   def face_equip(equip_arr = [])
  161.     self.note.split(/[\r\n]+/).each { |line|
  162.       case line
  163.       when Jene::FACE_EQUIP
  164.         equip_arr.push([$1.to_i, $2.to_s, $3.to_i])
  165.       end
  166.     }
  167.     equip_arr.concat(Jene.face_equip(@id))
  168.     return equip_arr
  169.   end
  170. end
  171.  
  172. #==============================================================================
  173. # ** Game_Actor
  174. #------------------------------------------------------------------------------
  175. #  This class handles actors. It's used within the Game_Actors class
  176. # ($game_actors) and referenced by the Game_Party class ($game_party).
  177. #==============================================================================
  178.  
  179. class Game_Actor < Game_Battler
  180.   #--------------------------------------------------------------------------
  181.   # * Public Instance Variables
  182.   #--------------------------------------------------------------------------
  183.   attr_reader   :default_character_name           # character graphic filename
  184.   attr_reader   :default_character_index          # character graphic index
  185.   attr_reader   :default_face_name                # face graphic filename
  186.   attr_reader   :default_face_index               # face graphic index
  187.   #--------------------------------------------------------------------------
  188.   # * Setup
  189.   #     actor_id : actor ID
  190.   #--------------------------------------------------------------------------
  191.   alias jene_setup setup
  192.   def setup(actor_id)
  193.     jene_setup(actor_id)
  194.     actor = $data_actors[actor_id]
  195.     @default_character_name = actor.character_name
  196.     @default_character_index = actor.character_index
  197.     @default_face_name = actor.face_name
  198.     @default_face_index = actor.face_index
  199.     refresh_graphic_equip
  200.   end
  201.   #--------------------------------------------------------------------------
  202.   # * Change Equipment (designate object)
  203.   #     equip_type : Equip region (0..4)
  204.   #     item       : Weapon or armor (nil is used to unequip)
  205.   #     test       : Test flag (for battle test or temporary equipment)
  206.   #--------------------------------------------------------------------------
  207.   alias jene_change_equip change_equip
  208.   def change_equip(slot_id, item)
  209.     jene_change_equip(slot_id, item)
  210.     refresh_graphic_equip
  211.     $game_player.refresh
  212.   end
  213.   #--------------------------------------------------------------------------
  214.   # * Graphic Equipment
  215.   #     item  : Weapon or Armor
  216.   #--------------------------------------------------------------------------
  217.   def graphic_equip(item)
  218.     return unless item.is_a?(RPG::Weapon) || item.is_a?(RPG::Armor)
  219.     id = item.id
  220.     for graphic in item.graphic_equip
  221.       if @actor_id == graphic[0]
  222.         set_graphic(graphic[1], graphic[2], @face_name, @face_index)
  223.         break
  224.       end
  225.     end
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # * Face Equipment
  229.   #     item  : Weapon or Armor
  230.   #--------------------------------------------------------------------------
  231.   def face_equip(item)
  232.     return unless item.is_a?(RPG::Weapon) || item.is_a?(RPG::Armor)
  233.     id = item.id
  234.     for graphic in item.face_equip
  235.       if @actor_id == graphic[0]
  236.         set_graphic(@character_name, @character_index, graphic[1], graphic[2])
  237.         break
  238.       end
  239.     end
  240.   end
  241.   #--------------------------------------------------------------------------
  242.   # * Refresh Graphic Equip
  243.   #--------------------------------------------------------------------------
  244.   def refresh_graphic_equip
  245.     set_graphic(@default_character_name, @default_character_index,
  246.       @default_face_name, @default_face_index)
  247.     for i in Jene::PRIORITY_EQUIP
  248.       graphic_code = 'graphic_equip(equips[' + i.to_s + '])'
  249.       face_code = 'face_equip(equips[' + i.to_s + '])'
  250.       eval(graphic_code)
  251.       eval(face_code)
  252.     end
  253.   end
  254. end
  255.  
  256. #==============================================================================
  257. # ** Game_Party
  258. #------------------------------------------------------------------------------
  259. #  This class handles the party. It includes information on amount of gold
  260. # and items. The instance of this class is referenced by $game_party.
  261. #==============================================================================
  262.  
  263. class Game_Party < Game_Unit
  264.   #--------------------------------------------------------------------------
  265.   # * Object Initialization
  266.   #--------------------------------------------------------------------------
  267.   alias jene_initialize initialize
  268.   def initialize
  269.     jene_initialize
  270.     refresh_graphic_equip
  271.   end
  272.   #--------------------------------------------------------------------------
  273.   # * Refresh Graphic Equip
  274.   #--------------------------------------------------------------------------
  275.   def refresh_graphic_equip
  276.     for actor in members
  277.       actor.refresh_graphic_equip
  278.     end
  279.   end
  280. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement