代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二0八.鱼人入侵(每个傍晚都可能遭到众多鱼人的伏击)
3
4 用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/forest.lua文件,在inst:AddComponent("frograin")的下一行插入以下内容:
5
6local function OnNight(inst)
7 local player = GetPlayer()
8 local pt = Vector3(player.Transform:GetWorldPosition())
9 local nummerms = math.random(15)
10 local ground = GetWorld()
11 if math.random()< .2 then
12 for k = 1, nummerms do
13 local theta = 1 * 2 * PI
14 local radius = 12
15 local result_offset = FindValidPositionByFan(theta, radius, nummerms, function(offset)
16 local x,y,z = (pt + offset):Get()
17 local ents = TheSim:FindEntities(x,y,z , 1)
18 return not next(ents)
19 end)
20 if result_offset and ground.Map:GetTileAtPoint((pt + result_offset):Get()) ~= GROUND.IMPASSABLE then
21 local merm = SpawnPrefab("merm")
22 merm.Transform:SetPosition((pt + result_offset):Get())
23 merm.components.combat.target = player
24 GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 0.2, 0.02, .25, 40)
25 local fx = SpawnPrefab("collapse_small")
26 local pos = pt + result_offset
27 fx.Transform:SetPosition(pos.x, pos.y, pos.z)
28 end
29 end
30 end
31end
32 inst:ListenForEvent( "dusktime", function() OnNight( inst ) end, GetWorld())
33
34 即可让主角在地面时,每天傍晚都有一定概率遭到众多鱼人(数字随机)的伏击。建议鱼人人数少时就和它们拼了,人数多时就跑,它们会暂时占据这个地区,等到白天它们睡着时再各个击破