石器LUA战后事件

今天给大家讲解一下ABLUA里的战后事件,这里的战后时间仅针对和NPC战斗的战后事件。

先看一下下列代码:

function Talked(meindex, talkerindex , szMes, color )
	if npc.isFaceToFace(meindex, talkerindex) == 1 then 
		lssproto.windows(talkerindex, "对话框", "确定|取消", 1, char.getWorkInt( meindex, "对象"), "是否要进行神奇的战后事件测试?")
	end
end

function WindowTalked ( meindex, talkerindex, seqno, select, data)
	if npc.isFaceToFace(meindex, talkerindex) == 1 then 
		if select == 1 then
	        bosstable = {1610, -1, -1, -1, -1, -1, -1, -1, -1, -1}
			battleindex = battle.CreateVsEnemy(talkerindex, meindex, bosstable)
		end
	end
end

--和NPC战斗结束事件(NPC索引, 战斗索引,胜负)
function BattleOver(meindex, battleindex, iswin)
		--iswin表示NPC的输赢,1为NPC输了,0为NPC赢里
		if iswin == 1 then
			--从0到4循环开始需要搜索位置
			for i=0, 4 do
				--这里玩家索引是通过战斗库的getCharOne来获取上方或者下方的索引
				--battle.getCharOne中0表示下方,1则表示上方,i则表示位置数值范围0~4
				charaindex = battle.getCharOne(battleindex, i, 0)
				--检查索引是否存在
				if char.check(charaindex) == 1 then
					--这里就可以增加任意代码了,比如让赢的玩家随机得到一件物品
					--做一个奖励的数组。
					itemid = {21000,21002,21003}
					--定义一个随机值
					r = math.random(1, table.getn(itemid))
					--得到物品(当道具栏满的时则无法得到)
					char.Additem(charaindex, itemid[r])
					--系统提示
			        char.TalkToCli(charaindex, -1, "恭喜获得"..item.getNameFromNumber(itemid[r]), "青色")
				end
			end
		end
end

function Create(name, metamo, floorid, x, y, dir)
	index = npc.CreateNpc(name, metamo, floorid, x, y, dir)
	if char.check(index) == 1 then
		char.setFunctionPointer(index, "对话事件", "Talked", "")
		char.setFunctionPointer(index, "窗口事件", "WindowTalked", "")
		char.setFunctionPointer(index, "战后事件", "BattleOver", "")
	end
end

function main()
	Create("神奇战后事件", 100000, 2000, 50, 50, 4)
end


我们重点看function BattleOver(meindex, battleindex, iswin)这个函数,代码中已经做了注释,相信很好理解。

在战后事件可以发挥自己的想象,增加道具,增加各种货币,或者再增加新的NPC等。

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。