Advertisement
Falmc

FA Tool Selector + Service pack

Sep 18th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.84 KB | None | 0 0
  1. #==============================================================================#
  2. #  #*****************#                                                         #
  3. #  #*** By Falcao ***#          * Int System Tool Selector + service pack      #
  4. #  #*****************#          This script display a quick tool selection menu#
  5. #                               and provide a bug fix pack and add-ons to      #
  6. #       RMVXACE                 Falcao Interactive System 2.0                  #
  7. #                               Date: September 18 2012                        #
  8. #                                                                              #
  9. # Falcao RGSS site:  http://falcaorgss.wordpress.com                           #
  10. # Falcao Forum site: http://makerpalace.com                                    #
  11. #                                                                              #
  12. #==============================================================================#
  13. #-------------------------------------------------------------------------------
  14. # * Installation
  15. #
  16. # Paste this script BELOW FA Interactive System 2.0
  17. #-------------------------------------------------------------------------------
  18. # * Int System Tool Selector Features
  19. #
  20. #  - Display a quick tool selection menu
  21. #  - Display interactive weapon icon on map
  22. #  - Display item cost value below interactive weapon icon
  23. #
  24. # * Service pack add-ons and fixes
  25. #
  26. #  - Added move animation to Game_Arrow
  27. #  - Added one more non movable method by input keys when using a tool
  28. #  - Added mouse support (plugin is activated if Mouse System button is installe
  29. #  - You can now add more weapon ids to be used as interactive weapon
  30. #  - Fixed minor bug when planting bombs or a barrel next to fall tiles
  31. #  - Fixed bug when making a bomb arrow at real time (bomb movemenmet now reset)
  32. #  - Fixed bug when bomb explode forcing the player to remove pick up graphic
  33.  
  34. msgbox(sprintf('Paste me below FA Interactive System 2.0 bitch!')) if
  35. not defined?(FalInt).is_a?(String)
  36.  
  37. # Configuration module
  38. module IntTool
  39.   include FalInt
  40.  
  41.   # Slot you want to use as tools:   true = weapon slot   false = armor slot
  42.   WToolSlot = true
  43.  
  44.   # X position in tiles of the tool hud on screen
  45.   Pos_X = 9
  46.  
  47.   # Y position in tiles of the tool hud on screen
  48.   Pos_Y = 11
  49.  
  50.   # Input key to call the tool selectionwindow
  51.   ToolSelectorKey = :ALT
  52.  
  53.   # Weapon/armors ids that equips the same tool, put inside the array the corr-
  54.   # esponding weapon/armor ids (this function is helpful in case you want more
  55.   # than one id to trigger the assigned tool), separate each id with a coma
  56.   Interactive_Weapons = {
  57.  
  58.   HweaponId     => [ ],  # HookShot
  59.   FweaponId     => [ ],  # Flame
  60.   BweaponId     => [ ],  # Bomb
  61.   BAweaponId    => [ ],  # Barrel
  62.   BladeWeaponId => [ ],  # Blade
  63.   ArrowWeaponId => [ ],  # Arrow
  64.  
  65.   }
  66.  
  67.   #-----------------------------------------------------------------------------
  68.   # * Available scripts calls
  69.   #
  70.   # SceneManager.goto(Scene_ToolSelector)   - Call the tools window manually
  71.   # $game_system.hide_mhud                  - Hide tool hud on map
  72.   # $game_system.show_mhud                  - Show tool hud on map
  73.  
  74.   # Note: The tool hud on map is visible when the player have equipped an
  75.   # interactive weapon/armor.
  76.  
  77.   #-----------------------------------------------------------------------------
  78.   # get interactive weapons / armor array
  79.   def self.tool_weapons
  80.     weapons = []  ; collected = []
  81.     Interactive_Weapons.each do |w , value|
  82.       value.each {|i| collected.push(i)}
  83.       collected.push(w) unless value.include?(w)
  84.     end
  85.     WToolSlot ? data = $data_weapons : data = $data_armors
  86.     collected.each {|w_id| weapons.push(data[w_id]) }
  87.     return weapons
  88.   end
  89.  
  90.   # check if specific interactive weapon / armor is equipped?
  91.   def self.equipped?(dw, value)
  92.     value.push(dw) unless value.include?(dw)
  93.     if WToolSlot
  94.       value.any? {|wep| $game_player.actor.weapons.include?($data_weapons[wep])}
  95.     else
  96.       value.any? {|arm| $game_player.actor.armors.include?($data_armors[arm])}
  97.     end
  98.   end
  99.  
  100.   # get equipped weapon / armor icon index
  101.   def self.icon_index
  102.     for t in tool_weapons
  103.       return t.icon_index if $game_player.actor.weapons.include?(t) if WToolSlot
  104.       return t.icon_index if $game_player.actor.armors.include?(t) if !WToolSlot
  105.     end
  106.     return nil
  107.   end
  108. end
  109.  
  110. #-------------------------------------------------------------------------------
  111. # * Game system new variables
  112. class Game_System
  113.   attr_accessor :tool_icon_index
  114.   attr_accessor :showing_twindow
  115.   attr_accessor :enable_ctool
  116.   attr_accessor :over_msbutton
  117.   attr_accessor :hide_thud
  118.  
  119.   def hide_mhud
  120.     @hide_thud = true
  121.   end
  122.  
  123.   def show_mhud
  124.     @hide_thud = nil
  125.   end
  126. end
  127.  
  128. #-------------------------------------------------------------------------------
  129. # * Tools toolbar class
  130. class Weapons_ToolBar
  131.   include FalInt
  132.   def initialize
  133.     @globalpos_x = IntTool::Pos_X * 32
  134.     @globalpos_y = IntTool::Pos_Y * 32
  135.     $game_system.tool_icon_index = IntTool::icon_index
  136.   end
  137.  
  138.   def create_sprites
  139.     create_back_sprite
  140.     create_icon_sprite
  141.     create_itemcost_sprite  if item_cost > 0
  142.   end
  143.  
  144.   def create_back_sprite
  145.     return if not @back_sprite.nil?
  146.     @back_sprite = Window_Base.new(@globalpos_x, @globalpos_y, 32, 32)
  147.     @back_sprite.opacity = 150
  148.     @back_sprite.z = 0
  149.   end
  150.  
  151.   def dispose_back_sprite
  152.     return if @back_sprite.nil?
  153.     @back_sprite.dispose
  154.     @back_sprite = nil
  155.   end
  156.  
  157.   def create_icon_sprite
  158.     return if not @icon_sprite.nil?
  159.     @icon_sprite = Sprite.new
  160.     @icon_sprite.bitmap = Bitmap.new(24, 24)
  161.     @icon_sprite.x = @globalpos_x + 4
  162.     @icon_sprite.y = @globalpos_y + 4
  163.     refresh_icon_sprite
  164.   end
  165.  
  166.   def refresh_icon_sprite
  167.     @icon_sprite.bitmap.clear
  168.     return if $game_system.tool_icon_index.nil?
  169.     icon = $game_system.tool_icon_index
  170.     bitmap = Cache.system("Iconset")
  171.     rect = Rect.new(icon % 16 * 24, icon / 16 * 24, 24, 24)
  172.     @icon_sprite.bitmap.blt(0, 0, bitmap, rect)
  173.   end
  174.  
  175.   def dispose_icon_sprite
  176.     return if @icon_sprite.nil?
  177.     @icon_sprite.dispose
  178.     @icon_sprite.bitmap.dispose
  179.     @icon_sprite = nil
  180.   end
  181.  
  182.   def create_itemcost_sprite
  183.     return if not @itemcost_sprite.nil?
  184.     @itemcost_sprite = Sprite.new
  185.     @itemcost_sprite.bitmap = Bitmap.new(32, 32)
  186.     @itemcost_sprite.bitmap.font.size = 13
  187.     @itemcost_sprite.bitmap.font.bold = true
  188.     @itemcost_sprite.z = 50
  189.     @itemcost_sprite.x = @globalpos_x + 10
  190.     @itemcost_sprite.y = @globalpos_y + 12
  191.     refresh_itemcost_sprite
  192.   end
  193.  
  194.   def dispose_itemcost_sprite
  195.     return if @itemcost_sprite.nil?
  196.     @itemcost_sprite.dispose
  197.     @itemcost_sprite.bitmap.dispose
  198.     @itemcost_sprite = nil
  199.   end
  200.  
  201.   def refresh_itemcost_sprite
  202.     return if @itemcost_sprite.nil?
  203.     @itemcost_sprite.bitmap.clear
  204.     @itemcost_sprite.bitmap.draw_text(0, 0, 212, 32, item_cost.to_s)
  205.   end
  206.  
  207.   def create_blink_sprite
  208.     return if not @blink_sprite.nil?
  209.     @blink_sprite = Sprite.new
  210.     @blink_sprite.bitmap = Bitmap.new(32, 32)
  211.     @blink_sprite.opacity = 60
  212.     @blink_sprite.bitmap.fill_rect(0, 0, 24, 24, Color.new(255, 255, 255, 255))
  213.     @blink_sprite.x = @globalpos_x + 4
  214.     @blink_sprite.y = @globalpos_y + 4
  215.     @blink_sprite.z = 50
  216.   end
  217.  
  218.   def dispose_blink_sprite
  219.     return if @blink_sprite.nil?
  220.     @blink_sprite.dispose
  221.     @blink_sprite.bitmap.dispose
  222.     @blink_sprite = nil
  223.   end
  224.  
  225.   # item cost value
  226.   def item_cost
  227.     cost = 0
  228.     IntTool::Interactive_Weapons.each do |dw , value|
  229.       cost = $game_party.item_number($data_items[BcostItemId]) if
  230.       dw == BweaponId and IntTool.equipped?(dw, value)
  231.       cost = $game_party.item_number($data_items[BarrelItemCost]) if
  232.       dw == BAweaponId and IntTool.equipped?(dw, value)
  233.       cost = $game_party.item_number($data_items[ArrowItemCost]) if
  234.       dw == ArrowWeaponId and IntTool.equipped?(dw, value)
  235.       cost = $game_player.actor.mp if dw == FweaponId and
  236.       IntTool.equipped?(dw, value)
  237.     end
  238.     return cost
  239.   end
  240.  
  241.   def dispose
  242.     dispose_back_sprite
  243.     dispose_icon_sprite
  244.     dispose_itemcost_sprite
  245.     dispose_blink_sprite
  246.   end
  247.  
  248.   def update
  249.     update_call_selector
  250.     if $game_system.hide_thud.nil?
  251.       $game_system.tool_icon_index.nil? ?  dispose  : create_sprites
  252.       item_cost > 0 ? create_itemcost_sprite : dispose_itemcost_sprite
  253.     else
  254.       dispose
  255.       return
  256.     end
  257.     update_icon_sprite
  258.     update_blink_sprite
  259.   end
  260.  
  261.   def update_icon_sprite
  262.     if defined?(Map_Buttons).is_a?(String)
  263.       if !@back_sprite.nil? && Mouse.object_area?(@back_sprite.x,@back_sprite.y,
  264.         @back_sprite.width, @back_sprite.height)
  265.         $game_system.enable_ctool = true
  266.         refresh_itemcost_sprite if Mouse.trigger?(0)
  267.         create_blink_sprite
  268.       else
  269.         $game_system.enable_ctool = nil
  270.         dispose_blink_sprite
  271.       end
  272.     else
  273.       refresh_itemcost_sprite if Input.trigger?(ToolActionKey)
  274.     end
  275.     if $game_system.tool_icon_index != IntTool::icon_index
  276.       $game_system.tool_icon_index = IntTool::icon_index
  277.       refresh_icon_sprite
  278.     end
  279.   end
  280.  
  281.   def update_call_selector
  282.     if Input.trigger?(IntTool::ToolSelectorKey)
  283.       SceneManager.goto(Scene_ToolSelector)
  284.       Sound.play_ok
  285.     end
  286.   end
  287.  
  288.   def update_blink_sprite
  289.     return if @blink_sprite.nil?
  290.     @blink_sprite.opacity -= 3
  291.     @blink_sprite.opacity = 60 if @blink_sprite.opacity <= 0
  292.   end
  293. end
  294.  
  295. #-------------------------------------------------------------------------------
  296. # Window tool selection
  297. class Window_Tool_Select < Window_Selectable
  298.   def initialize(x=0, y=0, w=150, h=192)
  299.     super(x, y,  w, h)
  300.     self.z = 101
  301.     refresh
  302.     self.index = 0
  303.     activate
  304.   end
  305.  
  306.   def item
  307.     return @data[self.index]
  308.   end
  309.  
  310.   def refresh
  311.     self.contents.clear if self.contents != nil
  312.     @data = []
  313.     for weapon in IntTool.tool_weapons
  314.       if $game_player.actor.equippable?(weapon) and
  315.         $game_party.has_item?(weapon, true)
  316.         @data.push(weapon)
  317.       end
  318.     end
  319.     @item_max = @data.size
  320.     if @item_max > 0
  321.       self.contents = Bitmap.new(width - 32, row_max * 26)
  322.       for i in 0...@item_max
  323.         draw_item(i)
  324.       end
  325.     end
  326.   end
  327.  
  328.   def draw_item(index)
  329.     item = @data[index]
  330.     x, y = index % col_max * (120 + 32), index / col_max  * 24
  331.     self.contents.font.size = 18
  332.     draw_icon(item.icon_index, x, y)
  333.     self.contents.draw_text(x + 24, y, 212, 32, item.name, 0)
  334.   end
  335.  
  336.   def item_max
  337.     return @item_max.nil? ? 0 : @item_max
  338.   end
  339.  
  340.   def col_max
  341.     return IntTool.tool_weapons.size > 6 ? 2 : 1
  342.   end
  343. end
  344.  
  345. #-------------------------------------------------------------------------------
  346. # Scene tool selector
  347. class Scene_ToolSelector < Scene_MenuBase
  348.   def start
  349.     super
  350.     IntTool.tool_weapons.size > 6 ? w = 300 : w = 150
  351.     @tool_window = Window_Tool_Select.new(544/2 - w / 2, 416 / 2 - 192/2, w)
  352.     @tool_window.opacity = 200
  353.     @tool_header = Window_Base.new(@tool_window.x, @tool_window.y - 40, w, 40)
  354.     @tool_header.contents.draw_text(-6, -6, @tool_header.width, 32, 'Tools', 1)
  355.     @tool_header.opacity = @tool_window.opacity
  356.   end
  357.  
  358.   def update
  359.     super
  360.     if Input.trigger?(:B)
  361.       SceneManager.goto(Scene_Map)
  362.       Sound.play_cancel
  363.     end
  364.     if Input.trigger?(:C)
  365.       if @tool_window.item.nil?
  366.         SceneManager.goto(Scene_Map)
  367.         Sound.play_cancel
  368.         return
  369.       end
  370.       type = @tool_window.item.etype_id
  371.       $game_player.actor.change_equip_by_id(type, @tool_window.item.id)
  372.       Sound.play_equip
  373.       SceneManager.goto(Scene_Map)
  374.     end
  375.   end
  376.  
  377.   def terminate
  378.     super
  379.     @tool_window.dispose
  380.     @tool_header.dispose
  381.   end
  382. end
  383.  
  384. #-------------------------------------------------------------------------------
  385. # Sprite sets
  386. class Spriteset_Map
  387.   alias falint_toolbar_ini initialize
  388.   def initialize
  389.     @int_toolbar = Weapons_ToolBar.new
  390.     falint_toolbar_ini
  391.   end
  392.  
  393.   alias falint_toolbar_dis dispose
  394.   def dispose
  395.     @int_toolbar.dispose
  396.     falint_toolbar_dis
  397.   end
  398.  
  399.   alias falint_toolbar_up update
  400.   def update
  401.     @int_toolbar.update
  402.     falint_toolbar_up
  403.     if defined?(Map_Buttons).is_a?(String)
  404.       @interact_buttoms.mouse_over_button? ? $game_system.over_msbutton = true :
  405.       $game_system.over_msbutton = nil
  406.     end
  407.   end
  408. end
  409.  
  410. #-------------------------------------------------------------------------------
  411. # * Plugins
  412. class Game_Player < Game_Character
  413.   alias falint_toolbar_pickup_int_character pickup_int_character
  414.   def pickup_int_character(char)
  415.     return if @tool_anime > 0 || $game_system.enable_ctool ||
  416.     $game_system.over_msbutton
  417.     falint_toolbar_pickup_int_character(char)
  418.   end
  419.  
  420.   alias falint_toolbar_perform_jump perform_jump
  421.   def perform_jump
  422.     return if $game_system.enable_ctool || $game_system.over_msbutton
  423.     falint_toolbar_perform_jump
  424.   end
  425. end
  426.  
  427. #-------------------------------------------------------------------------------
  428. # * Service pack script
  429. class Game_CharacterBase
  430.   alias falcao_intservice_pack_bombcoll collide_with_bomb
  431.   def collide_with_bomb(x, y)
  432.     return false if self.is_a?(Game_Player) and self.obfalling > 0
  433.     falcao_intservice_pack_bombcoll(x, y)
  434.   end
  435.  
  436.   alias falcao_intservice_pack_barrelcoll collide_with_barrel
  437.   def collide_with_barrel(x, y)
  438.     return false if self.is_a?(Game_Player) and self.obfalling > 0
  439.     falcao_intservice_pack_barrelcoll(x, y)
  440.   end
  441. end
  442.  
  443. class Game_Player < Game_Character
  444.   def tool_canuse?(id)
  445.     return false if @obfalling > 0
  446.     IntTool::Interactive_Weapons.each do |dw , value|
  447.       if dw == id
  448.         if defined?(Map_Buttons).is_a?(String)
  449.           return false if $game_system.showing_twindow
  450.           return true if Mouse.trigger?(0) && !$game_map.interpreter.running? &&
  451.           $game_system.enable_ctool && !@player_busy &&
  452.           IntTool.equipped?(dw, value)
  453.         else
  454.           return true if Input.trigger?(ToolActionKey) && !@player_busy &&
  455.           !$game_map.interpreter.running? && IntTool.equipped?(dw, value)
  456.         end
  457.       end
  458.     end
  459.     return false
  460.   end
  461.  
  462.   alias falcao_intservice_pack_start_bomb_impact start_bomb_impact
  463.   def start_bomb_impact
  464.     falcao_intservice_pack_start_bomb_impact
  465.     applypick_grafhic if @player_busy
  466.     @gamebomb.char_steps = 0
  467.   end
  468.  
  469.   alias falcao_intservice_pack_move_straight move_straight
  470.   def move_straight(d, turn_ok = true)
  471.     return if @obfalling > 0 || @showing_hook || @showing_fire|| @tool_anime > 0
  472.     falcao_intservice_pack_move_straight(d, turn_ok = true)
  473.   end
  474. end
  475.  
  476. class Game_Arrow < Game_Character
  477.   alias falcao_intservice_pack_aini initialize
  478.   def initialize
  479.     falcao_intservice_pack_aini
  480.     @step_anime = true
  481.   end
  482. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement