用ABLUA写一个会移动的NPC - 神奇石器时代技术研究交流
神奇石器技术研究交流网 - 业务联系QQ:420004208

用ABLUA写一个会移动的NPC

  • 内容
  • 相关

首先我们创建一个空的LUA文件,取名为walk.lua

先定义一个名为Loop的循环函数

function Loop(meindex)
	--随机0~7的方向
	local dir = math.random(0, 7)
	--随机1~3步子
	local walk = math.random(1, 3)
	--NPC移动函数
	char.Walk(meindex, dir, walk)
end

再建立个创建NPC的函数

function Create(name, metamo, floor, x, y, dir)
	--创建NPC(NPC名字,图像号,地图号,坐标X,坐标Y,方向号)将返回一个NPC索引
	local npcindex = npc.CreateNpc(name, metamo, floor, x, y, dir)
	--设置事件触发(NPC索引,事件,执行函数,执行函数文件路径)
	char.setFunctionPointer(npcindex, "循环事件", "Loop", "")
end

写入的循环事件Loop对应上面的循环函数名,最后在主函数加入创建函数

function main()
	Create("乌力", 100250, 2000, 50, 50, 6)
end
放入到ablua下就可以创造出一个会移动的NPC了。

版权声明:若无特殊注明,本文皆为《sa60》原创,转载请保留文章出处。

本文链接:用ABLUA写一个会移动的NPC - http://sa60.com/post-123.html

本文标签:

用ABLUA写一个会移动的NPC