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

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


 1
 2一八五.音浪太强(戴兔耳罩周围形成音浪,敌人被弹开)
 3
 4	MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/hats.lua文件,将下列内容:
 5
 6	local function earmuffs()
 7		local inst = simple()
 8		inst:AddComponent("insulator")
 9		inst.components.insulator.insulation = TUNING.INSULATION_SMALL
10		inst.components.equippable:SetOnEquip( opentop_onequip )
11		inst:AddComponent("fueled")
12		inst.components.fueled.fueltype = "USAGE"
13		inst.components.fueled:InitializeFuelLevel(TUNING.EARMUFF_PERISHTIME)
14		inst.components.fueled:SetDepletedFn(generic_perish)
15		inst.AnimState:SetRayTestOnBB(true)
16		return inst
17	end
18
19	替换为:
20
21local colours=
22{
23	{198/255,43/255,43/255},
24	{79/255,153/255,68/255},
25	{35/255,105/255,235/255},
26	{233/255,208/255,69/255},
27	{109/255,50/255,163/255},
28	{222/255,126/255,39/255},
29}
30local function pickup(inst, owner)
31	inst.colour_idx = math.random(#colours)
32	local light = inst.entity:AddLight() 
33	light:SetIntensity(.8)
34	light:SetRadius(3)
35	light:SetFalloff(1)
36	light:Enable(true)
37	light:SetColour(colours[inst.colour_idx][1],colours[inst.colour_idx][2],colours[inst.colour_idx][3])
38	local pt = Vector3(owner.Transform:GetWorldPosition())
39	local result_offset = FindValidPositionByFan(math.random()*2*PI, 10, 75, function(offset)
40		  local x,y,z = (pt + offset):Get()
41		  local ents = TheSim:FindEntities(x,y,z , 1)
42		  return not next(ents) 
43	end)
44	local ents2 = TheSim:FindEntities(pt.x,pt.y,pt.z, 8)
45	for k,v in pairs(ents2) do
46		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
47		   v.Transform:SetPosition((pt + result_offset):Get())
48		end
49	end
50end
51local function earmuffs_onequip(inst, owner)
52	inst.task = inst:DoPeriodicTask(.033, function() pickup(inst, owner) end)
53	GetPlayer().SoundEmitter:PlaySound("dontstarve/music/music_hoedown", "beavermusic")
54	opentop_onequip(inst, owner)
55end
56local function earmuffs_onunequip(inst, owner)
57	if inst.task then inst.task:Cancel() inst.task = nil end
58	GetPlayer().SoundEmitter:KillSound("beavermusic")
59	onunequip(inst, owner)
60	inst.Light:Enable(false)
61end
62local function earmuffs()
63	local inst = simple()
64	inst:AddComponent("insulator")
65	inst.components.insulator.insulation = TUNING.INSULATION_SMALL
66	inst.components.equippable:SetOnEquip( earmuffs_onequip )
67	inst.components.equippable:SetOnUnequip( earmuffs_onunequip )
68	inst.AnimState:SetRayTestOnBB(true)
69	return inst
70end
71
72	即可在戴兔耳罩时,周围形成音浪,敌人靠近会被弹开,拆杀人蜂窝、偷高鸟蛋毫发无伤。兔耳罩在穿戴选项(画着礼帽)下,用2个兔子、1个树枝制造