查看: 2870|回复: 6

[交流讨论] 萌新猫幻的VA脚本学习帐

[复制链接]
梦石
0
星屑
2291
在线时间
329 小时
注册时间
2012-5-8
回帖
88

开拓者

发表于 2019-10-23 03:33:43 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 condir 于 2019-10-23 04:05 编辑

本人猫の幻想。
作为一只脚本萌新,这是本人在解决自己遇到的问题时修改过的脚本合集。
有高手对我说:“不要害怕!随便改!”,那我就拿出勇气放上论坛,如果其中错漏多多,大大们多多包涵之余还请不吝赐教。

ps:之后也会不定期更新


1、将选项窗口的上下移动换页显示改为翻页显示

  1. class Window_Selectable < Window_Base
  2.   def cursor_down(wrap = false)
  3.     if index < item_max - col_max || (wrap && col_max == 1)
  4.       select_index = (index + col_max) % item_max
  5.       self.top_row = select_index - select_index % page_row_max
  6.       select(select_index)
  7.     end
  8.   end
  9.   
  10.   def cursor_up(wrap = false)
  11.     if index >= col_max || (wrap && col_max == 1)
  12.       select_index = (index - col_max + item_max) % item_max
  13.       self.top_row = select_index - select_index % page_row_max
  14.       select(select_index)
  15.     end
  16.   end
  17. end
复制代码


2、跳过标题场景,直接进入地图(测试专用)
  1. module SceneManager
  2.   def self.run
  3.     DataManager.init
  4.     Audio.setup_midi if use_midi?
  5.    
  6.     DataManager.setup_new_game
  7.     $game_map.autoplay
  8.     @scene = first_scene_class.new
  9.     @scene.main while @scene
  10.   end
  11.   
  12.   def self.first_scene_class
  13.     Scene_Map
  14.   end
  15. end
复制代码


3、取消对敌群中区分复数敌人的字母后缀
  1. class Game_Enemy < Game_Battler
  2.   def name
  3.     @original_name# + (@plural ? letter : "")
  4.   end
  5. end
复制代码


4、窗口大小加大为640 * 480
  1. Graphics.resize_screen(640, 480)
复制代码

可是这样在最初启动窗口时,还是有一瞬间是小窗口,有没有直接就是640 * 480的办法?

5、更改游戏标题画面的菜单位置
  1. class Window_TitleCommand < Window_Command
  2.   def update_placement
  3.     self.x = (Graphics.width - width) / 2
  4.     self.y = (Graphics.height * 1.3 - height) / 2 #重新设定高度
  5.   end
  6. end
复制代码


6、删除游戏标题画面的“退出游戏”选项
  1. class Window_TitleCommand < Window_Command
  2.   def make_command_list
  3.     add_command(Vocab::new_game, :new_game)
  4.     add_command(Vocab::continue, :continue, continue_enabled)
  5. #    add_command(Vocab::shutdown, :shutdown) #删除“退出游戏”的选项
  6.   end
  7. end
复制代码


7、取消菜单背景模糊效果
  1. module SceneManager
  2.   def self.snapshot_for_background
  3.     @background_bitmap.dispose if @background_bitmap
  4.     @background_bitmap = Graphics.snap_to_bitmap
  5. #    @background_bitmap.blur
  6.   end
  7. end
复制代码


8、取消菜单背景发暗效果
  1. class Scene_MenuBase < Scene_Base  
  2.   def create_background
  3.     @background_sprite = Sprite.new
  4.     @background_sprite.bitmap = SceneManager.background_bitmap
  5. #    @background_sprite.color.set(16, 16, 16, 128)
  6.   end
  7. end
复制代码


9、降低游戏里NPC的运动频率
  1. class Game_CharacterBase
  2.   def update_animation
  3.     update_anime_count
  4.     if @anime_count > 36 - real_move_speed * 2
  5.       update_anime_pattern
  6.       @anime_count = 0
  7.     end
  8.   end
  9. end
复制代码

然而效果并不怎么好,有时候跟随的人物会发生轻微卡顿……

  1. class Game_CharacterBase
  2.    def update_anime_count
  3.      if moving? && @walk_anime
  4.        @anime_count += 1.5
  5.      elsif @step_anime || @pattern != @original_pattern
  6.        @anime_count += 0.25 #运动速度改为原本的四分之一
  7.      end
  8.    end
  9. end
复制代码

问题同上,轻微卡顿……

10、精灵与图块向上错开8像素(原版为4像素)
  1. class Game_CharacterBase
  2.   def shift_y
  3.     object_character? ? 0 : 8 #向上错开8像素(仅限人物)
  4.   end
  5. end
复制代码


11、静止时主角也保持踏步动作
  1. class Game_Player < Game_Character
  2.   def initialize
  3.     super
  4.     @vehicle_type = :walk
  5.     @vehicle_getting_on = false
  6.     @vehicle_getting_off = false
  7.     @followers = Game_Followers.new(self)
  8.     @step_anime = true       #主角踏步动画
  9.     @transparent = $data_system.opt_transparent
  10.     clear_transfer_info
  11.   end
  12. end
复制代码


12、跟随对象(开火车)最多3人
  1. class Game_Followers
  2.   def initialize(leader)
  3.     @visible = $data_system.opt_followers
  4.     @gathering = false                    
  5.     @data = []
  6.     @data.push(Game_Follower.new(1, leader))
  7.     (2...3).each do |index| # 跟随对象最多3人
  8.       @data.push(Game_Follower.new(index, @data[-1]))
  9.     end
  10.   end
  11. end
复制代码



评分

参与人数 2赞 +2 收起 理由
小小西 + 1 我很赞同
百里_飞柳 + 1 我很赞同

查看全部评分

老鹰

梦石
40
星屑
38044
在线时间
7127 小时
注册时间
2012-5-26
回帖
3306

极短24评委极短23参与极短22参与极短21评委老司机慢点开短篇十吟唱者组别冠军开拓者剧作品鉴家

发表于 2019-10-23 10:39:27 | 显示全部楼层
可以分类一下
比如 地图事件相关、菜单相关、战斗相关

以及总觉得这样的帖子并不好被搜索到(x)

点评

谢谢提醒!不好搜索这点我也挺挠头的不知道该怎么办,毕竟分着发内容太单薄,现在内容太少太杂,多了我会考虑分类的  发表于 2019-10-23 15:43
回复

使用道具 举报

梦石
10
星屑
39550
在线时间
1919 小时
注册时间
2010-11-14
回帖
3214

R考场第七期纪念奖

发表于 2019-10-23 20:07:57 | 显示全部楼层
小插件建议使用环绕别名(又名 猴子补丁),可以提高代码兼容性。
例
12、跟随对象(开火车)最多3人
  1. class Game_Followers  
  2.   alias initialize_for_no_more_than_3_followers initialize
  3.   def initialize(leader)
  4.     initialize_for_no_more_than_3_followers(leader)
  5.     @data = @data[0, 2]
  6.   end
  7. end
复制代码


点评

原来还能这样!  发表于 2019-10-24 05:00

评分

参与人数 1赞 +1 收起 理由
condir + 1

查看全部评分

用头画头像,用脚写脚本
回复

使用道具 举报

梦石
0
星屑
2291
在线时间
329 小时
注册时间
2012-5-8
回帖
88

开拓者

 楼主| 发表于 2019-10-24 05:44:57 | 显示全部楼层
13.将选项窗口位置调整到右下角,显示选项时缩小对话窗口
  1. class Game_Message
  2.   attr_accessor :choices_state              # 选项窗口状态
  3.   
  4.   alias xjpt013_clear clear
  5.   def clear
  6.     xjpt013_clear
  7.     @choices_state = true
  8.   end
  9. end

  10. class Window_ChoiceList < Window_Command
  11.   def update_placement
  12.     self.width = [max_choice_width + 12, 96].max + padding * 2
  13.     self.width = [width, Graphics.width].min
  14.     #调整选项窗口的位置
  15.     self.x = Graphics.width - width
  16.     self.y = @message_window.y
  17.     self.height = fitting_height($game_message.choices.size)
  18.     #将对话窗口缩小,留出选项窗口的位置
  19.     @message_window.width = Graphics.width - width
  20.   end

  21.   #选项窗口并不随选项结束(确定分支)立即关闭
  22.   def call_ok_handler
  23.     $game_message.choice_proc.call(index)
  24.     #close
  25.   end
  26.   
  27.   #选项窗口并不随选项结束(取消分支)立即关闭
  28.   def call_cancel_handler
  29.     $game_message.choice_proc.call($game_message.choice_cancel_type - 1)
  30.     #close
  31.   end
  32. end

  33. class Window_Message < Window_Base
  34.   alias xjpt013_open open
  35.   def open
  36.     if $game_message.choices_state
  37.       if $game_message.choice? then
  38.         self.width = Graphics.width -
  39.         [max_choice_width + 12, 96].max - padding * 2
  40.       end
  41.     else
  42.       self.width = Graphics.width
  43.       $game_message.choices_state = true
  44.     end
  45.     xjpt013_open
  46.   end

  47.   def max_choice_width
  48.     $game_message.choices.collect {|s| text_size(s).width }.max
  49.   end
  50.   #选项窗口改为随上级窗口(对话窗口)一起关闭  
  51.   def close
  52.     @choice_window.close unless @choice_window.close?
  53.     @gold_window.close unless @gold_window.close?
  54.     super
  55.   end
  56. end

  57. # 在本次对话结束后,恢复对话窗口的长度
  58. class Game_Interpreter
  59.   def run
  60.     wait_for_message
  61.     while @list[@index] do
  62.       execute_command
  63.       @index += 1
  64.     end
  65.     $game_message.choices_state = false
  66.     Fiber.yield
  67.     @fiber = nil
  68.   end
  69. end
复制代码

效果图:
回复

使用道具 举报

梦石
0
星屑
2291
在线时间
329 小时
注册时间
2012-5-8
回帖
88

开拓者

 楼主| 发表于 2019-10-28 02:35:03 | 显示全部楼层
本帖最后由 condir 于 2019-10-28 06:57 编辑

14.将宋体15号字线性放大两倍作为像素字体
效果图:


  1. #加载DLL
  2. module OutsideFunc
  3.   Push_character =
  4.       Win32API.new('.\\System\\test.dll', 'set_16bit_char', 'p', 'v')
  5.   Get_character_pixel =
  6.       Win32API.new('.\\System\\test.dll', 'get_16bit_pixel', 'ii', 'i')  
  7. end

  8. #重写文本输出的部分
  9. class Window_Base < Window
  10.   
  11.   include OutsideFunc
  12.   
  13.   def line_height
  14.     return Font.default_size
  15.   end
  16.   
  17.   def draw_text(*args)
  18.     #统一参数形式
  19.     if (args.size == 2||args.size == 3)
  20.       x = args[0].x
  21.       y = args[0].y
  22.       h = args[0].height
  23.       w = args[0].width
  24.       str = args[1]
  25.       align = (args[2] != nil ? args[2] : 0)
  26.     else
  27.       x = args[0]
  28.       y = args[1]
  29.       w = args[2]
  30.       h = args[3]
  31.       str = args[4]
  32.       align = (args[5] != nil ? args[5] : 0)
  33.     end
  34.     str = str.to_s unless str.is_a?(String)
  35.    
  36.     #对齐格式:0-左 1-中 2-右
  37.     if (align == 1)
  38.       x = x + (w - text_size(str).width) / 2
  39.     elsif (align == 2)
  40.       x = x + w - text_size(str).width
  41.     end
  42.    
  43.     #拆解为单个字符输出
  44.     for n in 0 ... str.size
  45.       c = str[n]
  46.       w = text_size(c).width
  47.       draw_one_character(x, y, w, h, c) unless c == nil
  48.       x += w
  49.     end
  50.   end
  51.   
  52.   #输出单个字符:以点阵方式描绘
  53.   def draw_one_character(*args)
  54.     Push_character.call(args[4].encode("UTF-16LE"))
  55.     for x in 0 ... args[2] / 2 - 1
  56.       for y in 0 .. 14
  57.         if Get_character_pixel.call(x, y) == 0 then
  58.           px = args[0] + x * 2
  59.           py = args[1] + y * 2
  60.           contents.set_pixel(px, py, contents.font.color)
  61.           contents.set_pixel(px + 1, py, contents.font.color)
  62.           contents.set_pixel(px, py + 1, contents.font.color)
  63.           contents.set_pixel(px + 1, py + 1, contents.font.color)
  64.         end
  65.       end
  66.     end
  67.   end
  68. end
复制代码


再使用VS2019,建立一个DLL项目,
设置静态编译(配置属性>C/C++>代码生成>运行库>多线程调试/MTd)
  1. // test.cpp : 定义 DLL 应用程序的导出函数。
  2. #include <windows.h>
  3. #include <stdio.h>

  4. int hasInit = FALSE;
  5. HFONT hfBuffer;       
  6. HDC hdcBuffer;
  7. HBITMAP hBitmapBuffer, hOldBitmapBuffer;

  8. //第五版:测试版字体放大程序

  9. void init() {
  10.         //获取缓冲区句柄
  11.         hdcBuffer = CreateCompatibleDC(NULL);
  12.         //获取缓冲区画刷
  13.         hBitmapBuffer = CreateCompatibleBitmap(hdcBuffer, 16, 16);
  14.         //关联缓冲区句柄和画刷
  15.         hOldBitmapBuffer = (HBITMAP)SelectObject(hdcBuffer, hBitmapBuffer);

  16.         //创建字体
  17.         hfBuffer = ::CreateFont(
  18.                 15,                 //字体高度
  19.                 0,                  //字体宽度
  20.                 0,                  //字体显示角度
  21.                 0,                  //字体的角度
  22.                 0,                  //字体的磅数
  23.                 FALSE,              //斜体字体
  24.                 FALSE,              //带下划线的字体
  25.                 0,                  //带删除线的字体
  26.                 GB2312_CHARSET,     //所需的字符集
  27.                 OUT_DEFAULT_PRECIS, //输出的精度
  28.                 CLIP_DEFAULT_PRECIS,//裁剪的精度
  29.                 DEFAULT_QUALITY,    //逻辑字体与输入设备实际字体之间的精度
  30.                 DEFAULT_PITCH,      //字体间距和字体集
  31.                 L"宋体"             //字体名称
  32.                 );

  33.         //关联字体画刷与临时缓冲区句柄
  34.         SelectObject(hdcBuffer, hfBuffer);

  35.         //初始化完成
  36.         hasInit = TRUE;
  37. }

  38. extern "C" _declspec(dllexport) void set_16bit_char(wchar_t *str) {
  39.         //没有初始化则进行初始化
  40.         if (hasInit == FALSE) init();
  41.         //设置缓冲区字体颜色为黑色
  42.         SetTextColor(hdcBuffer, 0x000000);
  43.         //输出该字到缓冲区
  44.         TextOut(hdcBuffer, 0, 0, str, 1);
  45. }

  46. extern "C" _declspec(dllexport) int get_16bit_pixel(int x, int y) {
  47.         return GetPixel(hdcBuffer, x, y);
  48. }
复制代码
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部