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

Project1

 找回密码
 注册会员
搜索
查看: 2010|回复: 6

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

[复制链接]

Lv3.寻梦者

梦石
0
星屑
2240
在线时间
325 小时
注册时间
2012-5-8
帖子
99

开拓者

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

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

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

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

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

ps:之后也会不定期更新


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

RUBY 代码复制
  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、跳过标题场景,直接进入地图(测试专用)
RUBY 代码复制
  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、取消对敌群中区分复数敌人的字母后缀
RUBY 代码复制
  1. class Game_Enemy < Game_Battler
  2.   def name
  3.     @original_name# + (@plural ? letter : "")
  4.   end
  5. end


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

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

5、更改游戏标题画面的菜单位置
RUBY 代码复制
  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、删除游戏标题画面的“退出游戏”选项
RUBY 代码复制
  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、取消菜单背景模糊效果
RUBY 代码复制
  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、取消菜单背景发暗效果
RUBY 代码复制
  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的运动频率
RUBY 代码复制
  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

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

RUBY 代码复制
  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像素)
RUBY 代码复制
  1. class Game_CharacterBase
  2.   def shift_y
  3.     object_character? ? 0 : 8 #向上错开8像素(仅限人物)
  4.   end
  5. end


11、静止时主角也保持踏步动作
RUBY 代码复制
  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人
RUBY 代码复制
  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 我很赞同

查看全部评分

Lv6.析梦学徒

老鹰

梦石
39
星屑
33308
在线时间
6542 小时
注册时间
2012-5-26
帖子
3176

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

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

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

点评

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

使用道具 举报

Lv5.捕梦者

梦石
10
星屑
39440
在线时间
1914 小时
注册时间
2010-11-14
帖子
3315

R考场第七期纪念奖

发表于 2019-10-23 20:07:57 | 显示全部楼层
小插件建议使用环绕别名(又名 猴子补丁),可以提高代码兼容性。

12、跟随对象(开火车)最多3人
RUBY 代码复制
  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

查看全部评分

用头画头像,用脚写脚本
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2240
在线时间
325 小时
注册时间
2012-5-8
帖子
99

开拓者

 楼主| 发表于 2019-10-24 05:44:57 | 显示全部楼层
13.将选项窗口位置调整到右下角,显示选项时缩小对话窗口
RUBY 代码复制
  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.  
  11. class Window_ChoiceList < Window_Command
  12.   def update_placement
  13.     self.width = [max_choice_width + 12, 96].max + padding * 2
  14.     self.width = [width, Graphics.width].min
  15.     #调整选项窗口的位置
  16.     self.x = Graphics.width - width
  17.     self.y = @message_window.y
  18.     self.height = fitting_height($game_message.choices.size)
  19.     #将对话窗口缩小,留出选项窗口的位置
  20.     @message_window.width = Graphics.width - width
  21.   end
  22.  
  23.   #选项窗口并不随选项结束(确定分支)立即关闭
  24.   def call_ok_handler
  25.     $game_message.choice_proc.call(index)
  26.     #close
  27.   end
  28.  
  29.   #选项窗口并不随选项结束(取消分支)立即关闭
  30.   def call_cancel_handler
  31.     $game_message.choice_proc.call($game_message.choice_cancel_type - 1)
  32.     #close
  33.   end
  34. end
  35.  
  36. class Window_Message < Window_Base
  37.   alias xjpt013_open open
  38.   def open
  39.     if $game_message.choices_state
  40.       if $game_message.choice? then
  41.         self.width = Graphics.width -
  42.         [max_choice_width + 12, 96].max - padding * 2
  43.       end
  44.     else
  45.       self.width = Graphics.width
  46.       $game_message.choices_state = true
  47.     end
  48.     xjpt013_open
  49.   end
  50.  
  51.   def max_choice_width
  52.     $game_message.choices.collect {|s| text_size(s).width }.max
  53.   end
  54.   #选项窗口改为随上级窗口(对话窗口)一起关闭  
  55.   def close
  56.     @choice_window.close unless @choice_window.close?
  57.     @gold_window.close unless @gold_window.close?
  58.     super
  59.   end
  60. end
  61.  
  62. # 在本次对话结束后,恢复对话窗口的长度
  63. class Game_Interpreter
  64.   def run
  65.     wait_for_message
  66.     while @list[@index] do
  67.       execute_command
  68.       @index += 1
  69.     end
  70.     $game_message.choices_state = false
  71.     Fiber.yield
  72.     @fiber = nil
  73.   end
  74. end

效果图:
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2240
在线时间
325 小时
注册时间
2012-5-8
帖子
99

开拓者

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

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

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


再使用VS2019,建立一个DLL项目,
设置静态编译(配置属性>C/C++>代码生成>运行库>多线程调试/MTd)
C 代码复制
  1. // test.cpp : 定义 DLL 应用程序的导出函数。
  2. #include <windows.h>
  3. #include <stdio.h>
  4.  
  5. int hasInit = FALSE;
  6. HFONT hfBuffer;       
  7. HDC hdcBuffer;
  8. HBITMAP hBitmapBuffer, hOldBitmapBuffer;
  9.  
  10. //第五版:测试版字体放大程序
  11.  
  12. void init() {
  13.         //获取缓冲区句柄
  14.         hdcBuffer = CreateCompatibleDC(NULL);
  15.         //获取缓冲区画刷
  16.         hBitmapBuffer = CreateCompatibleBitmap(hdcBuffer, 16, 16);
  17.         //关联缓冲区句柄和画刷
  18.         hOldBitmapBuffer = (HBITMAP)SelectObject(hdcBuffer, hBitmapBuffer);
  19.  
  20.         //创建字体
  21.         hfBuffer = ::CreateFont(
  22.                 15,                 //字体高度
  23.                 0,                  //字体宽度
  24.                 0,                  //字体显示角度
  25.                 0,                  //字体的角度
  26.                 0,                  //字体的磅数
  27.                 FALSE,              //斜体字体
  28.                 FALSE,              //带下划线的字体
  29.                 0,                  //带删除线的字体
  30.                 GB2312_CHARSET,     //所需的字符集
  31.                 OUT_DEFAULT_PRECIS, //输出的精度
  32.                 CLIP_DEFAULT_PRECIS,//裁剪的精度
  33.                 DEFAULT_QUALITY,    //逻辑字体与输入设备实际字体之间的精度
  34.                 DEFAULT_PITCH,      //字体间距和字体集
  35.                 L"宋体"             //字体名称
  36.                 );
  37.  
  38.         //关联字体画刷与临时缓冲区句柄
  39.         SelectObject(hdcBuffer, hfBuffer);
  40.  
  41.         //初始化完成
  42.         hasInit = TRUE;
  43. }
  44.  
  45. extern "C" _declspec(dllexport) void set_16bit_char(wchar_t *str) {
  46.         //没有初始化则进行初始化
  47.         if (hasInit == FALSE) init();
  48.         //设置缓冲区字体颜色为黑色
  49.         SetTextColor(hdcBuffer, 0x000000);
  50.         //输出该字到缓冲区
  51.         TextOut(hdcBuffer, 0, 0, str, 1);
  52. }
  53.  
  54. extern "C" _declspec(dllexport) int get_16bit_pixel(int x, int y) {
  55.         return GetPixel(hdcBuffer, x, y);
  56. }
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-3-28 18:29

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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