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

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



一八五.音浪太强(戴兔耳罩周围形成音浪,敌人被弹开)

	用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/hats.lua文件,将下列内容:

	local function earmuffs()
		local inst = simple()
		inst:AddComponent("insulator")
		inst.components.insulator.insulation = TUNING.INSULATION_SMALL
		inst.components.equippable:SetOnEquip( opentop_onequip )
		inst:AddComponent("fueled")
		inst.components.fueled.fueltype = "USAGE"
		inst.components.fueled:InitializeFuelLevel(TUNING.EARMUFF_PERISHTIME)
		inst.components.fueled:SetDepletedFn(generic_perish)
		inst.AnimState:SetRayTestOnBB(true)
		return inst
	end

	替换为:

local colours=
{
	{198/255,43/255,43/255},
	{79/255,153/255,68/255},
	{35/255,105/255,235/255},
	{233/255,208/255,69/255},
	{109/255,50/255,163/255},
	{222/255,126/255,39/255},
}
local function pickup(inst, owner)
	inst.colour_idx = math.random(#colours)
	local light = inst.entity:AddLight() 
	light:SetIntensity(.8)
	light:SetRadius(3)
	light:SetFalloff(1)
	light:Enable(true)
	light:SetColour(colours[inst.colour_idx][1],colours[inst.colour_idx][2],colours[inst.colour_idx][3])
	local pt = Vector3(owner.Transform:GetWorldPosition())
	local result_offset = FindValidPositionByFan(math.random()*2*PI, 10, 75, function(offset)
		  local x,y,z = (pt + offset):Get()
		  local ents = TheSim:FindEntities(x,y,z , 1)
		  return not next(ents) 
	end)
	local ents2 = TheSim:FindEntities(pt.x,pt.y,pt.z, 8)
	for k,v in pairs(ents2) do
		if v.components.health and not v.components.health:IsDead() and not v:HasTag("player") and not v:HasTag("smallbird") and not v:HasTag("chester") and not v:HasTag("wall") and not v:HasTag("structure") then
		   v.Transform:SetPosition((pt + result_offset):Get())
		end
	end
end
local function earmuffs_onequip(inst, owner)
	inst.task = inst:DoPeriodicTask(.033, function() pickup(inst, owner) end)
	GetPlayer().SoundEmitter:PlaySound("dontstarve/music/music_hoedown", "beavermusic")
	opentop_onequip(inst, owner)
end
local function earmuffs_onunequip(inst, owner)
	if inst.task then inst.task:Cancel() inst.task = nil end
	GetPlayer().SoundEmitter:KillSound("beavermusic")
	onunequip(inst, owner)
	inst.Light:Enable(false)
end
local function earmuffs()
	local inst = simple()
	inst:AddComponent("insulator")
	inst.components.insulator.insulation = TUNING.INSULATION_SMALL
	inst.components.equippable:SetOnEquip( earmuffs_onequip )
	inst.components.equippable:SetOnUnequip( earmuffs_onunequip )
	inst.AnimState:SetRayTestOnBB(true)
	return inst
end

	即可在戴兔耳罩时,周围形成音浪,敌人靠近会被弹开,拆杀人蜂窝、偷高鸟蛋毫发无伤。兔耳罩在穿戴选项(画着礼帽)下,用2个兔子、1个树枝制造