代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二五四.噩梦草(用鸟粪种噩梦草,可采噩梦燃料,有一定概率出现地下巨人)
3
4 用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/guano.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
5
6local items = { SWORD = "swap_ham_bat" }
7local function EquipItem(inst, item)
8 if item then
9 inst.AnimState:OverrideSymbol("swap_object", item, item)
10 inst.AnimState:Show("ARM_carry")
11 inst.AnimState:Hide("ARM_normal")
12 end
13end
14 inst.items = items
15 inst.equipfn = EquipItem
16 EquipItem(inst)
17local function OnDeploy (inst, pt)
18 local darkgrass = SpawnPrefab("guano")
19 darkgrass.Transform:SetPosition(pt.x, pt.y, pt.z)
20 darkgrass.AnimState:SetBank("marsh_plant")
21 darkgrass.AnimState:SetBuild("marsh_plant")
22 darkgrass.AnimState:PlayAnimation("idle")
23 darkgrass.Transform:SetScale(1.8, 1.8, 1.8)
24 darkgrass.AnimState:SetMultColour(255/255,255/255,0/255,1)
25 darkgrass:RemoveComponent("stackable")
26 darkgrass:RemoveComponent("inventoryitem")
27 darkgrass:RemoveComponent("fertilizer")
28 darkgrass:RemoveComponent("smotherer")
29 darkgrass:RemoveComponent("fuel")
30 darkgrass:RemoveComponent("burnable")
31 darkgrass:RemoveComponent("propagator")
32 darkgrass:RemoveComponent("deployable")
33 MakeMediumBurnable(darkgrass)
34 MakeSmallPropagator(darkgrass)
35 if darkgrass.flies then darkgrass.flies:Remove() darkgrass.flies = nil end
36 darkgrass:AddComponent("workable")
37 darkgrass.components.workable:SetWorkAction(ACTIONS.DIG)
38 darkgrass.components.workable:SetWorkLeft(1)
39 darkgrass.components.workable:SetOnFinishCallback(function(darkgrass)
40 SpawnPrefab("nightmarefuel").Transform:SetPosition(darkgrass.Transform:GetWorldPosition())
41 darkgrass:Remove()
42 end )
43 darkgrass:AddComponent("pickable")
44 darkgrass.components.pickable:SetUp("nightmarefuel", 480)
45 darkgrass.components.pickable:SetOnRegenFn(function(darkgrass) darkgrass.AnimState:SetMultColour(255/255,255/255,0/255,1) end )
46 darkgrass.components.pickable:SetOnPickedFn(function(darkgrass)
47 darkgrass.AnimState:SetMultColour(255/255,255/255,255/255,1)
48 if math.random()<0.05 then
49 GetPlayer().components.playercontroller:ShakeCamera(darkgrass, "FULL", 1.5, 0.03, 2, 30)
50 GetPlayer().SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
51 SpawnPrefab("collapse_big").Transform:SetPosition(darkgrass.Transform:GetWorldPosition())
52 local giant = SpawnPrefab("guano")
53 giant.Transform:SetPosition(darkgrass.Transform:GetWorldPosition())
54 giant.entity:AddSoundEmitter()
55 giant.AnimState:SetBank("wilson")
56 giant.AnimState:SetBuild("wolfgang")
57 giant.AnimState:PlayAnimation("idle")
58 giant.AnimState:OverrideSymbol("swap_object", "swap_ham_bat", "swap_ham_bat")
59 giant.AnimState:OverrideSymbol("swap_body", "armor_slurper", "swap_body")
60 giant.AnimState:Show("ARM_carry")
61 giant.AnimState:Hide("ARM_normal")
62 giant.Transform:SetFourFaced()
63 giant.Transform:SetScale(3.5,3.5,3.5)
64 local sound = giant.entity:AddSoundEmitter()
65 local shadow = giant.entity:AddDynamicShadow()
66 shadow:SetSize( 6, 3.5 )
67 MakeCharacterPhysics(giant, 200, 1)
68 local minimap = giant.entity:AddMiniMapEntity()
69 minimap:SetIcon("wolfgang.png")
70 local brain = require "brains/leifbrain"
71 giant:SetBrain(brain)
72 giant:AddComponent("locomotor")
73 giant.components.locomotor.walkspeed = 1
74 giant.components.locomotor.runspeed = 2
75 giant:SetStateGraph("SGshadowwaxwell")
76 giant:RemoveComponent("stackable")
77 giant:RemoveComponent("inventoryitem")
78 giant:RemoveComponent("fertilizer")
79 giant:RemoveComponent("smotherer")
80 giant:RemoveComponent("fuel")
81 giant:RemoveComponent("burnable")
82 giant:RemoveComponent("propagator")
83 giant:RemoveComponent("deployable")
84 if giant.flies then giant.flies:Remove() giant.flies = nil end
85 giant:AddComponent("follower")
86 giant:AddComponent("inventory")
87 giant:AddComponent("combat")
88 giant.components.combat.hiteffectsymbol = "torso"
89 giant.components.combat:SetDefaultDamage(70)
90 giant.components.combat:SetAttackPeriod(3)
91 giant.components.combat.onhitotherfn = function()
92 giant.SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
93 GetPlayer().components.playercontroller:ShakeCamera(giant, "FULL", 0.5, 0.05, 2, 40)
94 end
95 giant.components.combat:SetAreaDamage(5, 0.8)
96 giant.components.combat:SetRetargetFunction(3, function(giant)
97 if not giant.components.health:IsDead() then
98 return FindEntity(giant, 20, function(guy)
99 return giant.components.combat:CanTarget(guy) and not guy:HasTag("giant")
100 end )
101 end
102 end )
103 giant:ListenForEvent("attacked", function(giant, data)
104 giant.components.combat:SetTarget(data.attacker)
105 end )
106 giant.Physics:SetCollisionCallback(function(giant, other)
107 if other and other.components.workable and other.components.workable.workleft > 0 then
108 other.components.workable:Destroy(giant)
109 end
110 end )
111 giant:AddComponent("health")
112 giant.components.health:SetMaxHealth(8000)
113 giant.components.health.nofadeout = true
114 giant:AddComponent("sanityaura")
115 giant.components.sanityaura.aura = -TUNING.SANITYAURA_LARGE
116 giant:ListenForEvent("death", function()
117 local pt1 = giant:GetPosition()
118 for k = 1,math.random(20,35) do
119 local gold = SpawnPrefab("goldnugget")
120 gold.Transform:SetPosition(pt1.x+(math.random(3)-math.random(3)), 0, pt1.z+(math.random(3)-math.random(3)))
121 end
122 local rewards = {"walrus_tusk","trunk_summer","trunk_winter","deerclops_eyeball","minotaurhorn"}
123 local reward = rewards[math.random(#rewards)]
124 SpawnPrefab(reward).Transform:SetPosition(pt1.x, 0, pt1.z)
125 end )
126 giant:DoTaskInTime(480, function(giant)
127 giant:Remove()
128 end )
129 giant:AddTag("monster")
130 giant:AddTag("giant")
131 end
132 end )
133 darkgrass:AddTag("darkgrass")
134 inst.components.stackable:Get():Remove()
135end
136 inst:AddComponent("deployable")
137 inst.components.deployable.ondeploy = OnDeploy
138local function onsave(inst, data)
139 if inst:HasTag("darkgrass") then
140 data.darkgrass = true
141 end
142 if inst:HasTag("giant") then
143 data.giant = true
144 end
145end
146local function onload(inst, data)
147 if data and data.darkgrass then
148 inst.AnimState:SetBank("marsh_plant")
149 inst.AnimState:SetBuild("marsh_plant")
150 inst.AnimState:PlayAnimation("idle")
151 inst.Transform:SetScale(1.8, 1.8, 1.8)
152 inst.AnimState:SetMultColour(255/255,255/255,0/255,1)
153 inst:RemoveComponent("stackable")
154 inst:RemoveComponent("inventoryitem")
155 inst:RemoveComponent("fertilizer")
156 inst:RemoveComponent("smotherer")
157 inst:RemoveComponent("fuel")
158 inst:RemoveComponent("burnable")
159 inst:RemoveComponent("propagator")
160 inst:RemoveComponent("deployable")
161 MakeMediumBurnable(inst)
162 MakeSmallPropagator(inst)
163 if inst.flies then inst.flies:Remove() inst.flies = nil end
164 inst:AddComponent("workable")
165 inst.components.workable:SetWorkAction(ACTIONS.DIG)
166 inst.components.workable:SetWorkLeft(1)
167 inst.components.workable:SetOnFinishCallback(function(inst)
168 SpawnPrefab("nightmarefuel").Transform:SetPosition(inst.Transform:GetWorldPosition())
169 inst:Remove()
170 end )
171 inst:AddComponent("pickable")
172 inst.components.pickable:SetUp("nightmarefuel", 480)
173 inst.components.pickable:SetOnRegenFn(function(inst) inst.AnimState:SetMultColour(255/255,255/255,0/255,1) end )
174 inst.components.pickable:SetOnPickedFn(function(inst)
175 inst.AnimState:SetMultColour(255/255,255/255,255/255,1)
176 if math.random()<0.05 then
177 GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 1.5, 0.03, 2, 30)
178 GetPlayer().SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
179 SpawnPrefab("collapse_big").Transform:SetPosition(inst.Transform:GetWorldPosition())
180 local giant = SpawnPrefab("guano")
181 giant.Transform:SetPosition(inst.Transform:GetWorldPosition())
182 giant.entity:AddSoundEmitter()
183 giant.AnimState:SetBank("wilson")
184 giant.AnimState:SetBuild("wolfgang")
185 giant.AnimState:PlayAnimation("idle")
186 giant.AnimState:OverrideSymbol("swap_object", "swap_ham_bat", "swap_ham_bat")
187 giant.AnimState:OverrideSymbol("swap_body", "armor_slurper", "swap_body")
188 giant.AnimState:Show("ARM_carry")
189 giant.AnimState:Hide("ARM_normal")
190 giant.Transform:SetFourFaced()
191 giant.Transform:SetScale(3.5,3.5,3.5)
192 local sound = giant.entity:AddSoundEmitter()
193 local shadow = giant.entity:AddDynamicShadow()
194 shadow:SetSize( 6, 3.5 )
195 MakeCharacterPhysics(giant, 200, 1)
196 local minimap = giant.entity:AddMiniMapEntity()
197 minimap:SetIcon("wolfgang.png")
198 local brain = require "brains/leifbrain"
199 giant:SetBrain(brain)
200 giant:AddComponent("locomotor")
201 giant.components.locomotor.walkspeed = 1
202 giant.components.locomotor.runspeed = 2
203 giant:SetStateGraph("SGshadowwaxwell")
204 giant:RemoveComponent("stackable")
205 giant:RemoveComponent("inventoryitem")
206 giant:RemoveComponent("fertilizer")
207 giant:RemoveComponent("smotherer")
208 giant:RemoveComponent("fuel")
209 giant:RemoveComponent("burnable")
210 giant:RemoveComponent("propagator")
211 giant:RemoveComponent("deployable")
212 if giant.flies then giant.flies:Remove() giant.flies = nil end
213 giant:AddComponent("follower")
214 giant:AddComponent("inventory")
215 giant:AddComponent("combat")
216 giant.components.combat.hiteffectsymbol = "torso"
217 giant.components.combat:SetDefaultDamage(70)
218 giant.components.combat:SetAttackPeriod(3)
219 giant.components.combat.onhitotherfn = function()
220 giant.SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
221 GetPlayer().components.playercontroller:ShakeCamera(giant, "FULL", 0.5, 0.05, 2, 40)
222 end
223 giant.components.combat:SetAreaDamage(5, 0.8)
224 giant.components.combat:SetRetargetFunction(3, function(giant)
225 if not giant.components.health:IsDead() then
226 return FindEntity(giant, 20, function(guy)
227 return giant.components.combat:CanTarget(guy) and not guy:HasTag("giant")
228 end )
229 end
230 end )
231 giant:ListenForEvent("attacked", function(giant, data)
232 giant.components.combat:SetTarget(data.attacker)
233 end )
234 giant.Physics:SetCollisionCallback(function(giant, other)
235 if other and other.components.workable and other.components.workable.workleft > 0 then
236 other.components.workable:Destroy(giant)
237 end
238 end )
239 giant:AddComponent("health")
240 giant.components.health:SetMaxHealth(8000)
241 giant.components.health.nofadeout = true
242 giant:AddComponent("sanityaura")
243 giant.components.sanityaura.aura = -TUNING.SANITYAURA_LARGE
244 giant:ListenForEvent("death", function()
245 local pt1 = giant:GetPosition()
246 for k = 1,math.random(20,35) do
247 local gold = SpawnPrefab("goldnugget")
248 gold.Transform:SetPosition(pt1.x+(math.random(3)-math.random(3)), 0, pt1.z+(math.random(3)-math.random(3)))
249 end
250 local rewards = {"walrus_tusk","trunk_summer","trunk_winter","deerclops_eyeball","minotaurhorn"}
251 local reward = rewards[math.random(#rewards)]
252 SpawnPrefab(reward).Transform:SetPosition(pt1.x, 0, pt1.z)
253 end )
254 giant:DoTaskInTime(480, function(giant)
255 giant:Remove()
256 end )
257 giant:AddTag("monster")
258 giant:AddTag("giant")
259 end
260 end )
261 inst:AddTag("darkgrass")
262 end
263 if data and data.giant then
264 inst.entity:AddSoundEmitter()
265 inst.AnimState:SetBank("wilson")
266 inst.AnimState:SetBuild("wolfgang")
267 inst.AnimState:PlayAnimation("idle")
268 inst.AnimState:OverrideSymbol("swap_object", "swap_ham_bat", "swap_ham_bat")
269 inst.AnimState:OverrideSymbol("swap_body", "armor_slurper", "swap_body")
270 inst.AnimState:Show("ARM_carry")
271 inst.AnimState:Hide("ARM_normal")
272 inst.Transform:SetFourFaced()
273 inst.Transform:SetScale(3.5,3.5,3.5)
274 local sound = inst.entity:AddSoundEmitter()
275 local shadow = inst.entity:AddDynamicShadow()
276 shadow:SetSize( 6, 3.5 )
277 MakeCharacterPhysics(inst, 200, 1)
278 local minimap = inst.entity:AddMiniMapEntity()
279 minimap:SetIcon("wolfgang.png")
280 local brain = require "brains/leifbrain"
281 inst:SetBrain(brain)
282 inst:AddComponent("locomotor")
283 inst.components.locomotor.walkspeed = 1
284 inst.components.locomotor.runspeed = 2
285 inst:SetStateGraph("SGshadowwaxwell")
286 inst:RemoveComponent("stackable")
287 inst:RemoveComponent("inventoryitem")
288 inst:RemoveComponent("fertilizer")
289 inst:RemoveComponent("smotherer")
290 inst:RemoveComponent("fuel")
291 inst:RemoveComponent("burnable")
292 inst:RemoveComponent("propagator")
293 inst:RemoveComponent("deployable")
294 if inst.flies then inst.flies:Remove() inst.flies = nil end
295 inst:AddComponent("follower")
296 inst:AddComponent("inventory")
297 inst:AddComponent("combat")
298 inst.components.combat.hiteffectsymbol = "torso"
299 inst.components.combat:SetDefaultDamage(70)
300 inst.components.combat:SetAttackPeriod(3)
301 inst.components.combat.onhitotherfn = function()
302 inst.SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
303 GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 0.5, 0.05, 2, 40)
304 end
305 inst.components.combat:SetAreaDamage(5, 0.8)
306 inst.components.combat:SetRetargetFunction(3, function(inst)
307 if not inst.components.health:IsDead() then
308 return FindEntity(inst, 20, function(guy)
309 return inst.components.combat:CanTarget(guy) and not guy:HasTag("giant")
310 end )
311 end
312 end )
313 inst:ListenForEvent("attacked", function(inst, data)
314 inst.components.combat:SetTarget(data.attacker)
315 end )
316 inst.Physics:SetCollisionCallback(function(inst, other)
317 if other and other.components.workable and other.components.workable.workleft > 0 then
318 other.components.workable:Destroy(inst)
319 end
320 end )
321 inst:AddComponent("health")
322 inst.components.health:SetMaxHealth(8000)
323 inst.components.health.nofadeout = true
324 inst:AddComponent("sanityaura")
325 inst.components.sanityaura.aura = -TUNING.SANITYAURA_LARGE
326 inst:ListenForEvent("death", function()
327 local pt1 = inst:GetPosition()
328 for k = 1,math.random(20,35) do
329 local gold = SpawnPrefab("goldnugget")
330 gold.Transform:SetPosition(pt1.x+(math.random(3)-math.random(3)), 0, pt1.z+(math.random(3)-math.random(3)))
331 end
332 local rewards = {"walrus_tusk","trunk_summer","trunk_winter","deerclops_eyeball","minotaurhorn"}
333 local reward = rewards[math.random(#rewards)]
334 SpawnPrefab(reward).Transform:SetPosition(pt1.x, 0, pt1.z)
335 end )
336 inst:DoTaskInTime(480, function(inst)
337 inst:Remove()
338 end )
339 inst:AddTag("monster")
340 inst:AddTag("giant")
341 end
342end
343 inst.OnSave = onsave
344 inst.OnLoad = onload
345
346 即可用鸟粪(白色便便)种噩梦草(请远离基地种植),可采摘噩梦燃料,每天都能采一次。采摘时有一定概率出现地下巨人,将攻击你,消灭巨人可获得黄金、巨鹿眼球、远古守护者角、海象牙等宝物。巨人的血量及攻击力都很强,如果打不过,就先逃跑避避风头,一天后巨人将回到地下。巨人在小地图上显示为大力士的图标,绕着点走吧