Project1
标题:
【ACE】随机行走图\脸图NPC
[打印本页]
作者:
fux2
时间:
2012-1-11 13:53
标题:
【ACE】随机行走图\脸图NPC
本帖最后由 fux2 于 2012-1-15 13:34 编辑
范例在此
http://115.com/file/be4xpqz5
随机形象NPC范例.rar
由于Dir不能访问加密包,所以要加密的游戏请勿使用此脚本.
脚本如下
#~ 2012.1.11
#~ by Fux2
#~
#~ 随机形象事件设置方法:
#~ 1.随意给事件设置一个行走图
#~ 2.事件名称后面加上\r
#~ 随机脸图呼出方法:
#~ 1.显示文章的内容末尾加上'fs
#~ 脸图拼接时会有需要同步颜色的问题,将同步的文件名末尾加上!同步组编号
#~ 末尾加上?的用途自行揣摩(PIA
module Fux2
Partres = ['Cloak','Body','Cloth','Glasses','Head','Kemono']
FacePartres = ['RearHair!2','Neck','Face!1','Neck?','Eyes?','Eyes','Mouth!1','Nose!1','FrontHair?!2','FrontHair!2']
def self.get_random_character
bit = Bitmap.new(96,128)
tbit=[]
result = [];Partres.size.times{result<<[]}
Dir["Graphics/rand_cha/*"].each do |i|
Partres.each_with_index do |j,k|
result[k] << i if i[/\/#{j}\d*\.png$/]
end
end
result.each_index do |i|
result[i]=result[i][rand(result[i].size)]
tbit<<Bitmap.new(result[i])
end
tbit.each do |i|
a=rand(i.width/96)*96
b=rand(i.height/128)*128
bit.blt(0,0,i,Rect.new(a,b,96,128))
end
return bit
end
def self.get_random_face
bit = Bitmap.new(96,96)
tbit = []
ext = {};pext = {};rxt = {};pxt = {}
result = [];FacePartres.size.times{result<<[]}
Dir["Graphics/rand_face/*"].each do |i|
FacePartres.each_with_index do |j,k|
if j[/\?/]
result[k] << i if i[/\/#{j.gsub(/\?|\!\d+/){''}}\d*[^\d]\.png$/]
sorts = [k,FacePartres.index(j.gsub('?'){''})].sort!
ext[sorts[0]] = sorts[1]
pext[sorts[1]] = sorts[0]
if j[/\!\d+$/]
index = j.gsub(/^.*\!(\d+)$/){$1}.to_i
rxt[index] ||= []
rxt[index] << k unless rxt[index].include?(k)
end
elsif j[/\!\d+$/]
result[k] << i if i[/\/#{j.gsub(/\!\d+/){''}}\d*\.png$/]
index = j.gsub(/^.*\!(\d+)$/){$1}.to_i
rxt[index] ||= []
rxt[index] << k unless rxt[index].include?(k)
else
result[k] << i if i[/\/#{j}\d*\.png$/]
end
end
end
rxt.each_value{|i| i.sort!;[*1...i.size].each{|j| pxt[i[j]] = i[0]}}
result.each_index do |i|
if ext[i]
num=rand(result[i].size)
result[i]=result[i][num]
result[ext[i]]=result[ext[i]][num]
else
result[i]=result[i][rand(result[i].size)] if result[i].is_a?(Array)
end
tbit<<Bitmap.new(result[i]) if result[i]
end
posiarr = []
tbit.each_with_index do |i,j|
if pext[j]
a = posiarr[pext[j]][0]
b = posiarr[pext[j]][1]
bit.blt(-16,-16,i,Rect.new(a,b,128,128))
elsif pxt[j]
a = posiarr[pxt[j]][0]
b = posiarr[pxt[j]][1]
bit.blt(-16,-16,i,Rect.new(a,b,128,128))
else
a=rand(i.width/128)*128
b=rand(i.height/128)*128
bit.blt(-16,-16,i,Rect.new(a,b,128,128))
end
posiarr << [a,b]
end
return bit
end
end
class Game_Event < Game_Character
alias ini initialize unless $@
def initialize(map_id, event)
ini(map_id, event)
end
def randc
return @event.name[/\\r/]
end
def name
return @event.name.gsub(/\\r/){""}
end
end
class Sprite_Character < Sprite_Base
def set_character_bitmap
if @character.is_a?(Game_Event) && @character.randc
self.bitmap = Fux2.get_random_character
sign = 66
else
self.bitmap = Cache.character(@character_name)
sign = @character_name[/^[\!\$]./]
end
if sign == 66 or (sign && sign.include?('))
@cw = bitmap.width / 3
@ch = bitmap.height / 4
else
@cw = bitmap.width / 12
@ch = bitmap.height / 8
end
self.ox = @cw / 2
self.oy = @ch
end
end
class Window_Message < Window_Base
def new_page(text, pos)
contents.clear
if text[/'fs/]
fux2randface = true
text.gsub!(/'fs/){''}
$game_message.face_name = "?"
else
fux2randface = false
end
draw_face($game_message.face_name, $game_message.face_index, 0, 0,true,fux2randface)
reset_font_settings
pos[:x] = new_line_x
pos[:y] = 0
pos[:new_x] = new_line_x
pos[:height] = calc_line_height(text)
clear_flags
end
end
class Window_Base < Window
def draw_face(face_name, face_index, x, y, enabled = true, randface = false)
bitmap = randface ? Fux2.get_random_face : Cache.face(face_name)
rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
bitmap.dispose
end
end
复制代码
作者:
Sonic1997
时间:
2012-1-11 13:59
本帖最后由 Sonic1997 于 2012-1-10 22:03 编辑
沙发{:nm_6:}的确是一个很实用的功能,这样NPC就不用每次都一模一样了{:nm_7:}
作者:
xuzhengchi
时间:
2012-1-11 16:19
对同一个NPC对话两次脸也随机了
作者:
fux2
时间:
2012-1-11 18:09
xuzhengchi 发表于 2012-1-11 16:19
对同一个NPC对话两次脸也随机了
当然啦,不然为什么脸图和行走图在编辑器里要分开编辑呢.
作者:
xiangelt
时间:
2012-1-12 02:47
可以用來創作變臉高手
作者:
越前リョーマ
时间:
2012-1-13 19:17
xiangelt 发表于 2012-1-12 02:47
可以用來創作變臉高手
根本就是槽点嘛我了个去 = =
作者:
zeldafd
时间:
2012-1-16 07:30
樓主腳本的效果讓我又爱又恨...是,npc的样子更多元化,但,在对話时…同一劇情中的数次对話也不同样-_-:
作者:
jessekiss
时间:
2012-1-28 21:16
楼主的脚本稍微改动一下实现了同步,但是貌似衣服无法对应?
作者:
垨護Satr婞諨
时间:
2012-2-6 17:04
谢谢楼主~
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1