Advertisement
TheSixth

Tool Cycler for XAS ABS by Sixth

Sep 30th, 2015
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.79 KB | None | 0 0
  1. #===============================================================================
  2. # * [ACE] Tool Cycler Addon for XAS ABS
  3. #===============================================================================
  4. # * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
  5. # * Version: 1.2
  6. # * Updated: 18/05/2018
  7. # * Requires: XAS ABS
  8. #-------------------------------------------------------------------------------
  9. # * < Change Log >
  10. #-------------------------------------------------------------------------------
  11. # * Version 1.0 (30/09/2015)
  12. #   - Initial release.
  13. # * Version 1.1 (14/10/2016)
  14. #   - Fixed a typo that could have trigger crashes.
  15. # * Version 1.2 (18/05/2018)
  16. #   - Fixed a crash issue with item cycling.
  17. #-------------------------------------------------------------------------------
  18. # * < Description >
  19. #-------------------------------------------------------------------------------
  20. # * This script will allow you to implement button triggers which will cycle
  21. #   through the available tools when they are used.
  22. # * You can set up cycle tool buttons for every tool slot.
  23. # * Previous and next tool buttons are both available, and both are optional.
  24. # * You can either use the default input methods for button checks, or you can
  25. #   use buttons from a custom input/keyboard script as well (if it uses the
  26. #   Input.trigger?(button) check, that is).
  27. # * Enable/disable the script during the game anytime.
  28. # * Automatic "anti-duplicate tool" feature, so it will prevent the player to
  29. #   equip the same tool on different slots at the same time.
  30. #-------------------------------------------------------------------------------
  31. # * < Note-Tags: >
  32. #-------------------------------------------------------------------------------
  33. # * If you want a tool to be skipped from the cycles, just tag them with
  34. #   the following note-tag:
  35. #
  36. #     Exclude From Tool Cycle
  37. #-------------------------------------------------------------------------------
  38. # * < Installation >
  39. #-------------------------------------------------------------------------------
  40. # * Place this scipt below the last script from XAS ABS script series
  41. #   but above Main!
  42. #-------------------------------------------------------------------------------
  43. # * < Compatibility Info >
  44. #-------------------------------------------------------------------------------
  45. # * No known incompatibilities.
  46. #-------------------------------------------------------------------------------
  47. # * < Known Issues >
  48. #-------------------------------------------------------------------------------
  49. # * No known issues.
  50. #-------------------------------------------------------------------------------
  51. # * < Terms of Use >
  52. #-------------------------------------------------------------------------------
  53. # * Free to use for whatever purposes you want.
  54. # * Credit me (Sixth) in your game, pretty please! :P
  55. # * Posting modified versions of this script is allowed as long as you notice me
  56. #   about it with a link to it!
  57. #===============================================================================
  58. $imported = {} if $imported.nil?
  59. $imported["SixthABSToolCycler"] = true
  60. #===============================================================================
  61. # Settings:
  62. #===============================================================================
  63. module ToolCycler
  64.   #-----------------------------------------------------------------------------
  65.   # Enable Switch Settings:
  66.   #-----------------------------------------------------------------------------
  67.   # You can enable/disable the script with the switch you set up here.
  68.   # If the switch is turned ON, the script is enabled, if it is OFF, the script
  69.   # is disabled.
  70.   # If you don't want to disable this script at all in your game, you can set
  71.   # this setting to 0, and it will be always enabled.
  72.   #-----------------------------------------------------------------------------
  73.   EnableSwitch = 88
  74.    
  75.   #-----------------------------------------------------------------------------
  76.   # Tool Cycle Button Settings:
  77.   #-----------------------------------------------------------------------------
  78.   # This is where you set up your tool cycling buttons.
  79.   # Note that any setting here is optional!
  80.   # Simply comment out the ones you don't need and remove the comment signs
  81.   # from the ones you need.
  82.   #
  83.   #   Format: [:tool_type,:cycle_dir] => button,
  84.   #
  85.   # :tool_type = This is the type of the tool you set the button up.
  86.   #              Can be: :weapon, :armor, :item, :item.
  87.   #              Should be obvious what these mean.
  88.   # :cycle_dir = The direction of cycling. Can be: :prev or :next.
  89.   #              :prev will switch to the previous tool on the list while
  90.   #              :next will switch to the next tool on the list.
  91.   # button = This can be one of the default VX Ace engine button symbols, or
  92.   #          a keyboard button from a custom input/keyboard script.
  93.   #          The default buttons are detailed below.
  94.   #
  95.   #   :DOWN, :LEFT, :RIGHT, :UP - direction keys. These are used for player
  96.   #                               movement by default, so it's not a good idea  
  97.   #                               to use them here.
  98.   #   :F5, :F6, :F7, :F8, :ALT  - Feel free to use any of these keys, they do
  99.   #                               nothing by default.
  100.   #                               They are pretty self explanatory.
  101.   #   :A  - This is the Shift on the keyboard and is the Dash feature by defaut.
  102.   #         If you are using this button for dashing, don't use it here.
  103.   #   :X  - This is the A key on the keyboard and does nothing by default.
  104.   #   :Y  - This is the S key on the keyboard and does nothing by default.
  105.   #   :Z  - This is the D key on the keyboard and does nothing by default.
  106.   #   :L  - This is the Q or Page Up key on the keyboard.
  107.   #         Does nothing by default.
  108.   #   :R  - This is the W or Page Down key on the keyboard.
  109.   #         Does nothing by default.
  110.   #-----------------------------------------------------------------------------
  111.   Cycles = {
  112.     [:weapon,:prev] => :k1, # Previous weapon trigger.
  113.     [:weapon,:next] => :k2, # Next weapon trigger.
  114.     [:armor,:prev] => :k3,  # Previous "shield" trigger (off-hand).
  115.     [:armor,:next] => :k4,  # Next "shield" trigger (off-hand).
  116.     [:item,:prev] => :k5,  # Previous item trigger.
  117.     [:item,:next] => :k6,  # Next item trigger.
  118.     [:skill,:prev] => :k7, # Previous skill trigger.
  119.     [:skill,:next] => :k8, # Next skill trigger.
  120.   }
  121.  
  122.   #-----------------------------------------------------------------------------
  123.   # Sound Effect Settings:
  124.   #-----------------------------------------------------------------------------
  125.   # Each time you switch a toool with a tool cycle button, a sound effect will
  126.   # be played. You can set up a sound effect for each tool type here.
  127.   #
  128.   #   Format: :tool_type => RPG::SE.new("file name",volume,pitch)
  129.   #
  130.   # "file name" = The name of the audio file to be played.
  131.   #               The file must be in the game's Audio\SE folder!
  132.   # volume = The volume of the sound effect.
  133.   # pitch = The pitch level of the sound effect.
  134.   #
  135.   # You can set them to nil if you don't want any SE to be played when switching.
  136.   #-----------------------------------------------------------------------------
  137.   SoundEffects = {
  138.     :weapon => RPG::SE.new("Sword4",80,100),  # For weapon tool.
  139.     :armor => RPG::SE.new("Equip1",80,100),   # For shield tool (off hand).
  140.     :item => RPG::SE.new("Evasion1",80,100), # For item tool.
  141.     :skill => RPG::SE.new("Saint5",80,100),  # For skill tool.
  142.   }
  143.  
  144. end
  145. #===============================================================================
  146. # End of settings! O.o
  147. #===============================================================================
  148.  
  149. class Game_Actor < Game_Battler
  150.  
  151.   alias add_cycling_tools5541 setup
  152.   def setup(actor_id)
  153.     @cycleskill = { :weapon => 0, :armor => 0, :item => 0, :skill => 0 }
  154.     add_cycling_tools5541(actor_id)
  155.   end
  156.  
  157.   def cycle_tool(type,dir)
  158.     dir = dir == :prev ? -1 : 1
  159.     case type
  160.     when :weapon
  161.       data = $game_party.weapons_unsorted.select {|wp|
  162.         equippable?(wp) && !wp.note.include?("Exclude From Tool Cycle")
  163.       }
  164.       data << equips[0] if !equips[0].nil? && !data.include?(equips[0])
  165.       max = data.size
  166.       return if max <= 1
  167.       data = data.sort_by {|item| item.id }
  168.       $game_system.disable_item_pop = true
  169.       @cycleskill[:weapon] = data.index(equips[0]) if !equips[0].nil?
  170.       cycle_tool_vars(type,dir,max)
  171.       change_equip_by_id(0, data[@cycleskill[:weapon]].id)
  172.       ToolCycler::SoundEffects[type].play if !ToolCycler::SoundEffects[type].nil?
  173.       $game_system.disable_item_pop = false
  174.     when :armor
  175.       data = $game_party.armors_unsorted.select {|ar|
  176.         equippable?(ar) && ar.etype_id == 1 &&
  177.         !ar.note.include?("Exclude From Tool Cycle")
  178.       }
  179.       data << equips[1] if !equips[1].nil? && !data.include?(equips[1])
  180.       max = data.size
  181.       return if max <= 1
  182.       data = data.sort_by {|item| item.id }
  183.       $game_system.disable_item_pop = true
  184.       @cycleskill[:armor] = data.index(equips[1]) if !equips[1].nil?
  185.       cycle_tool_vars(type,dir,max)
  186.       change_equip_by_id(1, data[@cycleskill[:armor]].id)
  187.       ToolCycler::SoundEffects[type].play if !ToolCycler::SoundEffects[type].nil?
  188.       $game_system.disable_item_pop = false
  189.     when :item
  190.       data = $game_party.items
  191.       if !@item_id.nil? && @item_id > 0 && !data.include?($data_items[@item_id])
  192.         data.insert(@cycleskill[:item] || 0, $data_items[@item_id])
  193.       end
  194.       data.delete_if {|it| it.note.include?("Exclude From Tool Cycle")}
  195.       max = data.size
  196.       return if max == 0
  197.       return if max <= 1 && !@item_id.nil? && @item_id > 0
  198.       $game_system.disable_item_pop = true
  199.       @cycleskill[:item] = data.index($data_items[@item_id]) if !@item_id.nil? && @item_id > 0
  200.       cycle_tool_vars(type,dir,max)
  201.       @item_id = data[@cycleskill[:item]].id
  202.       ToolCycler::SoundEffects[type].play if !ToolCycler::SoundEffects[type].nil?
  203.       $game_system.disable_item_pop = false
  204.     when :skill
  205.       data = skills
  206.       data.delete_if {|it| it.note.include?("Exclude From Tool Cycle")}
  207.       max = data.size
  208.       return if max == 0
  209.       return if max <= 1 && !@skill_id.nil? && @skill_id > 0
  210.       @cycleskill[:skill] = data.index($data_skills[@skill_id]) if !@skill_id.nil? && @skill_id > 0
  211.       cycle_tool_vars(type,dir,max)
  212.       @skill_id = data[@cycleskill[:skill]].id
  213.       ToolCycler::SoundEffects[type].play if !ToolCycler::SoundEffects[type].nil?
  214.     end
  215.   end
  216.  
  217.   def cycle_tool_vars(type,dir,max)
  218.     @cycleskill[type] += dir
  219.     @cycleskill[type] = 0 if @cycleskill[type] >= max && dir == 1
  220.     @cycleskill[type] = max - 1 if @cycleskill[type] < 0 && dir == -1    
  221.   end
  222.    
  223. end
  224.  
  225. class Game_Party < Game_Unit
  226.  
  227.   def weapons_unsorted
  228.     @weapons.keys.collect {|id| $data_weapons[id] }
  229.   end
  230.  
  231.   def armors_unsorted
  232.     @armors.keys.collect {|id| $data_armors[id] }
  233.   end
  234.  
  235. end
  236.  
  237. class Game_System
  238.  
  239.   attr_accessor :disable_item_pop
  240.  
  241.   alias disable_pop_switch9974 initialize
  242.   def initialize
  243.     @disable_item_pop = false
  244.     disable_pop_switch9974
  245.   end
  246.  
  247. end
  248.  
  249. class Scene_Map < Scene_Base
  250.  
  251.   alias add_cycling_tools7732 update
  252.   def update
  253.     if (ToolCycler::EnableSwitch == 0 || $game_switches[ToolCycler::EnableSwitch]) &&
  254.        !$game_message.busy? && !$game_map.interpreter.running?
  255.       ToolCycler::Cycles.each do |key,button|
  256.         $game_party.members[0].cycle_tool(key[0],key[1]) if Input.trigger?(button)
  257.       end
  258.     end
  259.     add_cycling_tools7732
  260.   end
  261.    
  262. end
  263. #==============================================================================
  264. # !!END OF SCRIPT - OHH, NOES!!
  265. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement