SHARE
TWEET

[RMXP] Battle Arena 1.0

ForeverZer0 May 21st, 2011 199 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # Battle Arena  
  3. # Author: ForeverZer0
  4. # Date: 4.28.2010
  5. # Version: 1.0
  6. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  7. #
  8. # Explanation:
  9. #
  10. #   Relatively simple idea. Let's the player bet an item, weapon, or armor and
  11. #   then fight against an enemy to receive a different item in return. Very
  12. #   much like the system used in Final Fantasy VI for the SNES. If they win,
  13. #   they get to keep their own item and get the enemy's item, if they lose, they
  14. #   will lose the item they bet.
  15. #
  16. # Feature:
  17. #
  18. #   - Can easily configure to most battle systems
  19. #   - Fully configurable results for any item, weapon, or armor
  20. #   - Allows for 'one-time' rewards for specific bets
  21. #   - Simple to install. After configuration, uses only two script
  22. #     calls in game
  23. #   - All wins/losses are logged in variables for easy access
  24. #
  25. # Instructions:
  26. #
  27. #   - Place script below default scripts and above main
  28. #   - Instructions for each configuration are below
  29. #   - Use these script calls:
  30. #
  31. #  --> $scene = Scene_BattleArena.new  
  32. #
  33. #      - calls the 'registration' scene
  34. #
  35. #  --> $game_temp.arena_battle_call(MAP_ID, X, Y)    
  36. #
  37. #      - after registering, use this where the actual battle will occur
  38. #      - the values in ( ) will be where the player is transfered to after
  39. #        battle. If you do not want them to move, just don't include the ( )
  40. #                                          
  41. #  --> $game_temp.arena_battle = false
  42. #
  43. #      - place this at every exit to your 'arena', otherwise it will cause
  44. #        errors if the player leaves after registering, but before fighting
  45. #
  46. # Author's Notes:
  47. #
  48. #   - Make sure the player cannot save in between registering and fighting.
  49. #     Anytime before or after is fine, but if they register then save and quit,
  50. #     once the game is loaded the 'registraion' will have been lost.
  51. #   - This system only uses one aliased method of the actual battle system. It
  52. #     is basically just a redirect to the Arena Result screen if the flag was
  53. #     present, so you can easily use any battle system you wish.
  54. #   - The only problem you may have is if your battle system is not triggered
  55. #     by the "$game_temp.battle_calling" flag, which most non-ABSs use.
  56. #   - If your game freezes with the "$game_temp.arena_battle = false" script
  57. #     call, it is not a problem with this script. You need to fix your
  58. #     Interpreter command_355. Just look around where you found this script for
  59. #     a fix for it, which you will likely want even if you don't use this system.
  60. #
  61. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  62.  
  63. module Zer0_CFG
  64. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  65. #                         BEGIN CONFIGURATION
  66. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  67.  
  68.   WIN_VARIABLE = 1
  69.   LOSS_VARIABLE = 2
  70.  
  71.   # These are the IDs of the variables that the will keep track of your wins
  72.   # and losses.
  73.  
  74.   NO_BET_ITEMS = []
  75.   NO_BET_WEAPONS = []
  76.   NO_BET_ARMORS = []
  77.  
  78.   # Include IDs of any items/weapon/armors that the player cannot bet.
  79.   # Any item that is "NO_BET" will not even show up as a choice in the window.
  80.  
  81.   ONLY_ONCE_ITEMS = []
  82.   ONLY_ONCE_WEAPONS = []
  83.   ONLY_ONCE_ARMORS = []
  84.  
  85.   # Include IDs of items/weapons/armors that the player will receive the reward
  86.   # for only once. After that, if they re-bet the same item again it will only
  87.   # return the DEFAULT_REWARD as the prize.
  88.  
  89. #-------------------------------------------------------------------------------
  90. #                         BEGIN BATTLE ARENA DATABASE
  91. #-------------------------------------------------------------------------------
  92. #
  93. #   There are 3 sections that will need configured; one each for Items, Weapons,
  94. #   and Armors. Set each section up like this:
  95. #
  96. #         when ID then return [TROOP, REWARD_TYPE, REWARD_ID]
  97. #
  98. #   ID       - The database ID of the Item, Weapon, or Armor that is being bet.
  99. #   TROOP    - The database ID of the troop that will be fought.
  100. #
  101. #   REWARD_TYPE - The 'type' of the reward that will be given if victorious  
  102. #                 0 = Item
  103. #                 1 = Weapon
  104. #                 2 = Armor
  105. #   REWARD_ID   - The ID in the database of the item (depending on type) that
  106. #                 will be received.
  107. #
  108. #   Here's an example:
  109. #
  110. #     when 5 then return [4, 2, 34]  (let's pretend it is in the Item Database)
  111. #
  112. #     This would mean that if the player chose to wager Item with ID(5), they
  113. #     would have to fight Troop with ID(4), and if they won would receive
  114. #     Armor with ID(34). It is an armor because the TYPE is 2.
  115. #
  116. #-------------------------------------------------------------------------------
  117.  
  118.   DEFAULT_REWARD = [1, 0, 1]
  119.   # This will be the configuration for any item/weapon/armor not defined.
  120.  
  121.   def self.wagers(item)
  122.     if item.is_a?(RPG::Item)
  123.       return DEFAULT_REWARD if $game_system.arena_one_time[0].include?(item.id)
  124.       case item.id
  125. #-------------------------------------------------------------------------------
  126. # * Begin Item Wager Database
  127. #-------------------------------------------------------------------------------
  128.    
  129.       when 1 then return [1, 0, 2]
  130.       when 2 then return [3, 0, 3]
  131.       when 3 then return [5, 0, 4]
  132.       when 4 then return [8, 1, 1]
  133.       when 5 then return [9, 2, 1]
  134.        
  135. #-------------------------------------------------------------------------------
  136. # * End Item Wager Database
  137. #-------------------------------------------------------------------------------
  138.       end
  139.     elsif item.is_a?(RPG::Weapon)
  140.       return DEFAULT_REWARD if $game_system.arena_one_time[1].include?(item.id)
  141.       case item.id
  142. #-------------------------------------------------------------------------------
  143. # * Begin Weapon Wager Database
  144. #-------------------------------------------------------------------------------
  145.  
  146.       when 1 then return [1, 2, 1]
  147.       when 2 then return [12, 1, 3]
  148.       when 3 then return [20, 1, 5]
  149.       when 4 then return [15, 2, 4]
  150.       when 5 then return [25, 0, 10]
  151.        
  152. #-------------------------------------------------------------------------------
  153. # * End Weapon Wager Database
  154. #-------------------------------------------------------------------------------
  155.       end
  156.     elsif item.is_a?(RPG::Armor)
  157.       return DEFAULT_REWARD if $game_system.arena_one_time[2].include?(item.id)
  158.       case item.id
  159. #-------------------------------------------------------------------------------
  160. # * Begin Armor Wager Database
  161. #-------------------------------------------------------------------------------
  162.      
  163.       when 1 then return [1, 1, 1]
  164.       when 2 then return [5, 2, 3]
  165.       when 3 then return [13, 2, 5]
  166.       when 4 then return [10, 1, 5]
  167.       when 5 then return [21, 2, 10]
  168.        
  169. #-------------------------------------------------------------------------------
  170. # * End Armor Wager Database
  171. #-------------------------------------------------------------------------------
  172.  
  173. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  174. #                           END CONFIGURATION
  175. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  176.       end
  177.     end
  178.     return DEFAULT_REWARD
  179.   end
  180. end
  181.  
  182. #-------------------------------------------------------------------------------
  183. # ** Game_System
  184. #-------------------------------------------------------------------------------
  185.  
  186. class Game_System
  187.  
  188.   attr_accessor :arena_one_time   # Retains data on all the ONCE_ONLY bets
  189.  
  190.   alias zer0_arena_once_only_init initialize
  191.   def initialize
  192.     zer0_arena_once_only_init
  193.     @arena_one_time = [[],[],[]]
  194.   end
  195. end
  196.  
  197. #-------------------------------------------------------------------------------
  198. # ** Game_Temp
  199. #-------------------------------------------------------------------------------
  200.  
  201. class Game_Temp
  202.  
  203.   attr_accessor :arena_data      # Holds info for bet, reward, battler, etc
  204.   attr_accessor :arena_battle    # Arena Battle flag
  205.   attr_accessor :party_memory    # Memorizes party pre-battle to return after
  206.  
  207.   alias zer0_battle_arena_temp_init initialize
  208.   def initialize
  209.     zer0_battle_arena_temp_init
  210.     @arena_data = []
  211.     @party_memory = []
  212.     @arena_battle = false
  213.   end
  214.  
  215.   def arena_battle_call(map_id=$game_map.map_id, x=$game_player.x , y=$game_player.y)
  216.     @party_memory.clear
  217.     $game_party.actors.each {|actor| @party_memory.push(actor.id)}
  218.     $game_party.actors.clear
  219.     $game_party.add_actor(@arena_data[2])
  220.     @battle_calling = true
  221.     @battle_can_escape = false
  222.     @battle_can_lose = true
  223.     @battle_proc = nil
  224.     @player_new_map_id = map_id
  225.     @player_new_x = x
  226.     @player_new_y = y
  227.     @player_new_direction = 2
  228.     Graphics.freeze
  229.     @player_transferring = true
  230.   end
  231. end
  232.  
  233. #-------------------------------------------------------------------------------
  234. # ** Scene_BattleArena
  235. #-------------------------------------------------------------------------------
  236.  
  237. class Scene_BattleArena
  238.  
  239.   def main
  240.     @help_window = Window_Help.new
  241.     @item_window = Window_ItemBet.new
  242.     @item_window.help_window = @help_window
  243.     @status_window = Window_ArenaStatus.new
  244.     @header1 = Window_Base.new(320, 64, 320, 64)
  245.     @header1.contents = Bitmap.new(288, 32)
  246.     @header1.contents.draw_text(0, 0, 288, 32, 'Which item will you wager?', 1)
  247.     @header2 = Window_Base.new(176, 128, 288, 64)
  248.     @header2.contents = Bitmap.new(256, 32)
  249.     @header2.contents.draw_text(0, 0, 256, 32, 'Who will battle?', 1)
  250.     @header2.z = 5000
  251.     @actor_window = Window_BattlerSelect.new
  252.     @actor_window.active = @actor_window.visible = @header2.visible = false
  253.     Graphics.transition
  254.     loop {Graphics.update; Input.update; update; break if $scene != self}
  255.     [@help_window, @item_window, @status_window, @header1, @header2,
  256.      @actor_window].each {|window| window.dispose}
  257.   end
  258.  
  259.   def update
  260.     [@help_window, @status_window, @item_window,
  261.       @actor_window].each {|window| window.update}
  262.     if @item_window.active
  263.        @status_window.data = @item_window.item
  264.       if Input.trigger?(Input::B)
  265.         $game_system.se_play($data_system.cancel_se)
  266.         $scene = Scene_Map.new
  267.       elsif Input.trigger?(Input::C)
  268.         $game_system.se_play($data_system.decision_se)
  269.         @data = Zer0_CFG.wagers(@item_window.item)
  270.         @actor_window.active = @actor_window.visible = @header2.visible = true
  271.         @item_window.active = false
  272.         return
  273.       end
  274.     elsif @actor_window.active
  275.       if Input.trigger?(Input::B)
  276.         $game_system.se_play($data_system.cancel_se)
  277.         @actor_window.active = @actor_window.visible = @header2.visible = false
  278.         @item_window.active = true
  279.         return
  280.       elsif Input.trigger?(Input::C)
  281.         if $game_party.actors[@actor_window.index].dead?
  282.           $game_system.se_play($data_system.buzzer_se)
  283.           return
  284.         end
  285.         $game_system.se_play($data_system.decision_se)
  286.         if $data_troops[@data[0]] != nil
  287.           $game_temp.battle_troop_id = @data[0]
  288.           $game_temp.arena_data[2] = $game_party.actors[@actor_window.index].id
  289.           $game_temp.arena_data[0] = @item_window.item
  290.           $game_temp.arena_data[1] = case @data[1]
  291.           when 0 then $data_items[@data[2]]
  292.           when 1 then $data_weapons[@data[2]]
  293.           when 2 then $data_armors[@data[2]]
  294.           end
  295.           $game_temp.arena_battle = true
  296.           $scene = Scene_Map.new
  297.         end  
  298.       end
  299.     end
  300.   end
  301. end
  302.  
  303. #-------------------------------------------------------------------------------
  304. # ** Scene_ArenaResult
  305. #-------------------------------------------------------------------------------
  306.  
  307. class Scene_ArenaResult
  308.  
  309.   def initialize(battle_result)
  310.     @result = battle_result
  311.   end
  312.  
  313.   def main
  314.     @map = Spriteset_Map.new
  315.     $game_party.actors[0].hp = 1 if @result != 0
  316.     $game_party.actors.clear
  317.     $game_temp.party_memory.each_index {|i|
  318.       $game_party.add_actor($game_temp.party_memory[i])}
  319.     @message_window = Window_Message.new
  320.     Graphics.transition
  321.     bet_item = $game_temp.arena_data[0]
  322.     case bet_item
  323.     when RPG::Item
  324.       if Zer0_CFG::ONLY_ONCE_ITEMS.include?(bet_item.id)
  325.         unless $game_system.arena_one_time[0].include?(bet_item.id)
  326.           $game_system.arena_one_time[0].push(bet_item.id)
  327.         end
  328.       end
  329.     when RPG::Weapon
  330.       if Zer0_CFG::ONLY_ONCE_WEAPONS.include?(bet_item.id)
  331.         unless $game_system.arena_one_time[1].include?(bet_item.id)
  332.           $game_system.arena_one_time[1].push(bet_item.id)
  333.         end
  334.       end
  335.     when RPG::Armor
  336.       if Zer0_CFG::ONLY_ONCE_ARMORS.include?(bet_item.id)
  337.         unless $game_system.arena_one_time[2].include?(bet_item.id)
  338.         $game_system.arena_one_time[2].push(bet_item.id)
  339.         end
  340.       end
  341.     end
  342.     if @result == 0
  343.       Audio.se_play('Audio/SE/060-Cheer01', 80, 100)
  344.       $game_variables[Zer0_CFG::WIN_VARIABLE] += 1
  345.       reward = $game_temp.arena_data[1].name
  346.       id = $game_temp.arena_data[1].id
  347.       case $game_temp.arena_data[1]
  348.       when RPG::Item then $game_party.gain_item(id, 1)
  349.       when RPG::Weapon then $game_party.gain_weapon(id, 1)
  350.       when RPG::Armor then $game_party.gain_armor(id, 1)
  351.       end
  352.       text = "Congratulations!\n" + 'You have won a ' + reward + '!'
  353.     else      
  354.       $game_variables[Zer0_CFG::LOSS_VARIABLE] += 1
  355.       id = $game_temp.arena_data[0].id
  356.       case $game_temp.arena_data[0]
  357.       when RPG::Item then $game_party.lose_item(id, 1)
  358.       when RPG::Weapon then $game_party.lose_weapon(id, 1)
  359.       when RPG::Armor then $game_party.lose_armor(id, 1)
  360.       end
  361.       text = 'Lost...'
  362.     end
  363.     $game_temp.message_text = text
  364.     loop {Graphics.update; Input.update; update; break if $scene != self}
  365.     $game_temp.arena_battle = false
  366.     $game_temp.arena_data.clear
  367.     $scene = Scene_Map.new
  368.     [@map, @message_window].each {|sprite| sprite.dispose}
  369.   end
  370.  
  371.   def update
  372.     [@map, @message_window].each {|sprite| sprite.update}
  373.     if Input.trigger?(Input::C)
  374.       $scene = Scene_Map.new
  375.     end
  376.   end
  377. end
  378.  
  379. #-------------------------------------------------------------------------------
  380. # ** Scene_Battle
  381. #-------------------------------------------------------------------------------
  382.  
  383. class Scene_Battle
  384.  
  385.   alias zer0_battle_arena_result battle_end
  386.   def battle_end(result)
  387.     # This will just redirect the scene to the Arena Result screen instead
  388.     # of Scene_Map if the arena flag is present
  389.     zer0_battle_arena_result(result)
  390.     if $game_temp.arena_battle
  391.       $scene = Scene_ArenaResult.new(result)
  392.     end
  393.   end
  394. end
  395.  
  396. #-------------------------------------------------------------------------------
  397. # ** Window_ArenaStatus
  398. #-------------------------------------------------------------------------------
  399.  
  400. class Window_ArenaStatus < Window_Base
  401.  
  402.   def initialize
  403.     super(320, 128, 320, 352)
  404.     self.contents = Bitmap.new(width - 32, height - 32)
  405.     @data = nil
  406.     refresh
  407.   end
  408.  
  409.   def refresh
  410.     self.contents.clear
  411.     return if @data == nil
  412.     @data = Zer0_CFG.wagers(@data)
  413.     self.contents.font.color = system_color
  414.     self.contents.draw_text(4, 0, 288, 32, 'Enemies:')
  415.     self.contents.draw_text(4, 256, 288, 32, 'Reward:')
  416.     self.contents.font.color = normal_color
  417.     member = $data_troops[@data[0]].members
  418.     names = []
  419.     member.each_index {|i| names[i] = $data_enemies[member[i].enemy_id].name
  420.       y = (i * 32) + 32
  421.       self.contents.draw_text(4, y, 288, 32, names[i]) if y < 256}  
  422.     case @data[1]
  423.     when 0
  424.       reward = $data_items[@data[2]].name
  425.       icon = $data_items[@data[2]].icon_name
  426.     when 1
  427.       reward = $data_weapons[@data[2]].name
  428.       icon = $data_weapons[@data[2]].icon_name
  429.     when 2
  430.       reward = $data_armors[@data[2]].name
  431.       icon = $data_armors[@data[2]].icon_name
  432.     end
  433.     self.contents.draw_text(32, 288, 288, 32, reward)
  434.     rect = Rect.new(x, y, self.width - 32, 32)
  435.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  436.     self.contents.blt(4, 292, RPG::Cache.icon(icon), Rect.new(0, 0, 24, 24))
  437.   end
  438.  
  439.   def data=(data)
  440.     if @data != data
  441.       @data = data
  442.       refresh
  443.     end
  444.   end
  445. end
  446.  
  447. #-------------------------------------------------------------------------------
  448. # ** Window_ItemBet
  449. #-------------------------------------------------------------------------------
  450.  
  451. class Window_ItemBet < Window_Selectable
  452.  
  453.   def initialize
  454.     super(0, 64, 320, 416)
  455.     @column_max, self.index = 1, 0
  456.     refresh
  457.   end
  458.  
  459.   def item
  460.     return @data[self.index]
  461.   end
  462.  
  463.   def refresh
  464.     if self.contents != nil
  465.       self.contents.dispose
  466.       self.contents = nil
  467.     end
  468.     @data = []
  469.     (1...$data_items.size).each {|i|
  470.       if $game_party.item_number(i) > 0
  471.         unless Zer0_CFG::NO_BET_ITEMS.include?(i)
  472.           @data.push($data_items[i])
  473.         end
  474.       end
  475.     }
  476.     (1...$data_weapons.size).each {|i|
  477.       if $game_party.weapon_number(i) > 0
  478.         unless Zer0_CFG::NO_BET_WEAPONS.include?(i)
  479.           @data.push($data_weapons[i])
  480.         end
  481.       end
  482.     }
  483.     (1...$data_armors.size).each {|i|
  484.       if $game_party.armor_number(i) > 0
  485.         unless Zer0_CFG::NO_BET_ARMORS.include?(i)
  486.           @data.push($data_armors[i])
  487.         end
  488.       end
  489.     }
  490.     @item_max = @data.size
  491.     if @item_max > 0
  492.       self.contents = Bitmap.new(width - 32, row_max * 32)
  493.       (0...@item_max).each {|i| draw_item(i)}
  494.     end
  495.   end
  496.  
  497.   def draw_item(index)
  498.     item = @data[index]
  499.     number = case item
  500.     when RPG::Item then $game_party.item_number(item.id)
  501.     when RPG::Weapon then $game_party.weapon_number(item.id)
  502.     when RPG::Armor then $game_party.armor_number(item.id)
  503.     end
  504.     x = 4
  505.     y = index * 32
  506.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  507.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  508.     bitmap = RPG::Cache.icon(item.icon_name)
  509.     opacity = self.contents.font.color == normal_color ? 255 : 128
  510.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  511.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  512.     self.contents.draw_text(x + 240, y, 16, 32, ':', 1)
  513.     self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  514.   end
  515.  
  516.   def update_help
  517.     @help_window.set_text(self.item == nil ? '' : self.item.description)
  518.   end
  519. end
  520.  
  521. #-------------------------------------------------------------------------------
  522. # ** Window_BattlerSelect
  523. #-------------------------------------------------------------------------------
  524.  
  525. class Window_BattlerSelect < Window_Selectable
  526.  
  527.   def initialize
  528.     w = ($game_party.actors.size * 64) + 32
  529.     x = (640 - w) / 2
  530.     super(x, 192, w, 96)
  531.     self.contents = Bitmap.new(width - 32, height - 32)
  532.     @row_max, self.index, self.z = 1, 0, 5000
  533.     @item_max = @column_max = $game_party.actors.size
  534.     refresh
  535.   end
  536.  
  537.   def refresh
  538.     $game_party.actors.each_index {|i|
  539.     x = 32 + i * 64
  540.     self.draw_actor_graphic($game_party.actors[i], x, 64)}
  541.   end
  542.  
  543.   def update_cursor_rect
  544.     cursor_width = 48
  545.     x = @index * 64 + 8
  546.     y = @index / @column_max * 32 - self.oy
  547.     self.cursor_rect.set(x, y, cursor_width, 64)
  548.   end
  549. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top