天龍八部玄武島BOSS

loovpfoxmail發表於2018-09-07

在玩天龍八部的時候, 玄武島BOSS 在指令碼里面是一個什麼樣的構造呢?就讓小的來位大家說說,我們拿SF的指令碼示例如下:


x810100_CreateChildTbl = {


MotherID=962, CreateTime=5*1000, CreateNum=2, AllChildNum=5, ChildID=1082, BaseAI=0, ExtAIScript=-1, ScriptID=-1, LifeTime=10*1000 }


--玄武島BOSS 毒蛤王刷小怪....

{ MotherID=9100, CreateTime=60000, CreateNum=6, AllChildNum=900, ChildID=9150, BaseAI=0, ExtAIScript=-1, ScriptID=-1, LifeTime=45000 },

--玄武島BOSS 小BOSS刷小怪....

{ MotherID=9101, CreateTime=60000, CreateNum=6, AllChildNum=900, ChildID=9151, BaseAI=0, ExtAIScript=-1, ScriptID=-1, LifeTime=45000 },

{ MotherID=9102, CreateTime=60000, CreateNum=6, AllChildNum=900, ChildID=9152, BaseAI=0, ExtAIScript=-1, ScriptID=-1, LifeTime=45000 },

{ MotherID=9103, CreateTime=60000, CreateNum=6, AllChildNum=900, ChildID=9153, BaseAI=0, ExtAIScript=-1, ScriptID=-1, LifeTime=45000 },

{ MotherID=9104, CreateTime=60000, CreateNum=6, AllChildNum=900, ChildID=9154, BaseAI=0, ExtAIScript=-1, ScriptID=-1, LifeTime=45000 },

{ MotherID=9105, CreateTime=60000, CreateNum=6, AllChildNum=900, ChildID=9155, BaseAI=0, ExtAIScript=-1, ScriptID=-1, LifeTime=45000 },

{ MotherID=9106, CreateTime=60000, CreateNum=6, AllChildNum=900, ChildID=9156, BaseAI=0, ExtAIScript=-1, ScriptID=-1, LifeTime=45000 },

{ MotherID=9107, CreateTime=60000, CreateNum=6, AllChildNum=900, ChildID=9157, BaseAI=0, ExtAIScript=-1, ScriptID=-1, LifeTime=45000 },

{ MotherID=9108, CreateTime=60000, CreateNum=6, AllChildNum=900, ChildID=9158, BaseAI=0, ExtAIScript=-1, ScriptID=-1, LifeTime=45000 },

{ MotherID=9109, CreateTime=60000, CreateNum=6, AllChildNum=900, ChildID=9159, BaseAI=0, ExtAIScript=-1, ScriptID=-1, LifeTime=45000 },


}


--小怪重新整理點列表....

--座標為相對於本BOSS的相對座標....可以填寫任意數目個座標....刷小怪時從中隨機選取一個使用....

x810100_MonsterPosTbl = {


{ x = 0,  y = 0  },


}


x810100_IDX_UpdateMonsterTime = 1

x810100_IDX_NeedCreateMonsterNum = 2

x810100_IDX_EnableCreateMonster = 1

x810100_IDX_CombatFlag = 2


function x810100_OnDie( sceneId, selfId, killerId )

MonsterAI_SetIntParamByIndex(sceneId, selfId,  x810100_IDX_UpdateMonsterTime, 0)

MonsterAI_SetIntParamByIndex(sceneId, selfId,  x810100_IDX_NeedCreateMonsterNum, 0)

MonsterAI_SetBoolParamByIndex(sceneId, selfId, x810100_IDX_EnableCreateMonster, 0)

MonsterAI_SetBoolParamByIndex(sceneId, selfId, x810100_IDX_CombatFlag, 0)

end


function x810100_OnHeartBeat(sceneId, selfId, nTick)


--檢測是不是死了....

if LuaFnIsCharacterLiving(sceneId, selfId) ~= 1 then

return

end


--檢測是否不在戰鬥狀態....

if 0 == MonsterAI_GetBoolParamByIndex(sceneId, selfId, x810100_IDX_CombatFlag) then

return

end


--檢測是否已經不需要再刷小怪了....

if 0 == MonsterAI_GetBoolParamByIndex(sceneId, selfId, x810100_IDX_EnableCreateMonster) then

return

end


--還未到刷小怪的時間....

local UpdateTime = MonsterAI_GetIntParamByIndex(sceneId, selfId, x810100_IDX_UpdateMonsterTime)

if nTick < UpdateTime then

UpdateTime = UpdateTime - nTick

MonsterAI_SetIntParamByIndex(sceneId, selfId,  x810100_IDX_UpdateMonsterTime, UpdateTime)

return

end



--到了刷小怪的時間了....刷小怪....


--尋找本BOSS的刷怪資料表....

local BossDataID = GetMonsterDataID( sceneId, selfId )

local bFind = 0

local CreateData

for _, Data in x810100_CreateChildTbl do

if BossDataID == Data.MotherID then

CreateData = Data

bFind = 1

break

end

end


local CreateNum = 0

local NeedCreateNum = MonsterAI_GetIntParamByIndex(sceneId, selfId,  x810100_IDX_NeedCreateMonsterNum, 0)


if NeedCreateNum <= CreateData.CreateNum then

CreateNum = NeedCreateNum

MonsterAI_SetBoolParamByIndex(sceneId, selfId, x810100_IDX_EnableCreateMonster, 0)

else

CreateNum = CreateData.CreateNum

end

LuaFnNpcChat(sceneId, selfId, 0, "不知死活的傢伙,我的手下就能幹掉你!")

for i = 1, CreateNum do

x810100_CreateChildMonster( sceneId, selfId, CreateData )

end


MonsterAI_SetIntParamByIndex(sceneId, selfId,  x810100_IDX_NeedCreateMonsterNum, NeedCreateNum-CreateNum)

MonsterAI_SetIntParamByIndex(sceneId, selfId,  x810100_IDX_UpdateMonsterTime, CreateData.CreateTime)


end


function x810100_OnInit(sceneId, selfId)


--尋找本BOSS的刷怪資料表....

local BossDataID = GetMonsterDataID( sceneId, selfId )

local bFind = 0

local CreateData

for _, Data in x810100_CreateChildTbl do

if BossDataID == Data.MotherID then

CreateData = Data

bFind = 1

break

end

end


--初始化AI引數....

MonsterAI_SetIntParamByIndex(sceneId, selfId,  x810100_IDX_UpdateMonsterTime, 0)

MonsterAI_SetIntParamByIndex(sceneId, selfId,  x810100_IDX_NeedCreateMonsterNum, 0)

MonsterAI_SetBoolParamByIndex(sceneId, selfId, x810100_IDX_EnableCreateMonster, 0)

MonsterAI_SetBoolParamByIndex(sceneId, selfId, x810100_IDX_CombatFlag, 0)


if bFind == 1 then

if CreateData.CreateTime>0 and CreateData.CreateNum>0 and CreateData.AllChildNum>0 then

MonsterAI_SetIntParamByIndex(sceneId, selfId,  x810100_IDX_UpdateMonsterTime, CreateData.CreateTime)

MonsterAI_SetIntParamByIndex(sceneId, selfId,  x810100_IDX_NeedCreateMonsterNum, CreateData.AllChildNum)

MonsterAI_SetBoolParamByIndex(sceneId, selfId, x810100_IDX_EnableCreateMonster, 1)

end

end


end


function x810100_OnKillCharacter(sceneId, selfId, targetId)


--LuaFnNpcChat(sceneId, selfId, 0, "我殺死一個人了....去死吧你....")


--if(-1~=targetId) then

--local szTarget = GetName(sceneId, targetId)

--local str = format( "我殺死一個人了....%s(殺死的玩家名),我早看你不爽了....", szTarget )

--LuaFnNpcChat(sceneId, selfId, 0, str)

--end


end


function x810100_OnEnterCombat(sceneId, selfId, enmeyId)

--LuaFnNpcChat(sceneId, selfId, 0, "我進入戰鬥了....你們等著去找孟婆吧....")

MonsterAI_SetBoolParamByIndex(sceneId, selfId, x810100_IDX_CombatFlag, 1)

end


function x810100_OnLeaveCombat(sceneId, selfId)

--LuaFnNpcChat(sceneId, selfId, 0, "我離開戰鬥了....大家先停下吃點藥吧....")

MonsterAI_SetBoolParamByIndex(sceneId, selfId, x810100_IDX_CombatFlag, 0)

end


--建立一個小怪....

function x810100_CreateChildMonster(sceneId, selfId, CreateData)


local PosX, PosY = LuaFnGetWorldPos( sceneId, selfId )

local PosNum = getn( x810100_MonsterPosTbl )

local PosIndex = random( PosNum )

PosX = PosX + x810100_MonsterPosTbl[PosIndex].x

PosY = PosY + x810100_MonsterPosTbl[PosIndex].y


MonId = LuaFnCreateMonster(sceneId, CreateData.ChildID, PosX, PosY, CreateData.BaseAI, CreateData.ExtAIScript, CreateData.ScriptID )

if CreateData.LifeTime > 0 then

SetCharacterDieTime(sceneId, MonId, CreateData.LifeTime )

end


end


相信有部分夥伴們還是不大明白,這裡需要懂一定LUA指令碼語言基礎的就能看明白了。(指令碼中也有註釋)


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31553491/viewspace-2213751/,如需轉載,請註明出處,否則將追究法律責任。

相關文章