用ABLUA写一个包裹道具
1、老规矩,先创建个LUA的空文本,就叫additem.lua吧
2、创建道具执行函数,就写additem
3、整个LUA代码我就贴出来了,转载请附上SA60神奇石器发布站
--为了方便写了一个检查道具栏是否为满的函数,这个函数记下,在写其他LUA的时候也可以使用到的。
function checkEmptItemNum(charaindex)
EmptyItemNum = 0
for i = 9, 23 do
if char.getItemIndex(charaindex, i) == -1 then
EmptyItemNum = EmptyItemNum + 1
end
end
return EmptyItemNum
end
--声明道具执行函数(道具索引, 使用者索引, 物品作用对象索引, 道具栏位置)
function additem(itemindex, charaindex, toindex, haveitemindex)
--获取道具字段内容
local data = item.getChar(itemindex, "字段")
--分割字符串,取得第一个|前的内容,这里定义成包裹内的总道具数量
local num = other.atoi(other.getString(data, "|", 1))
--这里就是调用上面那个检查道具栏是否满的函数,做下判断,如果道具栏要小于包裹内的物品数则提示返回
if checkEmptItemNum(charaindex) < num then
char.TalkToCli(charaindex, -1, "请空出"..num.."格道具栏。", "红色")
return
end
--当物品最大数为1的时候
if num == 1 then
--分割字符串,取得第二个|前的内容,这里定义成道具ID
local itemid = other.atoi(other.getString(data, "|", 2))
--如果道具ID大于1
if itemid > -1 then
--则给予物品
npc.AddItem(charaindex, itemid)
end
--当物品最大数大于1的时候
elseif num > 1 then
--从1开始循环到道具最大数
for i=1, num do
--按照循环开始取第i+1个|的内容,并定义成道具ID
local itemid = other.atoi(other.getString(data, "|", i+1))
--循环给予道具
npc.AddItem(charaindex, itemid)
end
end
--删除包裹道具
char.DelItem(charaindex, haveitemindex)
end
--这个不用我神奇的牧羊人说了,主函数内注册道具的功能字段以及调用函数名
function main()
item.addLUAListFunction( "ITEM_ADDITEM", "additem", "")
end
4、道具代码如下:
智慧果包裹,智慧果包裹,装有10个智慧果的包裹,10|21000|21000|21000|21000|21000|21000|21000|21000|21000|21000|,,,,,,,ITEM_ADDITEM,,,,,,20851,24312,0,16,2,0,0,-1,,,,,,,,,,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0,,,,,,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,1,1,0,0,,0,,,,,,,,

