代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2三0三.良种山羊(用闪电羊角种良种山羊,会生小羊,能跟随、产羊奶)
3
4 用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/lightninggoathorn.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
5
6local function OnDeploy (inst, pt)
7 local goodgoat = SpawnPrefab("lightninggoathorn")
8 goodgoat.Transform:SetPosition(pt.x, pt.y, pt.z)
9 goodgoat.AnimState:SetBank("lightning_goat")
10 goodgoat.AnimState:SetBuild("lightning_goat_build")
11 goodgoat.AnimState:PlayAnimation("idle_loop", true)
12 goodgoat.Transform:SetFourFaced()
13 goodgoat.entity:AddSoundEmitter()
14 local shadow = goodgoat.entity:AddDynamicShadow()
15 shadow:SetSize(1.75,.75)
16 MakeCharacterPhysics(goodgoat, 100, 1)
17 goodgoat.entity:AddLight()
18 goodgoat.Light:Enable(false)
19 local minimap = goodgoat.entity:AddMiniMapEntity()
20 minimap:SetIcon( "toothtrap.png" )
21 goodgoat:RemoveComponent("stackable")
22 goodgoat:RemoveComponent("inventoryitem")
23 goodgoat:RemoveComponent("deployable")
24 goodgoat:AddComponent("knownlocations")
25 goodgoat:AddComponent("leader")
26 goodgoat:AddComponent("follower")
27 goodgoat.components.follower:SetLeader(GetPlayer())
28 goodgoat.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
29 goodgoat:AddTag("followme")
30 goodgoat:AddComponent("locomotor")
31 goodgoat.components.locomotor.walkspeed = 4
32 goodgoat.components.locomotor.runspeed = 8
33 goodgoat:SetStateGraph("SGlightninggoat")
34 local brain = require "brains/chesterbrain"
35 goodgoat:SetBrain(brain)
36 goodgoat:AddComponent("health")
37 goodgoat.components.health:SetMaxHealth(200)
38 goodgoat:AddComponent("combat")
39 goodgoat.components.combat.hiteffectsymbol = "lightning_goat_body"
40 goodgoat.components.combat:SetAttackPeriod(1)
41 goodgoat.components.combat:SetRange(1, 2)
42 goodgoat.components.combat:SetDefaultDamage(10)
43 goodgoat:AddComponent("lootdropper")
44 goodgoat.components.lootdropper:SetLoot({"meat","meat","meat","meat","meat","meat"})
45 goodgoat:ListenForEvent("attacked", function(goodgoat, data)
46 if data.attacker ~= GetPlayer() then
47 goodgoat.components.combat:SetTarget(data.attacker)
48 goodgoat.components.combat:ShareTarget(data.attacker, 30, function(dude) return dude:HasTag("goodgoats") and not dude.components.health:IsDead() end, 10)
49 else
50 goodgoat.components.health:Kill()
51 end
52 end )
53 goodgoat.components.inspectable.getstatus = function(goodgoat)
54 if not goodgoat:HasTag("followme") then
55 local brain = require "brains/chesterbrain"
56 goodgoat:SetBrain(brain)
57 goodgoat:RestartBrain()
58 goodgoat.components.follower:SetLeader(GetPlayer())
59 goodgoat.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
60 goodgoat:AddTag("followme")
61 else
62 local brain = require "brains/frogbrain"
63 goodgoat:SetBrain(brain)
64 goodgoat:RestartBrain()
65 goodgoat.components.follower:SetLeader(nil)
66 goodgoat.AnimState:SetBloomEffectHandle("")
67 goodgoat:RemoveTag("followme")
68 end
69 end
70 goodgoat:DoPeriodicTask(math.random(180, 360), function(goodgoat)
71 SpawnPrefab("goatmilk").Transform:SetPosition(goodgoat.Transform:GetWorldPosition())
72 end )
73 goodgoat:ListenForEvent( "nighttime", function()
74 if math.random()<.3 then
75 local pt0 = goodgoat:GetPosition()
76 local smallgoat = SpawnPrefab("lightninggoathorn")
77 smallgoat.Transform:SetPosition(pt0.x, pt0.y, pt0.z)
78 smallgoat.AnimState:SetBank("lightning_goat")
79 smallgoat.AnimState:SetBuild("lightning_goat_build")
80 smallgoat.AnimState:PlayAnimation("idle_loop", true)
81 smallgoat.Transform:SetFourFaced()
82 smallgoat.Transform:SetScale(0.6, 0.6, 0.6)
83 smallgoat.entity:AddSoundEmitter()
84 local shadow = smallgoat.entity:AddDynamicShadow()
85 shadow:SetSize(1,.5)
86 MakeCharacterPhysics(smallgoat, 60, 0.6)
87 smallgoat.entity:AddLight()
88 smallgoat.Light:Enable(false)
89 local minimap = smallgoat.entity:AddMiniMapEntity()
90 minimap:SetIcon( "toothtrap.png" )
91 smallgoat:RemoveComponent("stackable")
92 smallgoat:RemoveComponent("inventoryitem")
93 smallgoat:RemoveComponent("deployable")
94 smallgoat:AddComponent("knownlocations")
95 smallgoat:AddComponent("follower")
96 smallgoat:AddComponent("locomotor")
97 smallgoat.components.locomotor.walkspeed = 4
98 smallgoat.components.locomotor.runspeed = 8
99 smallgoat:SetStateGraph("SGlightninggoat")
100 smallgoat:AddComponent("health")
101 smallgoat.components.health:SetMaxHealth(100)
102 smallgoat:AddComponent("combat")
103 smallgoat.components.combat.hiteffectsymbol = "lightning_goat_body"
104 smallgoat.components.combat:SetAttackPeriod(1)
105 smallgoat.components.combat:SetRange(1, 2)
106 smallgoat.components.combat:SetDefaultDamage(5)
107 smallgoat:AddComponent("lootdropper")
108 smallgoat.components.lootdropper:SetLoot({"meat","meat","meat","lightninggoathorn"})
109 smallgoat:ListenForEvent("attacked", function(smallgoat, data)
110 if data.attacker ~= GetPlayer() then
111 smallgoat.components.combat:SetTarget(data.attacker)
112 smallgoat.components.combat:ShareTarget(data.attacker, 30, function(dude) return dude:HasTag("goodgoats") and not dude.components.health:IsDead() end, 10)
113 else
114 smallgoat.components.health:Kill()
115 end
116 end )
117 smallgoat:DoPeriodicTask(math.random(180, 360), function(smallgoat)
118 SpawnPrefab("poop").Transform:SetPosition(smallgoat.Transform:GetWorldPosition())
119 end )
120 smallgoat:DoTaskInTime(1, function(smallgoat)
121 local mama = FindEntity(smallgoat, 100, function(guy)
122 return guy:HasTag("goodgoats") and guy.components.leader and guy.components.health and not guy.components.health:IsDead()
123 end)
124 if mama then
125 local brain = require "brains/chesterbrain"
126 smallgoat:SetBrain(brain)
127 smallgoat:RestartBrain()
128 smallgoat.components.follower:SetLeader(mama)
129 else
130 local brain = require "brains/frogbrain"
131 smallgoat:SetBrain(brain)
132 smallgoat:RestartBrain()
133 smallgoat.components.follower:SetLeader(nil)
134 end
135 end )
136 smallgoat.components.inspectable.getstatus = function(smallgoat)
137 local mama = FindEntity(smallgoat, 100, function(guy)
138 return guy:HasTag("goodgoats") and guy.components.leader and guy.components.health and not guy.components.health:IsDead()
139 end)
140 if mama then
141 local brain = require "brains/chesterbrain"
142 smallgoat:SetBrain(brain)
143 smallgoat:RestartBrain()
144 smallgoat.components.follower:SetLeader(mama)
145 else
146 local brain = require "brains/frogbrain"
147 smallgoat:SetBrain(brain)
148 smallgoat:RestartBrain()
149 smallgoat.components.follower:SetLeader(nil)
150 end
151 end
152 smallgoat:AddTag("smallgoats")
153 end
154 end , GetWorld())
155 goodgoat:AddTag("goodgoats")
156 inst.components.stackable:Get():Remove()
157end
158 inst:AddComponent("deployable")
159 inst.components.deployable.ondeploy = OnDeploy
160local function onsave(inst, data)
161 if inst:HasTag("goodgoats") then
162 data.goodgoats = true
163 end
164 if inst:HasTag("followme") then
165 data.followme = true
166 end
167 if inst:HasTag("smallgoats") then
168 data.smallgoats = true
169 end
170end
171local function onload(inst, data)
172 if data and data.goodgoats then
173 inst.AnimState:SetBank("lightning_goat")
174 inst.AnimState:SetBuild("lightning_goat_build")
175 inst.AnimState:PlayAnimation("idle_loop", true)
176 inst.Transform:SetFourFaced()
177 inst.entity:AddSoundEmitter()
178 local shadow = inst.entity:AddDynamicShadow()
179 shadow:SetSize(1.75,.75)
180 MakeCharacterPhysics(inst, 100, 1)
181 inst.entity:AddLight()
182 inst.Light:Enable(false)
183 local minimap = inst.entity:AddMiniMapEntity()
184 minimap:SetIcon( "toothtrap.png" )
185 inst:RemoveComponent("stackable")
186 inst:RemoveComponent("inventoryitem")
187 inst:RemoveComponent("deployable")
188 inst:AddComponent("knownlocations")
189 inst:AddComponent("leader")
190 inst:AddComponent("follower")
191 inst:AddComponent("locomotor")
192 inst.components.locomotor.walkspeed = 4
193 inst.components.locomotor.runspeed = 8
194 inst:SetStateGraph("SGlightninggoat")
195 local brain = require "brains/frogbrain"
196 inst:SetBrain(brain)
197 inst:AddComponent("health")
198 inst.components.health:SetMaxHealth(200)
199 inst:AddComponent("combat")
200 inst.components.combat.hiteffectsymbol = "lightning_goat_body"
201 inst.components.combat:SetAttackPeriod(1)
202 inst.components.combat:SetRange(1, 2)
203 inst.components.combat:SetDefaultDamage(10)
204 inst:AddComponent("lootdropper")
205 inst.components.lootdropper:SetLoot({"meat","meat","meat","meat","meat","meat"})
206 inst:ListenForEvent("attacked", function(inst, data)
207 if data.attacker ~= GetPlayer() then
208 inst.components.combat:SetTarget(data.attacker)
209 inst.components.combat:ShareTarget(data.attacker, 30, function(dude) return dude:HasTag("goodgoats") and not dude.components.health:IsDead() end, 10)
210 else
211 inst.components.health:Kill()
212 end
213 end )
214 inst.components.inspectable.getstatus = function(inst)
215 if not inst:HasTag("followme") then
216 local brain = require "brains/chesterbrain"
217 inst:SetBrain(brain)
218 inst:RestartBrain()
219 inst.components.follower:SetLeader(GetPlayer())
220 inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
221 inst:AddTag("followme")
222 else
223 local brain = require "brains/frogbrain"
224 inst:SetBrain(brain)
225 inst:RestartBrain()
226 inst.components.follower:SetLeader(nil)
227 inst.AnimState:SetBloomEffectHandle("")
228 inst:RemoveTag("followme")
229 end
230 end
231 inst:DoPeriodicTask(math.random(180, 360), function(inst)
232 SpawnPrefab("goatmilk").Transform:SetPosition(inst.Transform:GetWorldPosition())
233 end )
234 inst:ListenForEvent( "nighttime", function()
235 if math.random()<.3 then
236 local pt0 = inst:GetPosition()
237 local smallgoat = SpawnPrefab("lightninggoathorn")
238 smallgoat.Transform:SetPosition(pt0.x, pt0.y, pt0.z)
239 smallgoat.AnimState:SetBank("lightning_goat")
240 smallgoat.AnimState:SetBuild("lightning_goat_build")
241 smallgoat.AnimState:PlayAnimation("idle_loop", true)
242 smallgoat.Transform:SetFourFaced()
243 smallgoat.Transform:SetScale(0.6, 0.6, 0.6)
244 smallgoat.entity:AddSoundEmitter()
245 local shadow = smallgoat.entity:AddDynamicShadow()
246 shadow:SetSize(1,.5)
247 MakeCharacterPhysics(smallgoat, 60, 0.6)
248 smallgoat.entity:AddLight()
249 smallgoat.Light:Enable(false)
250 local minimap = smallgoat.entity:AddMiniMapEntity()
251 minimap:SetIcon( "toothtrap.png" )
252 smallgoat:RemoveComponent("stackable")
253 smallgoat:RemoveComponent("inventoryitem")
254 smallgoat:RemoveComponent("deployable")
255 smallgoat:AddComponent("knownlocations")
256 smallgoat:AddComponent("follower")
257 smallgoat:AddComponent("locomotor")
258 smallgoat.components.locomotor.walkspeed = 4
259 smallgoat.components.locomotor.runspeed = 8
260 smallgoat:SetStateGraph("SGlightninggoat")
261 smallgoat:AddComponent("health")
262 smallgoat.components.health:SetMaxHealth(100)
263 smallgoat:AddComponent("combat")
264 smallgoat.components.combat.hiteffectsymbol = "lightning_goat_body"
265 smallgoat.components.combat:SetAttackPeriod(1)
266 smallgoat.components.combat:SetRange(1, 2)
267 smallgoat.components.combat:SetDefaultDamage(5)
268 smallgoat:AddComponent("lootdropper")
269 smallgoat.components.lootdropper:SetLoot({"meat","meat","meat","lightninggoathorn"})
270 smallgoat:ListenForEvent("attacked", function(smallgoat, data)
271 if data.attacker ~= GetPlayer() then
272 smallgoat.components.combat:SetTarget(data.attacker)
273 smallgoat.components.combat:ShareTarget(data.attacker, 30, function(dude) return dude:HasTag("goodgoats") and not dude.components.health:IsDead() end, 10)
274 else
275 smallgoat.components.health:Kill()
276 end
277 end )
278 smallgoat:DoPeriodicTask(math.random(180, 360), function(smallgoat)
279 SpawnPrefab("poop").Transform:SetPosition(smallgoat.Transform:GetWorldPosition())
280 end )
281 smallgoat:DoTaskInTime(1, function(smallgoat)
282 local mama = FindEntity(smallgoat, 100, function(guy)
283 return guy:HasTag("goodgoats") and guy.components.leader and guy.components.health and not guy.components.health:IsDead()
284 end)
285 if mama then
286 local brain = require "brains/chesterbrain"
287 smallgoat:SetBrain(brain)
288 smallgoat:RestartBrain()
289 smallgoat.components.follower:SetLeader(mama)
290 else
291 local brain = require "brains/frogbrain"
292 smallgoat:SetBrain(brain)
293 smallgoat:RestartBrain()
294 smallgoat.components.follower:SetLeader(nil)
295 end
296 end )
297 smallgoat.components.inspectable.getstatus = function(smallgoat)
298 local mama = FindEntity(smallgoat, 100, function(guy)
299 return guy:HasTag("goodgoats") and guy.components.leader and guy.components.health and not guy.components.health:IsDead()
300 end)
301 if mama then
302 local brain = require "brains/chesterbrain"
303 smallgoat:SetBrain(brain)
304 smallgoat:RestartBrain()
305 smallgoat.components.follower:SetLeader(mama)
306 else
307 local brain = require "brains/frogbrain"
308 smallgoat:SetBrain(brain)
309 smallgoat:RestartBrain()
310 smallgoat.components.follower:SetLeader(nil)
311 end
312 end
313 smallgoat:AddTag("smallgoats")
314 end
315 end , GetWorld())
316 inst:AddTag("goodgoats")
317 end
318 if data and data.followme then
319 local brain = require "brains/chesterbrain"
320 inst:SetBrain(brain)
321 inst:RestartBrain()
322 inst.components.follower:SetLeader(GetPlayer())
323 inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
324 inst:AddTag("followme")
325 end
326 if data and data.smallgoats then
327 inst.AnimState:SetBank("lightning_goat")
328 inst.AnimState:SetBuild("lightning_goat_build")
329 inst.AnimState:PlayAnimation("idle_loop", true)
330 inst.Transform:SetFourFaced()
331 inst.Transform:SetScale(0.6, 0.6, 0.6)
332 inst.entity:AddSoundEmitter()
333 local shadow = inst.entity:AddDynamicShadow()
334 shadow:SetSize(1,.5)
335 MakeCharacterPhysics(inst, 60, 0.6)
336 inst.entity:AddLight()
337 inst.Light:Enable(false)
338 local minimap = inst.entity:AddMiniMapEntity()
339 minimap:SetIcon( "toothtrap.png" )
340 inst:RemoveComponent("stackable")
341 inst:RemoveComponent("inventoryitem")
342 inst:RemoveComponent("deployable")
343 inst:AddComponent("knownlocations")
344 inst:AddComponent("follower")
345 inst:AddComponent("locomotor")
346 inst.components.locomotor.walkspeed = 4
347 inst.components.locomotor.runspeed = 8
348 inst:SetStateGraph("SGlightninggoat")
349 inst:AddComponent("health")
350 inst.components.health:SetMaxHealth(100)
351 inst:AddComponent("combat")
352 inst.components.combat.hiteffectsymbol = "lightning_goat_body"
353 inst.components.combat:SetAttackPeriod(1)
354 inst.components.combat:SetRange(1, 2)
355 inst.components.combat:SetDefaultDamage(5)
356 inst:AddComponent("lootdropper")
357 inst.components.lootdropper:SetLoot({"meat","meat","meat","lightninggoathorn"})
358 inst:ListenForEvent("attacked", function(inst, data)
359 if data.attacker ~= GetPlayer() then
360 inst.components.combat:SetTarget(data.attacker)
361 inst.components.combat:ShareTarget(data.attacker, 30, function(dude) return dude:HasTag("goodgoats") and not dude.components.health:IsDead() end, 10)
362 else
363 inst.components.health:Kill()
364 end
365 end )
366 inst:DoPeriodicTask(math.random(180, 360), function(inst)
367 SpawnPrefab("poop").Transform:SetPosition(inst.Transform:GetWorldPosition())
368 end )
369 inst:DoTaskInTime(1, function(inst)
370 local mama = FindEntity(inst, 100, function(guy)
371 return guy:HasTag("goodgoats") and guy.components.leader and guy.components.health and not guy.components.health:IsDead()
372 end)
373 if mama then
374 local brain = require "brains/chesterbrain"
375 inst:SetBrain(brain)
376 inst:RestartBrain()
377 inst.components.follower:SetLeader(mama)
378 else
379 local brain = require "brains/frogbrain"
380 inst:SetBrain(brain)
381 inst:RestartBrain()
382 inst.components.follower:SetLeader(nil)
383 end
384 end )
385 inst.components.inspectable.getstatus = function(inst)
386 local mama = FindEntity(inst, 100, function(guy)
387 return guy:HasTag("goodgoats") and guy.components.leader and guy.components.health and not guy.components.health:IsDead()
388 end)
389 if mama then
390 local brain = require "brains/chesterbrain"
391 inst:SetBrain(brain)
392 inst:RestartBrain()
393 inst.components.follower:SetLeader(mama)
394 else
395 local brain = require "brains/frogbrain"
396 inst:SetBrain(brain)
397 inst:RestartBrain()
398 inst.components.follower:SetLeader(nil)
399 end
400 end
401 inst:AddTag("smallgoats")
402 end
403end
404 inst.OnSave = onsave
405 inst.OnLoad = onload
406
407 即可用闪电羊角种良种山羊,鼠标左键点山羊(手里不要拿武器,以免误伤)可跟随,再次点击取消跟随。良种山羊每天可产1-2份羊奶,夜里还有一定概率生下小羊,杀掉良种山羊可得6块大肉。小羊只跟随大羊,如果你杀掉了小羊的妈妈,它会乱跑,这时带一只大羊,用鼠标左键点小羊,可让它认新的妈妈。小羊会产便便,不会长大,可作为你的肉食来源,屠宰后得到3块大肉和闪电羊角,其中闪电羊角可用于再种良种山羊,逐步壮大你的羊群。良种山羊在小地图上显示为犬牙陷阱图标。闪电羊角可打闪电羊获得,如修改了“巨型超市”,也可花1-3个黄金购得