代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二0四.宠物蜻蜓(用蜻蜓盔甲种宠物蜻蜓,攻击力超强,鼠标右键点击可帮你捡地上的物品)
3
4 用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/armor_dragonfly.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
5
6local function OnDeploy (inst, pt)
7 local myfly = SpawnPrefab("armordragonfly")
8 myfly.Transform:SetPosition(pt.x, pt.y, pt.z)
9 myfly.AnimState:SetBank("dragonfly")
10 myfly.AnimState:SetBuild("dragonfly_build")
11 myfly.AnimState:PlayAnimation("idle", true)
12 myfly.Transform:SetScale(0.5, 0.5, 0.5)
13 myfly.Transform:SetFourFaced()
14 local sound = myfly.entity:AddSoundEmitter()
15 local shadow = myfly.entity:AddDynamicShadow()
16 shadow:SetSize(3, 1.8)
17 MakeCharacterPhysics(myfly, 50, 0.7)
18 local light = myfly.entity:AddLight()
19 myfly.Light:Enable(false)
20 myfly.Light:SetRadius(2)
21 myfly.Light:SetFalloff(0.5)
22 myfly.Light:SetIntensity(.75)
23 myfly.Light:SetColour(235/255,121/255,12/255)
24 myfly:RemoveComponent("inventoryitem")
25 myfly:RemoveComponent("armor")
26 myfly:RemoveComponent("equippable")
27 myfly:RemoveComponent("deployable")
28 MakeLargePropagator(myfly)
29 myfly.components.propagator.decayrate = 0
30 myfly:AddComponent("groundpounder")
31 myfly.components.groundpounder.numRings = 2
32 myfly.components.groundpounder.burner = true
33 myfly.components.groundpounder.groundpoundfx = "firesplash_fx"
34 myfly.components.groundpounder.groundpounddamagemult = .5
35 myfly.components.groundpounder.groundpoundringfx = "firering_fx"
36 myfly:AddComponent("named")
37 myfly.components.named:SetName("My Dragonfly")
38 myfly:AddComponent("inventory")
39 myfly:AddComponent("knownlocations")
40 myfly:AddComponent("follower")
41 myfly.components.follower:SetLeader(GetPlayer())
42 myfly:AddComponent("lootdropper")
43 myfly.components.lootdropper:SetLoot({"meat", "meat", "meat", "meat", "dragon_scales"})
44 myfly:AddComponent("health")
45 myfly.components.health:SetMaxHealth(5000)
46 myfly:AddComponent("combat")
47 myfly.components.combat:SetDefaultDamage(300)
48 myfly.components.combat:SetAttackPeriod(0.5)
49 myfly.components.combat.hiteffectsymbol = "dragonfly_body"
50 myfly.components.combat:SetAreaDamage(6, 0.8)
51 myfly.components.combat.playerdamagepercent = 0
52 myfly.components.combat:SetRange(4)
53 myfly.components.combat.battlecryenabled = false
54 myfly.components.combat:SetHurtSound("dontstarve_DLC001/creatures/dragonfly/hurt")
55 myfly.components.combat:SetRetargetFunction(1, function(myfly)
56 if not myfly.components.health:IsDead() then
57 return FindEntity(myfly, 25, function(guy)
58 if guy.components.combat then
59 return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy or guy:HasTag("monster")
60 end
61 end )
62 end
63 end )
64 myfly.components.combat:SetKeepTargetFunction(function(myfly, target) return target and target:IsValid() end )
65 myfly:ListenForEvent("attacked", function(myfly, data)
66 if data.attacker ~= GetPlayer() then
67 if not data.attacker:HasTag("myflys") then
68 myfly.components.combat:SetTarget(data.attacker)
69 end
70 else
71 myfly.components.health:Kill()
72 end
73 end )
74 myfly:AddComponent("locomotor")
75 myfly.components.locomotor.walkspeed = 25
76 myfly:SetStateGraph("SGdragonfly")
77 local brain = require "brains/abigailbrain"
78 myfly:SetBrain(brain)
79 myfly:DoPeriodicTask(5, function()
80 if myfly.components.combat and not myfly.components.combat.target then
81 if myfly.fire_build then
82 myfly.sg:GoToState("flameoff")
83 end
84 if myfly.components.health and myfly.components.health:GetPercent() < 1 then
85 myfly.components.health:DoDelta(200)
86 end
87 end
88 end )
89 myfly:AddComponent("machine")
90 myfly.components.machine.turnonfn = function()
91 myfly:AddTag("inhaling")
92 myfly.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
93 myfly.task = myfly:DoPeriodicTask(.5, function(myfly)
94 local pos = Vector3(myfly.Transform:GetWorldPosition())
95 local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, 15)
96 for k,v in pairs(ents) do
97 local pt1 = v:GetPosition()
98 if v.components.inventoryitem and v.components.inventoryitem.canbepickedup and v.components.inventoryitem.cangoincontainer
99 and not v.components.inventoryitem:IsHeld() and not v:HasTag("trap") and not v:HasTag("light") and not v:HasTag("blowdart")
100 and not v:HasTag("projectile") then
101 if not GetPlayer().components.inventory:IsFull() then
102 SpawnPrefab("small_puff").Transform:SetPosition(pt1.x, pt1.y, pt1.z)
103 GetPlayer().components.inventory:GiveItem(v)
104 GetPlayer().SoundEmitter:PlaySound("dontstarve/HUD/research_available")
105 end
106 end
107 end
108 end )
109 end
110 myfly.components.machine.turnofffn = function()
111 myfly:RemoveTag("inhaling")
112 myfly.AnimState:SetBloomEffectHandle( "" )
113 if myfly.task then myfly.task:Cancel() myfly.task = nil end
114 end
115 myfly.components.inspectable.getstatus = function(myfly)
116 if not myfly:HasTag("stophere") then
117 myfly:AddTag("stophere")
118 myfly.components.locomotor:Stop()
119 myfly:SetBrain(nil)
120 myfly.components.follower:SetLeader(nil)
121 myfly.sg:GoToState("flameoff")
122 else
123 myfly:RemoveTag("stophere")
124 local brain = require "brains/abigailbrain"
125 myfly:SetBrain(brain)
126 myfly:RestartBrain()
127 myfly.components.follower:SetLeader(GetPlayer())
128 end
129 end
130 myfly:ListenForEvent("death", function()
131 myfly.components.machine:TurnOff()
132 end )
133 myfly:AddTag("companion")
134 myfly:AddTag("myflys")
135 inst:Remove()
136end
137 inst:AddComponent("deployable")
138 inst.components.deployable.ondeploy = OnDeploy
139local function onsave(inst, data)
140 if inst:HasTag("myflys") then
141 data.myflys = true
142 end
143 if inst:HasTag("stophere") then
144 data.stophere = true
145 end
146 if inst:HasTag("inhaling") then
147 data.inhaling = true
148 end
149end
150local function onload(inst, data)
151 if data and data.myflys then
152 inst.AnimState:SetBank("dragonfly")
153 inst.AnimState:SetBuild("dragonfly_build")
154 inst.AnimState:PlayAnimation("idle", true)
155 inst.Transform:SetScale(0.5, 0.5, 0.5)
156 inst.Transform:SetFourFaced()
157 local sound = inst.entity:AddSoundEmitter()
158 local shadow = inst.entity:AddDynamicShadow()
159 shadow:SetSize(3, 1.8)
160 MakeCharacterPhysics(inst, 50, 0.7)
161 local light = inst.entity:AddLight()
162 inst.Light:Enable(false)
163 inst.Light:SetRadius(2)
164 inst.Light:SetFalloff(0.5)
165 inst.Light:SetIntensity(.75)
166 inst.Light:SetColour(235/255,121/255,12/255)
167 inst:RemoveComponent("inventoryitem")
168 inst:RemoveComponent("armor")
169 inst:RemoveComponent("equippable")
170 inst:RemoveComponent("deployable")
171 MakeLargePropagator(inst)
172 inst.components.propagator.decayrate = 0
173 inst:AddComponent("groundpounder")
174 inst.components.groundpounder.numRings = 2
175 inst.components.groundpounder.burner = true
176 inst.components.groundpounder.groundpoundfx = "firesplash_fx"
177 inst.components.groundpounder.groundpounddamagemult = .5
178 inst.components.groundpounder.groundpoundringfx = "firering_fx"
179 inst:AddComponent("named")
180 inst.components.named:SetName("My Dragonfly")
181 inst:AddComponent("inventory")
182 inst:AddComponent("knownlocations")
183 inst:AddComponent("follower")
184 inst.components.follower:SetLeader(GetPlayer())
185 inst:AddComponent("lootdropper")
186 inst.components.lootdropper:SetLoot({"meat", "meat", "meat", "meat", "dragon_scales"})
187 inst:AddComponent("health")
188 inst.components.health:SetMaxHealth(5000)
189 inst:AddComponent("combat")
190 inst.components.combat:SetDefaultDamage(300)
191 inst.components.combat:SetAttackPeriod(0.5)
192 inst.components.combat.hiteffectsymbol = "dragonfly_body"
193 inst.components.combat:SetAreaDamage(6, 0.8)
194 inst.components.combat.playerdamagepercent = 0
195 inst.components.combat:SetRange(4)
196 inst.components.combat.battlecryenabled = false
197 inst.components.combat:SetHurtSound("dontstarve_DLC001/creatures/dragonfly/hurt")
198 inst.components.combat:SetRetargetFunction(1, function(inst)
199 if not inst.components.health:IsDead() then
200 return FindEntity(inst, 25, function(guy)
201 if guy.components.combat then
202 return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy or guy:HasTag("monster")
203 end
204 end )
205 end
206 end )
207 inst.components.combat:SetKeepTargetFunction(function(inst, target) return target and target:IsValid() end )
208 inst:ListenForEvent("attacked", function(inst, data)
209 if data.attacker ~= GetPlayer() then
210 if not data.attacker:HasTag("myflys") then
211 inst.components.combat:SetTarget(data.attacker)
212 end
213 else
214 inst.components.health:Kill()
215 end
216 end )
217 inst:AddComponent("locomotor")
218 inst.components.locomotor.walkspeed = 25
219 inst:SetStateGraph("SGdragonfly")
220 local brain = require "brains/abigailbrain"
221 inst:SetBrain(brain)
222 inst:DoPeriodicTask(5, function()
223 if inst.components.combat and not inst.components.combat.target then
224 if inst.fire_build then
225 inst.sg:GoToState("flameoff")
226 end
227 if inst.components.health and inst.components.health:GetPercent() < 1 then
228 inst.components.health:DoDelta(200)
229 end
230 end
231 end )
232 inst:AddComponent("machine")
233 inst.components.machine.turnonfn = function()
234 inst:AddTag("inhaling")
235 inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
236 inst.task = inst:DoPeriodicTask(.5, function(inst)
237 local pos = Vector3(inst.Transform:GetWorldPosition())
238 local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, 15)
239 for k,v in pairs(ents) do
240 local pt1 = v:GetPosition()
241 if v.components.inventoryitem and v.components.inventoryitem.canbepickedup and v.components.inventoryitem.cangoincontainer
242 and not v.components.inventoryitem:IsHeld() and not v:HasTag("trap") and not v:HasTag("light") and not v:HasTag("blowdart")
243 and not v:HasTag("projectile") then
244 if not GetPlayer().components.inventory:IsFull() then
245 SpawnPrefab("small_puff").Transform:SetPosition(pt1.x, pt1.y, pt1.z)
246 GetPlayer().components.inventory:GiveItem(v)
247 GetPlayer().SoundEmitter:PlaySound("dontstarve/HUD/research_available")
248 end
249 end
250 end
251 end )
252 end
253 inst.components.machine.turnofffn = function()
254 inst:RemoveTag("inhaling")
255 inst.AnimState:SetBloomEffectHandle( "" )
256 if inst.task then inst.task:Cancel() inst.task = nil end
257 end
258 inst.components.inspectable.getstatus = function(inst)
259 if not inst:HasTag("stophere") then
260 inst:AddTag("stophere")
261 inst.components.locomotor:Stop()
262 inst:SetBrain(nil)
263 inst.components.follower:SetLeader(nil)
264 inst.sg:GoToState("flameoff")
265 else
266 inst:RemoveTag("stophere")
267 local brain = require "brains/abigailbrain"
268 inst:SetBrain(brain)
269 inst:RestartBrain()
270 inst.components.follower:SetLeader(GetPlayer())
271 end
272 end
273 inst:ListenForEvent("death", function()
274 inst.components.machine:TurnOff()
275 end )
276 inst:AddTag("companion")
277 inst:AddTag("myflys")
278 end
279 if data and data.stophere then
280 inst:AddTag("stophere")
281 inst.components.locomotor:Stop()
282 inst:SetBrain(nil)
283 inst.components.follower:SetLeader(nil)
284 inst.sg:GoToState("flameoff")
285 end
286 if data and data.inhaling then
287 inst.components.machine.ison = true
288 inst.components.machine:TurnOn()
289 end
290end
291 inst.OnSave = onsave
292 inst.OnLoad = onload
293
294 即可用蜻蜓盔甲种宠物蜻蜓,攻击力超强,并自动补血,是战斗时的好帮手。鼠标左键点蜻蜓,可让它停在原地,再次点击可继续跟随。鼠标右键点蜻蜓,可让它帮你捡地上的东西(快速吸取至主角物品栏),再次点击可停止捡东西。不想要宠物蜻蜓了,杀死即可(按Ctrl + 鼠标左键攻击),打一下即死。宠物蜻蜓攻击时会引发火灾,所以带它战斗时不要离基地太近,也不要同时带1个以上的宠物蜻蜓去战斗,否则容易互殴。蜻蜓盔甲在战斗选项(画着两把剑)下,用1个蜻蜓鳞片、1个木盔甲、3个猪皮制造