Project1
标题: 萌新猫幻的VA脚本学习帐 [打印本页]
作者: condir 时间: 2019-10-23 03:33
标题: 萌新猫幻的VA脚本学习帐
本帖最后由 condir 于 2019-10-23 04:05 编辑
本人猫の幻想。
作为一只脚本萌新,这是本人在解决自己遇到的问题时修改过的脚本合集。
有高手对我说:“不要害怕!随便改!”,那我就拿出勇气放上论坛,如果其中错漏多多,大大们多多包涵之余还请不吝赐教。
ps:之后也会不定期更新
1、将选项窗口的上下移动换页显示改为翻页显示
class Window_Selectable < Window_Base
def cursor_down(wrap = false)
if index < item_max - col_max || (wrap && col_max == 1)
select_index = (index + col_max) % item_max
self.top_row = select_index - select_index % page_row_max
select(select_index)
end
end
def cursor_up(wrap = false)
if index >= col_max || (wrap && col_max == 1)
select_index = (index - col_max + item_max) % item_max
self.top_row = select_index - select_index % page_row_max
select(select_index)
end
end
end
class Window_Selectable < Window_Base
def cursor_down(wrap = false)
if index < item_max - col_max || (wrap && col_max == 1)
select_index = (index + col_max) % item_max
self.top_row = select_index - select_index % page_row_max
select(select_index)
end
end
def cursor_up(wrap = false)
if index >= col_max || (wrap && col_max == 1)
select_index = (index - col_max + item_max) % item_max
self.top_row = select_index - select_index % page_row_max
select(select_index)
end
end
end
2、跳过标题场景,直接进入地图(测试专用)
module SceneManager
def self.run
DataManager.init
Audio.setup_midi if use_midi?
DataManager.setup_new_game
$game_map.autoplay
@scene = first_scene_class.new
@scene.main while @scene
end
def self.first_scene_class
Scene_Map
end
end
module SceneManager
def self.run
DataManager.init
Audio.setup_midi if use_midi?
DataManager.setup_new_game
$game_map.autoplay
@scene = first_scene_class.new
@scene.main while @scene
end
def self.first_scene_class
Scene_Map
end
end
3、取消对敌群中区分复数敌人的字母后缀
class Game_Enemy < Game_Battler
def name
@original_name# + (@plural ? letter : "")
end
end
class Game_Enemy < Game_Battler
def name
@original_name# + (@plural ? letter : "")
end
end
4、窗口大小加大为640 * 480
Graphics.resize_screen(640, 480)
Graphics.resize_screen(640, 480)
可是这样在最初启动窗口时,还是有一瞬间是小窗口,有没有直接就是640 * 480的办法?
5、更改游戏标题画面的菜单位置
class Window_TitleCommand < Window_Command
def update_placement
self.x = (Graphics.width - width) / 2
self.y = (Graphics.height * 1.3 - height) / 2 #重新设定高度
end
end
class Window_TitleCommand < Window_Command
def update_placement
self.x = (Graphics.width - width) / 2
self.y = (Graphics.height * 1.3 - height) / 2 #重新设定高度
end
end
6、删除游戏标题画面的“退出游戏”选项
class Window_TitleCommand < Window_Command
def make_command_list
add_command(Vocab::new_game, :new_game)
add_command(Vocab::continue, :continue, continue_enabled)
# add_command(Vocab::shutdown, :shutdown) #删除“退出游戏”的选项
end
end
class Window_TitleCommand < Window_Command
def make_command_list
add_command(Vocab::new_game, :new_game)
add_command(Vocab::continue, :continue, continue_enabled)
# add_command(Vocab::shutdown, :shutdown) #删除“退出游戏”的选项
end
end
7、取消菜单背景模糊效果
module SceneManager
def self.snapshot_for_background
@background_bitmap.dispose if @background_bitmap
@background_bitmap = Graphics.snap_to_bitmap
# @background_bitmap.blur
end
end
module SceneManager
def self.snapshot_for_background
@background_bitmap.dispose if @background_bitmap
@background_bitmap = Graphics.snap_to_bitmap
# @background_bitmap.blur
end
end
8、取消菜单背景发暗效果
class Scene_MenuBase < Scene_Base
def create_background
@background_sprite = Sprite.new
@background_sprite.bitmap = SceneManager.background_bitmap
# @background_sprite.color.set(16, 16, 16, 128)
end
end
class Scene_MenuBase < Scene_Base
def create_background
@background_sprite = Sprite.new
@background_sprite.bitmap = SceneManager.background_bitmap
# @background_sprite.color.set(16, 16, 16, 128)
end
end
9、降低游戏里NPC的运动频率
class Game_CharacterBase
def update_animation
update_anime_count
if @anime_count > 36 - real_move_speed * 2
update_anime_pattern
@anime_count = 0
end
end
end
class Game_CharacterBase
def update_animation
update_anime_count
if @anime_count > 36 - real_move_speed * 2
update_anime_pattern
@anime_count = 0
end
end
end
然而效果并不怎么好,有时候跟随的人物会发生轻微卡顿……
class Game_CharacterBase
def update_anime_count
if moving? && @walk_anime
@anime_count += 1.5
elsif @step_anime || @pattern != @original_pattern
@anime_count += 0.25 #运动速度改为原本的四分之一
end
end
end
class Game_CharacterBase
def update_anime_count
if moving? && @walk_anime
@anime_count += 1.5
elsif @step_anime || @pattern != @original_pattern
@anime_count += 0.25 #运动速度改为原本的四分之一
end
end
end
问题同上,轻微卡顿……
10、精灵与图块向上错开8像素(原版为4像素)
class Game_CharacterBase
def shift_y
object_character? ? 0 : 8 #向上错开8像素(仅限人物)
end
end
class Game_CharacterBase
def shift_y
object_character? ? 0 : 8 #向上错开8像素(仅限人物)
end
end
11、静止时主角也保持踏步动作
class Game_Player < Game_Character
def initialize
super
@vehicle_type = :walk
@vehicle_getting_on = false
@vehicle_getting_off = false
@followers = Game_Followers.new(self)
@step_anime = true #主角踏步动画
@transparent = $data_system.opt_transparent
clear_transfer_info
end
end
class Game_Player < Game_Character
def initialize
super
@vehicle_type = :walk
@vehicle_getting_on = false
@vehicle_getting_off = false
@followers = Game_Followers.new(self)
@step_anime = true #主角踏步动画
@transparent = $data_system.opt_transparent
clear_transfer_info
end
end
12、跟随对象(开火车)最多3人
class Game_Followers
def initialize(leader)
@visible = $data_system.opt_followers
@gathering = false
@data = []
@data.push(Game_Follower.new(1, leader))
(2...3).each do |index| # 跟随对象最多3人
@data.push(Game_Follower.new(index, @data[-1]))
end
end
end
class Game_Followers
def initialize(leader)
@visible = $data_system.opt_followers
@gathering = false
@data = []
@data.push(Game_Follower.new(1, leader))
(2...3).each do |index| # 跟随对象最多3人
@data.push(Game_Follower.new(index, @data[-1]))
end
end
end
作者: 百里_飞柳 时间: 2019-10-23 10:39
可以分类一下
比如 地图事件相关、菜单相关、战斗相关
以及总觉得这样的帖子并不好被搜索到(x)
作者: KB.Driver 时间: 2019-10-23 20:07
小插件建议使用环绕别名(又名 猴子补丁),可以提高代码兼容性。
例
12、跟随对象(开火车)最多3人
class Game_Followers
alias initialize_for_no_more_than_3_followers initialize
def initialize(leader)
initialize_for_no_more_than_3_followers(leader)
@data = @data[0, 2]
end
end
class Game_Followers
alias initialize_for_no_more_than_3_followers initialize
def initialize(leader)
initialize_for_no_more_than_3_followers(leader)
@data = @data[0, 2]
end
end
作者: condir 时间: 2019-10-24 05:44
13.将选项窗口位置调整到右下角,显示选项时缩小对话窗口
class Game_Message
attr_accessor :choices_state # 选项窗口状态
alias xjpt013_clear clear
def clear
xjpt013_clear
@choices_state = true
end
end
class Window_ChoiceList < Window_Command
def update_placement
self.width = [max_choice_width + 12, 96].max + padding * 2
self.width = [width, Graphics.width].min
#调整选项窗口的位置
self.x = Graphics.width - width
self.y = @message_window.y
self.height = fitting_height($game_message.choices.size)
#将对话窗口缩小,留出选项窗口的位置
@message_window.width = Graphics.width - width
end
#选项窗口并不随选项结束(确定分支)立即关闭
def call_ok_handler
$game_message.choice_proc.call(index)
#close
end
#选项窗口并不随选项结束(取消分支)立即关闭
def call_cancel_handler
$game_message.choice_proc.call($game_message.choice_cancel_type - 1)
#close
end
end
class Window_Message < Window_Base
alias xjpt013_open open
def open
if $game_message.choices_state
if $game_message.choice? then
self.width = Graphics.width -
[max_choice_width + 12, 96].max - padding * 2
end
else
self.width = Graphics.width
$game_message.choices_state = true
end
xjpt013_open
end
def max_choice_width
$game_message.choices.collect {|s| text_size(s).width }.max
end
#选项窗口改为随上级窗口(对话窗口)一起关闭
def close
@choice_window.close unless @choice_window.close?
@gold_window.close unless @gold_window.close?
super
end
end
# 在本次对话结束后,恢复对话窗口的长度
class Game_Interpreter
def run
wait_for_message
while @list[@index] do
execute_command
@index += 1
end
$game_message.choices_state = false
Fiber.yield
@fiber = nil
end
end
class Game_Message
attr_accessor :choices_state # 选项窗口状态
alias xjpt013_clear clear
def clear
xjpt013_clear
@choices_state = true
end
end
class Window_ChoiceList < Window_Command
def update_placement
self.width = [max_choice_width + 12, 96].max + padding * 2
self.width = [width, Graphics.width].min
#调整选项窗口的位置
self.x = Graphics.width - width
self.y = @message_window.y
self.height = fitting_height($game_message.choices.size)
#将对话窗口缩小,留出选项窗口的位置
@message_window.width = Graphics.width - width
end
#选项窗口并不随选项结束(确定分支)立即关闭
def call_ok_handler
$game_message.choice_proc.call(index)
#close
end
#选项窗口并不随选项结束(取消分支)立即关闭
def call_cancel_handler
$game_message.choice_proc.call($game_message.choice_cancel_type - 1)
#close
end
end
class Window_Message < Window_Base
alias xjpt013_open open
def open
if $game_message.choices_state
if $game_message.choice? then
self.width = Graphics.width -
[max_choice_width + 12, 96].max - padding * 2
end
else
self.width = Graphics.width
$game_message.choices_state = true
end
xjpt013_open
end
def max_choice_width
$game_message.choices.collect {|s| text_size(s).width }.max
end
#选项窗口改为随上级窗口(对话窗口)一起关闭
def close
@choice_window.close unless @choice_window.close?
@gold_window.close unless @gold_window.close?
super
end
end
# 在本次对话结束后,恢复对话窗口的长度
class Game_Interpreter
def run
wait_for_message
while @list[@index] do
execute_command
@index += 1
end
$game_message.choices_state = false
Fiber.yield
@fiber = nil
end
end
效果图:
作者: condir 时间: 2019-10-28 02:35
本帖最后由 condir 于 2019-10-28 06:57 编辑
14.将宋体15号字线性放大两倍作为像素字体
效果图:
#加载DLL
module OutsideFunc
Push_character =
Win32API.new('.\\System\\test.dll', 'set_16bit_char', 'p', 'v')
Get_character_pixel =
Win32API.new('.\\System\\test.dll', 'get_16bit_pixel', 'ii', 'i')
end
#重写文本输出的部分
class Window_Base < Window
include OutsideFunc
def line_height
return Font.default_size
end
def draw_text(*args)
#统一参数形式
if (args.size == 2||args.size == 3)
x = args[0].x
y = args[0].y
h = args[0].height
w = args[0].width
str = args[1]
align = (args[2] != nil ? args[2] : 0)
else
x = args[0]
y = args[1]
w = args[2]
h = args[3]
str = args[4]
align = (args[5] != nil ? args[5] : 0)
end
str = str.to_s unless str.is_a?(String)
#对齐格式:0-左 1-中 2-右
if (align == 1)
x = x + (w - text_size(str).width) / 2
elsif (align == 2)
x = x + w - text_size(str).width
end
#拆解为单个字符输出
for n in 0 ... str.size
c = str[n]
w = text_size(c).width
draw_one_character(x, y, w, h, c) unless c == nil
x += w
end
end
#输出单个字符:以点阵方式描绘
def draw_one_character(*args)
Push_character.call(args[4].encode("UTF-16LE"))
for x in 0 ... args[2] / 2 - 1
for y in 0 .. 14
if Get_character_pixel.call(x, y) == 0 then
px = args[0] + x * 2
py = args[1] + y * 2
contents.set_pixel(px, py, contents.font.color)
contents.set_pixel(px + 1, py, contents.font.color)
contents.set_pixel(px, py + 1, contents.font.color)
contents.set_pixel(px + 1, py + 1, contents.font.color)
end
end
end
end
end
#加载DLL
module OutsideFunc
Push_character =
Win32API.new('.\\System\\test.dll', 'set_16bit_char', 'p', 'v')
Get_character_pixel =
Win32API.new('.\\System\\test.dll', 'get_16bit_pixel', 'ii', 'i')
end
#重写文本输出的部分
class Window_Base < Window
include OutsideFunc
def line_height
return Font.default_size
end
def draw_text(*args)
#统一参数形式
if (args.size == 2||args.size == 3)
x = args[0].x
y = args[0].y
h = args[0].height
w = args[0].width
str = args[1]
align = (args[2] != nil ? args[2] : 0)
else
x = args[0]
y = args[1]
w = args[2]
h = args[3]
str = args[4]
align = (args[5] != nil ? args[5] : 0)
end
str = str.to_s unless str.is_a?(String)
#对齐格式:0-左 1-中 2-右
if (align == 1)
x = x + (w - text_size(str).width) / 2
elsif (align == 2)
x = x + w - text_size(str).width
end
#拆解为单个字符输出
for n in 0 ... str.size
c = str[n]
w = text_size(c).width
draw_one_character(x, y, w, h, c) unless c == nil
x += w
end
end
#输出单个字符:以点阵方式描绘
def draw_one_character(*args)
Push_character.call(args[4].encode("UTF-16LE"))
for x in 0 ... args[2] / 2 - 1
for y in 0 .. 14
if Get_character_pixel.call(x, y) == 0 then
px = args[0] + x * 2
py = args[1] + y * 2
contents.set_pixel(px, py, contents.font.color)
contents.set_pixel(px + 1, py, contents.font.color)
contents.set_pixel(px, py + 1, contents.font.color)
contents.set_pixel(px + 1, py + 1, contents.font.color)
end
end
end
end
end
再使用VS2019,建立一个DLL项目,
设置静态编译(配置属性>C/C++>代码生成>运行库>多线程调试/MTd)
// test.cpp : 定义 DLL 应用程序的导出函数。
#include <windows.h>
#include <stdio.h>
int hasInit = FALSE;
HFONT hfBuffer;
HDC hdcBuffer;
HBITMAP hBitmapBuffer, hOldBitmapBuffer;
//第五版:测试版字体放大程序
void init() {
//获取缓冲区句柄
hdcBuffer = CreateCompatibleDC(NULL);
//获取缓冲区画刷
hBitmapBuffer = CreateCompatibleBitmap(hdcBuffer, 16, 16);
//关联缓冲区句柄和画刷
hOldBitmapBuffer = (HBITMAP)SelectObject(hdcBuffer, hBitmapBuffer);
//创建字体
hfBuffer = ::CreateFont(
15, //字体高度
0, //字体宽度
0, //字体显示角度
0, //字体的角度
0, //字体的磅数
FALSE, //斜体字体
FALSE, //带下划线的字体
0, //带删除线的字体
GB2312_CHARSET, //所需的字符集
OUT_DEFAULT_PRECIS, //输出的精度
CLIP_DEFAULT_PRECIS,//裁剪的精度
DEFAULT_QUALITY, //逻辑字体与输入设备实际字体之间的精度
DEFAULT_PITCH, //字体间距和字体集
L"宋体" //字体名称
);
//关联字体画刷与临时缓冲区句柄
SelectObject(hdcBuffer, hfBuffer);
//初始化完成
hasInit = TRUE;
}
extern "C" _declspec(dllexport) void set_16bit_char(wchar_t *str) {
//没有初始化则进行初始化
if (hasInit == FALSE) init();
//设置缓冲区字体颜色为黑色
SetTextColor(hdcBuffer, 0x000000);
//输出该字到缓冲区
TextOut(hdcBuffer, 0, 0, str, 1);
}
extern "C" _declspec(dllexport) int get_16bit_pixel(int x, int y) {
return GetPixel(hdcBuffer, x, y);
}
// test.cpp : 定义 DLL 应用程序的导出函数。
#include <windows.h>
#include <stdio.h>
int hasInit = FALSE;
HFONT hfBuffer;
HDC hdcBuffer;
HBITMAP hBitmapBuffer, hOldBitmapBuffer;
//第五版:测试版字体放大程序
void init() {
//获取缓冲区句柄
hdcBuffer = CreateCompatibleDC(NULL);
//获取缓冲区画刷
hBitmapBuffer = CreateCompatibleBitmap(hdcBuffer, 16, 16);
//关联缓冲区句柄和画刷
hOldBitmapBuffer = (HBITMAP)SelectObject(hdcBuffer, hBitmapBuffer);
//创建字体
hfBuffer = ::CreateFont(
15, //字体高度
0, //字体宽度
0, //字体显示角度
0, //字体的角度
0, //字体的磅数
FALSE, //斜体字体
FALSE, //带下划线的字体
0, //带删除线的字体
GB2312_CHARSET, //所需的字符集
OUT_DEFAULT_PRECIS, //输出的精度
CLIP_DEFAULT_PRECIS,//裁剪的精度
DEFAULT_QUALITY, //逻辑字体与输入设备实际字体之间的精度
DEFAULT_PITCH, //字体间距和字体集
L"宋体" //字体名称
);
//关联字体画刷与临时缓冲区句柄
SelectObject(hdcBuffer, hfBuffer);
//初始化完成
hasInit = TRUE;
}
extern "C" _declspec(dllexport) void set_16bit_char(wchar_t *str) {
//没有初始化则进行初始化
if (hasInit == FALSE) init();
//设置缓冲区字体颜色为黑色
SetTextColor(hdcBuffer, 0x000000);
//输出该字到缓冲区
TextOut(hdcBuffer, 0, 0, str, 1);
}
extern "C" _declspec(dllexport) int get_16bit_pixel(int x, int y) {
return GetPixel(hdcBuffer, x, y);
}
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |