代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2三0一.斗蜘蛛(用啜食者皮种斗蜘蛛场,购买迷你蜘蛛与庄家PK,赢奖金)
3
4 用MT管理器打开游戏目录/assets/scripts/prefabs/slurperpelt.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
5
6local colours=
7{
8 {198/255,43/255,43/255},
9 {79/255,153/255,68/255},
10 {35/255,105/255,235/255},
11 {233/255,208/255,69/255},
12 {109/255,50/255,163/255},
13 {222/255,126/255,39/255},
14}
15local function boxing(inst)
16 local pt = inst:GetPosition()
17 local boxer = SpawnPrefab("slurper_pelt")
18 boxer.Transform:SetPosition(pt.x, pt.y, pt.z)
19 boxer.AnimState:SetBank("wilson")
20 boxer.AnimState:SetBuild("wes")
21 boxer.AnimState:OverrideSymbol("swap_hat", "hat_top", "swap_hat")
22 boxer.AnimState:Show("HAT")
23 boxer.AnimState:Show("HAT_HAIR")
24 boxer.AnimState:Hide("HAIR_NOHAT")
25 boxer.AnimState:Hide("HAIR")
26 boxer.AnimState:Hide("ARM_carry")
27 boxer.AnimState:Show("ARM_normal")
28 boxer.Transform:SetFourFaced()
29 boxer.AnimState:PlayAnimation("idle")
30 boxer:RemoveComponent("stackable")
31 boxer:RemoveComponent("tradable")
32 boxer:RemoveComponent("inventoryitem")
33 boxer:RemoveComponent("edible")
34 boxer:RemoveComponent("deployable")
35 MakeLargeBurnable(boxer)
36 MakeLargePropagator(boxer)
37 boxer:AddTag("boxer")
38 boxer:AddComponent("trader")
39 boxer.components.trader:SetAcceptTest(function(boxer, item)
40 if GetPlayer().components.inventory:Has("goldnugget", 100) then
41 if item.prefab == "goldnugget" then
42 return true
43 end
44 end
45 return false
46 end )
47 boxer.components.trader.onaccept = function(boxer, giver, item)
48 GetPlayer().components.inventory:ConsumeByName("goldnugget", 99)
49 boxer.AnimState:PlayAnimation("give")
50 local cricket = SpawnPrefab("slurper_pelt")
51 cricket.Transform:SetPosition(pt.x+1.5, 0, pt.z+1.5)
52 cricket.AnimState:SetBank("spider_queen")
53 cricket.AnimState:SetBuild("spider_queen_build")
54 cricket.AnimState:PlayAnimation("idle", true)
55 cricket.Transform:SetFourFaced()
56 cricket.entity:AddSoundEmitter()
57 cricket.Transform:SetScale(0.3, 0.3, 0.3)
58 cricket.colour_idx = math.random(#colours)
59 cricket.AnimState:SetMultColour(colours[cricket.colour_idx][1],colours[cricket.colour_idx][2],colours[cricket.colour_idx][3],1)
60 cricket.components.inventoryitem:ChangeImageName("spidereggsack")
61 cricket:RemoveComponent("stackable")
62 cricket:RemoveComponent("tradable")
63 cricket:RemoveComponent("edible")
64 cricket:RemoveComponent("burnable")
65 cricket:RemoveComponent("propagator")
66 cricket:RemoveComponent("deployable")
67 local brain = require "brains/abigailbrain"
68 cricket:SetBrain(brain)
69 cricket:AddComponent("lootdropper")
70 cricket.components.lootdropper:SetLoot({"silk"})
71 cricket:AddComponent("locomotor")
72 cricket.components.locomotor.walkspeed = 5
73 cricket.components.locomotor.runspeed = 8
74 cricket:SetStateGraph("SGspiderqueen")
75 cricket:AddComponent("follower")
76 cricket.components.follower:SetLeader(GetPlayer())
77 cricket.health_num = math.random(100,300)
78 cricket.damage_num = math.random(20,50)
79 cricket:AddComponent("health")
80 cricket.components.health:SetMaxHealth(cricket.health_num)
81 cricket:AddComponent("trader")
82 cricket.components.trader:SetAcceptTest(function(cricket, item)
83 if item.prefab == "smallmeat" then
84 return cricket.components.health:GetPercent() < 1
85 end
86 return false
87 end )
88 cricket.components.trader.onaccept = function(cricket, giver, item)
89 cricket.components.health:DoDelta(300)
90 end
91 cricket:AddComponent("combat")
92 cricket.components.combat:SetRetargetFunction(1, function(cricket)
93 if not cricket.components.health:IsDead() then
94 return FindEntity(cricket, 20, function(guy)
95 if guy.components.health and not guy.components.health:IsDead() then
96 return guy:HasTag("cricket") or guy:HasTag("cricket0")
97 end
98 end )
99 end
100 end )
101 cricket.components.combat:SetKeepTargetFunction(function(cricket, target) return target and target:IsValid() end )
102 cricket.components.combat:SetAttackPeriod(2)
103 cricket.components.combat:SetRange(1, 2)
104 cricket.components.combat:SetDefaultDamage(cricket.damage_num)
105 cricket:AddTag("cricket")
106 end
107 boxer.components.inspectable.getstatus = function(boxer)
108 if not boxer:HasTag("startgame") then
109 if GetPlayer().components.inventory:Has("goldnugget", 100) then
110 local target0 = FindEntity(boxer, 30, function(guy)
111 return guy:HasTag("cricket") and guy.components.inventoryitem and not guy.components.inventoryitem:IsHeld()
112 end )
113 if target0 then
114 boxer:AddTag("startgame")
115 boxer.AnimState:PlayAnimation("give")
116 GetPlayer().components.playercontroller:Enable(false)
117 TheCamera:SetTarget(target0)
118 target0:RemoveComponent("inventoryitem")
119 boxer.task = boxer:DoPeriodicTask(1, function(boxer)
120 if target0.components.health:IsDead() then
121 if boxer.task then boxer.task:Cancel() boxer.task = nil end
122 GetPlayer().components.inventory:ConsumeByName("goldnugget", 100)
123 TheCamera:SetTarget(GetPlayer())
124 GetPlayer().SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
125 boxer.AnimState:PlayAnimation("idle_onemanband1_loop",true)
126 boxer:DoTaskInTime(2, function()
127 boxer.AnimState:PlayAnimation("idle")
128 local target1 = FindEntity(boxer, 30, function(guy)
129 return guy:HasTag("cricket0")
130 end )
131 if target1 then
132 target1:Remove()
133 end
134 boxer:RemoveTag("startgame")
135 GetPlayer().components.playercontroller:Enable(true)
136 end )
137 end
138 end )
139 local cricket0 = SpawnPrefab("slurper_pelt")
140 cricket0.Transform:SetPosition(pt.x+1.5, 0, pt.z+1.5)
141 cricket0.AnimState:SetBank("spider_queen")
142 cricket0.AnimState:SetBuild("spider_queen_build")
143 cricket0.AnimState:PlayAnimation("idle", true)
144 cricket0.Transform:SetFourFaced()
145 cricket0.entity:AddSoundEmitter()
146 cricket0.Transform:SetScale(0.3, 0.3, 0.3)
147 cricket0:RemoveComponent("stackable")
148 cricket0:RemoveComponent("tradable")
149 cricket0:RemoveComponent("inventoryitem")
150 cricket0:RemoveComponent("edible")
151 cricket0:RemoveComponent("burnable")
152 cricket0:RemoveComponent("propagator")
153 cricket0:RemoveComponent("deployable")
154 local brain = require "brains/abigailbrain"
155 cricket0:SetBrain(brain)
156 cricket0:AddComponent("lootdropper")
157 cricket0.components.lootdropper:SetLoot({"silk"})
158 cricket0:AddComponent("locomotor")
159 cricket0.components.locomotor.walkspeed = 5
160 cricket0.components.locomotor.runspeed = 8
161 cricket0:SetStateGraph("SGspiderqueen")
162 cricket0:AddComponent("follower")
163 cricket0.components.follower:SetLeader(boxer)
164 cricket0:AddComponent("health")
165 cricket0.components.health:SetMaxHealth(math.random(110,330))
166 cricket0:AddComponent("combat")
167 cricket0.components.combat:SetRetargetFunction(1, function(cricket0)
168 if not cricket0.components.health:IsDead() then
169 return FindEntity(cricket0, 20, function(guy)
170 if guy.components.health and not guy.components.health:IsDead() then
171 return guy:HasTag("cricket")
172 end
173 end )
174 end
175 end )
176 cricket0.components.combat:SetKeepTargetFunction(function(cricket0, target) return target and target:IsValid() end )
177 cricket0.components.combat:SetAttackPeriod(2)
178 cricket0.components.combat:SetRange(1, 2)
179 cricket0.components.combat:SetDefaultDamage(math.random(22,55))
180 cricket0:ListenForEvent("death", function()
181 boxer.AnimState:PlayAnimation("give")
182 if boxer.task then boxer.task:Cancel() boxer.task = nil end
183 for k = 1, 100 do
184 local goldnugget = SpawnPrefab("goldnugget")
185 GetPlayer().components.inventory:GiveItem(goldnugget)
186 end
187 boxer:RemoveTag("startgame")
188 GetPlayer().components.playercontroller:Enable(true)
189 TheCamera:SetTarget(GetPlayer())
190 target0:AddComponent("inventoryitem")
191 target0.components.inventoryitem:ChangeImageName("spidereggsack")
192 end )
193 cricket0:AddTag("cricket0")
194 cricket0:AddTag("goodbye")
195 end
196 end
197 end
198 end
199 local advert = SpawnPrefab("slurper_pelt")
200 advert.Transform:SetPosition(pt.x-2, 0, pt.z-2)
201 advert.AnimState:SetBank("barrel")
202 advert.AnimState:SetBuild("monkey_barrel")
203 advert.AnimState:PlayAnimation("idle", true)
204 advert.Transform:SetScale(1.5, 1.5, 1.5)
205 advert:RemoveComponent("stackable")
206 advert:RemoveComponent("tradable")
207 advert:RemoveComponent("inventoryitem")
208 advert:RemoveComponent("edible")
209 advert:RemoveComponent("deployable")
210 MakeLargeBurnable(advert)
211 MakeLargePropagator(advert)
212 advert:AddTag("lightningrod")
213 local light = advert.entity:AddLight()
214 light:SetFalloff(1)
215 light:SetIntensity(.8)
216 light:SetRadius(10)
217 light:SetColour(180/255, 195/255, 50/255)
218 light:Enable(true)
219 advert:DoPeriodicTask(6, function(advert)
220 advert.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
221 advert:DoTaskInTime(3, function(advert) advert.AnimState:SetBloomEffectHandle("") end )
222 end )
223 advert:AddTag("goodbye")
224end
225local function OnDeploy (inst, pt)
226 boxing(inst)
227 inst.components.stackable:Get():Remove()
228end
229 inst:AddComponent("deployable")
230 inst.components.deployable.ondeploy = OnDeploy
231local function onsave(inst, data)
232 if inst:HasTag("goodbye") then
233 data.goodbye = true
234 end
235 if inst:HasTag("boxer") then
236 data.boxer = true
237 end
238 if inst:HasTag("cricket") then
239 data.cricket = true
240 end
241 data.colour_idx = inst.colour_idx
242 data.health_num = inst.health_num
243 data.damage_num = inst.damage_num
244end
245local function onload(inst, data)
246 if data and data.goodbye then
247 inst:Remove()
248 end
249 if data and data.boxer then
250 boxing(inst)
251 inst:Remove()
252 end
253 if data and data.cricket then
254 inst.AnimState:SetBank("spider_queen")
255 inst.AnimState:SetBuild("spider_queen_build")
256 inst.AnimState:PlayAnimation("idle", true)
257 inst.Transform:SetFourFaced()
258 inst.entity:AddSoundEmitter()
259 inst.Transform:SetScale(0.3, 0.3, 0.3)
260 inst.colour_idx = math.random(#colours)
261 inst.AnimState:SetMultColour(colours[inst.colour_idx][1],colours[inst.colour_idx][2],colours[inst.colour_idx][3],1)
262 inst.components.inventoryitem:ChangeImageName("spidereggsack")
263 inst:RemoveComponent("stackable")
264 inst:RemoveComponent("tradable")
265 inst:RemoveComponent("edible")
266 inst:RemoveComponent("burnable")
267 inst:RemoveComponent("propagator")
268 inst:RemoveComponent("deployable")
269 local brain = require "brains/abigailbrain"
270 inst:SetBrain(brain)
271 inst:AddComponent("lootdropper")
272 inst.components.lootdropper:SetLoot({"silk"})
273 inst:AddComponent("locomotor")
274 inst.components.locomotor.walkspeed = 5
275 inst.components.locomotor.runspeed = 8
276 inst:SetStateGraph("SGspiderqueen")
277 inst:AddComponent("follower")
278 inst.components.follower:SetLeader(GetPlayer())
279 inst.health_num = math.random(100,300)
280 inst.damage_num = math.random(20,50)
281 inst:AddComponent("health")
282 inst.components.health:SetMaxHealth(inst.health_num)
283 inst:AddComponent("trader")
284 inst.components.trader:SetAcceptTest(function(inst, item)
285 if item.prefab == "smallmeat" then
286 return inst.components.health:GetPercent() < 1
287 end
288 return false
289 end )
290 inst.components.trader.onaccept = function(inst, giver, item)
291 inst.components.health:DoDelta(300)
292 end
293 inst:AddComponent("combat")
294 inst.components.combat:SetRetargetFunction(1, function(inst)
295 if not inst.components.health:IsDead() then
296 return FindEntity(inst, 20, function(guy)
297 if guy.components.health and not guy.components.health:IsDead() then
298 return guy:HasTag("cricket") or guy:HasTag("cricket0")
299 end
300 end )
301 end
302 end )
303 inst.components.combat:SetKeepTargetFunction(function(inst, target) return target and target:IsValid() end )
304 inst.components.combat:SetAttackPeriod(2)
305 inst.components.combat:SetRange(1, 2)
306 inst.components.combat:SetDefaultDamage(inst.damage_num)
307 inst:AddTag("cricket")
308 end
309 if data and data.colour_idx then
310 inst.colour_idx = math.min(#colours, data.colour_idx)
311 inst.AnimState:SetMultColour(colours[inst.colour_idx][1],colours[inst.colour_idx][2],colours[inst.colour_idx][3],1)
312 end
313 if data and data.health_num then
314 inst.health_num = data.health_num
315 inst.components.health:SetMaxHealth(inst.health_num)
316 inst.components.health:DoDelta(inst.components.health.maxhealth)
317 end
318 if data and data.damage_num then
319 inst.damage_num = data.damage_num
320 inst.components.combat:SetDefaultDamage(inst.damage_num)
321 end
322end
323 inst.OnSave = onsave
324 inst.OnLoad = onload
325
326 即可用啜食者皮种斗蜘蛛场(拿着1个啜食者皮对地面点鼠标右键,如果拿着多个啜食者皮,则不会种出来),给庄家100个黄金(拿着黄金对庄家点鼠标左键),可购买迷你蜘蛛,鼠标左键点蜘蛛,可将其放入物品栏,显示为蜘蛛卵的图标。如果想与庄家比赛,主角身上至少有100个黄金,将自己的一只蜘蛛放在庄家面前,鼠标左键点庄家,庄家会拿出另一只蜘蛛与你的蜘蛛PK。如果你赢了,将赢得100个黄金的奖金,如果输了就输掉100个黄金,并损失掉自己的蜘蛛。为防止作弊,比赛中主角操作将暂停,比赛结束后恢复。每只迷你蜘蛛的血量、攻击力都不同,如果你买到厉害的蜘蛛,一定要用心呵护,因为它就是你的摇钱树,给蜘蛛喂一块小肉(拿着小肉对蜘蛛点鼠标左键),可以为其补满血。你也可以多买几只蜘蛛,内部PK,挑选出好的品种,再与庄家对赌,会增大你的胜率。不想要斗蜘蛛场了,烧掉即可。啜食者皮可以打啜食者获得,也可在“巨型超市”中,花1-3个黄金购得