efeberk 84 Posted March 27, 2014 (edited) Treasure Chests by efeberk Introduction This script will allow player open a treasure chest and get item which hidden in the treasure chest after won battle. Screenshot: Script : =begin =============================================================================== Treasure Chests Date : 28.03.2014 00:53 Version: RGSS3 =============================================================================== This script will allow player open a treasure chest with event call & after won battle and get item which hidden in the treasure chest. Additional Features - ON/OFF with switches - Show screen with event call - Open all treasures after choosing - Adjustable background image example : treasure_chests(8) It will show treasure chests which related to 8.loop with current battle background. treasure_chests(8, "picture file") It will show treasure chests which related to 8.loop with special background picture. -------------------------------------------------------------------------------- =end module BERK CHEST_PICTURE_FILE = "closed_chest" SWITCH = 0 # 0 for active 4ever, 1,2,3,4... for switches. TEXT = "Select one chest" LOOPS = { #troop_id => [[item_type, item_id, item_count], ....] #item_type = 0 for Items, 1 for Weapons, 2 for Armors #example : [0, 12, 13] -> 13 'Guard Up' item 1 => [[0, 14, 4] , [0, 4, 16], [1, 12, 1], [2, 3, 1]], 4 => [[0, 15, 14] , [1, 2, 1], [1, 16, 1], [2, 5, 1], [0, 1, 16], [0 ,2, 16]], 8 => [ [0, 1, 16], [0, 1, 16], [0, 1, 16], [0, 1, 16], [0, 1, 16], [0, 1, 16], [0, 1, 16], [0, 1, 16], [0, 1, 16], [1, 32, 1]] } WSB = 3 # Window Space Base CHEST_COUNT = 4 COLUMN_COUNT = 4 CHEST_OPEN_SE = ["Chest", 100, 100] end class << BattleManager alias battleManagerForEfe battle_end end class Game_Interpreter def treasure_chests(loop_id, picture = nil) SceneManager.call(Scene_Treasures) SceneManager.scene.prepare(loop_id, picture) Fiber.yield while SceneManager.scene_is?(Scene_Treasures) end end $result_for_efe = :none class Scene_Battle < Scene_Base alias efeberk_scene_battle_terminate terminate def terminate SceneManager.call(Scene_Treasures) if $result_for_efe == :win && BERK::LOOPS.include?($game_troop.troop_id) && (BERK::SWITCH > 0 ? $game_switches[BERK::SWITCH] : true) efeberk_scene_battle_terminate end end module BattleManager def self.battle_end(result) $result_for_efe = :win if result == 0 $result_for_efe = :nowin if result != 0 battleManagerForEfe(result) end end class Window_Treasures < Window_Command attr_accessor :selected_treasure attr_accessor :loops def initialize(x, y) super(x, y) @selected_treasure = -1 @loops = nil draw_header_text end def draw_header_text draw_text(0,5, contents_width,line_height, BERK::TEXT, 1) draw_horz_line(20) end def draw_item(index) rect = item_rect(index) unless @loops == nil item = $data_items[@loops[index][1]] if @loops[index][0] == 0 item = $data_weapons[@loops[index][1]] if @loops[index][0] == 1 item = $data_armors[@loops[index][1]] if @loops[index][0] == 2 draw_icon(item.icon_index, rect.x + 12, rect.y + 12) draw_text(rect.x,rect.y+24, 48,line_height, "x" + @loops[index][2].to_s, 2) else draw_picture(BERK::CHEST_PICTURE_FILE,rect.x, rect.y) end end def draw_picture(name, x, y) bitmap = Cache.picture(name) rect = Rect.new(0,0,bitmap.width, bitmap.height) contents.blt(x, y, bitmap, rect, 255) end def item_height 48 end def item_width 48 end def item_rect(index) rect = Rect.new rect.width = item_width rect.height = item_height rect.x = index % col_max * (item_width + spacing) rect.y = index / col_max * item_height rect.y += 42 rect end def draw_horz_line(y) line_y = y + line_height / 2 - 1 contents.fill_rect(0, line_y, contents_width, 2, line_color) end def line_color color = normal_color color.alpha = 48 color end def col_max BERK::COLUMN_COUNT end def spacing 0 end def window_width ([BERK::CHEST_COUNT, col_max].min * 48) + (BERK::WSB * 8) end def window_height value = 0 value += (BERK::CHEST_COUNT / col_max) * 48 value += 48 if BERK::CHEST_COUNT % col_max > 0 value += (BERK::WSB * 10) value += 42 value end def make_command_list BERK::CHEST_COUNT.times {|i| add_command(i, i) } end end class Window_ItemDescTreasure < Window_Base def initialize(x, y, width, item) width += 24 super(x, y, width, fitting_height(1)) refresh(item) end def update if Input.trigger?(:C) SceneManager.return end end def refresh(item) x = (contents_width - (text_size(item.name).width + 24)) / 2 draw_item_name(item, x, 0, true, text_size(item.name).width + 24) update end end class Scene_Treasures < Scene_Base def prepare(t_id = nil, background_img = nil) @troop_id = t_id @b_img = background_img end def start super create_background create_treasures end def create_background @background_sprite = @b_img != nil ? Sprite.new : Spriteset_Battle.new @background_sprite.bitmap = Cache.picture(@b_img) unless @b_img == nil #@background_sprite.color.set(16, 16, 16, 128) end def create_treasures @treasures = Window_Treasures.new(0,0) @treasures.set_handler(:ok, method(:treasure_ok)) @treasures.x = (Graphics.width / 2) - (@treasures.width / 2) @treasures.y = (Graphics.height / 2) - (@treasures.height / 2) end def shuffled_loops result_loops = [] t_id = @troop_id == nil ? $game_troop.troop_id : @troop_id BERK::LOOPS[t_id].each { |i| result_loops.push(i) } for i in 0..BERK::CHEST_COUNT - result_loops.size - 1 result_loops.push(BERK::LOOPS[t_id][rand(BERK::LOOPS[t_id].size)]) end result_loops.shuffle result_loops end def treasure_ok loops = shuffled_loops RPG::SE.new(BERK::CHEST_OPEN_SE[0], BERK::CHEST_OPEN_SE[1], BERK::CHEST_OPEN_SE[2]).play @treasures.loops = loops @treasures.refresh @treasures.draw_header_text index = @treasures.current_symbol item = $data_items[@treasures.loops[index][1]] if @treasures.loops[index][0] == 0 item = $data_weapons[@treasures.loops[index][1]] if @treasures.loops[index][0] == 1 item = $data_armors[@treasures.loops[index][1]] if @treasures.loops[index][0] == 2 $game_party.gain_item(item, @treasures.loops[index][2], false) desc_width = @treasures.text_size(item.name).width + 24 @desc_window = Window_ItemDescTreasure.new(@treasures.x, @treasures.y + @treasures.height, [@treasures.width, desc_width].max, item) @desc_window.x -= (@desc_window.width - @treasures.width)/2 if @desc_window.width > @treasures.width @desc_window.x += (@treasures.width - @desc_window.width)/2 if @desc_window.width < @treasures.width end def returning return_scene end end class Game_Troop < Game_Unit def troop_id @troop_id end end Please post any error & trouble & request. Edited April 14, 2014 by efeberk 7 ShidoLionheart, Allusion, AlliedG and 4 others reacted to this Share this post Link to post Share on other sites
KayDgirl91 99 Posted March 28, 2014 I was confused at what this script did, until I saw the screenshot. Awesome idea! I'll definitely be testing this out! Share this post Link to post Share on other sites
Shad3 34 Posted March 28, 2014 Cool script. Now if you made it possible to reveal all items after choosing, it might be better (to make players lament more at their unluckiness). 1 Bunni89 reacted to this Share this post Link to post Share on other sites
Blackvivi 10 Posted March 28, 2014 Yep, this is pretty nice Share this post Link to post Share on other sites
Coolie 147 Posted March 28, 2014 Can this be turned on/off via a switch or something? Share this post Link to post Share on other sites
efeberk 84 Posted March 28, 2014 Thanks for your requests and comments. I added some features for you. Additional Features - ON/OFF with switches - Show screen with event call - Open all treasures after choosing - Adjustable background image 2 Allusion and AlliedG reacted to this Share this post Link to post Share on other sites
ShidoLionheart 5 Posted March 28, 2014 So with the script call we can use this also outside of battles? Share this post Link to post Share on other sites
efeberk 84 Posted March 28, 2014 (edited) Yes of course. Just try it. But only works on event call. If you wanna call it into another script, you need call like this SceneManager.call(Scene_Treasures) SceneManager.scene.prepare(loop_id, picture) Edited March 28, 2014 by efeberk Share this post Link to post Share on other sites
Blackvivi 10 Posted March 28, 2014 Nice! It now works outside of battle Share this post Link to post Share on other sites
dinhbat3 57 Posted April 9, 2014 Love the idea efeberk! I tried it out on a clean game file. It was the only script in the project and I got this error: Any suggestion on what I should do? ~ Dinhbat 1 ShidoLionheart reacted to this Share this post Link to post Share on other sites
efeberk 84 Posted April 9, 2014 Love the idea efeberk! I tried it out on a clean game file. It was the only script in the project and I got this error: Any suggestion on what I should do? ~ Dinhbat May you say me how you run treasure_chests? in event call or won battle? Share this post Link to post Share on other sites
dinhbat3 57 Posted April 9, 2014 Thanks for the quick response efeberk! I am using it after a won battle. The only things in the script I editted was the switch number. I get the error both when the switch is on and off. ~ Dinhbat Share this post Link to post Share on other sites
efeberk 84 Posted April 9, 2014 Okay thanks for your report, I fixed problem, you can use edited script. Share this post Link to post Share on other sites
dinhbat3 57 Posted April 10, 2014 Hey efeberk. Thanks for the quick response. I finally got to try it out when I got home from work. The chest selection now pops up! So the initial problem is solved, but now I get this warning after selecting a chest: Also, Just a suggestion for the header. Make sure it includes instructions to make a picture file in Graphics/Pictures folder. Almost there =D Thanks again for the help so far! ~ Dinhbat Share this post Link to post Share on other sites
efeberk 84 Posted April 10, 2014 I didn't get any error in my demo. Be sure you set your loop items truely. Share this post Link to post Share on other sites
dinhbat3 57 Posted April 10, 2014 Oh I see. I mixed up the item type number with item id. My mistake! It works out great now =D Thanks for all the quick replies and active support for such a fun script ~ Dinhbat Share this post Link to post Share on other sites
Naridar 9 Posted April 14, 2014 (edited) I made sure everything is set up correctly, and after a battle I get this error regardless of whether this script should've activated or not. After-battle treasure chests:99:in 'terminate': undefined method 'troop_id' for #<Game_Troop:0x91bb1fc> (NoMethod Error) from Scene_Base:16:in 'main' from SceneManager:23:in: 'run' from Main:9:in 'block in (main)' I made sure the defeated troop has a loop, all items within it are defined correctly (as in, the 3 numbers are, in order, item type (0,1,2), item id, quantity), I have no idea where it goes wrong. Note: line 99 usedto be 94 before I added some lines for additional troops so that every troop I can encounter has a loop. Edited April 14, 2014 by Naridar Share this post Link to post Share on other sites
efeberk 84 Posted April 14, 2014 You can post the code you trying so I can try this code on my editor. Share this post Link to post Share on other sites
Naridar 9 Posted April 14, 2014 That's odd... pasting the script from here again solved the problem, even though the version numbers were the same. I guess it must've been an old version. It works fine now, thanks. Share this post Link to post Share on other sites
Coolie 147 Posted June 27, 2014 After using the script a bit, here's some more suggestions... - Allow us to keep the option of only displaying the prize chosen. - Allow for an "opened chest" image just like there is a "closed chest" image (having all the chests just disappear looks odd to me). - If we're using the option to only show the prize chosen, only change that chest image to "open" when opened. - Allow the prizes within the loop to be RANDOMLY ordered (for people using large numbers of items in a loop). Right now, if I keep picking the first chest, it's always the first item in the loop (Potion x16 in your example; I changed the items to only make one instance of Potion x16 to test it properly). The loop doesn't randomize until the second instance is called if it's needed (when you have, say, 8 items in a loop, but 32 chests). Great script! Share this post Link to post Share on other sites
estriole 326 Posted June 29, 2014 do you mean now we only allowed to take one chest if enemy drop four of them? . sure the game developer is teaching us to not be greedy. . just kidding. nice script. like the layout of the chest and item shown. Share this post Link to post Share on other sites
Naridar 9 Posted July 13, 2014 It could also be used in addition to normal drops, as a type of "battle bonus". E.g. the enemy drops more realistic items (such as fangs, pelts, other monster parts) and this bonus contains usable items, weapons, accesories, rare non-enemy materials, etc. Share this post Link to post Share on other sites
+ AdamSakuru 43 Posted July 17, 2014 It could also be used in addition to normal drops, as a type of "battle bonus". E.g. the enemy drops more realistic items (such as fangs, pelts, other monster parts) and this bonus contains usable items, weapons, accesories, rare non-enemy materials, etc. After using the script a bit, here's some more suggestions... - Allow us to keep the option of only displaying the prize chosen. - Allow for an "opened chest" image just like there is a "closed chest" image (having all the chests just disappear looks odd to me). - If we're using the option to only show the prize chosen, only change that chest image to "open" when opened. - Allow the prizes within the loop to be RANDOMLY ordered (for people using large numbers of items in a loop). Right now, if I keep picking the first chest, it's always the first item in the loop (Potion x16 in your example; I changed the items to only make one instance of Potion x16 to test it properly). The loop doesn't randomize until the second instance is called if it's needed (when you have, say, 8 items in a loop, but 32 chests). Great script! I second both of these. Share this post Link to post Share on other sites