用ABLUA写一个战斗NPC
1、首先建立个lua就叫battle.lua吧
2、先创建NPC对话事件的函数吧,代码如下
--NPC对话事件(NPC索引) function Talked(meindex, talkerindex , szMes, color ) --和NPC面对面,1是1格距离,等于1就是条件达成 if npc.isFaceToFace(meindex, talkerindex, 1) == 1 then --token表示建立NPC窗口对话文字 token = "欢迎挑战神奇大魔王。" .."\n点击确定你我将和你战斗。" --发送窗口封包(玩家索引, 窗口类型, 按钮类型, 窗口ID号, NPC对象, 窗口文字) lssproto.windows(talkerindex, "对话框", "确定|取消", 1, char.getWorkInt( meindex, "对象"), token) end end3、接着咱们在创建NPC窗口事件的函数,代码如下
--NPC窗口事件(NPC索引) function WindowTalked ( meindex, talkerindex, seqno, select, data) --和NPC面对面,1是1格距离,等于1就是条件达成 if npc.isFaceToFace(meindex, talkerindex, 1) == 1 then --seqno对应Talked函数里发送窗口封包中的窗口ID号参数 if seqno == 1 then --select表示按钮类似数值,等于0是取消,等于1是确定 if select == 1 then --定义一个数组,数组里最多可以写10个怪物的ID,如果没有就用-1代替,这里1690是黑暗精灵王的ID enemytable = {1690, -1, -1, -1, -1, -1, -1, -1, -1, -1} --创建一个战斗索引,即可玩家和NPC战斗的索引 battleindex = battle.CreateVsEnemy(talkerindex, meindex, enemytable) end end end end4、最后写个创建NPC的函数并加入到main主函数里即可,上次已讲过,直接看代码
function Create(name, metamo, floor, x, y, dir) npcindex = npc.CreateNpc(name, metamo, floor, x, y, dir) char.setFunctionPointer(npcindex, "对话事件", "Talked", "") char.setFunctionPointer(npcindex, "窗口事件", "WindowTalked", "") end function main() Create("黑暗精灵王", 100444, 2000, 82, 84, 6) end