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

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


 1
 2二三九.高尔夫球(用蜗牛壳碎片种高尔夫球,锤子作球杆,将球打进兔子洞吧)
 3
 4	MT管理器打开游戏目录/assets/scripts/prefabs/slurtle_shellpieces.lua文件,在inst:AddComponent("inventoryitem")的下一行插入以下内容:
 5
 6local function OnDeploy (inst, pt)
 7	local golf = SpawnPrefab("slurtle_shellpieces")
 8	golf.Transform:SetPosition(pt.x, pt.y, pt.z)
 9	golf.AnimState:SetBank("bulb")
10	golf.AnimState:SetBuild("bulb")
11	golf.AnimState:PlayAnimation("idle")
12	golf.Transform:SetScale(0.8, 0.8, 0.8)
13	golf.components.inventoryitem.canbepickedup = false
14	MakeSmallBurnable(golf)
15	golf:AddComponent("perishable")
16	golf.components.perishable:SetPerishTime(TUNING.PERISH_ONE_DAY)
17	golf.components.perishable:StartPerishing()
18	golf.components.perishable.onperishreplacement = "ash"
19	golf:AddComponent("workable")
20	golf.components.workable:SetWorkAction(ACTIONS.HAMMER)
21	golf.components.workable:SetWorkLeft(10)
22	golf.components.workable:SetOnFinishCallback(function(golf)
23		SpawnPrefab("ground_chunks_breaking").Transform:SetPosition(golf.Transform:GetWorldPosition())
24		golf:Remove()
25	end )
26	golf.components.workable:SetOnWorkCallback(function(golf)
27		local pt2 = Vector3(golf.Transform:GetWorldPosition())
28		local pos = Vector3(GetPlayer().Transform:GetWorldPosition())
29		golf.Physics:SetMotorVelOverride((pt2.x-pos.x)*13,0,(pt2.z-pos.z)*13)
30		golf:DoTaskInTime(0.2, function() golf.Physics:ClearMotorVelOverride() end )
31		GetPlayer().components.sanity:DoDelta(5)
32	end )
33	golf:DoPeriodicTask(.05, function(golf)
34		local pos2 = Vector3(golf.Transform:GetWorldPosition())
35		local ents = TheSim:FindEntities(pos2.x,pos2.y,pos2.z, 0.5)
36		for k,v in pairs(ents) do
37			if v.prefab == "rabbithole" then
38			   GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/use_axe_tree")
39			   golf:Remove()
40			   GetPlayer().components.sanity:DoDelta(50)
41			end
42		end
43	end )
44	golf:AddTag("golfs")
45	inst.components.stackable:Get():Remove()
46end
47	inst:AddComponent("deployable")
48	inst.components.deployable.ondeploy = OnDeploy
49local function onsave(inst, data)
50	if inst:HasTag("golfs") then
51		data.golfs = true
52	end
53end
54local function onload(inst, data)
55  if data and data.golfs then
56	inst.AnimState:SetBank("bulb")
57	inst.AnimState:SetBuild("bulb")
58	inst.AnimState:PlayAnimation("idle")
59	inst.Transform:SetScale(0.8, 0.8, 0.8)
60	inst.components.inventoryitem.canbepickedup = false
61	MakeSmallBurnable(inst)
62	inst:AddComponent("perishable")
63	inst.components.perishable:SetPerishTime(TUNING.PERISH_ONE_DAY)
64	inst.components.perishable:StartPerishing()
65	inst.components.perishable.onperishreplacement = "ash"
66	inst:AddComponent("workable")
67	inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
68	inst.components.workable:SetWorkLeft(10)
69	inst.components.workable:SetOnFinishCallback(function(inst)
70		SpawnPrefab("ground_chunks_breaking").Transform:SetPosition(inst.Transform:GetWorldPosition())
71		inst:Remove()
72	end )
73	inst.components.workable:SetOnWorkCallback(function(inst)
74		local pt2 = Vector3(inst.Transform:GetWorldPosition())
75		local pos = Vector3(GetPlayer().Transform:GetWorldPosition())
76		inst.Physics:SetMotorVelOverride((pt2.x-pos.x)*13,0,(pt2.z-pos.z)*13)
77		inst:DoTaskInTime(0.2, function() inst.Physics:ClearMotorVelOverride() end )
78		GetPlayer().components.sanity:DoDelta(5)
79	end )
80	inst:DoPeriodicTask(.05, function(inst)
81		local pos2 = Vector3(inst.Transform:GetWorldPosition())
82		local ents = TheSim:FindEntities(pos2.x,pos2.y,pos2.z, 0.5)
83		for k,v in pairs(ents) do
84			if v.prefab == "rabbithole" then
85			   GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/use_axe_tree")
86			   inst:Remove()
87			   GetPlayer().components.sanity:DoDelta(50)
88			end
89		end
90	end )
91	inst:AddTag("golfs")
92  end
93end
94	inst.OnSave = onsave
95	inst.OnLoad = onload
96
97	即可用蜗牛壳碎片种高尔夫球(请种在兔子洞附近),装备锤子对高尔夫球按一下鼠标右键(注意不要按住不放)可以击球。主角站得离球越近,击球的力量越小;站得越远,击球的力量越大。每次挥杆奖励5点脑,将球打入兔子洞奖励50点脑(进洞的球会被兔子拿走,再玩请重新种球)。球能准确入洞的诀窍在于,人、球、洞三点成一线。每个高尔夫球可以击打10次,如果10杆都没有进洞,说明你的技术太烂了,再种一个球重来吧。不想要高尔夫球时,烧掉即可,不会引燃周边物品,如果球打得太远找不到了,1天后会自动降解为灰烬,不会污染环境。蜗牛壳碎片可以通过打蜗牛龟和蜗牛窝得到,如果你同时修改了“巨型超市”,也可以花1-2个黄金购得