代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二一七.角斗场(用铥矿石种角斗场,参与生死角斗赚奖金,也可观看比赛)
3
4 用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/thulecite.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
5
6local names = {"swap_goldenaxe","swap_spear","swap_spike","swap_batbat","swap_ruins_bat"}
7local weapon = names[math.random(#names)]
8local items = { SWORD = weapon }
9local function EquipItem(inst, item)
10 if item then
11 inst.AnimState:OverrideSymbol("swap_object", item, item)
12 inst.AnimState:Show("ARM_carry")
13 inst.AnimState:Hide("ARM_normal")
14 end
15end
16 inst.items = items
17 inst.equipfn = EquipItem
18 EquipItem(inst)
19local function fightgame(inst)
20 local pt = inst:GetPosition()
21 local gamehost = SpawnPrefab("thulecite")
22 gamehost.Transform:SetPosition(pt.x, pt.y, pt.z)
23 gamehost.AnimState:SetBank("wilson")
24 gamehost.AnimState:SetBuild("wolfgang")
25 gamehost.AnimState:OverrideSymbol("swap_hat", "hat_top", "swap_hat")
26 gamehost.AnimState:Show("HAT")
27 gamehost.AnimState:Show("HAT_HAIR")
28 gamehost.AnimState:Hide("HAIR_NOHAT")
29 gamehost.AnimState:Hide("HAIR")
30 gamehost.AnimState:Hide("ARM_carry")
31 gamehost.AnimState:Show("ARM_normal")
32 gamehost.Transform:SetFourFaced()
33 gamehost.AnimState:PlayAnimation("idle")
34 gamehost:RemoveComponent("repairer")
35 gamehost:RemoveComponent("edible")
36 gamehost:RemoveComponent("tradable")
37 gamehost:RemoveComponent("inventoryitem")
38 gamehost:RemoveComponent("stackable")
39 gamehost:RemoveComponent("deployable")
40 gamehost:RemoveComponent("bait")
41 gamehost:RemoveTag("molebait")
42 gamehost:AddTag("gamehost")
43 gamehost:AddComponent("workable")
44 gamehost.components.workable:SetWorkAction(ACTIONS.HAMMER)
45 gamehost.components.workable:SetWorkLeft(3)
46 gamehost.components.workable:SetOnFinishCallback(function(gamehost)
47 local pos = Vector3(gamehost.Transform:GetWorldPosition())
48 local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, 50)
49 for k,v in pairs(ents) do
50 if v:HasTag("candel") then
51 SpawnPrefab("collapse_big").Transform:SetPosition(v.Transform:GetWorldPosition())
52 GetPlayer().SoundEmitter:PlaySound("dontstarve/common/destroy_wood")
53 v:Remove()
54 end
55 end
56 gamehost:Remove()
57 end )
58 local fountain = SpawnPrefab("thulecite")
59 fountain.Transform:SetPosition(pt.x-11, 0, pt.z-11)
60 fountain.AnimState:SetBank("staff_purple_base")
61 fountain.AnimState:SetBuild("staff_purple_base")
62 fountain.AnimState:PlayAnimation("idle_full_loop")
63 fountain.Transform:SetScale(1.5, 1.5, 1.5)
64 fountain.AnimState:SetOrientation( ANIM_ORIENTATION.OnGround )
65 fountain.AnimState:SetLayer( LAYER_BACKGROUND )
66 fountain.AnimState:SetSortOrder( 1 )
67 fountain.Transform:SetRotation( 45 )
68 fountain:AddTag("NOCLICK")
69 fountain:RemoveComponent("repairer")
70 fountain:RemoveComponent("edible")
71 fountain:RemoveComponent("tradable")
72 fountain:RemoveComponent("inventoryitem")
73 fountain:RemoveComponent("stackable")
74 fountain:RemoveComponent("deployable")
75 fountain:RemoveComponent("bait")
76 fountain:RemoveTag("molebait")
77 local light = fountain.entity:AddLight()
78 light:SetFalloff(1)
79 light:SetIntensity(.8)
80 light:SetRadius(18)
81 light:SetColour(180/255, 195/255, 50/255)
82 light:Enable(true)
83 fountain:AddTag("candel")
84 local pt0 = Vector3(fountain.Transform:GetWorldPosition())
85 for k = 1, 60 do
86 local result_offset = FindValidPositionByFan(1 * 2 * PI, 12, 60, function(offset)
87 local x,y,z = (pt0 + offset):Get()
88 local ents = TheSim:FindEntities(x,y,z , 1)
89 return not next(ents)
90 end)
91 if result_offset then
92 local fence = SpawnPrefab("thulecite")
93 fence.AnimState:SetBank("marble_pillar")
94 fence.AnimState:SetBuild("marble_pillar")
95 fence.AnimState:PlayAnimation("full")
96 MakeObstaclePhysics(fence, 1)
97 fence:RemoveComponent("repairer")
98 fence:RemoveComponent("edible")
99 fence:RemoveComponent("tradable")
100 fence:RemoveComponent("inventoryitem")
101 fence:RemoveComponent("stackable")
102 fence:RemoveComponent("deployable")
103 fence:RemoveComponent("bait")
104 fence:RemoveTag("molebait")
105 fence:AddTag("candel")
106 fence.Transform:SetPosition((pt0 + result_offset):Get())
107 end
108 end
109 gamehost:AddComponent("trader")
110 gamehost.components.trader:SetAcceptTest(function(gamehost, item)
111 if not gamehost:HasTag("startgame") then
112 if GetPlayer().components.inventory:Has("goldnugget", 100) then
113 if item.prefab == "goldnugget" then
114 return true
115 end
116 end
117 end
118 return false
119 end )
120 gamehost.components.trader.onaccept = function(gamehost, giver, item)
121 GetPlayer().components.inventory:ConsumeByName("goldnugget", 99)
122 GetPlayer().components.locomotor:Stop()
123 GetPlayer().Transform:SetPosition(pt.x-11+5, 0, pt.z-11-5)
124 GetPlayer().SoundEmitter:PlaySound("dontstarve/common/horn_beefalo")
125 gamehost:AddTag("startgame")
126 local warrior0 = SpawnPrefab("thulecite")
127 warrior0.Transform:SetPosition(pt.x-11-5, 0, pt.z-11+5)
128 warrior0.AnimState:SetBank("wilson")
129 local names = {"wilson","wendy","wes","wickerbottom","willow","wolfgang","wx78"}
130 local buildname = names[math.random(#names)]
131 warrior0.AnimState:SetBuild(buildname)
132 local hats = {"hat_beefalo","hat_feather","hat_football","hat_ruins","hat_slurper","hat_slurtle","hat_spider"}
133 local hat = hats[math.random(#hats)]
134 warrior0.AnimState:OverrideSymbol("swap_hat", hat, "swap_hat")
135 local armors = {"armor_grass","armor_marble","armor_ruins","armor_sanity","armor_slurper","armor_wood"}
136 local armor = armors[math.random(#armors)]
137 warrior0.AnimState:OverrideSymbol("swap_body", armor, "swap_body")
138 warrior0.AnimState:Show("HAT")
139 warrior0.AnimState:Show("HAT_HAIR")
140 warrior0.AnimState:Hide("HAIR_NOHAT")
141 warrior0.AnimState:Hide("HAIR")
142 warrior0.AnimState:Hide("ARM_carry")
143 warrior0.AnimState:Show("ARM_normal")
144 warrior0.AnimState:PlayAnimation("idle")
145 warrior0.Transform:SetFourFaced()
146 local sound = warrior0.entity:AddSoundEmitter()
147 local shadow = warrior0.entity:AddDynamicShadow()
148 shadow:SetSize( 1.3, .6 )
149 local brain = require "brains/frogbrain"
150 warrior0:SetBrain(brain)
151 warrior0:AddComponent("locomotor")
152 warrior0.components.locomotor.walkspeed = 5
153 warrior0.components.locomotor.runspeed = 10
154 warrior0:SetStateGraph("SGshadowwaxwell")
155 MakeCharacterPhysics(warrior0, 75, .5)
156 warrior0:RemoveComponent("repairer")
157 warrior0:RemoveComponent("edible")
158 warrior0:RemoveComponent("tradable")
159 warrior0:RemoveComponent("inventoryitem")
160 warrior0:RemoveComponent("stackable")
161 warrior0:RemoveComponent("deployable")
162 warrior0:RemoveComponent("bait")
163 warrior0:RemoveTag("molebait")
164 warrior0:AddComponent("inventory")
165 warrior0:AddComponent("knownlocations")
166 warrior0:AddComponent("health")
167 warrior0.components.health:SetMaxHealth(math.random(2500,5000))
168 warrior0:AddComponent("combat")
169 warrior0.components.combat:SetDefaultDamage(math.random(25,50))
170 warrior0.components.combat:SetAttackPeriod(2)
171 warrior0.components.combat:SetRetargetFunction(1, function(warrior0)
172 if not warrior0.components.health:IsDead() then
173 return FindEntity(warrior0, 30, function(guy)
174 return guy:HasTag("player")
175 end )
176 end
177 end )
178 warrior0:DoPeriodicTask(1, function(warrior0)
179 if not warrior0:HasTag("noplay") then
180 if warrior0.components.health.currenthealth <= 100 then
181 warrior0:AddTag("noplay")
182 warrior0.components.combat:SetTarget(nil)
183 warrior0.components.combat:SetRetargetFunction(100, nil )
184 end
185 if GetPlayer().components.health.currenthealth <= 51 then
186 warrior0.components.locomotor:Stop()
187 warrior0:SetBrain(nil)
188 warrior0:AddTag("noplay")
189 warrior0.components.combat:SetTarget(nil)
190 warrior0.components.combat:SetRetargetFunction(100, nil )
191 warrior0.components.health:SetInvincible(true)
192 warrior0.AnimState:PlayAnimation("idle_onemanband1_loop",true)
193 GetPlayer().SoundEmitter:PlaySound("dontstarve/HUD/get_gold")
194 gamehost:DoTaskInTime(3, function()
195 warrior0:Remove()
196 GetPlayer().components.locomotor:Stop()
197 GetPlayer().Transform:SetPosition(pt.x-1, 0, pt.z+1)
198 if gamehost.task then gamehost.task:Cancel() gamehost.task = nil end
199 gamehost:RemoveTag("startgame")
200 end )
201 end
202 end
203 end )
204 warrior0:ListenForEvent("death", function()
205 GetPlayer().SoundEmitter:PlaySound("dontstarve/HUD/get_gold")
206 gamehost:DoTaskInTime(3, function()
207 GetPlayer().components.locomotor:Stop()
208 GetPlayer().Transform:SetPosition(pt.x-1, 0, pt.z+1)
209 for k = 1, 200 do
210 local goldnugget = SpawnPrefab("goldnugget")
211 GetPlayer().components.inventory:GiveItem(goldnugget)
212 end
213 if gamehost.task then gamehost.task:Cancel() gamehost.task = nil end
214 gamehost:RemoveTag("startgame")
215 end )
216 end )
217 warrior0:AddTag("candel")
218 gamehost.task = gamehost:DoPeriodicTask(1, function(gamehost)
219 local target = FindEntity(fountain, 13, function(guy)
220 return guy:HasTag("player")
221 end )
222 if not target then
223 GetPlayer().SoundEmitter:PlaySound("dontstarve/HUD/get_gold")
224 warrior0:Remove()
225 if gamehost.task then gamehost.task:Cancel() gamehost.task = nil end
226 gamehost:RemoveTag("startgame")
227 end
228 end )
229 end
230 gamehost.components.inspectable.getstatus = function(gamehost)
231 if not gamehost:HasTag("startgame") then
232 if GetPlayer().components.inventory:Has("goldnugget", 20) then
233 GetPlayer().components.inventory:ConsumeByName("goldnugget", 20)
234 GetPlayer().SoundEmitter:PlaySound("dontstarve/common/horn_beefalo")
235 gamehost:AddTag("startgame")
236 local warrior1 = SpawnPrefab("thulecite")
237 warrior1.Transform:SetPosition(pt.x-11+5, 0, pt.z-11-5)
238 warrior1.AnimState:SetBank("wilson")
239 local names = {"wilson","wendy","wes","wickerbottom","willow","wolfgang","wx78"}
240 local buildname = names[math.random(#names)]
241 warrior1.AnimState:SetBuild(buildname)
242 local hats = {"hat_beefalo","hat_feather","hat_football","hat_ruins","hat_slurper","hat_slurtle","hat_spider"}
243 local hat = hats[math.random(#hats)]
244 warrior1.AnimState:OverrideSymbol("swap_hat", hat, "swap_hat")
245 local armors = {"armor_grass","armor_marble","armor_ruins","armor_sanity","armor_slurper","armor_wood"}
246 local armor = armors[math.random(#armors)]
247 warrior1.AnimState:OverrideSymbol("swap_body", armor, "swap_body")
248 warrior1.AnimState:Show("HAT")
249 warrior1.AnimState:Show("HAT_HAIR")
250 warrior1.AnimState:Hide("HAIR_NOHAT")
251 warrior1.AnimState:Hide("HAIR")
252 warrior1.AnimState:Hide("ARM_carry")
253 warrior1.AnimState:Show("ARM_normal")
254 warrior1.AnimState:PlayAnimation("idle")
255 warrior1.Transform:SetFourFaced()
256 local sound = warrior1.entity:AddSoundEmitter()
257 local shadow = warrior1.entity:AddDynamicShadow()
258 shadow:SetSize( 1.3, .6 )
259 local brain = require "brains/frogbrain"
260 warrior1:SetBrain(brain)
261 warrior1:AddComponent("locomotor")
262 warrior1.components.locomotor.walkspeed = 5
263 warrior1.components.locomotor.runspeed = 10
264 warrior1:SetStateGraph("SGshadowwaxwell")
265 MakeCharacterPhysics(warrior1, 75, .5)
266 warrior1:RemoveComponent("repairer")
267 warrior1:RemoveComponent("edible")
268 warrior1:RemoveComponent("tradable")
269 warrior1:RemoveComponent("inventoryitem")
270 warrior1:RemoveComponent("stackable")
271 warrior1:RemoveComponent("deployable")
272 warrior1:RemoveComponent("bait")
273 warrior1:RemoveTag("molebait")
274 warrior1:AddComponent("inventory")
275 warrior1:AddComponent("knownlocations")
276 warrior1:AddComponent("health")
277 warrior1.components.health:SetMaxHealth(math.random(200,500))
278 warrior1:AddComponent("combat")
279 warrior1.components.combat:SetDefaultDamage(math.random(25,100))
280 warrior1.components.combat:SetAttackPeriod(3)
281 warrior1.components.combat:SetRetargetFunction(1, function(warrior1)
282 if not warrior1.components.health:IsDead() then
283 return FindEntity(warrior1, 30, function(guy)
284 return guy:HasTag("warrior2")
285 end )
286 end
287 end )
288 warrior1:AddTag("warrior1")
289 warrior1:AddTag("candel")
290 local warrior2 = SpawnPrefab("thulecite")
291 warrior2.Transform:SetPosition(pt.x-11-5, 0, pt.z-11+5)
292 warrior2.AnimState:SetBank("wilson")
293 local names = {"wilson","wendy","wes","wickerbottom","willow","wolfgang","wx78"}
294 local buildname = names[math.random(#names)]
295 warrior2.AnimState:SetBuild(buildname)
296 local hats = {"hat_beefalo","hat_feather","hat_football","hat_ruins","hat_slurper","hat_slurtle","hat_spider"}
297 local hat = hats[math.random(#hats)]
298 warrior2.AnimState:OverrideSymbol("swap_hat", hat, "swap_hat")
299 local armors = {"armor_grass","armor_marble","armor_ruins","armor_sanity","armor_slurper","armor_wood"}
300 local armor = armors[math.random(#armors)]
301 warrior2.AnimState:OverrideSymbol("swap_body", armor, "swap_body")
302 warrior2.AnimState:Show("HAT")
303 warrior2.AnimState:Show("HAT_HAIR")
304 warrior2.AnimState:Hide("HAIR_NOHAT")
305 warrior2.AnimState:Hide("HAIR")
306 warrior2.AnimState:Hide("ARM_carry")
307 warrior2.AnimState:Show("ARM_normal")
308 warrior2.AnimState:PlayAnimation("idle")
309 warrior2.Transform:SetFourFaced()
310 local sound = warrior2.entity:AddSoundEmitter()
311 local shadow = warrior2.entity:AddDynamicShadow()
312 shadow:SetSize( 1.3, .6 )
313 local brain = require "brains/frogbrain"
314 warrior2:SetBrain(brain)
315 warrior2:AddComponent("locomotor")
316 warrior2.components.locomotor.walkspeed = 5
317 warrior2.components.locomotor.runspeed = 10
318 warrior2:SetStateGraph("SGshadowwaxwell")
319 MakeCharacterPhysics(warrior2, 75, .5)
320 warrior2:RemoveComponent("repairer")
321 warrior2:RemoveComponent("edible")
322 warrior2:RemoveComponent("tradable")
323 warrior2:RemoveComponent("inventoryitem")
324 warrior2:RemoveComponent("stackable")
325 warrior2:RemoveComponent("deployable")
326 warrior2:RemoveComponent("bait")
327 warrior2:RemoveTag("molebait")
328 warrior2:AddComponent("inventory")
329 warrior2:AddComponent("knownlocations")
330 warrior2:AddComponent("health")
331 warrior2.components.health:SetMaxHealth(math.random(200,500))
332 warrior2:AddComponent("combat")
333 warrior2.components.combat:SetDefaultDamage(math.random(25,100))
334 warrior2.components.combat:SetAttackPeriod(3)
335 warrior2.components.combat:SetRetargetFunction(1, function(warrior2)
336 if not warrior2.components.health:IsDead() then
337 return FindEntity(warrior2, 30, function(guy)
338 return guy:HasTag("warrior1")
339 end )
340 end
341 end )
342 warrior2:AddTag("warrior2")
343 warrior2:AddTag("candel")
344 warrior1:DoPeriodicTask(1, function(warrior1)
345 if not warrior1:HasTag("noplay") and not warrior2:HasTag("noplay") then
346 if warrior1.components.health.currenthealth <= 100 then
347 warrior1:AddTag("noplay")
348 warrior1.components.combat:SetTarget(nil)
349 warrior1.components.combat:SetRetargetFunction(100, nil )
350 end
351 end
352 end )
353 warrior2:DoPeriodicTask(1, function(warrior2)
354 if not warrior2:HasTag("noplay") and not warrior1:HasTag("noplay") then
355 if warrior2.components.health.currenthealth <= 100 then
356 warrior2:AddTag("noplay")
357 warrior2.components.combat:SetTarget(nil)
358 warrior2.components.combat:SetRetargetFunction(100, nil )
359 end
360 end
361 end )
362 warrior1:ListenForEvent("death", function()
363 GetPlayer().SoundEmitter:PlaySound("dontstarve/HUD/get_gold")
364 warrior2.components.locomotor:Stop()
365 warrior2:SetBrain(nil)
366 warrior2.AnimState:PlayAnimation("idle_onemanband1_loop",true)
367 gamehost:DoTaskInTime(3, function() warrior2:Remove() gamehost:RemoveTag("startgame") end )
368 end )
369 warrior2:ListenForEvent("death", function()
370 GetPlayer().SoundEmitter:PlaySound("dontstarve/HUD/get_gold")
371 warrior1.components.locomotor:Stop()
372 warrior1:SetBrain(nil)
373 warrior1.AnimState:PlayAnimation("idle_onemanband1_loop",true)
374 gamehost:DoTaskInTime(3, function() warrior1:Remove() gamehost:RemoveTag("startgame") end )
375 end )
376 end
377 end
378 end
379end
380local function OnDeploy (inst, pt)
381 fightgame(inst)
382 inst.components.stackable:Get():Remove()
383end
384 inst:AddComponent("deployable")
385 inst.components.deployable.ondeploy = OnDeploy
386local function onsave(inst, data)
387 if inst:HasTag("candel") then
388 data.candel = true
389 end
390 if inst:HasTag("gamehost") then
391 data.gamehost = true
392 end
393end
394local function onload(inst, data)
395 if data and data.candel then
396 inst:Remove()
397 end
398 if data and data.gamehost then
399 fightgame(inst)
400 inst:Remove()
401 end
402end
403 inst.OnSave = onsave
404 inst.OnLoad = onload
405
406 即可在开阔的空地上,用铥矿石种角斗场,(拿着1个铥矿石对地面点鼠标右键,如果拿着多个铥矿石,则不会种出来)。当身上有20个黄金时,鼠标左键点老板,可以观看一场角斗。如果想参加角斗,就给老板100个黄金(拿着黄金对老板点鼠标左键),你将进入角斗场与其他角斗士对战。如果击败对手,将获得本金加奖金共200个黄金;如果你的血量小于50,则判定你失败,对手会饶你不死,但本金将不会退回;如果你逃出围墙,同样判定你失败。每次与你对战的对手都不同,如果上一次失败,不代表下次不会胜利哦,作个职业的角斗士吧