Advertisement
Demintika

RPGM VX Ace - DMTK Save Point

Jun 12th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.00 KB | None | 0 0
  1. #==============================================================================
  2. # *
  3. #==============================================================================
  4. =begin
  5.   #--------------------------------------------------------------------------
  6.   # *
  7.   #--------------------------------------------------------------------------
  8.   Item Note Tag:
  9.     <tent>  : The item can only usable when the player is at Save Point. You
  10.     can trigger Common Event for Sound and Visual effect (Fade out, play music,
  11.     Fade in, recovery all, special story process.)
  12.   #--------------------------------------------------------------------------
  13.   # *
  14.   #--------------------------------------------------------------------------
  15.   Event Command Tag:
  16.     <save_point>    : Make the event a normal save point.
  17.     <save_point: 1> : Save only
  18.     <save_point: 2> : Use tent only
  19.   #--------------------------------------------------------------------------
  20.   # *
  21.   #--------------------------------------------------------------------------
  22.   Event Setting:
  23.     If Above or Below player: Save point only active when the player is in the
  24.     same spot as the save point.
  25.     If Same as player: Save point only active when the player stand next to the
  26.     save point.
  27.   #--------------------------------------------------------------------------
  28.   # *
  29.   #--------------------------------------------------------------------------
  30.   About Save point:
  31.     Save point actives passively. It actives the Save command in the Menu and
  32.     Tent items in inventory.
  33.   #--------------------------------------------------------------------------
  34.   # *
  35.   #--------------------------------------------------------------------------
  36.   Disable Save:
  37.     You can disable Save Point by using normal event's Save Disable
  38.     (Event Commands / Page 3 / Change Save Access)
  39. =end
  40. #==============================================================================
  41. # *
  42. #==============================================================================
  43. module DMTK
  44.   module SAVE_POINT
  45.   #--------------------------------------------------------------------------
  46.   # * SAFE_MAPS: List of ids of maps which is savable and tent is usable.
  47.   #--------------------------------------------------------------------------
  48.     SAFE_MAPS = []
  49.   end
  50. end
  51.  
  52. #==============================================================================
  53. # *
  54. #==============================================================================
  55. module DataManager
  56.  
  57.   #--------------------------------------------------------------------------
  58.   # *
  59.   #--------------------------------------------------------------------------
  60.   class << self
  61.     alias dmtk_load_database_save load_database
  62.   end
  63.  
  64.   #--------------------------------------------------------------------------
  65.   # *
  66.   #--------------------------------------------------------------------------
  67.   def self.load_database
  68.     dmtk_load_database_save
  69.     dmtk_load_notetag_save
  70.   end
  71.  
  72.   #--------------------------------------------------------------------------
  73.   # *
  74.   #--------------------------------------------------------------------------
  75.   def self.dmtk_load_notetag_save
  76.     $data_items.each {|obj|
  77.       next if obj.nil?
  78.       obj.dmtk_load_notetag_save
  79.     }
  80.   end
  81. end
  82.  
  83. #==============================================================================
  84. # *
  85. #==============================================================================
  86. class RPG::Item < RPG::UsableItem
  87.  
  88.   attr_reader :is_tent
  89.   #--------------------------------------------------------------------------
  90.   # *
  91.   #--------------------------------------------------------------------------
  92.   def dmtk_load_notetag_save
  93.     self.note.split(/[\r\n]+/).each { |line|
  94.       if line =~ /<tent>/i
  95.         @is_tent = true
  96.         break
  97.       end
  98.     }
  99.   end
  100.  
  101. end
  102.  
  103. #==============================================================================
  104. # *
  105. #==============================================================================
  106. class Game_System
  107.   alias dmtk_save_point_disabled save_disabled
  108.   def save_disabled
  109.     return true if dmtk_save_point_disabled
  110.     return !$game_map.dmtk_savable?
  111.   end
  112. end
  113.  
  114. #==============================================================================
  115. # *
  116. #==============================================================================
  117. class Game_Map
  118.  
  119.   #--------------------------------------------------------------------------
  120.   # *
  121.   #--------------------------------------------------------------------------
  122.   def dmtk_setup_save_points
  123.     @save_points = []
  124.     self.events.values.each {|event|
  125.       @save_points.push(event) if event.save_point
  126.     }
  127.   end
  128.  
  129.   #--------------------------------------------------------------------------
  130.   # *
  131.   #--------------------------------------------------------------------------
  132.   def dmtk_savable?
  133.     return true if safe_map?
  134.     @save_points.each {|event|
  135.       next unless event.savable
  136.       return true if event.dmtk_player_contact?
  137.     }
  138.     return false
  139.   end
  140.  
  141.   #--------------------------------------------------------------------------
  142.   # *
  143.   #--------------------------------------------------------------------------
  144.   def dmtk_tent_usable?
  145.     return true if safe_map?
  146.     @save_points.each {|event|
  147.       next unless event.tent_usable
  148.       return true if event.dmtk_player_contact?
  149.     }
  150.     return false
  151.   end
  152.  
  153.   #--------------------------------------------------------------------------
  154.   # *
  155.   #--------------------------------------------------------------------------
  156.   def safe_map?
  157.     DMTK::SAVE_POINT::SAFE_MAPS.include?(@map_id)
  158.   end
  159.  
  160. end
  161.  
  162. #==============================================================================
  163. # *
  164. #==============================================================================
  165. class Game_Event < Game_Character
  166.  
  167.   #--------------------------------------------------------------------------
  168.   # *
  169.   #--------------------------------------------------------------------------
  170.   attr_reader :save_point
  171.   attr_reader :savable
  172.   attr_reader :tent_usable
  173.  
  174.   #--------------------------------------------------------------------------
  175.   # *
  176.   #--------------------------------------------------------------------------
  177.   alias dmtk_save_setup_page_settings setup_page_settings
  178.   def setup_page_settings
  179.     dmtk_save_setup_page_settings
  180.     dmtk_setup_save_point
  181.   end
  182.  
  183.   #--------------------------------------------------------------------------
  184.   # *
  185.   #--------------------------------------------------------------------------
  186.   def dmtk_setup_save_point
  187.     @list.each do |command|
  188.       next unless command.code == 108 || command.code == 408
  189.       if command.parameters[0] =~ /<save[ _]point(?::[ ]*(\d+))?>/i
  190.         @save_point = true
  191.         @savable = true
  192.         @tent_usable = true
  193.         unless $1.nil?
  194.           case $1.to_i
  195.           when 1
  196.             @tent_usable = false
  197.           when 2
  198.             @savable = false
  199.           end
  200.         end
  201.       end
  202.     end
  203.   end
  204.  
  205.   #--------------------------------------------------------------------------
  206.   # *
  207.   #--------------------------------------------------------------------------
  208.   def dmtk_player_contact?
  209.     return true if self.x == $game_player.x && self.y == $game_player.y
  210.     if normal_priority?
  211.       return dmtk_next_to_player?
  212.     end
  213.     return false
  214.   end
  215.  
  216.   #--------------------------------------------------------------------------
  217.   # *
  218.   #--------------------------------------------------------------------------
  219.   def dmtk_next_to_player?
  220.     return [2,4,6,8].any? {|dir|
  221.       $game_map.round_x_with_direction($game_player.x,dir) == self.x &&
  222.       $game_map.round_y_with_direction($game_player.y,dir) == self.y
  223.     }
  224.   end
  225.  
  226. end
  227.  
  228. #==============================================================================
  229. # *
  230. #==============================================================================
  231. class Game_BattlerBase
  232.  
  233.   #--------------------------------------------------------------------------
  234.   # *
  235.   #--------------------------------------------------------------------------
  236.   alias dmtk_tent_usable? usable?
  237.   def usable?(item)
  238.     return false unless dmtk_tent_usable?(item)
  239.     return true unless item.is_a?(RPG::Item) && item.is_tent
  240.     return $game_map.dmtk_tent_usable?
  241.   end
  242. end
  243.  
  244. #==============================================================================
  245. # *
  246. #==============================================================================
  247. class Scene_Map < Scene_Base
  248.  
  249.   #--------------------------------------------------------------------------
  250.   # *
  251.   #--------------------------------------------------------------------------
  252.   alias dmtk_save_point_start start
  253.   def start
  254.     dmtk_save_point_start
  255.     $game_map.dmtk_setup_save_points
  256.   end
  257.  
  258. end
  259.  
  260. #==============================================================================
  261. # *
  262. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement