TheoAllen

Theo - Gameover Choice v2

Nov 28th, 2013
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.85 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Gameover Choice + Battle Retry
  3. # Version : 2.1
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # Requester : Darken (RMID) / Agus Widhiantara (FB)
  6. # (This script documentation is written in informal indonesian language)
  7. # =============================================================================
  8. ($imported ||= {})[:Theo_GChoice] = true
  9. # =============================================================================
  10. # Change Logs:
  11. # -----------------------------------------------------------------------------
  12. # 2014.02.11 - Compatibility with TSBS
  13. # 2013.11.29 - Finished version 2.0
  14. # 2013.02.26 - Finished version 1.0
  15. # =============================================================================
  16. =begin
  17.  
  18.   Perkenalan :
  19.   Script ini nambah pilihan saat gameover berupa Battle Retry dan kembali ke
  20.   checkpoint terakhir
  21.  
  22.   Cara penggunaan :
  23.   Pasang script ini di bawah material namun di atas main.
  24.   Untuk menggunakan checkpoint, gunakan script call :
  25.  
  26.   $game_system.save_checkpoint
  27.   $game_system.load_checkpoint
  28.  
  29.   Dari namanya udah keliatan mana untuk save checkpoint dan mana yang load.
  30.  
  31.   Terms of use :
  32.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  33.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  34.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.        
  35.  
  36. =end
  37. # =============================================================================
  38. # Konfigurasi
  39. # =============================================================================
  40. module Theo
  41.   module GC
  42.   # ---------------------------------------------------------------------------
  43.   # Vocab untuk command di dalam window
  44.   # ---------------------------------------------------------------------------
  45.     VocabRetry  = "Battle Retry"      # Untuk battle retry
  46.     VocabCP     = "Last Checkpoint"   # Untuk checkpoint
  47.     VocabTitle  = "To title"          # Untuk ke title
  48.   # ---------------------------------------------------------------------------
  49.     Width       = 200  # Lebar window gameover choice
  50.   # ---------------------------------------------------------------------------
  51.   end
  52. end
  53. # =============================================================================
  54. # Akhir dari konfigurasi
  55. # =============================================================================
  56. class Game_System
  57.   class CheckPoint
  58.     attr_accessor :x
  59.     attr_accessor :y
  60.     attr_accessor :map_id
  61.     attr_accessor :d
  62.     attr_accessor :dumped_party
  63.     attr_accessor :dumped_actors
  64.    
  65.     def initialize
  66.       @x = $data_system.start_x
  67.       @y = $data_system.start_y
  68.       @map_id = $data_system.start_map_id
  69.       @d = 2
  70.       @dumped_party = nil
  71.       @dumped_actors = []
  72.     end
  73.   end
  74.  
  75.   attr_reader :checkpoint
  76.  
  77.   alias theo_gchoice_init initialize
  78.   def initialize
  79.     theo_gchoice_init
  80.     @checkpoint = CheckPoint.new
  81.   end
  82.  
  83.   def save_checkpoint
  84.     if $game_party.in_battle
  85.       return
  86.     end
  87.     checkpoint.x = $game_player.x
  88.     checkpoint.y = $game_player.y
  89.     checkpoint.map_id = $game_map.map_id
  90.     checkpoint.d = $game_player.direction
  91.     checkpoint.dumped_party = copy($game_party)
  92.     $game_party.members.each do |member|
  93.       checkpoint.dumped_actors[member.id] = copy(member)
  94.     end
  95.   end
  96.  
  97.   def load_checkpoint
  98.     $game_map.setup(checkpoint.map_id)
  99.     $game_player.moveto(checkpoint.x, checkpoint.y)
  100.     $game_player.set_direction(checkpoint.d)
  101.     $game_party = checkpoint.dumped_party if checkpoint.dumped_party
  102.     checkpoint.dumped_actors.each_with_index do |dump_actor, id|
  103.       next if dump_actor.nil?
  104.       $game_actors[id] = dump_actor
  105.     end
  106.     SceneManager.clear
  107.     SceneManager.goto(Scene_Map)
  108.   end
  109.  
  110. end
  111.  
  112. class Game_Temp
  113.   class Last_Troop
  114.     attr_accessor :id
  115.     attr_accessor :can_lose
  116.     attr_accessor :can_escape
  117.     def initialize
  118.       @id = 0
  119.       @can_lose = false
  120.       @can_escape = true
  121.     end
  122.   end
  123.  
  124.   attr_accessor :dumped_party
  125.   attr_accessor :battle_retry
  126.   attr_accessor :actor_fibers
  127.   attr_reader :dumped_actors
  128.   attr_reader :last_troop
  129.  
  130.   alias theo_gchoice_init initialize
  131.   def initialize
  132.     theo_gchoice_init
  133.     @battle_retry = false
  134.     @last_troop = Last_Troop.new
  135.     @dumped_actors = []
  136.     @dumped_party = nil
  137.   end
  138. end
  139.  
  140. class Game_Actor < Game_Battler
  141.  
  142.   def save_actor
  143.     $game_temp.dumped_actors[id] = copy(self)
  144.   end
  145.  
  146.   def load_actor
  147.     $game_actors[id] = copy($game_temp.dumped_actors[id])
  148.   end
  149.  
  150.   alias theo_gchoice_bstart on_battle_start
  151.   def on_battle_start
  152.     theo_gchoice_bstart
  153.     $game_temp.battle_retry ? load_actor : save_actor
  154.   end
  155.  
  156. end
  157.  
  158. class Game_Actors
  159.  
  160.   def []=(id, actor)
  161.     @data[id] = actor
  162.   end
  163.  
  164. end
  165.  
  166. class Game_Party < Game_Unit
  167.  
  168.   def save_party
  169.     $game_temp.dumped_party = copy(self)
  170.   end
  171.  
  172.   def load_party
  173.     $game_party = copy($game_temp.dumped_party)
  174.   end
  175.  
  176.   alias theo_gchoice_bstart on_battle_start
  177.   def on_battle_start
  178.     theo_gchoice_bstart
  179.     $game_temp.battle_retry ? load_party : save_party
  180.   end
  181.  
  182. end
  183.  
  184. class << BattleManager
  185.  
  186.   alias theo_gchoice_setup setup
  187.   def setup(troop_id, can_escape = true, can_lose = false)
  188.     theo_gchoice_setup(troop_id, can_escape, can_lose)
  189.     $game_temp.last_troop.id = troop_id
  190.     $game_temp.last_troop.can_escape = can_escape
  191.     $game_temp.last_troop.can_lose = can_lose
  192.   end
  193.  
  194.   def battle_retry
  195.     troop_id = $game_temp.last_troop.id
  196.     can_escape = $game_temp.last_troop.can_escape
  197.     can_lose = $game_temp.last_troop.can_lose
  198.     theo_gchoice_setup(troop_id, can_escape, can_lose)
  199.     Sound.play_battle_start
  200.     play_battle_bgm
  201.   end
  202.  
  203.   alias theo_gchoice_replay_music replay_bgm_and_bgs
  204.   def replay_bgm_and_bgs
  205.     begin
  206.       theo_gchoice_replay_music
  207.     rescue
  208.       $game_map.autoplay
  209.     end
  210.   end
  211.  
  212. end
  213.  
  214. class Window_GOChoice < Window_Command
  215.  
  216.   def initialize
  217.     super(0,0)
  218.     update_placement
  219.     self.openness = 0
  220.     activate
  221.   end
  222.  
  223.   def make_command_list
  224.     add_command(Theo::GC::VocabRetry, :retry)
  225.     add_command(Theo::GC::VocabCP, :checkpoint, $game_system.checkpoint)
  226.     add_command(Theo::GC::VocabTitle, :title)
  227.   end
  228.  
  229.   def update_placement
  230.     self.x = (Graphics.width - width)/2
  231.     self.y = (Graphics.height * 1.6 - height) / 2
  232.   end
  233.  
  234.   def window_width
  235.     Theo::GC::Width
  236.   end
  237.  
  238. end
  239.  
  240. class Scene_Gameover < Scene_Base
  241.  
  242.   alias theo_gchoice_start start
  243.   def start
  244.     theo_gchoice_start
  245.     @command_window = Window_GOChoice.new
  246.     @command_window.set_handler(:retry, method(:battle_retry))
  247.     @command_window.set_handler(:checkpoint, method(:goto_checkpoint))
  248.     @command_window.set_handler(:title, method(:goto_title))
  249.     @command_window.open
  250.   end
  251.  
  252.   def battle_retry
  253.     RPG::ME.stop
  254.     BattleManager.battle_retry
  255.     $game_temp.battle_retry = true
  256.     SceneManager.goto(Scene_Battle)
  257.     close_command
  258.   end
  259.  
  260.   def goto_checkpoint
  261.     RPG::ME.stop
  262.     $game_system.load_checkpoint
  263.     $game_map.autoplay
  264.     close_command
  265.   end
  266.  
  267.   def close_command
  268.     @command_window.close
  269.     update_basic until @command_window.close?
  270.   end
  271.   # ----------------------------------------
  272.   # Overwrites
  273.   # ----------------------------------------
  274.   def update
  275.     super
  276.   end
  277.  
  278. end
  279.  
  280. class Scene_Battle
  281.  
  282.   alias theo_gchoice_bt_start battle_start
  283.   def battle_start
  284.     theo_gchoice_bt_start
  285.     if $game_temp.battle_retry && $imported[:TSBS]
  286.       recreate_spriteset
  287.     else
  288.       $game_temp.battle_retry = false
  289.     end
  290.   end
  291.  
  292.   def recreate_spriteset
  293.     @spriteset.dispose
  294.     create_spriteset
  295.     $game_temp.battle_retry = false
  296.   end
  297.  
  298. end
  299.  
  300. def copy(object)
  301.   Marshal.load(Marshal.dump(object))
  302. end
Advertisement
Add Comment
Please, Sign In to add comment