代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。

原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html


 1
 2一三六.装备回旋镖召唤猎物(打猎游戏)
 3
 4	MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/boomerang.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
 5
 6local function cancreatelight(staff, caster, target, pos)
 7	local ground = GetWorld()
 8	if ground and pos then
 9	   local tile = ground.Map:GetTileAtPoint(pos.x, pos.y, pos.z)
10	   return tile ~= GROUND.IMPASSIBLE and tile < GROUND.UNDERGROUND
11	end
12	return false
13end
14local function createlight(staff, target, pos)
15	local names = {"crow","robin","robin_winter","frog","mosquito","bee","killerbee","butterfly","rabbit","babybeefalo"}
16	local name = names[math.random(#names)]
17	local prey = SpawnPrefab(name)
18	prey.Transform:SetPosition(pos.x, pos.y, pos.z)
19end
20	inst:AddComponent("spellcaster")
21	inst.components.spellcaster:SetSpellFn(createlight)
22	inst.components.spellcaster:SetSpellTestFn(cancreatelight)
23	inst.components.spellcaster.canuseonpoint = true
24	inst.components.spellcaster.canusefrominventory = false
25
26	即可在装备回旋镖后,在空地上点鼠标右键召唤猎物,包括鸟、昆虫、青蛙、兔子、小牛,尽情捕猎吧