代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2一九七.吸地牛(用大理石种吸地牛,地面物品自动吸入肚中,可开矿、砍树)
3
4 用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/inv_marble.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
5
6local slotpos = {}
7for y = 4, 0, -1 do
8 for x = 0, 14 do
9 table.insert(slotpos, Vector3(75*x-75*2+75, 75*y-75*2+75,0))
10 end
11end
12local sounds =
13{
14 walk = "dontstarve/beefalo/walk",
15 grunt = "dontstarve/beefalo/grunt",
16 yell = "dontstarve/beefalo/yell",
17 swish = "dontstarve/beefalo/tail_swish",
18 curious = "dontstarve/beefalo/curious",
19 angry = "dontstarve/beefalo/angry",
20}
21local function OnDeploy (inst, pt)
22 local bull = SpawnPrefab("marble")
23 bull.Transform:SetPosition(pt.x, pt.y, pt.z)
24 bull.AnimState:SetBank("beefalo")
25 bull.AnimState:SetBuild("beefalo_build")
26 bull.AnimState:PlayAnimation("idle_loop", true)
27 bull.Transform:SetFourFaced()
28 bull.Transform:SetScale(0.8, 0.8, 0.8)
29 local sound = bull.entity:AddSoundEmitter()
30 bull.sounds = sounds
31 local shadow = bull.entity:AddDynamicShadow()
32 shadow:SetSize( 3, 1.25 )
33 MakeCharacterPhysics(bull, 100, 1.5)
34 bull:AddTag("bull")
35 bull:AddTag("companion")
36 bull:AddComponent("locomotor")
37 bull.components.locomotor.walkspeed = 1.5
38 bull.components.locomotor.runspeed = 15
39 bull:SetStateGraph("SGBeefalo")
40 bull:AddComponent("follower")
41 bull:AddComponent("knownlocations")
42 bull.components.container.canbeopened = true
43 bull:AddComponent("combat")
44 bull:AddComponent("health")
45 bull.components.health:SetMaxHealth(10000)
46 bull.components.health:SetInvincible(true)
47 bull.components.health.nofadeout = true
48 bull:RemoveComponent("stackable")
49 bull:RemoveComponent("inventoryitem")
50 bull:RemoveComponent("bait")
51 bull:RemoveTag("molebait")
52 bull:AddComponent("workable")
53 bull.components.workable:SetWorkAction(ACTIONS.CHOP)
54 bull.components.workable:SetWorkLeft(3)
55 bull.components.workable:SetOnFinishCallback(function(bull)
56 bull.AnimState:PlayAnimation("death")
57 bull.SoundEmitter:PlaySound("dontstarve/beefalo/yell")
58 bull:DoTaskInTime(1.5, function() bull.components.container:DropEverything() bull:Remove() end)
59 end )
60 bull:DoPeriodicTask(1, function(bull)
61 if not bull.components.container:Has("cutgrass", 1) then
62 bull.components.locomotor:Stop()
63 bull:SetBrain(nil)
64 bull.components.follower:SetLeader(nil)
65 bull:RemoveTag("letgo")
66 else
67 local brain = require "brains/chesterbrain"
68 bull:SetBrain(brain)
69 bull:RestartBrain()
70 bull.components.follower:SetLeader(GetPlayer())
71 bull:AddTag("letgo")
72 end
73 end )
74 bull:DoPeriodicTask(180, function(bull)
75 if bull.components.container:Has("cutgrass", 1) then
76 bull.components.container:ConsumeByName("cutgrass", 1)
77 bull.AnimState:PlayAnimation("graze_loop")
78 end
79 end )
80 bull:DoPeriodicTask(.1, function(bull)
81 if bull:HasTag("letgo") then
82 local pos = Vector3(bull.Transform:GetWorldPosition())
83 local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, 15)
84 for k,v in pairs(ents) do
85 local pt1 = v:GetPosition()
86 if v.components.inventoryitem and v.components.inventoryitem.canbepickedup and v.components.inventoryitem.cangoincontainer
87 and not v.components.inventoryitem:IsHeld() and not v:HasTag("trap") and not v:HasTag("light") and not v:HasTag("blowdart")
88 and not v:HasTag("projectile") and not v:HasTag("helpers") then
89 if not bull.components.container:IsFull() then
90 SpawnPrefab("small_puff").Transform:SetPosition(pt1.x, pt1.y, pt1.z)
91 bull.components.container:GiveItem(v)
92 bull.SoundEmitter:PlaySound("dontstarve/HUD/research_available")
93 end
94 end
95 end
96 end
97 end )
98 bull.Physics:SetCollisionCallback(function(bull, other)
99 if other and other.components.workable and other.components.workable.workleft > 0 and not other:HasTag("bull") then
100 SpawnPrefab("collapse_small").Transform:SetPosition(other:GetPosition():Get())
101 other.components.workable:Destroy(bull)
102 end
103 end)
104 inst.components.stackable:Get():Remove()
105end
106 inst:AddComponent("deployable")
107 inst.components.deployable.ondeploy = OnDeploy
108local function onsave(inst, data)
109 if inst:HasTag("bull") then
110 data.bull = true
111 end
112end
113local function onload(inst, data)
114 if data and data.bull then
115 inst.AnimState:SetBank("beefalo")
116 inst.AnimState:SetBuild("beefalo_build")
117 inst.AnimState:PlayAnimation("idle_loop", true)
118 inst.Transform:SetFourFaced()
119 inst.Transform:SetScale(0.8, 0.8, 0.8)
120 local sound = inst.entity:AddSoundEmitter()
121 inst.sounds = sounds
122 local shadow = inst.entity:AddDynamicShadow()
123 shadow:SetSize( 3, 1.25 )
124 MakeCharacterPhysics(inst, 100, 1.5)
125 inst:AddTag("bull")
126 inst:AddTag("companion")
127 inst:AddComponent("locomotor")
128 inst.components.locomotor.walkspeed = 1.5
129 inst.components.locomotor.runspeed = 15
130 inst:SetStateGraph("SGBeefalo")
131 inst:AddComponent("follower")
132 inst:AddComponent("knownlocations")
133 inst.components.container.canbeopened = true
134 inst:AddComponent("combat")
135 inst:AddComponent("health")
136 inst.components.health:SetMaxHealth(10000)
137 inst.components.health:SetInvincible(true)
138 inst.components.health.nofadeout = true
139 inst:RemoveComponent("stackable")
140 inst:RemoveComponent("inventoryitem")
141 inst:RemoveComponent("bait")
142 inst:RemoveTag("molebait")
143 inst:AddComponent("workable")
144 inst.components.workable:SetWorkAction(ACTIONS.CHOP)
145 inst.components.workable:SetWorkLeft(3)
146 inst.components.workable:SetOnFinishCallback(function(inst)
147 inst.AnimState:PlayAnimation("death")
148 inst.SoundEmitter:PlaySound("dontstarve/beefalo/yell")
149 inst:DoTaskInTime(1.5, function() inst.components.container:DropEverything() inst:Remove() end)
150 end )
151 inst:DoPeriodicTask(1, function(inst)
152 if not inst.components.container:Has("cutgrass", 1) then
153 inst.components.locomotor:Stop()
154 inst:SetBrain(nil)
155 inst.components.follower:SetLeader(nil)
156 inst:RemoveTag("letgo")
157 else
158 local brain = require "brains/chesterbrain"
159 inst:SetBrain(brain)
160 inst:RestartBrain()
161 inst.components.follower:SetLeader(GetPlayer())
162 inst:AddTag("letgo")
163 end
164 end )
165 inst:DoPeriodicTask(180, function(inst)
166 if inst.components.container:Has("cutgrass", 1) then
167 inst.components.container:ConsumeByName("cutgrass", 1)
168 inst.AnimState:PlayAnimation("graze_loop")
169 end
170 end )
171 inst:DoPeriodicTask(.1, function(inst)
172 if inst:HasTag("letgo") then
173 local pos = Vector3(inst.Transform:GetWorldPosition())
174 local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, 15)
175 for k,v in pairs(ents) do
176 local pt1 = v:GetPosition()
177 if v.components.inventoryitem and v.components.inventoryitem.canbepickedup and v.components.inventoryitem.cangoincontainer
178 and not v.components.inventoryitem:IsHeld() and not v:HasTag("trap") and not v:HasTag("light") and not v:HasTag("blowdart")
179 and not v:HasTag("projectile") and not v:HasTag("helpers") then
180 if not inst.components.container:IsFull() then
181 SpawnPrefab("small_puff").Transform:SetPosition(pt1.x, pt1.y, pt1.z)
182 inst.components.container:GiveItem(v)
183 inst.SoundEmitter:PlaySound("dontstarve/HUD/research_available")
184 end
185 end
186 end
187 end
188 end )
189 inst.Physics:SetCollisionCallback(function(inst, other)
190 if other and other.components.workable and other.components.workable.workleft > 0 and not other:HasTag("bull") then
191 SpawnPrefab("collapse_small").Transform:SetPosition(other:GetPosition():Get())
192 other.components.workable:Destroy(inst)
193 end
194 end)
195 end
196end
197 inst.OnSave = onsave
198 inst.OnLoad = onload
199 inst:AddComponent("container")
200 inst.components.container:SetNumSlots(#slotpos)
201 inst.components.container.widgetslotpos = slotpos
202 inst.components.container.widgetpos = Vector3(-300,200,0)
203 inst.components.container.side_align_tip = 160
204 inst.components.container.canbeopened = false
205 inst:AddTag("fridge")
206
207 即可用大理石种吸地牛,鼠标左键点它可开启格子,放入草后会跟随你,吸取沿路所有物品(吸进肚中的格子里,鼠标左键点击可拿取)。拿出草后即停止跟随,在原地等待。吸地牛会消化肚中的草,每天消化2-3根,如果格子中的草被吃完了,就不会跟随你,直到再给它草为止。吸地牛可撞碎石头、撞倒树,并将掉落物品直接吸入肚中,带着它去开矿、砍树吧。不要让吸地牛靠近你的建筑物,它会将其撞毁,除非你想用它拆迁。不想要吸地牛时,用斧子砍它三下即可,肚中物品会掉在地上