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

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



八.鱼人入侵(每个傍晚都可能遭到众多鱼人的伏击)

	用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/forest.lua文件,在inst:AddComponent("frograin")的下一行插入以下内容:

local function OnNight(inst)
	local player = GetPlayer()
	local pt = Vector3(player.Transform:GetWorldPosition())
	local nummerms = math.random(15)
	local ground = GetWorld()
	if math.random()< .2 then 
		for k = 1, nummerms do
			local theta = 1 * 2 * PI
			local radius = 12
			local result_offset = FindValidPositionByFan(theta, radius, nummerms, function(offset)
				local x,y,z = (pt + offset):Get()
				local ents = TheSim:FindEntities(x,y,z , 1)
				return not next(ents) 
			end)
			if result_offset and ground.Map:GetTileAtPoint((pt + result_offset):Get()) ~= GROUND.IMPASSABLE then
				local merm = SpawnPrefab("merm")
				merm.Transform:SetPosition((pt + result_offset):Get())
				merm.components.combat.target = player
				GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 0.2, 0.02, .25, 40)
				local fx = SpawnPrefab("collapse_small")
				local pos = pt + result_offset
				fx.Transform:SetPosition(pos.x, pos.y, pos.z)
			end
		end
	end
end
	inst:ListenForEvent( "dusktime", function() OnNight( inst ) end, GetWorld()) 

	即可让主角在地面时,每天傍晚都有一定概率遭到众多鱼人(数字随机)的伏击。建议鱼人人数少时就和它们拼了,人数多时就跑,它们会暂时占据这个地区,等到白天它们睡着时再各个击破