Project1
标题:
【VX】怎么在NPC头上加1个计时器
[打印本页]
作者:
936586666
时间:
2011-12-16 17:47
标题:
【VX】怎么在NPC头上加1个计时器
本帖最后由 月夜神音 于 2011-12-16 18:34 编辑
我想做一个农场型的游戏我想在菜头上加个计时器,计时器的时间到0后可以显示“可摘取”的字样!
作者:
iisnow
时间:
2011-12-17 12:40
本帖最后由 iisnow 于 2011-12-17 13:41 编辑
嗯!这是一个好想法,农场游戏~
然后就写了一个脚本,基本可以实现你要的功能,不过要配合事件实现,于是就发个范例给你吧……
不多说了,效果:
捕获.PNG
(93.81 KB, 下载次数: 18)
下载附件
保存到相册
2011-12-17 12:33 上传
脚本:
$time = {}
code_time = Thread.new{
loop do
$time.each do |k,v|
$time[k] = [v - 1,0].max
end
sleep 1
end
}
class Game_Event
attr_accessor :event
end
class Game_Map
attr_accessor :map_id
end
class Sprite_time < Sprite_Base
def initialize(view_port,ch)
super(view_port)
@ch = ch
@time = $time[[$game_map.map_id,@ch.event.id]]
@new = true
self.bitmap = Bitmap.new(64,20)
end
def clear_self
if $time[[$game_map.map_id,@ch.event.id]] == 0
$time.delete([$game_map.map_id,@ch.event.id])
self.dispose
return true
else
return false
end
end
def update
if @time == nil
if @ch.event.name =~ /%(\d{0,2}[,,])?(\d+[,,])(\d+)/
hou = $1 ? $1.to_i : 0
min = $2.to_i
sec = $3.to_i
end
$time[[$game_map.map_id,@ch.event.id]] = hou * 3600 + min * 60 + sec
end
if @time != $time[[$game_map.map_id,@ch.event.id]] || @new
@time = $time[[$game_map.map_id,@ch.event.id]]
@new = false
if @time != 0
ho = @time / 3600
mi = @time / 60 - ho * 60
se = @time % 60
string = sprintf("%02d:%02d:%02d", ho,mi,se) if ho >0
string = sprintf("%02d:%02d", mi,se) if ho == 0
else
string = "收获啦~"
end
self.bitmap.clear
self.bitmap.font.size = 14
self.bitmap.draw_text(0,0,64,20,string,1)
end
self.x = @ch.screen_x - 32
self.y = @ch.screen_y - 50
end
end
class Game_Interpreter
def add_self
if $time[[$game_map.map_id,@event_id]] == nil
view_port = Viewport.new(0, 0, 544, 416)
sprite = Sprite_time.new(view_port,$game_map.events[@event_id])
$scene.spriteset.character_sprites.push(sprite)
$scene.spriteset.update
end
end
def get_result
if $time[[$game_map.map_id,@event_id]] > 0
return false
elsif $time[[$game_map.map_id,@event_id]] == 0
$scene.spriteset.clear_time
return true
end
end
alias :iisnow_command_201 :command_201
def command_201
$flag = @params[0] == 0 ? @params[1] : $game_variables[@params[1]]
iisnow_command_201
end
end
class Scene_Map < Scene_Base
attr_accessor :spriteset
alias :iisnow_start :start
def start
$flag = $game_map.map_id
iisnow_start
end
end
class Spriteset_Map
attr_accessor :character_sprites
alias :iisnow_update :update
def update
if $flag
$time.each do |k,v|
if k[0] == $flag && $flag == $game_map.map_id
view_port = Viewport.new(0, 0, 544, 416)
sprite = Sprite_time.new(view_port,$game_map.events[k[1]])
@character_sprites.push(sprite)
end
end
$flag = nil if $flag == $game_map.map_id
end
iisnow_update
end
def clear_time
@character_sprites.each do |s|
c = s.clear_self if s.is_a?(Sprite_time)
@character_sprites[@character_sprites.index(s)] = nil if c
end
@character_sprites.compact!
end
end
复制代码
然后说说缺点吧:
1.时间的不精确性,就是指精确度为1s小于1s的时间被忽视
2.存档的问题:即存档打开后会有错误,现在我在想办法修改,后面将会改正,就是增加一个文件记录
3.存档期间,游戏的时间会停止运转,即开始游戏蔬菜才会倒计时(估计改正存档以后这个问题可以解决),但是游戏中无论怎么暂停,蔬菜都不会停止生长
附件在下方,注意每个事件的设置方式,以及一定要将事件的优先级调整为“与普通角色相同”
另外时间的名称标识着蔬菜的种植时间格式为:“%x,y,z”
(x指小时,y指分钟,z指秒,其中x和它后面的,可以省略表示时间小于1个小时,x,y,z的值不限大小,但是毕竟希望你设置的合乎情理一点,比如y和z尽量小于60等等……)
iisnow_.rar
(240.77 KB, 下载次数: 141)
2011-12-17 12:40 上传
点击文件名下载附件
下面是存档改正:
脚本:
$last = false
$time = {}
code_time = Thread.new{
loop do
$time.each do |k,v|
$time[k] = [v - 1,0].max
end
sleep 1
end
}
class Game_Event
attr_accessor :event
end
class Game_Map
attr_accessor :map_id
end
class Sprite_time < Sprite_Base
def initialize(view_port,ch)
super(view_port)
@ch = ch
@time = $time[[$game_map.map_id,@ch.event.id]]
@new = true
self.bitmap = Bitmap.new(64,20)
end
def clear_self
if $time[[$game_map.map_id,@ch.event.id]] == 0
$time.delete([$game_map.map_id,@ch.event.id])
self.dispose
return true
else
return false
end
end
def update
if @time == nil
if @ch.event.name =~ /%(\d{0,2}[,,])?(\d+[,,])(\d+)/
hou = $1 ? $1.to_i : 0
min = $2.to_i
sec = $3.to_i
end
$time[[$game_map.map_id,@ch.event.id]] = hou * 3600 + min * 60 + sec
end
if @time != $time[[$game_map.map_id,@ch.event.id]] || @new
@time = $time[[$game_map.map_id,@ch.event.id]]
@new = false
if @time != 0
ho = @time / 3600
mi = @time / 60 - ho * 60
se = @time % 60
string = sprintf("%02d:%02d:%02d", ho,mi,se) if ho >0
string = sprintf("%02d:%02d", mi,se) if ho == 0
else
string = "收获啦~"
end
self.bitmap.clear
self.bitmap.font.size = 14
self.bitmap.draw_text(0,0,64,20,string,1)
end
self.x = @ch.screen_x - 32
self.y = @ch.screen_y - 50
end
end
class Game_Interpreter
def add_self
if $time[[$game_map.map_id,@event_id]] == nil
view_port = Viewport.new(0, 0, 544, 416)
sprite = Sprite_time.new(view_port,$game_map.events[@event_id])
$scene.spriteset.character_sprites.push(sprite)
$scene.spriteset.update
end
end
def get_result
if $time[[$game_map.map_id,@event_id]] > 0
return false
elsif $time[[$game_map.map_id,@event_id]] == 0
$scene.spriteset.clear_time
return true
end
end
alias :iisnow_command_201 :command_201
def command_201
$flag = @params[0] == 0 ? @params[1] : $game_variables[@params[1]]
iisnow_command_201
end
end
class Scene_Map < Scene_Base
attr_accessor :spriteset
alias :iisnow_start :start
def start
$flag = $game_map.map_id
iisnow_start
end
end
class Spriteset_Map
attr_accessor :character_sprites
alias :iisnow_update :update
def update
if $flag
$time.each do |k,v|
if k[0] == $flag && $flag == $game_map.map_id
view_port = Viewport.new(0, 0, 544, 416)
sprite = Sprite_time.new(view_port,$game_map.events[k[1]])
@character_sprites.push(sprite)
end
end
$flag = nil if $flag == $game_map.map_id
end
iisnow_update
end
def clear_time
@character_sprites.each do |s|
c = s.clear_self if s.is_a?(Sprite_time)
@character_sprites[@character_sprites.index(s)] = nil if c
end
@character_sprites.compact!
end
end
class Scene_File
alias :iisnow_write_save_data :write_save_data
def write_save_data(file)
iisnow_write_save_data(file)
Marshal.dump($time,file)
end
alias :iisnow_read_save_data :read_save_data
def read_save_data(file)
iisnow_read_save_data(file)
$time = Marshal.load(file)
if $last
time_last = (Time.now - file.mtime).to_i
$time.each do |k,v|
$time[k] = [v - time_last,0].max
end
end
end
end
复制代码
改变内容:
使得存档变的可行,并加入了$last变量用于管理持续的时间消耗:
$last = true表示存档以后,显示时间的消耗会反应在游戏中,即存档1个小时后打开,你会发现游戏也过了1个小时;
$last = false表示不进行上述操作,也就是,存档时有x分钟成熟,读档就还有x分钟;
那种你喜欢就手动修改吧
脚本修改后,事件的用法不变
增加115分流:
http://115.com/file/clj1zpal
改正后附件:
ii_snow_2.rar
(240.83 KB, 下载次数: 147)
2011-12-17 13:37 上传
点击文件名下载附件
(这个附件中的脚本,我改了一行Main,就是kill那个进程用的,改不改应该无所谓吧)
作者:
936586666
时间:
2011-12-18 12:21
谢谢了
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1