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

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


 1
 2二一二.许愿池(给池塘黄金消顽皮值,天上有机会下黄金雨,接到就是你的)
 3
 4	MT管理器打开游戏目录/assets/scripts/prefabs/pond.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
 5
 6local function ShouldAcceptItem(inst, item)
 7	if item.prefab == "goldnugget" then
 8	   return true
 9	end
10	return false
11end
12local function OnGetItemFromPlayer(inst, giver, item)
13	if GetPlayer().components.kramped and GetPlayer().components.kramped.threshold > 0 then
14	   GetPlayer().components.kramped.threshold = GetPlayer().components.kramped.threshold -1
15	   GetPlayer().SoundEmitter:PlaySound("dontstarve/creatures/krampus/beenbad_lvl3")
16	end
17	if math.random()<.1 then
18	   GetPlayer().SoundEmitter:PlaySound("dontstarve/music/music_hoedown", "beavermusic")
19	   inst:StartThread(function()
20		   for k = 1, 50 do
21			   local pt = Vector3(giver.Transform:GetWorldPosition())
22			   local gold = SpawnPrefab("goldnugget")
23			   gold.Transform:SetPosition(pt.x+(math.random(5)-math.random(5)), 20, pt.z+(math.random(5)-math.random(5)))
24			   gold.components.inventoryitem.canbepickedup = false
25			   inst:DoTaskInTime(1.8, function()
26				   local pos = Vector3(gold.Transform:GetWorldPosition())
27				   local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, 2)
28				   for k,v in pairs(ents) do
29					   if v:HasTag("player") then
30						  v.components.inventory:GiveItem(gold)
31					   end
32				   end
33			   end)
34			   inst:DoTaskInTime(2, function()
35					local pt2 = gold:GetPosition()
36					if not gold.components.inventoryitem:IsHeld() then
37					   GetPlayer().SoundEmitter:PlaySound("dontstarve/common/stone_drop")
38					   SpawnPrefab("ground_chunks_breaking").Transform:SetPosition(pt2.x, 0, pt2.z)
39					   gold:Remove()
40					else
41					   gold.components.inventoryitem.canbepickedup = true
42					end
43			   end)
44			   Sleep(1)
45		   end
46		   GetPlayer().SoundEmitter:KillSound("beavermusic")
47	   end)
48	end
49end
50	inst:AddComponent("trader")
51	inst.components.trader.onaccept = OnGetItemFromPlayer
52	inst.components.trader:SetAcceptTest(ShouldAcceptItem)
53
54	即可拿着黄金对池塘点左键,每次消减一点顽皮值(杀小动物的惩罚点数),并发出喘息声,如果没有喘息声,表示你的顽皮值已经为零,罪已经赎清了。许愿的过程中,天上有一定概率下起黄金雨(50个黄金),黄金落地弹起的刹那,如果你接到就归你了(跑到黄金掉落位置),否则会摔碎,试试你的反应能力吧