Project1
标题:
自动生成敌人队伍的问题
[打印本页]
作者:
海盗晴
时间:
2012-11-29 21:21
标题:
自动生成敌人队伍的问题
我用了这个自动敌人队伍的脚本 可是只有第一次遇敌是随机出现我设置的敌人队伍
然后再遇敌就一直是我第一次遇到的敌人队伍了 除非退出游戏再进来才会重新随机出现敌人队伍
高手帮我看一下 究竟是什么问题?是不是每次战斗都要重置脚本?怎么重置?
#==============================================================================
# ■ Game_Troop
#------------------------------------------------------------------------------
# 处理敌人队伍和战斗相关资料的类,也可执行如战斗事件管理之类的功能。
# 本类的实例请参考 $game_troop。
#==============================================================================
class Game_Troop < Game_Unit
#--------------------------------------------------------------------------
# ● 获取队伍队员
#--------------------------------------------------------------------------
def troop
return @group if @group != nil
@group = $data_troops[@troop_id] #组
name = @group.name
unless name.include?("类") & name.include?("个")
return @group #如果不是自动生成,则返回。
end
kinds = name.split("类")[0].split("-")
kinds = kinds[0].to_i + rand(kinds[1].to_i-kinds[0].to_i) #计算出最大种类数量。
quan = name.split("类")[1].split("-")
quan = quan[0].to_i+rand(quan[1].to_i-quan[0].to_i) #计算怪物总数
kind = bleed(kinds)
@group.members = army(kind,quan)
return @group
end
#--------------------------------------------------------------------------
# ● 抽取怪物
#--------------------------------------------------------------------------
def bleed(num)
n = []
for i in
[email protected]
n.push i
end
result = []
for i in 0..num-1
r = rand(n.size)
result.push n[r]
n.delete_at r
end
return result
end
#--------------------------------------------------------------------------
# ● 生成队伍
#--------------------------------------------------------------------------
def army(bleed,max)
result = []
group = @group.members
for i in 0..max-1
result.push group[bleed[rand(bleed.size)]]
end
return result
end
#--------------------------------------------------------------------------
# ● 设置
# troop_id : 队伍 ID
#--------------------------------------------------------------------------
def setup(troop_id)
clear
@troop_id = troop_id
@enemies = []
scr = screens
if troop.members.size <= 8
for i in 0..troop.members.size-1
member = troop.members[i]
enemy = Game_Enemy.new(@enemies.size, member.enemy_id)
enemy.hidden = member.hidden
enemy.immortal = member.immortal
enemy.screen_x = scr[i].x
enemy.screen_y = scr[i].y
@enemies.push(enemy)
end
else
for i in 0..7
member = troop.members[i]
enemy = Game_Enemy.new(@enemies.size, member.enemy_id)
enemy.hidden = member.hidden
enemy.immortal = member.immortal
enemy.screen_x = scr[i].x
enemy.screen_y = scr[i].y
@enemies.push(enemy)
end
for i in 8..troop.members.size-1
member = troop.members[i]
enemy = Game_Enemy.new(@enemies.size, member.enemy_id)
enemy.hidden = member.hidden
enemy.immortal = member.immortal
rsc = rscr
enemy.screen_x = rsc[0]
enemy.screen_y = rsc[1]
@enemies.push(enemy)
end
end
make_unique_names
end
#--------------------------------------------------------------------------
# ● 获取位置组
#--------------------------------------------------------------------------
def screens
for i in 1..$data_troops.size-1
if $data_troops[i].name == "排位组"
group = $data_troops[i] #获得排位组
break
end
end
return group.members
end
#--------------------------------------------------------------------------
# ● 获取随机位置
#--------------------------------------------------------------------------
def rscr
scr = screens
r = rand 8
s = rand 8
minx,maxx = [scr[r].x,scr[s].x].min,[scr[r].x,scr[s].x].max
miny,maxy = [scr[r].y,scr[s].y].min,[scr[r].y,scr[s].y].max
x = minx + rand(maxx-minx)
y = miny + rand(maxy-miny)
return [x,y]
end
end
复制代码
作者:
海盗晴
时间:
2012-11-29 21:22
补充一下 是明雷 设置的事件遇敌
作者:
怪蜀黍
时间:
2012-12-4 20:56
脚本报错,而且不会脚本的用法。
LZ你需要先教我们怎么使用本脚本。
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1