YN259-制冰机(用草伞种制冰机,下雨时自动制冰,可加工成大冰块永久保存,大冰块可砸碎成冰)
代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。 原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html 二五九.制冰机(用草伞种制冰机,下雨时自动制冰,可加工成大冰块永久保存,大冰块可砸碎成冰) 用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/umbrella.lua文件,在inst:AddTag("show_spoilage")的下一行插入以下内容: local function itemtest(inst, item, slot) if item.prefab == "ice" then return true end return false end local slotpos = { Vector3(0,-75,0)} local widgetbuttoninfo = { text = "Make", position = Vector3(0, -135, 0), fn = function(inst) if inst:HasTag("icemaker") then if inst.components.container:Has("ice", 10) then GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/rock_break") inst.components.container:ConsumeByName("ice", 10) local pt = inst:GetPosition() local bigice = SpawnPrefab("grass_umbrella") bigice.Transform:SetPosition(pt.x+(math.random(3)-math.random(3)), 0, pt.z+(math.random(3)-math.random(3))) bigice.AnimState:SetBank("icehat") bigice.AnimState:SetBuild("hat_ice") bigice.AnimState:PlayAnimation("anim") bigice.Transform:SetScale(1.5, 1.5, 1.5) bigice:RemoveComponent("waterproofer") bigice:RemoveComponent("equippable") bigice:RemoveComponent("insulator") bigice:RemoveComponent("perishable") bigice:RemoveComponent("fuel") bigice:RemoveComponent("burnable") bigice:RemoveComponent("propagator") bigice:RemoveComponent("deployable") bigice:RemoveComponent("container") bigice:RemoveTag("nopunch") bigice:RemoveTag("show_spoilage") bigice:RemoveAllEventCallbacks() bigice:AddComponent("named") bigice.components.named:SetName("Big ice") bigice.components.inventoryitem:ChangeImageName("icehat") bigice:AddComponent("heater") bigice.components.heater.iscooler = true bigice.components.heater.heatfn = function(bigice) return -40 end bigice:AddComponent("workable") bigice.components.workable:SetWorkAction(ACTIONS.HAMMER) bigice.components.workable:SetWorkLeft(1) bigice.components.workable:SetOnFinishCallback(function(bigice) SpawnPrefab("ground_chunks_breaking").Transform:SetPosition(bigice.Transform:GetWorldPosition()) GetPlayer().SoundEmitter:PlaySound("dontstarve/common/destroy_wood") for k = 1, 10 do local pt1 = bigice:GetPosition() local ice = SpawnPrefab("ice") ice.Transform:SetPosition(pt1.x+(math.random(3)-math.random(3)), 0, pt1.z+(math.random(3)-math.random(3))) end bigice:Remove() end ) bigice:AddTag("bigice") end end end } local function OnDeploy (inst, pt) local icemaker = SpawnPrefab("grass_umbrella") icemaker.Transform:SetPosition(pt.x, pt.y, pt.z) icemaker.AnimState:SetBank("eyeball_turret_base") icemaker.AnimState:SetBuild("eyeball_turret_base") icemaker.AnimState:PlayAnimation("idle_loop") icemaker.Transform:SetScale(0.8, 0.8, 0.8) icemaker.AnimState:SetMultColour(0/255,255/255,0/255,1) icemaker:RemoveComponent("waterproofer") icemaker:RemoveComponent("inventoryitem") icemaker:RemoveComponent("equippable") icemaker:RemoveComponent("insulator") icemaker:RemoveComponent("perishable") icemaker:RemoveComponent("fuel") icemaker:RemoveComponent("burnable") icemaker:RemoveComponent("propagator") icemaker:RemoveComponent("deployable") icemaker:RemoveTag("nopunch") icemaker:RemoveTag("show_spoilage") icemaker:RemoveAllEventCallbacks() icemaker:AddComponent("named") icemaker.components.named:SetName("Ice maker") icemaker.components.container.canbeopened = true icemaker:AddComponent("workable") icemaker.components.workable:SetWorkAction(ACTIONS.HAMMER) icemaker.components.workable:SetWorkLeft(3) icemaker.components.workable:SetOnFinishCallback(function(icemaker) SpawnPrefab("collapse_big").Transform:SetPosition(icemaker.Transform:GetWorldPosition()) GetPlayer().SoundEmitter:PlaySound("dontstarve/common/destroy_wood") icemaker:Remove() end ) icemaker:ListenForEvent("rainstart", function() icemaker.task = icemaker:DoPeriodicTask(10, function() local ice = SpawnPrefab("ice") icemaker.components.container:GiveItem(ice) end ) end, GetWorld()) icemaker:ListenForEvent("rainstop", function() if icemaker.task then icemaker.task:Cancel() icemaker.task = nil end end, GetWorld()) icemaker:AddTag("icemaker") inst:Remove() end inst:AddComponent("deployable") inst.components.deployable.ondeploy = OnDeploy inst:AddComponent("container") inst.components.container:SetNumSlots(#slotpos) inst.components.container.widgetslotpos = slotpos inst.components.container.widgetpos = Vector3(0,150,0) inst.components.container.side_align_tip = 160 inst.components.container.itemtestfn = itemtest inst.components.container.widgetbuttoninfo = widgetbuttoninfo inst.components.container.canbeopened = false inst.components.container.onopenfn = function(inst) GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold") end inst.components.container.onclosefn = function(inst) GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold") end inst:AddTag("fridge") local function onsave(inst, data) if inst:HasTag("icemaker") then data.icemaker = true end if inst:HasTag("bigice") then data.bigice = true end end local function onload(inst, data) if data and data.icemaker then inst.AnimState:SetBank("eyeball_turret_base") inst.AnimState:SetBuild("eyeball_turret_base") inst.AnimState:PlayAnimation("idle_loop") inst.Transform:SetScale(0.8, 0.8, 0.8) inst.AnimState:SetMultColour(0/255,255/255,0/255,1) inst:RemoveComponent("waterproofer") inst:RemoveComponent("inventoryitem") inst:RemoveComponent("equippable") inst:RemoveComponent("insulator") inst:RemoveComponent("perishable") inst:RemoveComponent("fuel") inst:RemoveComponent("burnable") inst:RemoveComponent("propagator") inst:RemoveComponent("deployable") inst:RemoveTag("nopunch") inst:RemoveTag("show_spoilage") inst:RemoveAllEventCallbacks() inst:AddComponent("named") inst.components.named:SetName("Ice maker") inst.components.container.canbeopened = true inst:AddComponent("workable") inst.components.workable:SetWorkAction(ACTIONS.HAMMER) inst.components.workable:SetWorkLeft(3) inst.components.workable:SetOnFinishCallback(function(inst) SpawnPrefab("collapse_big").Transform:SetPosition(inst.Transform:GetWorldPosition()) GetPlayer().SoundEmitter:PlaySound("dontstarve/common/destroy_wood") inst:Remove() end ) inst:ListenForEvent("rainstart", function() inst.task = inst:DoPeriodicTask(10, function() local ice = SpawnPrefab("ice") inst.components.container:GiveItem(ice) end ) end, GetWorld()) inst:ListenForEvent("rainstop", function() if inst.task then inst.task:Cancel() inst.task = nil end end, GetWorld()) inst:AddTag("icemaker") end if data and data.bigice then inst.AnimState:SetBank("icehat") inst.AnimState:SetBuild("hat_ice") inst.AnimState:PlayAnimation("anim") inst.Transform:SetScale(1.5, 1.5, 1.5) inst:RemoveComponent("waterproofer") inst:RemoveComponent("equippable") inst:RemoveComponent("insulator") inst:RemoveComponent("perishable") inst:RemoveComponent("fuel") inst:RemoveComponent("burnable") inst:RemoveComponent("propagator") inst:RemoveComponent("deployable") inst:RemoveComponent("container") inst:RemoveTag("nopunch") inst:RemoveTag("show_spoilage") inst:RemoveAllEventCallbacks() inst:AddComponent("named") inst.components.named:SetName("Big ice") inst.components.inventoryitem:ChangeImageName("icehat") inst:AddComponent("heater") inst.components.heater.iscooler = true inst.components.heater.heatfn = function(inst) return -40 end inst:AddComponent("workable") inst.components.workable:SetWorkAction(ACTIONS.HAMMER) inst.components.workable:SetWorkLeft(1) inst.components.workable:SetOnFinishCallback(function(inst) SpawnPrefab("ground_chunks_breaking").Transform:SetPosition(inst.Transform:GetWorldPosition()) GetPlayer().SoundEmitter:PlaySound("dontstarve/common/destroy_wood") for k = 1, 10 do local pt1 = inst:GetPosition() local ice = SpawnPrefab("ice") ice.Transform:SetPosition(pt1.x+(math.random(3)-math.random(3)), 0, pt1.z+(math.random(3)-math.random(3))) end inst:Remove() end ) inst:AddTag("bigice") end end inst.OnSave = onsave inst.OnLoad = onload 即可用草伞种制冰机,下雨时每10秒制成一块冰,鼠标左键点制冰机,可打开格子,在格子中拿取。当格子中至少有10块冰时,点格子下面的“Make”按钮,可将冰加工成大冰块,用以永久保存。靠近大冰块可降温,用锤子砸大冰块,可还原成小冰。不想要制冰机了,用锤子炸毁即可。草伞在生存选项(画着绳套)下,用4个树枝、3个草、6个花瓣制造