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

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


  1
  2.环保公司(用草种环保公司,将接收的垃圾搬到粉碎区,点铃粉碎后得黄金)
  3
  4	MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/cutgrass.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
  5
  6local function makegrinder(inst)
  7	local pt = inst:GetPosition()
  8	local redmark = SpawnPrefab("cutgrass")
  9	redmark.Transform:SetPosition(pt.x, pt.y, pt.z)
 10	redmark.AnimState:SetBank("gridplacer")
 11	redmark.AnimState:SetBuild("gridplacer")
 12	redmark.AnimState:PlayAnimation("anim", true)
 13	redmark.Transform:SetScale(1.5, 1.5, 1.5)
 14	redmark.AnimState:SetOrientation( ANIM_ORIENTATION.OnGround )
 15	redmark.AnimState:SetLayer( LAYER_BACKGROUND )
 16	redmark.AnimState:SetSortOrder( 3 )
 17	redmark.Transform:SetRotation( 45 )
 18	redmark.AnimState:SetMultColour(255/255,0/255,0/255,1)
 19	redmark.AnimState:SetLightOverride(1)
 20	redmark:AddTag("NOCLICK")
 21	redmark:RemoveComponent("stackable")
 22	redmark:RemoveComponent("edible")
 23	redmark:RemoveComponent("tradable")
 24	redmark:RemoveComponent("fuel")
 25	redmark:RemoveComponent("burnable")
 26	redmark:RemoveComponent("propagator")
 27	redmark:RemoveComponent("repairer")
 28	redmark:RemoveComponent("inventoryitem")
 29	redmark:RemoveComponent("deployable")
 30	redmark:RemoveTag("cattoy")
 31	redmark:AddTag("redmark")
 32	local yellowmark = SpawnPrefab("cutgrass")
 33	yellowmark.Transform:SetPosition(pt.x-12.5, 0, pt.z+12.5)
 34	yellowmark.AnimState:SetBank("gridplacer")
 35	yellowmark.AnimState:SetBuild("gridplacer")
 36	yellowmark.AnimState:PlayAnimation("anim", true)
 37	yellowmark.Transform:SetScale(2, 2, 2)
 38	yellowmark.AnimState:SetOrientation( ANIM_ORIENTATION.OnGround )
 39	yellowmark.AnimState:SetLayer( LAYER_BACKGROUND )
 40	yellowmark.AnimState:SetSortOrder( 3 )
 41	yellowmark.Transform:SetRotation( 45 )
 42	yellowmark.AnimState:SetMultColour(255/255,255/255,0/255,1)
 43	yellowmark.AnimState:SetLightOverride(1)
 44	yellowmark:AddTag("NOCLICK")
 45	yellowmark:RemoveComponent("stackable")
 46	yellowmark:RemoveComponent("edible")
 47	yellowmark:RemoveComponent("tradable")
 48	yellowmark:RemoveComponent("fuel")
 49	yellowmark:RemoveComponent("burnable")
 50	yellowmark:RemoveComponent("propagator")
 51	yellowmark:RemoveComponent("repairer")
 52	yellowmark:RemoveComponent("inventoryitem")
 53	yellowmark:RemoveComponent("deployable")
 54	yellowmark:RemoveTag("cattoy")
 55	yellowmark:ListenForEvent( "daytime", function()
 56		for k = 1,math.random(6,12) do
 57			local pt1 = yellowmark:GetPosition()
 58			local trash = SpawnPrefab("cutgrass")
 59			trash.Transform:SetPosition(pt1.x+(math.random(6)-math.random(6)), 0, pt1.z+(math.random(6)-math.random(6)))
 60			trash.AnimState:SetBank("fertilizer")
 61			trash.AnimState:SetBuild("fertilizer")
 62			trash.AnimState:PlayAnimation("idle")
 63			trash.Transform:SetScale(1.5, 1.5, 1.5)
 64			trash.AnimState:SetMultColour(0/255,255/255,0/255,1)
 65			trash.components.inventoryitem:ChangeImageName("fertilizer")
 66			trash:RemoveComponent("stackable")
 67			trash:RemoveComponent("edible")
 68			trash:RemoveComponent("tradable")
 69			trash:RemoveComponent("fuel")
 70			trash:RemoveComponent("burnable")
 71			trash:RemoveComponent("propagator")
 72			trash:RemoveComponent("repairer")
 73			trash:RemoveComponent("deployable")
 74			trash:RemoveTag("cattoy")
 75			trash:AddComponent("named")
 76			trash.components.named:SetName("Refuse")
 77			trash.flies = trash:SpawnChild("flies")
 78			trash.components.inventoryitem:SetOnDroppedFn(function() trash.flies = trash:SpawnChild("flies") end )
 79			trash.components.inventoryitem:SetOnPickupFn(function() if trash.flies then trash.flies:Remove() trash.flies = nil end end )
 80			trash.components.inventoryitem:SetOnPutInInventoryFn(function() if trash.flies then trash.flies:Remove() trash.flies = nil end end )
 81			MakeSmallBurnable(trash)
 82			MakeSmallPropagator(trash)
 83			trash:AddTag("trash")
 84		end
 85	end , GetWorld() )
 86	yellowmark:ListenForEvent( "nighttime", function()
 87		for k = 1,math.random(3,5) do
 88			local pt1 = yellowmark:GetPosition()
 89			local trash = SpawnPrefab("cutgrass")
 90			trash.Transform:SetPosition(pt1.x+(math.random(6)-math.random(6)), 0, pt1.z+(math.random(6)-math.random(6)))
 91			trash.AnimState:SetBank("fertilizer")
 92			trash.AnimState:SetBuild("fertilizer")
 93			trash.AnimState:PlayAnimation("idle")
 94			trash.Transform:SetScale(1.5, 1.5, 1.5)
 95			trash.AnimState:SetMultColour(0/255,255/255,0/255,1)
 96			trash.components.inventoryitem:ChangeImageName("fertilizer")
 97			trash:RemoveComponent("stackable")
 98			trash:RemoveComponent("edible")
 99			trash:RemoveComponent("tradable")
100			trash:RemoveComponent("fuel")
101			trash:RemoveComponent("burnable")
102			trash:RemoveComponent("propagator")
103			trash:RemoveComponent("repairer")
104			trash:RemoveComponent("deployable")
105			trash:RemoveTag("cattoy")
106			trash:AddComponent("named")
107			trash.components.named:SetName("Refuse")
108			trash.flies = trash:SpawnChild("flies")
109			trash.components.inventoryitem:SetOnDroppedFn(function() trash.flies = trash:SpawnChild("flies") end )
110			trash.components.inventoryitem:SetOnPickupFn(function() if trash.flies then trash.flies:Remove() trash.flies = nil end end )
111			trash.components.inventoryitem:SetOnPutInInventoryFn(function() if trash.flies then trash.flies:Remove() trash.flies = nil end end )
112			MakeSmallBurnable(trash)
113			MakeSmallPropagator(trash)
114			trash:AddTag("trash")
115		end
116	end , GetWorld() )
117	yellowmark:ListenForEvent( "dusktime", function()
118		for k = 1,math.random(5,7) do
119			local pt1 = yellowmark:GetPosition()
120			local trash = SpawnPrefab("cutgrass")
121			trash.Transform:SetPosition(pt1.x+(math.random(6)-math.random(6)), 0, pt1.z+(math.random(6)-math.random(6)))
122			trash.AnimState:SetBank("fertilizer")
123			trash.AnimState:SetBuild("fertilizer")
124			trash.AnimState:PlayAnimation("idle")
125			trash.Transform:SetScale(1.5, 1.5, 1.5)
126			trash.AnimState:SetMultColour(0/255,255/255,0/255,1)
127			trash.components.inventoryitem:ChangeImageName("fertilizer")
128			trash:RemoveComponent("stackable")
129			trash:RemoveComponent("edible")
130			trash:RemoveComponent("tradable")
131			trash:RemoveComponent("fuel")
132			trash:RemoveComponent("burnable")
133			trash:RemoveComponent("propagator")
134			trash:RemoveComponent("repairer")
135			trash:RemoveComponent("deployable")
136			trash:RemoveTag("cattoy")
137			trash:AddComponent("named")
138			trash.components.named:SetName("Refuse")
139			trash.flies = trash:SpawnChild("flies")
140			trash.components.inventoryitem:SetOnDroppedFn(function() trash.flies = trash:SpawnChild("flies") end )
141			trash.components.inventoryitem:SetOnPickupFn(function() if trash.flies then trash.flies:Remove() trash.flies = nil end end )
142			trash.components.inventoryitem:SetOnPutInInventoryFn(function() if trash.flies then trash.flies:Remove() trash.flies = nil end end )
143			MakeSmallBurnable(trash)
144			MakeSmallPropagator(trash)
145			trash:AddTag("trash")
146		end
147	end , GetWorld() )
148	yellowmark:AddTag("yellowmark")
149	local footbell = SpawnPrefab("cutgrass")
150	footbell.Transform:SetPosition(pt.x-5, 0, pt.z+5)
151	footbell.AnimState:SetBank("bell")
152	footbell.AnimState:SetBuild("bell")
153	footbell.AnimState:PlayAnimation("idle")
154	footbell.AnimState:SetMultColour(255/255,255/255,0/255,1)
155	footbell.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
156	footbell:RemoveComponent("stackable")
157	footbell:RemoveComponent("edible")
158	footbell:RemoveComponent("tradable")
159	footbell:RemoveComponent("fuel")
160	footbell:RemoveComponent("burnable")
161	footbell:RemoveComponent("propagator")
162	footbell:RemoveComponent("repairer")
163	footbell:RemoveComponent("inventoryitem")
164	footbell:RemoveComponent("deployable")
165	footbell:RemoveTag("cattoy")
166	footbell:AddComponent("named")
167	footbell.components.named:SetName("Bell")
168	footbell:AddTag("footbell")
169	footbell:AddComponent("workable")
170	footbell.components.workable:SetWorkAction(ACTIONS.HAMMER)
171	footbell.components.workable:SetWorkLeft(3)
172	footbell.components.workable:SetOnFinishCallback(function()
173		SpawnPrefab("ground_chunks_breaking").Transform:SetPosition(footbell.Transform:GetWorldPosition())
174		GetPlayer().SoundEmitter:PlaySound("dontstarve/common/destroy_wood")
175		local pos2 = Vector3(footbell.Transform:GetWorldPosition())
176		local ents2 = TheSim:FindEntities(pos2.x,pos2.y,pos2.z, 30)
177		for k,v in pairs(ents2) do
178			if v:HasTag("redmark") or v:HasTag("yellowmark") or v:HasTag("trash") or v:HasTag("footfoot") then
179			   SpawnPrefab("collapse_big").Transform:SetPosition(v.Transform:GetWorldPosition())
180			   v:Remove()
181			end
182		end
183		footbell:Remove()
184	end )
185	footbell.components.inspectable.getstatus = function()
186		GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold")
187		local foot = SpawnPrefab("cutgrass")
188		foot.Transform:SetPosition(pt.x, 10, pt.z)
189		foot.AnimState:SetBank("foot")
190		foot.AnimState:SetBuild("foot_build")
191		foot.AnimState:PlayAnimation("idle")
192		foot.Transform:SetFourFaced()
193		foot.Transform:SetRotation( 270 )
194		foot:RemoveComponent("stackable")
195		foot:RemoveComponent("edible")
196		foot:RemoveComponent("tradable")
197		foot:RemoveComponent("fuel")
198		foot:RemoveComponent("burnable")
199		foot:RemoveComponent("propagator")
200		foot:RemoveComponent("repairer")
201		foot:RemoveComponent("inventoryitem")
202		foot:RemoveComponent("deployable")
203		foot:RemoveTag("cattoy")
204		foot:AddTag("footfoot")
205		foot.falling = foot:DoPeriodicTask(.01, function() foot.Physics:SetMotorVelOverride(0,-55,0) end)
206		foot:DoTaskInTime(0.1, function()
207			if foot.falling then foot.falling:Cancel() foot.falling = nil end
208			GetPlayer().SoundEmitter:PlaySound("dontstarve_DLC001/creatures/glommer/foot_ground")
209			GetPlayer().components.playercontroller:ShakeCamera(foot, "FULL", 0.5, 0.05, 2, 40)
210			SpawnPrefab("collapse_big").Transform:SetPosition(pt.x, 0, pt.z)
211			local pos = Vector3(foot.Transform:GetWorldPosition())
212			local ents = TheSim:FindEntities(pos.x,0,pos.z, 5)
213			for k,v in pairs(ents) do
214				if v:HasTag("trash") and v.components.inventoryitem and not v.components.inventoryitem:IsHeld() then
215				   SpawnPrefab("goldnugget").Transform:SetPosition(v.Transform:GetWorldPosition())
216				   v:Remove()
217				end
218				if v:HasTag("player") then
219				   v.AnimState:PlayAnimation("hit")
220				   v.components.health:DoDelta(-5)
221				end
222			end
223			foot:DoTaskInTime(0.5, function()
224				GetPlayer().SoundEmitter:PlaySound("dontstarve/common/stone_drop")
225				SpawnPrefab("ground_chunks_breaking").Transform:SetPosition(foot.Transform:GetWorldPosition())
226				foot:Remove()
227			end )
228		end )
229	end
230end
231local function OnDeploy (inst, pt)
232	makegrinder(inst)
233	inst.components.stackable:Get():Remove()
234end
235	inst:AddComponent("deployable")
236	inst.components.deployable.ondeploy = OnDeploy
237local function onsave(inst, data)
238	if inst:HasTag("redmark") then
239		data.redmark = true
240	end
241	if inst:HasTag("yellowmark") then
242		data.yellowmark = true
243	end
244	if inst:HasTag("trash") then
245		data.trash = true
246	end
247	if inst:HasTag("footbell") then
248		data.footbell = true
249	end
250	if inst:HasTag("footfoot") then
251		data.footfoot = true
252	end
253end
254local function onload(inst, data)
255	if data and data.redmark then
256	   makegrinder(inst)
257	   inst:Remove()
258	end
259	if data and data.yellowmark then
260	   inst:Remove()
261	end
262	if data and data.footbell then
263	   inst:Remove()
264	end
265	if data and data.footfoot then
266	   inst:Remove()
267	end
268	if data and data.trash then
269	   inst.AnimState:SetBank("fertilizer")
270	   inst.AnimState:SetBuild("fertilizer")
271	   inst.AnimState:PlayAnimation("idle")
272	   inst.Transform:SetScale(1.5, 1.5, 1.5)
273	   inst.AnimState:SetMultColour(0/255,255/255,0/255,1)
274	   inst.components.inventoryitem:ChangeImageName("fertilizer")
275	   inst:RemoveComponent("stackable")
276	   inst:RemoveComponent("edible")
277	   inst:RemoveComponent("tradable")
278	   inst:RemoveComponent("fuel")
279	   inst:RemoveComponent("burnable")
280	   inst:RemoveComponent("propagator")
281	   inst:RemoveComponent("repairer")
282	   inst:RemoveComponent("deployable")
283	   inst:RemoveTag("cattoy")
284	   inst:AddComponent("named")
285	   inst.components.named:SetName("Refuse")
286	   inst.flies = inst:SpawnChild("flies")
287	   inst.components.inventoryitem:SetOnDroppedFn(function() inst.flies = inst:SpawnChild("flies") end )
288	   inst.components.inventoryitem:SetOnPickupFn(function() if inst.flies then inst.flies:Remove() inst.flies = nil end end )
289	   inst.components.inventoryitem:SetOnPutInInventoryFn(function() if inst.flies then inst.flies:Remove() inst.flies = nil end end )
290	   MakeSmallBurnable(inst)
291	   MakeSmallPropagator(inst)
292	   inst:AddTag("trash")
293	end
294end
295	inst.OnSave = onsave
296	inst.OnLoad = onload
297
298	即可在开阔的空地上,用草种环保公司(拿着1个草对地面点鼠标右键,如果拿着多个,则不会种出来),每天白天、傍晚、黑夜都会有垃圾被送到黄区,将它们搬到红区后,鼠标左键点地上的铃,可将垃圾粉碎,其中的贵金属(黄金)将留在地上,这就是环保公司的收入来源。粉碎垃圾时,不要站在红区附近,会被砸伤(减5点血)。黄区的垃圾如不及时清理,会越来越多,如果实在处理不过来,可以将垃圾烧掉,但那样就没有收入了。这是饥荒世界唯一一家环保公司,整块大陆的清洁就仰赖你了,承担起这肮脏而又崇高的事业吧。不想要环保公司了,用锤子砸掉铃即可