Advertisement
TheSixth

Tool Cycler for Falcao's ABS by Sixth

Sep 29th, 2015
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.98 KB | None | 0 0
  1. #===============================================================================
  2. # * [ACE] Tool Cycler Addon for Falcao's Pearl ABS Liquid v3
  3. #===============================================================================
  4. # * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
  5. # * Version: 1.2
  6. # * Updated: 18/10/2015
  7. # * Requires: Falcao's Pearl ABS Liquid v3
  8. #-------------------------------------------------------------------------------
  9. # * < Change Log >
  10. #-------------------------------------------------------------------------------
  11. # * Version 1.0 (29/09/2015)
  12. #   - Initial release.
  13. # * Version 1.1 (30/09/2015)
  14. #   - Fixed cycling errors when there are more weapon or armor tools of the same
  15. #     kind in the inventory.
  16. # * Version 1.2 (18/10/2015)
  17. #   - Added the possibility to require 2 buttons for the tool cycle triggers.
  18. #     You can set it up so that the player needs to hold down one button and
  19. #     press another one to change the tools.
  20. #-------------------------------------------------------------------------------
  21. # * < Description >
  22. #-------------------------------------------------------------------------------
  23. # * This script will allow you to implement button triggers which will cycle
  24. #   through the available tools when they are used.
  25. # * You can set up cycle tool buttons for every tool slot.
  26. # * Previous and next tool buttons are both available, and both are optional.
  27. # * You can either use the default input methods for button checks, or the one
  28. #   that Falcao provided with the ABS script, or you can use buttons from a
  29. #   custom input/keyboard script as well (if it uses the Input.trigger?(button)
  30. #   check, that is).
  31. # * Enable/disable the script during the game anytime.
  32. # * Automatic "anti-duplicate tool" feature, so it will prevent the player to
  33. #   equip the same tool on different slots at the same time.
  34. #-------------------------------------------------------------------------------
  35. # * < Installation >
  36. #-------------------------------------------------------------------------------
  37. # * Place this scipt below the last script from Falcao's Pearl ABS Liquid v3
  38. #   script series but above Main!
  39. # * You can do an optional edit in the "Pearl Item Pop Up" script. This edit
  40. #   will prevent the item gain popup when you change your tools with the cycle
  41. #   buttons. It's kinda annoying and looks bad to see that popup everytime the
  42. #   player changes an equipped tool.
  43. #
  44. #   Anyway, here is what you need to do:
  45. #   Right at the start, after the settings part, you will see this method:
  46. #
  47. #~   alias falcaopearl_itempop_gain gain_item
  48. #~   def gain_item(item, amount, include_equip = false)
  49. #~     if !item_container(item.class).nil? && SceneManager.scene_is?(Scene_Map)
  50. #~       if amount > 0
  51. #~         $game_system.item_object = [item, amount]
  52. #~         RPG::SE.new(PearlItemPop::ItemSe, 80).play rescue nil
  53. #~       end
  54. #~     end
  55. #~     falcaopearl_itempop_gain(item, amount, include_equip = false)
  56. #~   end
  57. #
  58. #   Replace that whole definition with the one below:
  59. #
  60. #~   alias falcaopearl_itempop_gain gain_item
  61. #~   def gain_item(item, amount, include_equip = false)
  62. #~     unless $game_system.disable_item_pop == true
  63. #~       if !item_container(item.class).nil? && SceneManager.scene_is?(Scene_Map)
  64. #~         if amount > 0
  65. #~           $game_system.item_object = [item, amount]
  66. #~           RPG::SE.new(PearlItemPop::ItemSe, 80).play rescue nil
  67. #~         end
  68. #~       end
  69. #~     end
  70. #~     falcaopearl_itempop_gain(item, amount, include_equip = false)
  71. #~   end
  72. #
  73. #   I couldn't just overwrite it, because that would make compatibility issues
  74. #   with many scripts, and I could not alias it in any way, because the popup
  75. #   mechanic is already in it, so that would be called no matter how I alias it.
  76. #
  77. #   Simply copy the above method, and paste it over the old method, deleting
  78. #   the old one in the process. After this, select the copied method and press
  79. #   CTRL+Q while it's highlighted to remove the comment sings from it.
  80. #   Do NOT remove the comment signs from this header!
  81. #
  82. #   I hope this little copy/paste job won't be hard to do for anyone. :P
  83. #-------------------------------------------------------------------------------
  84. # * < Compatibility Info >
  85. #-------------------------------------------------------------------------------
  86. # * No known incompatibilities.
  87. #-------------------------------------------------------------------------------
  88. # * < Known Issues >
  89. #-------------------------------------------------------------------------------
  90. # * No known issues.
  91. #-------------------------------------------------------------------------------
  92. # * < Terms of Use >
  93. #-------------------------------------------------------------------------------
  94. # * Free to use for whatever purposes you want.
  95. # * Credit me (Sixth) in your game, pretty please! :P
  96. # * Posting modified versions of this script is allowed as long as you notice me
  97. #   about it with a link to it!
  98. #===============================================================================
  99. $imported = {} if $imported.nil?
  100. $imported["SixthABSToolCycler"] = true
  101. #===============================================================================
  102. # Settings:
  103. #===============================================================================
  104. module ToolCycler
  105.   #-----------------------------------------------------------------------------
  106.   # Enable Switch Settings:
  107.   #-----------------------------------------------------------------------------
  108.   # You can enable/disable the script with the switch you set up here.
  109.   # If the switch is turned ON, the script is enabled, if it is OFF, the script
  110.   # is disabled.
  111.   # If you don't want to disable this scrpt at all in your game, you can set
  112.   # this setting to 0, and it will be always enabled.
  113.   #-----------------------------------------------------------------------------
  114.   EnableSwitch = 88
  115.  
  116.   #-----------------------------------------------------------------------------
  117.   # Input Type Settings:
  118.   #-----------------------------------------------------------------------------
  119.   # You can choose which input type you want to use here.
  120.   # ---- Type 1. ---------------------------------------------------------------
  121.   # :pearl = This is the keyboard input type Falcao provided with the ABS.
  122.   #          If you chose this, you will need to use his input buttons for the
  123.   #          'Cycles' settings below (PearlKey::Letter).
  124.   # ---- Type 2. ---------------------------------------------------------------
  125.   # :default = This is the default input type for the VX Ace engine.
  126.   #            If you chose this, you will need to use the default input buttons
  127.   #            for the 'Cycles' settings below. The default buttons are:
  128.   #   :DOWN, :LEFT, :RIGHT, :UP - direction keys. These are used for player
  129.   #                               movement by default, so it's not a good idea  
  130.   #                               to use them here.
  131.   #   :F5, :F6, :F7, :F8, :ALT  - Feel free to use any of these keys, they do
  132.   #                               nothing by default.
  133.   #                               They are pretty self explanatory.
  134.   #   :A  - This is the Shift on the keyboard and is the Dash feature by defaut.
  135.   #         If you are using this button for dashing, don't use it here.
  136.   #   :X  - This is the A key on the keyboard and does nothing by default.
  137.   #   :Y  - This is the S key on the keyboard and does nothing by default.
  138.   #   :Z  - This is the D key on the keyboard and does nothing by default.
  139.   #   :L  - This is the Q or Page Up key on the keyboard.
  140.   #         Does nothing by default.
  141.   #   :R  - This is the W or Page Down key on the keyboard.
  142.   #         Does nothing by default.
  143.   #-----------------------------------------------------------------------------
  144.   InputType = :pearl # :pearl or :default
  145.  
  146.   #-----------------------------------------------------------------------------
  147.   # Tool Cycle Button Settings:
  148.   #-----------------------------------------------------------------------------
  149.   # This is where you set up your tool cycling buttons.
  150.   # Note that any setting here is optional!
  151.   # Simply comment out the ones you don't need and remove the comment signs
  152.   # from the ones you need.
  153.   #
  154.   #   Format 1 : [:tool_type,:cycle_dir] => button,
  155.   # This format is for single button press triggers.
  156.   #
  157.   #   Format 2 : [:tool_type,:cycle_dir] => [hold_button,button],
  158.   # This format is for the new 2 buttons triggers. Using this, the player
  159.   # would need to hold down the 1st button entered and press the 2nd button
  160.   # while holding down the 1st button to change the tool.
  161.   #
  162.   # You can use both format if you want.
  163.   #
  164.   # :tool_type = This is the type of the tool you set the button up.
  165.   #              Can be: :weapon, :armor, :item1, :item2,
  166.   #                      :skill1, :skill2, :skill3, :skill4.
  167.   #              Should be obvious what these mean.
  168.   # :cycle_dir = The direction of cycling. Can be: :prev or :next.
  169.   #              :prev will switch to the previous tool on the list while
  170.   #              :next will switch to the next tool on the list.
  171.   # button = This can be one of the default VX Ace engine button symbols, or
  172.   #          a keyboard button from Falcao's PearlKey input module.
  173.   #          The default buttons are detailed above, for Pearl buttons refer to
  174.   #          the Pearl Kernel script of the ABS scripts.
  175.   #          The 'InputType' setting will determine which type of buttons you
  176.   #          can use here.
  177.   #          In case yoou are using another input module which uses the
  178.   #          Input.trigger?(button) method, you are free to use the buttons from
  179.   #          that script as well, just make sure to set the 'InputType' setting
  180.   #          above to :default.
  181.   # hold_button = Same as above, a button setting. This is only used for the 2
  182.   #               buttons triggers. This is the button the player would need
  183.   #               to hold down.
  184.   #-----------------------------------------------------------------------------
  185.   Cycles = {
  186.     [:weapon,:prev] => [PearlKey::Q,PearlKey::N1], # Previous weapon trigger.
  187.     [:weapon,:next] => [PearlKey::Q,PearlKey::N2], # Next weapon trigger.
  188.     [:armor,:prev] => PearlKey::N3,  # Previous "shield" trigger (off-hand).
  189.     [:armor,:next] => PearlKey::N4,  # Next "shield" trigger (off-hand).
  190.     [:item1,:prev] => PearlKey::N5,  # Previous item trigger (1st slot).
  191.     [:item1,:next] => PearlKey::N6,  # Next item trigger (1st slot).
  192.     [:item2,:prev] => PearlKey::N7,  # Previous item trigger (2nd slot).
  193.     [:item2,:next] => PearlKey::N8,  # Next item trigger (2nd slot).
  194.     [:skill1,:prev] => PearlKey::N9, # Previous skill trigger (1st slot).
  195.     [:skill1,:next] => PearlKey::N0, # Next skill trigger (1st slot).
  196.     #[:skill2,:prev] => PearlKey::N9, # Previous skill trigger (2nd slot).
  197.     #[:skill2,:next] => PearlKey::N0, # Next skill trigger (2nd slot).
  198.     #[:skill3,:prev] => PearlKey::N9, # Previous skill trigger (3rd slot).
  199.     #[:skill3,:next] => PearlKey::N0, # Next skill trigger (3rd slot).
  200.     #[:skill4,:prev] => PearlKey::N9, # Previous skill trigger (4th slot).
  201.     #[:skill4,:next] => PearlKey::N0, # Next skill trigger (4th slot).
  202.   }
  203.  
  204.   #-----------------------------------------------------------------------------
  205.   # Sound Effect Settings:
  206.   #-----------------------------------------------------------------------------
  207.   # Each time you switch a toool with a tool cycle button, a sound effect will
  208.   # be played. You can set up a sound effect for each tool type here.
  209.   #
  210.   #   Format: :tool_type => RPG::SE.new("file name",volume,pitch)
  211.   #
  212.   # "file name" = The name of the audio file to be played.
  213.   #               The file must be in the game's Audio\SE folder!
  214.   # volume = The volume of the sound effect.
  215.   # pitch = The pitch level of the sound effect.
  216.   #
  217.   # You can set them to nil if you don't want any SE to be played when switching.
  218.   #-----------------------------------------------------------------------------
  219.   SoundEffects = {
  220.     :weapon => RPG::SE.new("Sword4",80,100),  # For weapon tool.
  221.     :armor => RPG::SE.new("Equip1",80,100),   # For shield tool (off hand).
  222.     :item1 => RPG::SE.new("Evasion1",80,100), # For item tool (slot 1).
  223.     :item2 => RPG::SE.new("Evasion1",80,100), # For item tool (slot 2).
  224.     :skill1 => RPG::SE.new("Saint5",80,100),  # For skill tool (slot 1).
  225.     :skill2 => RPG::SE.new("Saint5",80,100),  # For skill tool (slot 2).
  226.     :skill3 => RPG::SE.new("Saint5",80,100),  # For skill tool (slot 3).
  227.     :skill4 => RPG::SE.new("Saint5",80,100),  # For skill tool (slot 4).
  228.   }
  229.  
  230. end
  231. #===============================================================================
  232. # End of settings! O.o
  233. #===============================================================================
  234.  
  235. class Game_Actor < Game_Battler
  236.  
  237.   alias add_cycling_tools5541 setup
  238.   def setup(actor_id)
  239.     @cycleskill = {
  240.       :weapon => 0, :armor => 0, :item1 => 0, :item2 => 0,
  241.       :skill1 => 0, :skill2 => 0, :skill3 => 0, :skill4 => 0,
  242.     }
  243.     add_cycling_tools5541(actor_id)
  244.   end
  245.  
  246.   def cycle_tool(type,dir)
  247.     dir = dir == :prev ? -1 : 1
  248.     case type
  249.     when :weapon
  250.       data = $game_party.weapons_unsorted.select {|wp|
  251.         equippable?(wp) && !wp.note.include?("Exclude From Tool Menu = true")
  252.       }
  253.       data << equips[0] if !equips[0].nil? && !data.include?(equips[0])
  254.       max = data.size
  255.       return if max <= 1
  256.       data = data.sort_by {|item| item.id }
  257.       $game_system.disable_item_pop = true
  258.       @cycleskill[:weapon] = data.index(equips[0]) if !equips[0].nil?
  259.       cycle_tool_vars(type,dir,max)
  260.       change_equip_by_id(0, data[@cycleskill[:weapon]].id)
  261.       ToolCycler::SoundEffects[type].play if !ToolCycler::SoundEffects[type].nil?
  262.       $game_system.disable_item_pop = false
  263.     when :armor
  264.       data = $game_party.armors_unsorted.select {|ar|
  265.         equippable?(ar) && ar.etype_id == 1 &&
  266.         !ar.note.include?("Exclude From Tool Menu = true")
  267.       }
  268.       data << equips[1] if !equips[1].nil? && !data.include?(equips[1])
  269.       max = data.size
  270.       return if max <= 1
  271.       data = data.sort_by {|item| item.id }
  272.       $game_system.disable_item_pop = true
  273.       @cycleskill[:armor] = data.index(equips[1]) if !equips[1].nil?
  274.       cycle_tool_vars(type,dir,max)
  275.       change_equip_by_id(1, data[@cycleskill[:armor]].id)
  276.       ToolCycler::SoundEffects[type].play if !ToolCycler::SoundEffects[type].nil?
  277.       $game_system.disable_item_pop = false
  278.     when :item1
  279.       data = $game_party.items
  280.       data.delete_if {|it| it.note.include?("Exclude From Tool Menu = true")}
  281.       data.delete(@assigned_item2) if !@assigned_item2.nil?
  282.       max = data.size
  283.       return if max == 0
  284.       return if max <= 1 && !@assigned_item.nil?
  285.       $game_system.disable_item_pop = true
  286.       @cycleskill[:item1] = data.index(@assigned_item) if !@assigned_item.nil?
  287.       cycle_tool_vars(type,dir,max)
  288.       @assigned_item = data[@cycleskill[:item1]]
  289.       ToolCycler::SoundEffects[type].play if !ToolCycler::SoundEffects[type].nil?
  290.       $game_system.disable_item_pop = false
  291.     when :item2
  292.       data = $game_party.items
  293.       data.delete_if {|it| it.note.include?("Exclude From Tool Menu = true")}
  294.       data.delete(@assigned_item) if !@assigned_item.nil?
  295.       max = data.size
  296.       return if max == 0
  297.       return if max <= 1 && !@assigned_item2.nil?
  298.       $game_system.disable_item_pop = true
  299.       @cycleskill[:item2] = data.index(@assigned_item2) if !@assigned_item2.nil?
  300.       cycle_tool_vars(type,dir,max)
  301.       @assigned_item2 = data[@cycleskill[:item2]]
  302.       ToolCycler::SoundEffects[type].play if !ToolCycler::SoundEffects[type].nil?
  303.       $game_system.disable_item_pop = false
  304.     when :skill1
  305.       data = skills
  306.       data.delete_if {|it| it.note.include?("Exclude From Tool Menu = ")}
  307.       data.delete(@assigned_skill2) if !@assigned_skill2.nil?
  308.       data.delete(@assigned_skill3) if !@assigned_skill3.nil?
  309.       data.delete(@assigned_skill4) if !@assigned_skill4.nil?
  310.       max = data.size
  311.       return if max == 0
  312.       return if max <= 1 && !@assigned_skill.nil?
  313.       @cycleskill[:skill1] = data.index(@assigned_skill) if !@assigned_skill.nil?
  314.       cycle_tool_vars(type,dir,max)
  315.       @assigned_skill = data[@cycleskill[:skill1]]
  316.       ToolCycler::SoundEffects[type].play if !ToolCycler::SoundEffects[type].nil?
  317.     when :skill2
  318.       data = skills
  319.       data.delete_if {|it| it.note.include?("Exclude From Tool Menu = true")}
  320.       data.delete(@assigned_skill) if !@assigned_skill.nil?
  321.       data.delete(@assigned_skill3) if !@assigned_skill3.nil?
  322.       data.delete(@assigned_skill4) if !@assigned_skill4.nil?
  323.       max = data.size
  324.       return if max == 0
  325.       return if max <= 1 && !@assigned_skill2.nil?
  326.       @cycleskill[:skill2] = data.index(@assigned_skill2) if !@assigned_skill2.nil?
  327.       cycle_tool_vars(type,dir,max)
  328.       @assigned_skill2 = data[@cycleskill[:skill2]]
  329.       ToolCycler::SoundEffects[type].play if !ToolCycler::SoundEffects[type].nil?
  330.     when :skill3
  331.       data = skills
  332.       data.delete_if {|it| it.note.include?("Exclude From Tool Menu = true")}
  333.       data.delete(@assigned_skill2) if !@assigned_skill2.nil?
  334.       data.delete(@assigned_skill) if !@assigned_skill.nil?
  335.       data.delete(@assigned_skill4) if !@assigned_skill4.nil?
  336.       max = data.size
  337.       return if max == 0
  338.       return if max <= 1 && !@assigned_skill3.nil?
  339.       @cycleskill[:skill3] = data.index(@assigned_skill3) if !@assigned_skill3.nil?
  340.       cycle_tool_vars(type,dir,max)
  341.       @assigned_skill3 = data[@cycleskill[:skill3]]
  342.       ToolCycler::SoundEffects[type].play if !ToolCycler::SoundEffects[type].nil?
  343.     when :skill4
  344.       data = skills
  345.       data.delete_if {|it| it.note.include?("Exclude From Tool Menu = true")}
  346.       data.delete(@assigned_skill2) if !@assigned_skill2.nil?
  347.       data.delete(@assigned_skill3) if !@assigned_skill3.nil?
  348.       data.delete(@assigned_skill) if !@assigned_skill.nil?
  349.       max = data.size
  350.       return if max == 0
  351.       return if max <= 1 && !@assigned_skill4.nil?
  352.       @cycleskill[:skill4] = data.index(@assigned_skill4) if !@assigned_skill4.nil?
  353.       cycle_tool_vars(type,dir,max)
  354.       @assigned_skill4 = data[@cycleskill[:skill4]]
  355.       ToolCycler::SoundEffects[type].play if !ToolCycler::SoundEffects[type].nil?
  356.     end
  357.   end
  358.  
  359.   def cycle_tool_vars(type,dir,max)
  360.     @cycleskill[type] += dir
  361.     @cycleskill[type] = 0 if @cycleskill[type] >= max && dir == 1
  362.     @cycleskill[type] = max - 1 if @cycleskill[type] < 0 && dir == -1    
  363.   end
  364.    
  365. end
  366.  
  367. class Game_Party < Game_Unit
  368.  
  369.   def weapons_unsorted
  370.     @weapons.keys.collect {|id| $data_weapons[id] }
  371.   end
  372.  
  373.   def armors_unsorted
  374.     @armors.keys.collect {|id| $data_armors[id] }
  375.   end
  376.  
  377. end
  378.  
  379. class Game_System
  380.  
  381.   attr_accessor :disable_item_pop
  382.  
  383.   alias disable_pop_switch9974 initialize
  384.   def initialize
  385.     @disable_item_pop = false
  386.     disable_pop_switch9974
  387.   end
  388.  
  389. end
  390.  
  391. class Scene_Map < Scene_Base
  392.  
  393.   alias add_cycling_tools7732 update
  394.   def update
  395.     if (ToolCycler::EnableSwitch == 0 || $game_switches[ToolCycler::EnableSwitch])&&
  396.        !$game_message.busy? && !$game_map.interpreter.running?
  397.       ToolCycler::Cycles.each do |key,button|
  398.         $game_party.members[0].cycle_tool(key[0],key[1]) if tool_cycle_trigger?(button)
  399.       end
  400.     end
  401.     add_cycling_tools7732
  402.   end
  403.  
  404.   def tool_cycle_trigger?(button)
  405.     case ToolCycler::InputType
  406.     when :pearl
  407.       if button.is_a?(Array)
  408.         return PearlKey.press?(button[0]) && PearlKey.trigger?(button[1])
  409.       else
  410.         return PearlKey.trigger?(button)
  411.       end
  412.     when :default
  413.       if button.is_a?(Array)
  414.         return Input.press?(button[0]) && Input.trigger?(button[1])
  415.       else
  416.         return Input.trigger?(button)
  417.       end
  418.     end
  419.   end
  420.  
  421. end
  422. #==============================================================================
  423. # !!END OF SCRIPT - OHH, NOES!!
  424. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement