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

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



二三九.高尔夫球(用蜗牛壳碎片种高尔夫球,锤子作球杆,将球打进兔子洞吧)

	用MT管理器打开游戏目录/assets/scripts/prefabs/slurtle_shellpieces.lua文件,在inst:AddComponent("inventoryitem")的下一行插入以下内容:

local function OnDeploy (inst, pt)
	local golf = SpawnPrefab("slurtle_shellpieces")
	golf.Transform:SetPosition(pt.x, pt.y, pt.z)
	golf.AnimState:SetBank("bulb")
	golf.AnimState:SetBuild("bulb")
	golf.AnimState:PlayAnimation("idle")
	golf.Transform:SetScale(0.8, 0.8, 0.8)
	golf.components.inventoryitem.canbepickedup = false
	MakeSmallBurnable(golf)
	golf:AddComponent("perishable")
	golf.components.perishable:SetPerishTime(TUNING.PERISH_ONE_DAY)
	golf.components.perishable:StartPerishing()
	golf.components.perishable.onperishreplacement = "ash"
	golf:AddComponent("workable")
	golf.components.workable:SetWorkAction(ACTIONS.HAMMER)
	golf.components.workable:SetWorkLeft(10)
	golf.components.workable:SetOnFinishCallback(function(golf)
		SpawnPrefab("ground_chunks_breaking").Transform:SetPosition(golf.Transform:GetWorldPosition())
		golf:Remove()
	end )
	golf.components.workable:SetOnWorkCallback(function(golf)
		local pt2 = Vector3(golf.Transform:GetWorldPosition())
		local pos = Vector3(GetPlayer().Transform:GetWorldPosition())
		golf.Physics:SetMotorVelOverride((pt2.x-pos.x)*13,0,(pt2.z-pos.z)*13)
		golf:DoTaskInTime(0.2, function() golf.Physics:ClearMotorVelOverride() end )
		GetPlayer().components.sanity:DoDelta(5)
	end )
	golf:DoPeriodicTask(.05, function(golf)
		local pos2 = Vector3(golf.Transform:GetWorldPosition())
		local ents = TheSim:FindEntities(pos2.x,pos2.y,pos2.z, 0.5)
		for k,v in pairs(ents) do
			if v.prefab == "rabbithole" then
			   GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/use_axe_tree")
			   golf:Remove()
			   GetPlayer().components.sanity:DoDelta(50)
			end
		end
	end )
	golf:AddTag("golfs")
	inst.components.stackable:Get():Remove()
end
	inst:AddComponent("deployable")
	inst.components.deployable.ondeploy = OnDeploy
local function onsave(inst, data)
	if inst:HasTag("golfs") then
		data.golfs = true
	end
end
local function onload(inst, data)
  if data and data.golfs then
	inst.AnimState:SetBank("bulb")
	inst.AnimState:SetBuild("bulb")
	inst.AnimState:PlayAnimation("idle")
	inst.Transform:SetScale(0.8, 0.8, 0.8)
	inst.components.inventoryitem.canbepickedup = false
	MakeSmallBurnable(inst)
	inst:AddComponent("perishable")
	inst.components.perishable:SetPerishTime(TUNING.PERISH_ONE_DAY)
	inst.components.perishable:StartPerishing()
	inst.components.perishable.onperishreplacement = "ash"
	inst:AddComponent("workable")
	inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
	inst.components.workable:SetWorkLeft(10)
	inst.components.workable:SetOnFinishCallback(function(inst)
		SpawnPrefab("ground_chunks_breaking").Transform:SetPosition(inst.Transform:GetWorldPosition())
		inst:Remove()
	end )
	inst.components.workable:SetOnWorkCallback(function(inst)
		local pt2 = Vector3(inst.Transform:GetWorldPosition())
		local pos = Vector3(GetPlayer().Transform:GetWorldPosition())
		inst.Physics:SetMotorVelOverride((pt2.x-pos.x)*13,0,(pt2.z-pos.z)*13)
		inst:DoTaskInTime(0.2, function() inst.Physics:ClearMotorVelOverride() end )
		GetPlayer().components.sanity:DoDelta(5)
	end )
	inst:DoPeriodicTask(.05, function(inst)
		local pos2 = Vector3(inst.Transform:GetWorldPosition())
		local ents = TheSim:FindEntities(pos2.x,pos2.y,pos2.z, 0.5)
		for k,v in pairs(ents) do
			if v.prefab == "rabbithole" then
			   GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/use_axe_tree")
			   inst:Remove()
			   GetPlayer().components.sanity:DoDelta(50)
			end
		end
	end )
	inst:AddTag("golfs")
  end
end
	inst.OnSave = onsave
	inst.OnLoad = onload

	即可用蜗牛壳碎片种高尔夫球(请种在兔子洞附近),装备锤子对高尔夫球按一下鼠标右键(注意不要按住不放)可以击球。主角站得离球越近,击球的力量越小;站得越远,击球的力量越大。每次挥杆奖励5点脑,将球打入兔子洞奖励50点脑(进洞的球会被兔子拿走,再玩请重新种球)。球能准确入洞的诀窍在于,人、球、洞三点成一线。每个高尔夫球可以击打10次,如果10杆都没有进洞,说明你的技术太烂了,再种一个球重来吧。不想要高尔夫球时,烧掉即可,不会引燃周边物品,如果球打得太远找不到了,1天后会自动降解为灰烬,不会污染环境。蜗牛壳碎片可以通过打蜗牛龟和蜗牛窝得到,如果你同时修改了“巨型超市”,也可以花1-2个黄金购得