YN242-自动门(用木盔甲种自动门,进出自动开关)
代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。 原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html 二四二.自动门(用木盔甲种自动门,进出自动开关) 用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/armor_wood.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容: local function OnDeploy (inst, pt) local door1 = SpawnPrefab("armorwood") door1.Transform:SetPosition(pt.x+0.55, pt.y, pt.z-0.55) door1.AnimState:SetBank("winter_meter") door1.AnimState:SetBuild("winter_meter") door1.AnimState:SetPercent("meter", 1) door1.Transform:SetScale(1, 0.7, 1) MakeObstaclePhysics(door1, 0.48) door1:RemoveComponent("inventoryitem") door1:RemoveComponent("fuel") door1:RemoveComponent("armor") door1:RemoveComponent("equippable") door1:RemoveComponent("burnable") door1:RemoveComponent("propagator") door1:RemoveComponent("deployable") door1:RemoveTag("wood") door1:AddComponent("workable") door1.components.workable:SetWorkAction(ACTIONS.HAMMER) door1.components.workable:SetWorkLeft(2) door1.components.workable:SetOnFinishCallback(function(door1) SpawnPrefab("collapse_big").Transform:SetPosition(door1.Transform:GetWorldPosition()) GetPlayer().SoundEmitter:PlaySound("dontstarve/common/destroy_wood") door1:Remove() end ) door1:AddComponent( "playerprox" ) door1.components.playerprox:SetDist(2,3) door1.components.playerprox:SetOnPlayerNear(function(door1) door1.Transform:SetScale(0.1, 0.7, 1) door1.Physics:SetActive(false) GetPlayer().SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup") end ) door1.components.playerprox:SetOnPlayerFar(function(door1) door1.Transform:SetScale(1, 0.7, 1) door1.Physics:SetActive(true) GetPlayer().SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup") end ) door1.components.inspectable.getstatus = function(door1) door1.Transform:SetScale(0.1, 0.7, 1) door1.Physics:SetActive(false) door1:DoTaskInTime(3, function(door1) door1.Transform:SetScale(1, 0.7, 1) door1.Physics:SetActive(true) end ) end door1:AddTag("doors") local door2 = SpawnPrefab("armorwood") door2.Transform:SetPosition(pt.x-0.55, pt.y, pt.z+0.55) door2.AnimState:SetBank("winter_meter") door2.AnimState:SetBuild("winter_meter") door2.AnimState:SetPercent("meter", 1) door2.Transform:SetScale(1, 0.7, 1) MakeObstaclePhysics(door2, 0.48) door2:RemoveComponent("inventoryitem") door2:RemoveComponent("fuel") door2:RemoveComponent("armor") door2:RemoveComponent("equippable") door2:RemoveComponent("burnable") door2:RemoveComponent("propagator") door2:RemoveComponent("deployable") door2:RemoveTag("wood") door2:AddComponent("workable") door2.components.workable:SetWorkAction(ACTIONS.HAMMER) door2.components.workable:SetWorkLeft(2) door2.components.workable:SetOnFinishCallback(function(door2) SpawnPrefab("collapse_big").Transform:SetPosition(door2.Transform:GetWorldPosition()) GetPlayer().SoundEmitter:PlaySound("dontstarve/common/destroy_wood") door2:Remove() end ) door2:AddComponent( "playerprox" ) door2.components.playerprox:SetDist(2,3) door2.components.playerprox:SetOnPlayerNear(function(door2) door2.Transform:SetScale(0.1, 0.7, 1) door2.Physics:SetActive(false) GetPlayer().SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup") end ) door2.components.playerprox:SetOnPlayerFar(function(door2) door2.Transform:SetScale(1, 0.7, 1) door2.Physics:SetActive(true) GetPlayer().SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup") end ) door2.components.inspectable.getstatus = function(door2) door2.Transform:SetScale(0.1, 0.7, 1) door2.Physics:SetActive(false) door2:DoTaskInTime(3, function(door2) door2.Transform:SetScale(1, 0.7, 1) door2.Physics:SetActive(true) end ) end door2:AddTag("doors") inst:Remove() end inst:AddComponent("deployable") inst.components.deployable.ondeploy = OnDeploy local function onsave(inst, data) if inst:HasTag("doors") then data.doors = true end end local function onload(inst, data) if data and data.doors then inst.AnimState:SetBank("winter_meter") inst.AnimState:SetBuild("winter_meter") inst.AnimState:SetPercent("meter", 1) inst.Transform:SetScale(1, 0.7, 1) MakeObstaclePhysics(inst, 0.48) inst:RemoveComponent("inventoryitem") inst:RemoveComponent("fuel") inst:RemoveComponent("armor") inst:RemoveComponent("equippable") inst:RemoveComponent("burnable") inst:RemoveComponent("propagator") inst:RemoveComponent("deployable") inst:RemoveTag("wood") inst:AddComponent("workable") inst.components.workable:SetWorkAction(ACTIONS.HAMMER) inst.components.workable:SetWorkLeft(2) 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:AddComponent( "playerprox" ) inst.components.playerprox:SetDist(2,3) inst.components.playerprox:SetOnPlayerNear(function(inst) inst.Transform:SetScale(0.1, 0.7, 1) inst.Physics:SetActive(false) GetPlayer().SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup") end ) inst.components.playerprox:SetOnPlayerFar(function(inst) inst.Transform:SetScale(1, 0.7, 1) inst.Physics:SetActive(true) GetPlayer().SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup") end ) inst.components.inspectable.getstatus = function(inst) inst.Transform:SetScale(0.1, 0.7, 1) inst.Physics:SetActive(false) inst:DoTaskInTime(3, function(inst) inst.Transform:SetScale(1, 0.7, 1) inst.Physics:SetActive(true) end ) end inst:AddTag("doors") end end inst.OnSave = onsave inst.OnLoad = onload 即可用木盔甲种自动门,进出时自动开关,为方便宠物进出,也可以手动开关,鼠标左键点击可开门,3秒后自动关门。种门时,可先建好一排墙,然后砸掉其中2堵,在留下的空地正中间种下自动门,即可与墙完美契合。自动门有方向的限制,只可种在正面的墙之间(进入游戏默认的方向),不能种在侧面的墙之间。不需要自动门时,用锤子砸毁即可。木盔甲在战斗选项(画着两把剑)下,用8个木头、2个绳子制造