设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1574|回复: 2
打印 上一主题 下一主题

[已经过期] 急,测试游戏保存脚本出现错误·

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1220
在线时间
57 小时
注册时间
2012-9-22
帖子
4
跳转到指定楼层
1
发表于 2012-10-29 23:51:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x

Lv3.寻梦者

梦石
0
星屑
1220
在线时间
57 小时
注册时间
2012-9-22
帖子
4
2
 楼主| 发表于 2012-10-29 23:56:35 | 只看该作者
本帖最后由 路边摊の芄子酱 于 2012-10-30 00:01 编辑

代码复制
  1. #===============================================================
  2. # ● [VX] ◦ Neo Save System III ◦ □
  3. #--------------------------------------------------------------
  4. # ◦ by Woratana [[url=mailto:[email protected]][email protected][/url]]
  5. # ◦ Thaiware RPG Maker Community
  6. # ◦ Released on: 15/02/2009
  7. # ◦ Version: 3.0
  8. #--------------------------------------------------------------
  9. # ◦ Log III:
  10. # - Change back to draw tilemap as screenshot. Don't need any image.
  11. # - For drawing tilemap, the characters won't show on the tilemap.
  12. #--------------------------------------------------------------
  13. # ◦ Log II:
  14. # - Screenshot DLL is not work with Vista Aero, so I remove it
  15. # and use image for each map instead of screenshot.
  16. # - Actor's level in last version (V.1) is incorrect.
  17. #--------------------------------------------------------------
  18. # ◦ Features:
  19. # - Unlimited save slots, you can choose max save slot
  20. # - You can use image for scene's background
  21. # - Choose your save file's name, and folder to store save files
  22. # - Choose to show only information you want
  23. # - Editable text for information's title
  24. # - Draw tilemap for map that player is currently in.
  25. # - Remove text you don't want from map's name (e.g. tags for special script)
  26. # - Choose map that you don't want to show its name
  27. # - Include save confirmation window before overwrite old save
  28. #=================================================================
  29.  
  30. module Wora_NSS
  31.   #==========================================================================
  32.   # * START NEO SAVE SYSTEM - SETUP
  33.   #--------------------------------------------------------------------------
  34.   NSS_WINDOW_OPACITY = 255 # All windows' opacity (Lowest 0 - 255 Highest)
  35.   # You can change this to 0 in case you want to use image for background
  36.   NSS_IMAGE_BG = '' # Background image file name, it must be in folder Picture.
  37.   # use '' for no background
  38.   NSS_IMAGE_BG_OPACITY = 255 # Opacity for background image
  39.  
  40.   MAX_SAVE_SLOT = 20 # Max save slots no.
  41.   SLOT_NAME = 'SLOT {id}'
  42.   # Name of the slot (show in save slots list), use {id} for slot ID
  43.   SAVE_FILE_NAME = 'Save{id}.rvdata'
  44.   # Save file name, you can also change its file type from .rvdata to other
  45.   # use {id} for save slot ID
  46.   SAVE_PATH = '' # Path to store save file, e.g. 'Save/' or '' (for game folder)
  47.  
  48.   SAVED_SLOT_ICON = 133 # Icon Index for saved slot
  49.   EMPTY_SLOT_ICON = 141 # Icon Index for empty slot
  50.  
  51.   EMPTY_SLOT_TEXT = '-NO DATA-' # Text to show for empty slot's data
  52.  
  53.   DRAW_GOLD = true # Draw Gold
  54.   DRAW_PLAYTIME = true # Draw Playtime
  55.   DRAW_LOCATION = true # Draw location
  56.   DRAW_FACE = true # Draw Actor's face
  57.   DRAW_LEVEL = true # Draw Actor's level
  58.   DRAW_NAME = true # Draw Actor's name
  59.  
  60.   PLAYTIME_TEXT = '游戏时间: '
  61.   GOLD_TEXT = '金钱: '
  62.   LOCATION_TEXT = '地点: '
  63.   LV_TEXT = 'Lv '
  64.  
  65.   MAP_NAME_TEXT_SUB = %w{}
  66.   # Text that you want to remove from map name,
  67.   # e.g. %w{[LN] [DA]} will remove text '[LN]' and '[DA]' from map name
  68.   MAP_NO_NAME_LIST = [] # ID of Map that will not show map name, e.g. [1,2,3]
  69.   MAP_NO_NAME_NAME = '??????????' # What you will use to call map in no name list
  70.  
  71.   MAP_BORDER = Color.new(0,0,0,200) # Map image border color (R,G,B,Opacity)
  72.   FACE_BORDER = Color.new(0,0,0,200) # Face border color
  73.  
  74.   ## SAVE CONFIRMATION WINDOW ##
  75.   SFC_Text_Confirm = 'Confirm to save' # Text to confirm to save file
  76.   SFC_Text_Cancel = 'Cancel' # Text to cancel to save
  77.   SFC_Window_Width = 200 # Width of Confirmation Window
  78.   SFC_Window_X_Offset = 0 # Move Confirmation Window horizontally
  79.   SFC_Window_Y_Offset = 0 # Move Confirmation Window vertically
  80.   #----------------------------------------------------------------------
  81.   # END NEO SAVE SYSTEM - SETUP
  82.   #=========================================================================
  83. end
  84.  
  85. class Scene_File < Scene_Base
  86.   include Wora_NSS
  87.   attr_reader :window_slotdetail
  88.   #--------------------------------------------------------------------------
  89.   # * Start processing
  90.   #--------------------------------------------------------------------------
  91.   def start
  92.     super
  93.     create_menu_background
  94.     if NSS_IMAGE_BG != ''
  95.       @bg = Sprite.new
  96.       @bg.bitmap = Cache.picture(NSS_IMAGE_BG)
  97.       @bg.opacity = NSS_IMAGE_BG_OPACITY
  98.     end
  99.     @help_window = Window_Help.new
  100.     command = []
  101.     (1..MAX_SAVE_SLOT).each do |i|
  102.       command << SLOT_NAME.clone.gsub!(/\{ID\}/i) { i.to_s }
  103.     end
  104.     @window_slotdetail = Window_NSS_SlotDetail.new
  105.     @window_slotlist = Window_SlotList.new(160, command)
  106.     @window_slotlist.y = @help_window.height
  107.     @window_slotlist.height = Graphics.height - @help_window.height
  108.     @help_window.opacity = NSS_WINDOW_OPACITY
  109.     @window_slotdetail.opacity = @window_slotlist.opacity = NSS_WINDOW_OPACITY
  110.  
  111.   # Create Folder for Save file
  112.   if SAVE_PATH != ''
  113.     Dir.mkdir(SAVE_PATH) if !FileTest.directory?(SAVE_PATH)
  114.   end
  115.     if @saving
  116.       @index = $game_temp.last_file_index
  117.       @help_window.set_text(Vocab::SaveMessage)
  118.     else
  119.       @index = self.latest_file_index
  120.       @help_window.set_text(Vocab::LoadMessage)
  121.       (1..MAX_SAVE_SLOT).each do |i|
  122.         @window_slotlist.draw_item(i-1, false) if !@window_slotdetail.file_exist?(i)
  123.       end
  124.     end
  125.     @window_slotlist.index = @index
  126.     # Draw Information
  127.     @last_slot_index = @window_slotlist.index
  128.     @window_slotdetail.draw_data(@last_slot_index + 1)
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # * Termination Processing
  132.   #--------------------------------------------------------------------------
  133.   def terminate
  134.     super
  135.     dispose_menu_background
  136.     unless @bg.nil?
  137.       @bg.bitmap.dispose
  138.       @bg.dispose
  139.     end
  140.     @window_slotlist.dispose
  141.     @window_slotdetail.dispose
  142.     @help_window.dispose
  143.   end
  144.   #--------------------------------------------------------------------------
  145.   # * Frame Update
  146.   #--------------------------------------------------------------------------
  147.   def update
  148.     super
  149.     if !@confirm_window.nil?
  150.       @confirm_window.update
  151.       if Input.trigger?(Input::C)
  152.         if @confirm_window.index == 0
  153.           determine_savefile
  154.           @confirm_window.dispose
  155.           @confirm_window = nil
  156.         else
  157.           Sound.play_cancel
  158.           @confirm_window.dispose
  159.           @confirm_window = nil
  160.         end
  161.       elsif Input.trigger?(Input::B)
  162.       Sound.play_cancel
  163.       @confirm_window.dispose
  164.       @confirm_window = nil
  165.       end
  166.     else
  167.       update_menu_background
  168.       @window_slotlist.update
  169.       if @window_slotlist.index != @last_slot_index
  170.         @last_slot_index = @window_slotlist.index
  171.         @window_slotdetail.draw_data(@last_slot_index + 1)
  172.       end
  173.       @help_window.update
  174.       update_savefile_selection
  175.     end
  176.   end
  177.   #--------------------------------------------------------------------------
  178.   # * Update Save File Selection
  179.   #--------------------------------------------------------------------------
  180.   def update_savefile_selection
  181.     if Input.trigger?(Input::C)
  182.       if @saving and @window_slotdetail.file_exist?(@last_slot_index + 1)
  183.         Sound.play_decision
  184.         text1 = SFC_Text_Confirm
  185.         text2 = SFC_Text_Cancel
  186.         @confirm_window = Window_Command.new(SFC_Window_Width,[text1,text2])
  187.         @confirm_window.x = ((544 - @confirm_window.width) / 2) + SFC_Window_X_Offset
  188.         @confirm_window.y = ((416 - @confirm_window.height) / 2) + SFC_Window_Y_Offset
  189.       else
  190.         determine_savefile
  191.       end
  192.     elsif Input.trigger?(Input::B)
  193.       Sound.play_cancel
  194.       return_scene
  195.     end
  196.   end
  197.   #--------------------------------------------------------------------------
  198.   # * Execute Save
  199.   #--------------------------------------------------------------------------
  200.   def do_save
  201.     file = File.open(make_filename(@last_slot_index), "wb")
  202.     write_save_data(file)
  203.     file.close
  204.     $scene = Scene_Map.new
  205.   end
  206.   #--------------------------------------------------------------------------
  207.   # * Execute Load
  208.   #--------------------------------------------------------------------------
  209.   def do_load
  210.     file = File.open(make_filename(@last_slot_index), "rb")
  211.     read_save_data(file)
  212.     file.close
  213.     $scene = Scene_Map.new
  214.     RPG::BGM.fade(1500)
  215.     Graphics.fadeout(60)
  216.     Graphics.wait(40)
  217.     @last_bgm.play
  218.     @last_bgs.play
  219.   end
  220.   #--------------------------------------------------------------------------
  221.   # * Confirm Save File
  222.   #--------------------------------------------------------------------------
  223.   def determine_savefile
  224.     if @saving
  225.       Sound.play_save
  226.       do_save
  227.     else
  228.       if @window_slotdetail.file_exist?(@last_slot_index + 1)
  229.         Sound.play_load
  230.         do_load
  231.       else
  232.         Sound.play_buzzer
  233.         return
  234.       end
  235.     end
  236.     $game_temp.last_file_index = @last_slot_index
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # * Create Filename
  240.   #     file_index : save file index (0-3)
  241.   #--------------------------------------------------------------------------
  242.   def make_filename(file_index)
  243.     return SAVE_PATH + SAVE_FILE_NAME.gsub(/\{ID\}/i) { (file_index + 1).to_s }
  244.   end
  245.   #--------------------------------------------------------------------------
  246.   # * Select File With Newest Timestamp
  247.   #--------------------------------------------------------------------------
  248.   def latest_file_index
  249.     latest_index = 0
  250.     latest_time = Time.at(0)
  251.     (1..MAX_SAVE_SLOT).each do |i|
  252.       file_name = make_filename(i - 1)
  253.       next if !@window_slotdetail.file_exist?(i)
  254.       file_time = File.mtime(file_name)
  255.       if file_time > latest_time
  256.         latest_time = file_time
  257.         latest_index = i - 1
  258.       end
  259.     end
  260.     return latest_index
  261.   end
  262. end
  263.  
  264. class Window_SlotList < Window_Command
  265.   #--------------------------------------------------------------------------
  266.   # * Draw Item
  267.   #--------------------------------------------------------------------------
  268.   def draw_item(index, enabled = true)
  269.     rect = item_rect(index)
  270.     rect.x += 4
  271.     rect.width -= 8
  272.     icon_index = 0
  273.     self.contents.clear_rect(rect)
  274.     if $scene.window_slotdetail.file_exist?(index + 1)
  275.       icon_index = Wora_NSS::SAVED_SLOT_ICON
  276.     else
  277.       icon_index = Wora_NSS::EMPTY_SLOT_ICON
  278.     end
  279.     if !icon_index.nil?
  280.       rect.x -= 4
  281.       draw_icon(icon_index, rect.x, rect.y, enabled) # Draw Icon
  282.       rect.x += 26
  283.       rect.width -= 20
  284.     end
  285.     self.contents.clear_rect(rect)
  286.     self.contents.font.color = normal_color
  287.     self.contents.font.color.alpha = enabled ? 255 : 128
  288.     self.contents.draw_text(rect, @commands[index])
  289.   end
  290.  
  291.   def cursor_down(wrap = false)
  292.     if @index < @item_max - 1 or wrap
  293.       @index = (@index + 1) % @item_max
  294.     end
  295.   end
  296.  
  297.   def cursor_up(wrap = false)
  298.     if @index > 0 or wrap
  299.       @index = (@index - 1 + @item_max) % @item_max
  300.     end
  301.   end
  302. end
  303.  
  304. class Window_NSS_SlotDetail < Window_Base
  305.   include Wora_NSS
  306.   def initialize
  307.     super(160, 56, 384, 360)
  308.     @data = []
  309.     @exist_list = []
  310.     @bitmap_list = {}
  311.     @map_name = []
  312.   end
  313.  
  314.   def dispose
  315.     dispose_tilemap
  316.     super
  317.   end
  318.  
  319.   def draw_data(slot_id)
  320.     contents.clear # 352, 328
  321.     dispose_tilemap
  322.     load_save_data(slot_id) if @data[slot_id].nil?
  323.     if @exist_list[slot_id]
  324.       save_data = @data[slot_id]
  325.       # DRAW SCREENSHOT~
  326.       contents.fill_rect(0,30,352,160, MAP_BORDER)
  327.       create_tilemap(save_data['gamemap'].data, save_data['gamemap'].display_x,
  328.     save_data['gamemap'].display_y)
  329.       if DRAW_GOLD
  330.         # DRAW GOLD
  331.         gold_textsize = contents.text_size(save_data['gamepar'].gold).width
  332.         goldt_textsize = contents.text_size(GOLD_TEXT).width
  333.         contents.font.color = system_color
  334.         contents.draw_text(0, 0, goldt_textsize, WLH, GOLD_TEXT)
  335.         contents.draw_text(goldt_textsize + gold_textsize,0,200,WLH, Vocab::gold)
  336.         contents.font.color = normal_color
  337.         contents.draw_text(goldt_textsize, 0, gold_textsize, WLH, save_data['gamepar'].gold)
  338.       end
  339.       if DRAW_PLAYTIME
  340.         # DRAW PLAYTIME
  341.         hour = save_data['total_sec'] / 60 / 60
  342.         min = save_data['total_sec'] / 60 % 60
  343.         sec = save_data['total_sec'] % 60
  344.         time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
  345.         pt_textsize = contents.text_size(PLAYTIME_TEXT).width
  346.         ts_textsize = contents.text_size(time_string).width
  347.         contents.font.color = system_color
  348.         contents.draw_text(contents.width - ts_textsize - pt_textsize, 0,
  349.         pt_textsize, WLH, PLAYTIME_TEXT)
  350.         contents.font.color = normal_color
  351.         contents.draw_text(0, 0, contents.width, WLH, time_string, 2)
  352.       end
  353.       if DRAW_LOCATION
  354.         # DRAW LOCATION
  355.         lc_textsize = contents.text_size(LOCATION_TEXT).width
  356.         mn_textsize = contents.text_size(save_data['map_name']).width
  357.         contents.font.color = system_color
  358.         contents.draw_text(0, 190, contents.width,
  359.         WLH, LOCATION_TEXT)
  360.         contents.font.color = normal_color
  361.         contents.draw_text(lc_textsize, 190, contents.width, WLH,
  362.         save_data['map_name'])
  363.       end
  364.         # DRAW FACE & Level & Name
  365.         save_data['gamepar'].members.each_index do |i|
  366.           actor = save_data['gameactor'][save_data['gamepar'].members[i].id]
  367.           face_x_base = (i*80) + (i*8)
  368.           face_y_base = 216
  369.           lvn_y_plus = 10
  370.           lv_textsize = contents.text_size(actor.level).width
  371.           lvt_textsize = contents.text_size(LV_TEXT).width
  372.         if DRAW_FACE
  373.           # Draw Face
  374.           contents.fill_rect(face_x_base, face_y_base, 84, 84, FACE_BORDER)
  375.           draw_face(actor.face_name, actor.face_index, face_x_base + 2,
  376.           face_y_base + 2, 80)
  377.         end
  378.         if DRAW_LEVEL
  379.           # Draw Level
  380.           contents.font.color = system_color
  381.           contents.draw_text(face_x_base + 2 + 80 - lv_textsize - lvt_textsize,
  382.           face_y_base + 2 + 80 - WLH + lvn_y_plus, lvt_textsize, WLH, LV_TEXT)
  383.           contents.font.color = normal_color
  384.           contents.draw_text(face_x_base + 2 + 80 - lv_textsize,
  385.           face_y_base + 2 + 80 - WLH + lvn_y_plus, lv_textsize, WLH, actor.level)
  386.         end
  387.         if DRAW_NAME
  388.           # Draw Name
  389.           contents.draw_text(face_x_base, face_y_base + 2 + 80 + lvn_y_plus - 6, 84,
  390.           WLH, actor.name, 1)
  391.         end
  392.       end
  393.     else
  394.       contents.draw_text(0,0, contents.width, contents.height - WLH, EMPTY_SLOT_TEXT, 1)
  395.     end
  396.   end
  397.  
  398.   def load_save_data(slot_id)
  399.     file_name = make_filename(slot_id)
  400.     if file_exist?(slot_id) or FileTest.exist?(file_name)
  401.       @exist_list[slot_id] = true
  402.       @data[slot_id] = {}
  403.       # Start load data
  404.       file = File.open(file_name, "r")
  405.       @data[slot_id]['time'] = file.mtime
  406.       @data[slot_id]['char'] = Marshal.load(file)
  407.       @data[slot_id]['frame'] = Marshal.load(file)
  408.       @data[slot_id]['last_bgm'] = Marshal.load(file)
  409.       @data[slot_id]['last_bgs'] = Marshal.load(file)
  410.       @data[slot_id]['gamesys'] = Marshal.load(file)
  411.       @data[slot_id]['gamemes'] = Marshal.load(file)
  412.       @data[slot_id]['gameswi'] = Marshal.load(file)
  413.       @data[slot_id]['gamevar'] = Marshal.load(file)
  414.       @data[slot_id]['gameselfvar'] = Marshal.load(file)
  415.       @data[slot_id]['gameactor'] = Marshal.load(file)
  416.       @data[slot_id]['gamepar'] = Marshal.load(file)
  417.       @data[slot_id]['gametro'] = Marshal.load(file)
  418.       @data[slot_id]['gamemap'] = Marshal.load(file)
  419.       @data[slot_id]['total_sec'] = @data[slot_id]['frame'] / Graphics.frame_rate
  420.       @data[slot_id]['map_name'] = get_mapname(@data[slot_id]['gamemap'].map_id)
  421.       file.close
  422.     else
  423.       @exist_list[slot_id] = false
  424.       @data[slot_id] = -1
  425.     end
  426.   end
  427.  
  428.   def make_filename(file_index)
  429.     return SAVE_PATH + SAVE_FILE_NAME.gsub(/\{ID\}/i) { (file_index).to_s }
  430.   end
  431.  
  432.   def file_exist?(slot_id)
  433.     return @exist_list[slot_id] if !@exist_list[slot_id].nil?
  434.     @exist_list[slot_id] = FileTest.exist?(make_filename(slot_id))
  435.     return @exist_list[slot_id]
  436.   end
  437.  
  438.   def get_mapname(map_id)
  439.     if @map_data.nil?
  440.       @map_data = load_data("Data/MapInfos.rvdata")
  441.     end
  442.     if @map_name[map_id].nil?
  443.       if MAP_NO_NAME_LIST.include?(map_id)
  444.         @map_name[map_id] = MAP_NO_NAME_NAME
  445.       else
  446.         @map_name[map_id] = @map_data[map_id].name
  447.         MAP_NAME_TEXT_SUB.each_index do |i|
  448.           @map_name[map_id].sub!(MAP_NAME_TEXT_SUB[i], '')
  449.         end
  450.       end
  451.     end
  452.     return @map_name[map_id]
  453.   end
  454.  
  455.   def create_tilemap(map_data, ox, oy)
  456.     @viewport = Viewport.new(self.x + 2 + 16, self.y + 32 + 16, 348,156)
  457.     @viewport.z = self.z
  458.     @tilemap = Tilemap.new(@viewport)
  459.     @tilemap.bitmaps[0] = Cache.system("TileA1")
  460.     @tilemap.bitmaps[1] = Cache.system("TileA2")
  461.     @tilemap.bitmaps[2] = Cache.system("TileA3")
  462.     @tilemap.bitmaps[3] = Cache.system("TileA4")
  463.     @tilemap.bitmaps[4] = Cache.system("TileA5")
  464.     @tilemap.bitmaps[5] = Cache.system("TileB")
  465.     @tilemap.bitmaps[6] = Cache.system("TileC")
  466.     @tilemap.bitmaps[7] = Cache.system("TileD")
  467.     @tilemap.bitmaps[8] = Cache.system("TileE")
  468.     @tilemap.map_data = map_data
  469.     @tilemap.ox = ox / 8 + 99
  470.     @tilemap.oy = oy / 8 + 90
  471.   end
  472.  
  473.   def dispose_tilemap
  474.     unless @tilemap.nil?
  475.       @tilemap.dispose
  476.       @tilemap = nil
  477.     end
  478.   end
  479. end
  480.  
  481. class Scene_Title < Scene_Base
  482.   def check_continue
  483.     file_name = Wora_NSS::SAVE_PATH + Wora_NSS::SAVE_FILE_NAME.gsub(/\{ID\}/i) { '*' }
  484.     @continue_enabled = (Dir.glob(file_name).size > 0)
  485.   end
  486. end
  487. #======================================================================
  488. # END - NEO SAVE SYSTEM by Woratana
  489. #======================================================================

点评

這個腳本..我開了一個新遊戲使用後 可以正常使用...不會跳出錯誤喔 會不會是什麼腳本衝突?  发表于 2012-10-30 07:14
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
38
在线时间
1165 小时
注册时间
2012-3-16
帖子
5336
3
发表于 2012-10-30 14:43:03 | 只看该作者
你不会插错地方了吧...
我想要到的是保护同伴的力量,能与同伴一起欢笑的未来的力量,如果无法做到的话,那就无需继承,如果是这样的彭格列的话,那我亲手毁掉它!
  
                       欢迎加入我们的家族~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-11-16 09:44

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表