Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2011
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.31 KB | None | 0 0
  1. #=============================================================================
  2. # Change the Leader in Map - By Ramiro
  3. #=============================================================================
  4. #
  5. # Instructions:
  6. # To know who is the leader call this: $game_party.leader
  7. #
  8. # Change PARTY_CHANGE_ACTIVE to the switch id than turns ON/OFF the party switcher
  9. #=============================================================================
  10.  
  11. module Party_Change
  12.   PARTY_CHANGE_ACTIVE = 1
  13. end
  14.  
  15. class Game_Player < Game_Character
  16.  
  17.   attr_reader :selected_index
  18.  
  19.   alias ch_initialize initialize
  20.  
  21.   def intialize
  22.     @selected_index = 0
  23.     ch_initialize
  24.   end
  25.  
  26.   #--------------------------------------------------------------------------
  27.   # * Refresh
  28.   #--------------------------------------------------------------------------
  29.   def refresh
  30.     if $game_party.members.size == 0
  31.       @character_name = ""
  32.       @character_index = 0
  33.     else
  34.       @selected_index = 0 unless @selected_index
  35.       actor = $game_party.members[@selected_index]   # Get front actor
  36.       @character_name = actor.character_name
  37.       @character_index = actor.character_index
  38.     end
  39.   end  
  40.  
  41.   def shift_left
  42.     @selected_index -= 1
  43.     @selected_index %= $game_party.members.size
  44.     refresh
  45.   end
  46.  
  47.   def shift_right
  48.     @selected_index += 1
  49.     @selected_index %= $game_party.members.size
  50.     refresh
  51.   end
  52.  
  53.   def reset_characters
  54.     @selected_index = 0
  55.     refresh
  56.   end
  57. end
  58.  
  59. class Game_Party < Game_Unit
  60.   alias game_party_remove_actor remove_actor
  61.   def remove_actor(id)
  62.     game_party_remove_actor(id)
  63.     $game_player.reset_characters
  64.   end
  65.  
  66.   def leader
  67.     return members[$game_player.selected_index]
  68.   end
  69.  
  70. end
  71.  
  72. class Scene_Map < Scene_Base
  73.  
  74.   include Party_Change
  75.  
  76.   alias scene_map_start start
  77.   alias scene_map_terminate terminate
  78.   alias scene_map_update update
  79.  
  80.  
  81.   def start
  82.     scene_map_start
  83.     @party_window = Window_HeroActive.new  
  84.     @party_window.visible = $game_switches[PARTY_CHANGE_ACTIVE]
  85.   end
  86.  
  87.   def terminate
  88.     scene_map_terminate
  89.      @party_window.dispose
  90.   end
  91.  
  92.   def update
  93.     scene_map_update
  94.     @party_window.update
  95.     @party_window.visible = $game_switches[PARTY_CHANGE_ACTIVE]
  96.     return if !$game_switches[PARTY_CHANGE_ACTIVE]
  97.     if Input.trigger?(Input::L)
  98.       @party_window.change_index(-1)
  99.       $game_player.shift_left
  100.     elsif Input.trigger?(Input::R)
  101.       @party_window.change_index(1)
  102.       $game_player.shift_right
  103.     end
  104.  
  105.   end
  106.  
  107. end
  108.  
  109. class Window_HeroActive
  110.  
  111.   def initialize
  112.     @index = $game_player.selected_index
  113.     @viewport = Viewport.new(0,0,108,36)
  114.     @viewport.z = 9999
  115.     @hud = Sprite.new(@viewport)
  116.     @hud.bitmap = Cache.picture("character change.png")
  117.     @hud.z = 9999
  118.     @ox = (@index - 1) * 36 - 2
  119.     refresh
  120.   end
  121.  
  122.   def update
  123.     if @ox > (@index - 1) * 36 - 2
  124.       @ox -= 2
  125.     elsif @ox < (@index - 1) * 36  - 2
  126.       @ox += 2
  127.     end  
  128.      @plane.ox = @ox
  129.   end
  130.  
  131.  
  132.   def refresh
  133.     create_battler_frame
  134.   end
  135.  
  136.   def dispose
  137.     @viewport.dispose
  138.     if @plane
  139.       @plane.bitmap.dispose
  140.       @plane.dispose
  141.     end  
  142.     @hud.bitmap.dispose
  143.     @hud.dispose
  144.   end
  145.  
  146.   def create_battler_frame
  147.     if @plane
  148.       @plane.bitmap.dispose
  149.       @plane.dispose
  150.     end  
  151.     @plane = Plane.new(@viewport)
  152.     @plane.bitmap = Bitmap.new(36 * $game_party.members.size,36)
  153.     draw_heros_on_bitmap(@plane.bitmap)
  154.     @plane.ox = @ox
  155.   end
  156.  
  157.  
  158.   def draw_heros_on_bitmap(bitmap)
  159.     for i in 0..$game_party.members.size
  160.       next if !$game_party.members[i]
  161.       actor = $game_party.members[i]
  162.       character_name = actor.character_name
  163.       bmp =Cache.character(character_name)
  164.       sign = character_name[/^[\!\$]./]
  165.       if sign != nil and sign.include?('$')
  166.         cw = bmp.width / 3
  167.         ch = bmp.height / 4
  168.       else
  169.         cw = bmp.width / 12
  170.         ch = bmp.height / 8
  171.       end
  172.         x = i * 36
  173.         y = 2
  174.         n = actor.character_index
  175.         src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
  176.         bitmap.blt(x, y, bmp, src_rect)        
  177.     end
  178.   end
  179.  
  180.   def visible=(value)
  181.     @plane.visible = value
  182.     @hud.visible = value
  183.   end
  184.  
  185.   def change_index(value)
  186.     @index += value
  187.   end
  188.  
  189. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement