代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
一九八.找矿蜗牛(用蜗牛龟盔甲种找矿蜗牛,为你勘探新石矿) 用MT管理器打开游戏目录/assets/scripts/prefabs/armor_snurtleshell.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容: local function OnDeploy (inst, pt) local snail = SpawnPrefab("armorsnurtleshell") snail.Transform:SetPosition(pt.x, pt.y, pt.z) snail.AnimState:SetBank("slurtle") snail.AnimState:SetBuild("slurtle") snail.AnimState:PlayAnimation("idle", true) snail.Transform:SetFourFaced() local sound = snail.entity:AddSoundEmitter() local brain = require "brains/leifbrain" snail:SetBrain(brain) snail:AddComponent("locomotor") snail.components.locomotor.walkspeed = 7 snail:SetStateGraph("SGslurtle") local minimap = snail.entity:AddMiniMapEntity() minimap:SetIcon( "slurtle_den.png" ) snail.components.inventoryitem:ChangeImageName("armorsnurtleshell") snail:RemoveComponent("armor") snail:RemoveComponent("equippable") snail:RemoveComponent("useableitem") snail:RemoveComponent("deployable") snail:RemoveTag("shell") snail:RemoveComponent("inventoryitem") snail:AddComponent("combat") snail:AddComponent("health") snail.components.health:SetMaxHealth(1000) snail.components.health:SetInvincible(true) snail.components.health.nofadeout = true snail.task = snail:DoPeriodicTask(math.random(8,12), function(snail) local pt1 = snail:GetPosition() local rocks = {"rock1","rock2","rock_flintless","rock_ice"} local rock = rocks[math.random(#rocks)] local newrock = SpawnPrefab(rock) newrock.Transform:SetPosition(pt1.x, 0, pt1.z) newrock.Physics:SetActive(false) newrock:DoTaskInTime(3, function(newrock) newrock.Physics:SetActive(true) end ) SpawnPrefab("splash_ocean").Transform:SetPosition(pt1.x, 0, pt1.z) snail.SoundEmitter:PlaySound("dontstarve/wilson/rock_break") GetPlayer().components.playercontroller:ShakeCamera(snail, "FULL", 0.2, 0.02, .25, 40) end ) snail:AddComponent("inventoryitem") snail.components.inventoryitem:SetOnPutInInventoryFn(function(snail) snail:RemoveTag("sports") snail.components.locomotor:Stop() snail:SetBrain(nil) if snail.task then snail.task:Cancel() snail.task = nil end end ) snail.components.inventoryitem:SetOnDroppedFn(function(snail) snail:AddTag("sports") local brain = require "brains/leifbrain" snail:SetBrain(brain) snail:RestartBrain() snail.task = snail:DoPeriodicTask(math.random(8,12), function(snail) local pt1 = snail:GetPosition() local rocks = {"rock1","rock2","rock_flintless","rock_ice"} local rock = rocks[math.random(#rocks)] local newrock = SpawnPrefab(rock) newrock.Transform:SetPosition(pt1.x, 0, pt1.z) newrock.Physics:SetActive(false) newrock:DoTaskInTime(3, function(newrock) newrock.Physics:SetActive(true) end ) SpawnPrefab("splash_ocean").Transform:SetPosition(pt1.x, 0, pt1.z) snail.SoundEmitter:PlaySound("dontstarve/wilson/rock_break") GetPlayer().components.playercontroller:ShakeCamera(snail, "FULL", 0.2, 0.02, .25, 40) end ) end ) snail:AddTag("sports") snail:AddTag("companion") snail:AddTag("snails") inst:Remove() end inst:AddComponent("deployable") inst.components.deployable.ondeploy = OnDeploy local function onsave(inst, data) if inst:HasTag("snails") then data.snails = true end if inst:HasTag("sports") then data.sports = true end end local function onload(inst, data) if data and data.snails then inst.AnimState:SetBank("slurtle") inst.AnimState:SetBuild("slurtle") inst.AnimState:PlayAnimation("idle", true) inst.Transform:SetFourFaced() local sound = inst.entity:AddSoundEmitter() inst:AddComponent("locomotor") inst.components.locomotor.walkspeed = 7 inst:SetStateGraph("SGslurtle") local minimap = inst.entity:AddMiniMapEntity() minimap:SetIcon( "slurtle_den.png" ) inst.components.inventoryitem:ChangeImageName("armorsnurtleshell") inst:RemoveComponent("armor") inst:RemoveComponent("equippable") inst:RemoveComponent("useableitem") inst:RemoveComponent("deployable") inst:RemoveTag("shell") inst:RemoveComponent("inventoryitem") inst:AddComponent("combat") inst:AddComponent("health") inst.components.health:SetMaxHealth(1000) inst.components.health:SetInvincible(true) inst.components.health.nofadeout = true inst:AddComponent("inventoryitem") inst.components.inventoryitem:SetOnPutInInventoryFn(function(inst) inst:RemoveTag("sports") inst.components.locomotor:Stop() inst:SetBrain(nil) if inst.task then inst.task:Cancel() inst.task = nil end end ) inst.components.inventoryitem:SetOnDroppedFn(function(inst) inst:AddTag("sports") local brain = require "brains/leifbrain" inst:SetBrain(brain) inst:RestartBrain() inst.task = inst:DoPeriodicTask(math.random(8,12), function(inst) local pt1 = inst:GetPosition() local rocks = {"rock1","rock2","rock_flintless","rock_ice"} local rock = rocks[math.random(#rocks)] local newrock = SpawnPrefab(rock) newrock.Transform:SetPosition(pt1.x, 0, pt1.z) newrock.Physics:SetActive(false) newrock:DoTaskInTime(3, function(newrock) newrock.Physics:SetActive(true) end ) SpawnPrefab("splash_ocean").Transform:SetPosition(pt1.x, 0, pt1.z) inst.SoundEmitter:PlaySound("dontstarve/wilson/rock_break") GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 0.2, 0.02, .25, 40) end ) end ) inst:AddTag("companion") inst:AddTag("snails") end if data and data.sports then local brain = require "brains/leifbrain" inst:SetBrain(brain) inst:RestartBrain() inst.task = inst:DoPeriodicTask(math.random(8,12), function(inst) local pt1 = inst:GetPosition() local rocks = {"rock1","rock2","rock_flintless","rock_ice"} local rock = rocks[math.random(#rocks)] local newrock = SpawnPrefab(rock) newrock.Transform:SetPosition(pt1.x, 0, pt1.z) newrock.Physics:SetActive(false) newrock:DoTaskInTime(3, function(newrock) newrock.Physics:SetActive(true) end ) SpawnPrefab("splash_ocean").Transform:SetPosition(pt1.x, 0, pt1.z) inst.SoundEmitter:PlaySound("dontstarve/wilson/rock_break") GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 0.2, 0.02, .25, 40) end ) inst:AddTag("sports") local pt2 = GetPlayer():GetPosition() inst.Transform:SetPosition(pt2.x+1, 0, pt2.z+1) end end inst.OnSave = onsave inst.OnLoad = onload 即可用蜗牛龟盔甲种找矿蜗牛,鼠标左键点蜗牛,可将其放入物品栏(显示为蜗牛龟盔甲的图标)。在空旷的地上放下找矿蜗牛,它会为你勘探出新的石矿,石头从此成为可再生资源。找矿蜗牛只会专注于找矿,不会跟随你,别把它弄丢了,如果真找不到了,存档退出后再读档,它会出现在你身边。不想要找矿蜗牛时,在物品栏中对其按鼠标右键即可。蜗牛龟盔甲可在地下一层打蜗牛龟时获得,如果修改了“巨型超市”,也可以花9-11个黄金购买