philipwayne 0 Posted June 26, 2013 Just a simple little house buying and selling system I wrote. Project is attached. You will need to edit the DataManager module/section in the scripts (to save and load house data). #============================================================================== # â– DataManager #------------------------------------------------------------------------------ #  データベースã¨ã‚²ãƒ¼ãƒ オブジェクトを管ç†ã™ã‚‹ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã§ã™ã€‚ゲームã§ä½¿ç”¨ã™ã‚‹ # ã»ã¼å…¨ã¦ã®ã‚°ãƒãƒ¼ãƒãƒ«å¤‰æ•°ã¯ã“ã®ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã§åˆæœŸåŒ–ã•れã¾ã™ã€‚ #============================================================================== module DataManager #-------------------------------------------------------------------------- # ◠モジュールã®ã‚¤ãƒ³ã‚¹ã‚¿ãƒ³ã‚¹å¤‰æ•° #-------------------------------------------------------------------------- @last_savefile_index = 0 # 最後ã«ã‚¢ã‚¯ã‚»ã‚¹ã—ãŸãƒ•ァイル #-------------------------------------------------------------------------- # â— ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«åˆæœŸåŒ– #-------------------------------------------------------------------------- def self.init @last_savefile_index = 0 load_database create_game_objects setup_battle_test if $BTEST end #-------------------------------------------------------------------------- # ◠データベースã®ãƒãƒ¼ãƒ‰ #-------------------------------------------------------------------------- def self.load_database if $BTEST load_battle_test_database else load_normal_database check_player_location end end #-------------------------------------------------------------------------- # ◠通常ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’ãƒãƒ¼ãƒ‰ #-------------------------------------------------------------------------- def self.load_normal_database $data_actors = load_data("Data/Actors.rvdata2") $data_classes = load_data("Data/Classes.rvdata2") $data_skills = load_data("Data/Skills.rvdata2") $data_items = load_data("Data/Items.rvdata2") $data_weapons = load_data("Data/Weapons.rvdata2") $data_armors = load_data("Data/Armors.rvdata2") $data_enemies = load_data("Data/Enemies.rvdata2") $data_troops = load_data("Data/Troops.rvdata2") $data_states = load_data("Data/States.rvdata2") $data_animations = load_data("Data/Animations.rvdata2") $data_tilesets = load_data("Data/Tilesets.rvdata2") $data_common_events = load_data("Data/CommonEvents.rvdata2") $data_system = load_data("Data/System.rvdata2") $data_mapinfos = load_data("Data/MapInfos.rvdata2") end #-------------------------------------------------------------------------- # ◠戦闘テスト用ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’ãƒãƒ¼ãƒ‰ #-------------------------------------------------------------------------- def self.load_battle_test_database $data_actors = load_data("Data/BT_Actors.rvdata2") $data_classes = load_data("Data/BT_Classes.rvdata2") $data_skills = load_data("Data/BT_Skills.rvdata2") $data_items = load_data("Data/BT_Items.rvdata2") $data_weapons = load_data("Data/BT_Weapons.rvdata2") $data_armors = load_data("Data/BT_Armors.rvdata2") $data_enemies = load_data("Data/BT_Enemies.rvdata2") $data_troops = load_data("Data/BT_Troops.rvdata2") $data_states = load_data("Data/BT_States.rvdata2") $data_animations = load_data("Data/BT_Animations.rvdata2") $data_tilesets = load_data("Data/BT_Tilesets.rvdata2") $data_common_events = load_data("Data/BT_CommonEvents.rvdata2") $data_system = load_data("Data/BT_System.rvdata2") end #-------------------------------------------------------------------------- # ◠プレイヤーã®åˆæœŸä½ç½®å˜åœ¨ãƒã‚§ãƒƒã‚¯ #-------------------------------------------------------------------------- def self.check_player_location if $data_system.start_map_id == 0 msgbox(Vocab::PlayerPosError) exit end end #-------------------------------------------------------------------------- # â— å„種ゲームオブジェクトã®ä½œæˆ #-------------------------------------------------------------------------- def self.create_game_objects $game_temp = Game_Temp.new $game_system = Game_System.new $game_timer = Game_Timer.new $game_message = Game_Message.new $game_switches = Game_Switches.new $game_variables = Game_Variables.new $game_self_switches = Game_SelfSwitches.new $game_actors = Game_Actors.new $game_party = Game_Party.new $game_troop = Game_Troop.new $game_map = Game_Map.new $game_player = Game_Player.new $BuildingManager = BuildingManager.new end #-------------------------------------------------------------------------- # ◠ニューゲームã®ã‚»ãƒƒãƒˆã‚¢ãƒƒãƒ— #-------------------------------------------------------------------------- def self.setup_new_game create_game_objects $game_party.setup_starting_members $game_map.setup($data_system.start_map_id) $game_player.moveto($data_system.start_x, $data_system.start_y) $game_player.refresh Graphics.frame_count = 0 end #-------------------------------------------------------------------------- # ◠戦闘テストã®ã‚»ãƒƒãƒˆã‚¢ãƒƒãƒ— #-------------------------------------------------------------------------- def self.setup_battle_test $game_party.setup_battle_test BattleManager.setup($data_system.test_troop_id) BattleManager.play_battle_bgm end #-------------------------------------------------------------------------- # ◠セーブファイルã®å˜åœ¨åˆ¤å®š #-------------------------------------------------------------------------- def self.save_file_exists? !Dir.glob('Save*.rvdata2').empty? end #-------------------------------------------------------------------------- # â— ã‚»ãƒ¼ãƒ–ãƒ•ã‚¡ã‚¤ãƒ«ã®æœ€å¤§æ•° #-------------------------------------------------------------------------- def self.savefile_max return 16 end #-------------------------------------------------------------------------- # ◠ファイルåã®ä½œæˆ # index : ファイルインデックス #-------------------------------------------------------------------------- def self.make_filename(index) sprintf("Save%02d.rvdata2", index + 1) end #-------------------------------------------------------------------------- # ◠セーブã®å®Ÿè¡Œ #-------------------------------------------------------------------------- def self.save_game(index) begin save_game_without_rescue(index) rescue delete_save_file(index) false end end #-------------------------------------------------------------------------- # â— ãƒãƒ¼ãƒ‰ã®å®Ÿè¡Œ #-------------------------------------------------------------------------- def self.load_game(index) load_game_without_rescue(index) rescue false end #-------------------------------------------------------------------------- # ◠セーブヘッダã®ãƒãƒ¼ãƒ‰ #-------------------------------------------------------------------------- def self.load_header(index) load_header_without_rescue(index) rescue nil end #-------------------------------------------------------------------------- # ◠セーブã®å®Ÿè¡Œï¼ˆä¾‹å¤–処ç†ãªã—) #-------------------------------------------------------------------------- def self.save_game_without_rescue(index) File.open(make_filename(index), "wb") do |file| $game_system.on_before_save Marshal.dump(make_save_header, file) Marshal.dump(make_save_contents, file) @last_savefile_index = index end return true end #-------------------------------------------------------------------------- # â— ãƒãƒ¼ãƒ‰ã®å®Ÿè¡Œï¼ˆä¾‹å¤–処ç†ãªã—) #-------------------------------------------------------------------------- def self.load_game_without_rescue(index) File.open(make_filename(index), "rb") do |file| Marshal.load(file) extract_save_contents(Marshal.load(file)) reload_map_if_updated @last_savefile_index = index end return true end #-------------------------------------------------------------------------- # ◠セーブヘッダã®ãƒãƒ¼ãƒ‰ï¼ˆä¾‹å¤–処ç†ãªã—) #-------------------------------------------------------------------------- def self.load_header_without_rescue(index) File.open(make_filename(index), "rb") do |file| return Marshal.load(file) end return nil end #-------------------------------------------------------------------------- # ◠セーブファイルã®å‰Šé™¤ #-------------------------------------------------------------------------- def self.delete_save_file(index) File.delete(make_filename(index)) rescue nil end #-------------------------------------------------------------------------- # ◠セーブヘッダã®ä½œæˆ #-------------------------------------------------------------------------- def self.make_save_header header = {} header[:characters] = $game_party.characters_for_savefile header[:playtime_s] = $game_system.playtime_s header end #-------------------------------------------------------------------------- # ◠セーブ内容ã®ä½œæˆ #-------------------------------------------------------------------------- def self.make_save_contents contents = {} contents[:system] = $game_system contents[:timer] = $game_timer contents[:message] = $game_message contents[:switches] = $game_switches contents[:variables] = $game_variables contents[:self_switches] = $game_self_switches contents[:actors] = $game_actors contents[:party] = $game_party contents[:troop] = $game_troop contents[:map] = $game_map contents[:player] = $game_player contents[:building_manager] = $BuildingManager contents end #-------------------------------------------------------------------------- # ◠セーブ内容ã®å±•é–‹ #-------------------------------------------------------------------------- def self.extract_save_contents(contents) $game_system = contents[:system] $game_timer = contents[:timer] $game_message = contents[:message] $game_switches = contents[:switches] $game_variables = contents[:variables] $game_self_switches = contents[:self_switches] $game_actors = contents[:actors] $game_party = contents[:party] $game_troop = contents[:troop] $game_map = contents[:map] $game_player = contents[:player] $BuildingManager = contents[:building_manager] end #-------------------------------------------------------------------------- # â— ãƒ‡ãƒ¼ã‚¿ãŒæ›´æ–°ã•れã¦ã„ã‚‹å ´åˆã¯ãƒžãƒƒãƒ—ã‚’å†èªã¿è¾¼ã¿ #-------------------------------------------------------------------------- def self.reload_map_if_updated if $game_system.version_id != $data_system.version_id $game_map.setup($game_map.map_id) $game_player.center($game_player.x, $game_player.y) $game_player.make_encounter_count end end #-------------------------------------------------------------------------- # â— ã‚»ãƒ¼ãƒ–ãƒ•ã‚¡ã‚¤ãƒ«ã®æ›´æ–°æ—¥æ™‚ã‚’å–å¾— #-------------------------------------------------------------------------- def self.savefile_time_stamp(index) File.mtime(make_filename(index)) rescue Time.at(0) end #-------------------------------------------------------------------------- # â— æ›´æ–°æ—¥æ™‚ãŒæœ€æ–°ã®ãƒ•ァイルインデックスをå–å¾— #-------------------------------------------------------------------------- def self.latest_savefile_index savefile_max.times.max_by {|i| savefile_time_stamp(i) } end #-------------------------------------------------------------------------- # ◠最後ã«ã‚¢ã‚¯ã‚»ã‚¹ã—ãŸãƒ•ァイルã®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’å–å¾— #-------------------------------------------------------------------------- def self.last_savefile_index @last_savefile_index end end and for the actual code class BuildingManager def initialize @Houses = [] end def AddHouse(id, price) @Houses[id] = House.new(price) end def Buy(id) return @Houses[id].Buy end def Sell(id) return @Houses[id].Sell end def IsOwned(id) if (@Houses[id].Owned == true) return true end return false end end class House attr_reader :Owned def initialize(price) @Owned = false @Price = price end def Buy if (@Owned == true) return false end if ($game_party.gold >= @Price) $game_party.lose_gold(@Price) @Owned = true return true end return false end def Sell if (@Owned == false) return false end $game_party.gain_gold(@Price) @Owned = false return true end end Usage is explained with the project, basically, just call $BuildingManager.AddHouse([id], [price]) on auto run/parallel entry then use the $BuildingManager.IsOwned([id]) method to check if a house is owned. Perhaps there could be a common event that you could store the current house number in a system variable then just auto fill everything else. Thank you and let me know what you all think. Project1.zip Share this post Link to post Share on other sites
Pikalyze 4 Posted June 27, 2013 One quick thing. Shouldn't this be in Completed Scripts? Anyways, cool. I'll try it out. Share this post Link to post Share on other sites
Sievnn 14 Posted June 27, 2013 (edited) It looks cool but .. I suppose this could be done using events. How about making the House shop better looking? Edited June 27, 2013 by Sievnn Share this post Link to post Share on other sites
philipwayne 0 Posted June 27, 2013 One quick thing. Shouldn't this be in Completed Scripts? Anyways, cool. I'll try it out. You're right my bad. Mod please move this thread. Share this post Link to post Share on other sites
philipwayne 0 Posted June 27, 2013 It looks cool but .. I suppose this could be done using events. How about making the House shop better looking? Perhaps, I'm new to the RGSS engine couldn't figure out the choice window and such, still trying to find tutorials on how to use it plus Ruby isn't my best language more of a PHP/C# curly brace language guy. Share this post Link to post Share on other sites
Galv 1,387 Posted June 27, 2013 philipwayne, please don't double post within 72 hours. Use the edit link instead (located to the left of the 'quote' button of your posts). Thanks. I recommend checking out some script tutorials or other scripts if you're interested in learning more. For example I don't recommend anyone edit the DataManager module in their scripts, I think it would be better to create alias' so people can paste your script below Materials and above Main - not needing to touch any of the default scripts. Good to see more people getting into it, though. Share this post Link to post Share on other sites
Sievnn 14 Posted June 27, 2013 It looks cool but .. I suppose this could be done using events. How about making the House shop better looking? Perhaps, I'm new to the RGSS engine couldn't figure out the choice window and such, still trying to find tutorials on how to use it plus Ruby isn't my best language more of a PHP/C# curly brace language guy. It looks like a great script for a start. When you figure out it would be nice to make a unique choice window but its great. 1 Share this post Link to post Share on other sites