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

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


  1
  2.商业采矿机(用晶体管种商业采矿机,20个黄金租用一次,收购采出的矿石,赔钱、赚钱天注定)
  3
  4	MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/transistor.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
  5
  6local function makeluckypit(inst)
  7	local pt = inst:GetPosition()
  8	local luckypit = SpawnPrefab("transistor")
  9	luckypit.Transform:SetPosition(pt.x, pt.y, pt.z)
 10	luckypit.AnimState:SetBank("coldfirepit")
 11	luckypit.AnimState:SetBuild("coldfirepit")
 12	luckypit.AnimState:PlayAnimation("idle",false)
 13	luckypit.entity:AddSoundEmitter()
 14	luckypit.Transform:SetScale(1.5,1.5,1.5)
 15	luckypit:RemoveComponent("stackable")
 16	luckypit:RemoveComponent("inventoryitem")
 17	luckypit:RemoveComponent("deployable")
 18	luckypit:AddComponent("workable")
 19	luckypit.components.workable:SetWorkAction(ACTIONS.HAMMER)
 20	luckypit.components.workable:SetWorkLeft(3)
 21	luckypit.components.workable:SetOnFinishCallback(function(luckypit)
 22		SpawnPrefab("collapse_big").Transform:SetPosition(luckypit.Transform:GetWorldPosition())
 23		GetPlayer().SoundEmitter:PlaySound("dontstarve/common/destroy_wood")
 24		luckypit:Remove()
 25	end )
 26	luckypit:AddComponent("trader")
 27	luckypit.components.trader:SetAcceptTest(function(luckypit, item) 
 28		if GetPlayer().components.inventory:Has("goldnugget", 20) then
 29		   if not luckypit:HasTag("domining") then
 30			  if item.prefab == "goldnugget" then
 31				 return true
 32			  end
 33		   end
 34		end
 35		if item.prefab == "rocks" or item.prefab == "nitre" or item.prefab == "flint" or item.prefab == "redgem" or item.prefab == "bluegem" or item.prefab == "purplegem" or item.prefab == "greengem" or item.prefab == "orangegem" or item.prefab == "yellowgem" or item.prefab == "thulecite" or item.prefab == "ice" then
 36		   return true
 37		end
 38		return false
 39	end )
 40	luckypit.components.trader.onaccept = function(luckypit, giver, item)
 41		if item.prefab == "goldnugget" then
 42		   giver.components.inventory:ConsumeByName("goldnugget", 19)
 43		   GetPlayer().SoundEmitter:PlaySound("dontstarve/HUD/research_available")
 44		   luckypit:AddTag("domining")
 45		   luckypit.task = luckypit:DoPeriodicTask(1, function()
 46			   local pt0 = luckypit:GetPosition()
 47			   luckypit.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
 48			   luckypit:DoTaskInTime(0.5, function() luckypit.AnimState:SetBloomEffectHandle("") end )
 49			   SpawnPrefab("collapse_small").Transform:SetPosition(pt0.x, 1, pt0.z)
 50			   luckypit.SoundEmitter:PlaySound("dontstarve/wilson/rock_break")
 51			   GetPlayer().components.playercontroller:ShakeCamera(luckypit, "FULL", 0.7, 0.02, .5, 40)
 52			   local ores = {"rocks","nitre","flint","redgem","bluegem","purplegem","greengem","orangegem","yellowgem","thulecite","ice","goldnugget","ash"}
 53			   local ore = ores[math.random(#ores)]
 54			   local myore = SpawnPrefab(ore)
 55			   myore.Transform:SetPosition(pt0.x, 0, pt0.z)
 56			   myore.components.inventoryitem.canbepickedup = false
 57		   myore:AddComponent("complexprojectile")
 58		   myore.components.complexprojectile.yOffset = 2.5
 59			   myore.components.complexprojectile:Launch(Point(pt0.x+(math.random(10)-math.random(10)), 0, pt0.z+(math.random(10)-math.random(10))))
 60		   myore.components.complexprojectile:SetOnHit(function()
 61				   SpawnPrefab("ground_chunks_breaking").Transform:SetPosition(myore.Transform:GetWorldPosition())
 62				   myore:RemoveComponent("complexprojectile")
 63				   myore.components.inventoryitem.canbepickedup = true
 64			   end )
 65		   end )
 66		   luckypit:DoTaskInTime(math.random(10,60), function()
 67			   SpawnPrefab("collapse_big").Transform:SetPosition(luckypit.Transform:GetWorldPosition())
 68			   luckypit.SoundEmitter:PlaySound("dontstarve/common/destroy_wood")
 69			   if luckypit.task then luckypit.task:Cancel() luckypit.task = nil end
 70			   luckypit:RemoveTag("domining")
 71		   end )
 72		end
 73		if item.prefab == "thulecite" then
 74		   for k = 1, 3 do
 75			   local goldnugget = SpawnPrefab("goldnugget")
 76			   giver.components.inventory:GiveItem(goldnugget)
 77		   end
 78		end
 79		if item.prefab == "rocks" or item.prefab == "nitre" or item.prefab == "flint" or item.prefab == "redgem" or item.prefab == "bluegem" or item.prefab == "purplegem" or item.prefab == "greengem" or item.prefab == "orangegem" or item.prefab == "yellowgem" or item.prefab == "ice" then
 80		   local goldnugget = SpawnPrefab("goldnugget")
 81		   giver.components.inventory:GiveItem(goldnugget)
 82		end
 83	end
 84	luckypit:AddTag("luckypit")
 85end
 86local function OnDeploy (inst, pt)
 87	makeluckypit(inst)
 88	inst.components.stackable:Get():Remove()
 89end
 90	inst:AddComponent("deployable")
 91	inst.components.deployable.ondeploy = OnDeploy
 92local function onsave(inst, data)
 93	if inst:HasTag("luckypit") then
 94	   data.luckypit = true
 95	end
 96end
 97local function onload(inst, data)
 98  if data and data.luckypit then
 99	 makeluckypit(inst)
100	 inst:Remove()
101  end
102end
103	inst.OnSave = onsave
104	inst.OnLoad = onload
105
106	即可用晶体管种商业采矿机(拿着1个晶体管对地面点鼠标右键,如果拿着多个,则不会种出来),给它20个黄金(拿着黄金对采矿机点鼠标左键)可租用一次,采出的矿石数量不确定,还有一定概率采出灰。你可以将矿石留下自用,也可以卖给商业采矿机(拿着矿石对采矿机点鼠标左键),除铥矿石可卖3个黄金外,其余每个矿石可卖1个黄金,能否平衡你支付的租金,就要看天意了,开启矿业大亨的生涯吧。不想要商业采矿机了,用锤子砸掉即可。晶体管在精炼选项(画着白色宝石)下,用2个黄金、1个石砖制造