代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。

原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html



二一七.角斗场(用铥矿石种角斗场,参与生死角斗赚奖金,也可观看比赛)

	用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/thulecite.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:

local names = {"swap_goldenaxe","swap_spear","swap_spike","swap_batbat","swap_ruins_bat"}
local weapon = names[math.random(#names)]
local items = { SWORD = weapon }
local function EquipItem(inst, item)
	if item then
	   inst.AnimState:OverrideSymbol("swap_object", item, item)
	   inst.AnimState:Show("ARM_carry") 
	   inst.AnimState:Hide("ARM_normal")
	end
end
	inst.items = items
	inst.equipfn = EquipItem
	EquipItem(inst)
local function fightgame(inst)
	local pt = inst:GetPosition()
	local gamehost = SpawnPrefab("thulecite")
	gamehost.Transform:SetPosition(pt.x, pt.y, pt.z)
	gamehost.AnimState:SetBank("wilson")
	gamehost.AnimState:SetBuild("wolfgang")
	gamehost.AnimState:OverrideSymbol("swap_hat", "hat_top", "swap_hat")
	gamehost.AnimState:Show("HAT")
	gamehost.AnimState:Show("HAT_HAIR")
	gamehost.AnimState:Hide("HAIR_NOHAT")
	gamehost.AnimState:Hide("HAIR")
	gamehost.AnimState:Hide("ARM_carry")
	gamehost.AnimState:Show("ARM_normal")
	gamehost.Transform:SetFourFaced()
	gamehost.AnimState:PlayAnimation("idle")
	gamehost:RemoveComponent("repairer")
	gamehost:RemoveComponent("edible")
	gamehost:RemoveComponent("tradable")
	gamehost:RemoveComponent("inventoryitem")
	gamehost:RemoveComponent("stackable")
	gamehost:RemoveComponent("deployable")
	gamehost:RemoveComponent("bait")
	gamehost:RemoveTag("molebait")
	gamehost:AddTag("gamehost")
	gamehost:AddComponent("workable")
	gamehost.components.workable:SetWorkAction(ACTIONS.HAMMER)
	gamehost.components.workable:SetWorkLeft(3)
	gamehost.components.workable:SetOnFinishCallback(function(gamehost)
		local pos = Vector3(gamehost.Transform:GetWorldPosition())
		local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, 50)
		for k,v in pairs(ents) do
			if v:HasTag("candel") then
			   SpawnPrefab("collapse_big").Transform:SetPosition(v.Transform:GetWorldPosition())
			   GetPlayer().SoundEmitter:PlaySound("dontstarve/common/destroy_wood")
			   v:Remove()
			end
		end
		gamehost:Remove()
	end )
	local fountain = SpawnPrefab("thulecite")
	fountain.Transform:SetPosition(pt.x-11, 0, pt.z-11)
	fountain.AnimState:SetBank("staff_purple_base")
	fountain.AnimState:SetBuild("staff_purple_base")
	fountain.AnimState:PlayAnimation("idle_full_loop")
	fountain.Transform:SetScale(1.5, 1.5, 1.5)
	fountain.AnimState:SetOrientation( ANIM_ORIENTATION.OnGround )
	fountain.AnimState:SetLayer( LAYER_BACKGROUND )
	fountain.AnimState:SetSortOrder( 1 )
	fountain.Transform:SetRotation( 45 )
	fountain:AddTag("NOCLICK")
	fountain:RemoveComponent("repairer")
	fountain:RemoveComponent("edible")
	fountain:RemoveComponent("tradable")
	fountain:RemoveComponent("inventoryitem")
	fountain:RemoveComponent("stackable")
	fountain:RemoveComponent("deployable")
	fountain:RemoveComponent("bait")
	fountain:RemoveTag("molebait")
	local light = fountain.entity:AddLight()
	light:SetFalloff(1)
	light:SetIntensity(.8)
	light:SetRadius(18)
	light:SetColour(180/255, 195/255, 50/255)
	light:Enable(true)
	fountain:AddTag("candel")
	local pt0 = Vector3(fountain.Transform:GetWorldPosition())
	for k = 1, 60 do
		local result_offset = FindValidPositionByFan(1 * 2 * PI, 12, 60, function(offset)
			local x,y,z = (pt0 + offset):Get()
			local ents = TheSim:FindEntities(x,y,z , 1)
			return not next(ents) 
		end)
		if result_offset then
		   local fence = SpawnPrefab("thulecite")
		   fence.AnimState:SetBank("marble_pillar")
		   fence.AnimState:SetBuild("marble_pillar")
		   fence.AnimState:PlayAnimation("full")
		   MakeObstaclePhysics(fence, 1)
		   fence:RemoveComponent("repairer")
		   fence:RemoveComponent("edible")
		   fence:RemoveComponent("tradable")
		   fence:RemoveComponent("inventoryitem")
		   fence:RemoveComponent("stackable")
		   fence:RemoveComponent("deployable")
		   fence:RemoveComponent("bait")
		   fence:RemoveTag("molebait")
		   fence:AddTag("candel")
		   fence.Transform:SetPosition((pt0 + result_offset):Get())
		end
	end
	gamehost:AddComponent("trader")
	gamehost.components.trader:SetAcceptTest(function(gamehost, item) 
	  if not gamehost:HasTag("startgame") then
		if GetPlayer().components.inventory:Has("goldnugget", 100) then
		   if item.prefab == "goldnugget" then
			  return true
		   end
		end
	  end
	  return false
	end )
	gamehost.components.trader.onaccept = function(gamehost, giver, item)
		GetPlayer().components.inventory:ConsumeByName("goldnugget", 99)
		GetPlayer().components.locomotor:Stop()
		GetPlayer().Transform:SetPosition(pt.x-11+5, 0, pt.z-11-5)
		GetPlayer().SoundEmitter:PlaySound("dontstarve/common/horn_beefalo")
		gamehost:AddTag("startgame")
		local warrior0 = SpawnPrefab("thulecite")
		warrior0.Transform:SetPosition(pt.x-11-5, 0, pt.z-11+5)
		warrior0.AnimState:SetBank("wilson")
		local names = {"wilson","wendy","wes","wickerbottom","willow","wolfgang","wx78"}
		local buildname = names[math.random(#names)]
		warrior0.AnimState:SetBuild(buildname)
		local hats = {"hat_beefalo","hat_feather","hat_football","hat_ruins","hat_slurper","hat_slurtle","hat_spider"}
		local hat = hats[math.random(#hats)]
		warrior0.AnimState:OverrideSymbol("swap_hat", hat, "swap_hat")
		local armors = {"armor_grass","armor_marble","armor_ruins","armor_sanity","armor_slurper","armor_wood"}
		local armor = armors[math.random(#armors)]
		warrior0.AnimState:OverrideSymbol("swap_body", armor, "swap_body")
		warrior0.AnimState:Show("HAT")
		warrior0.AnimState:Show("HAT_HAIR")
		warrior0.AnimState:Hide("HAIR_NOHAT")
		warrior0.AnimState:Hide("HAIR")
		warrior0.AnimState:Hide("ARM_carry")
		warrior0.AnimState:Show("ARM_normal")
		warrior0.AnimState:PlayAnimation("idle")
		warrior0.Transform:SetFourFaced()
		local sound = warrior0.entity:AddSoundEmitter()
		local shadow = warrior0.entity:AddDynamicShadow()
		shadow:SetSize( 1.3, .6 )
		local brain = require "brains/frogbrain"
		warrior0:SetBrain(brain)
		warrior0:AddComponent("locomotor")
		warrior0.components.locomotor.walkspeed = 5
		warrior0.components.locomotor.runspeed = 10
		warrior0:SetStateGraph("SGshadowwaxwell")
		MakeCharacterPhysics(warrior0, 75, .5)
		warrior0:RemoveComponent("repairer")
		warrior0:RemoveComponent("edible")
		warrior0:RemoveComponent("tradable")
		warrior0:RemoveComponent("inventoryitem")
		warrior0:RemoveComponent("stackable")
		warrior0:RemoveComponent("deployable")
		warrior0:RemoveComponent("bait")
		warrior0:RemoveTag("molebait")
		warrior0:AddComponent("inventory")
		warrior0:AddComponent("knownlocations")
		warrior0:AddComponent("health")
		warrior0.components.health:SetMaxHealth(math.random(2500,5000))
		warrior0:AddComponent("combat")
		warrior0.components.combat:SetDefaultDamage(math.random(25,50))
		warrior0.components.combat:SetAttackPeriod(2)
		warrior0.components.combat:SetRetargetFunction(1, function(warrior0)
			if not warrior0.components.health:IsDead() then
				return FindEntity(warrior0, 30, function(guy)
					return guy:HasTag("player")
				end )
			end
		end )
		warrior0:DoPeriodicTask(1, function(warrior0)
			if not warrior0:HasTag("noplay") then
			   if warrior0.components.health.currenthealth <= 100 then
				  warrior0:AddTag("noplay")
				  warrior0.components.combat:SetTarget(nil)
				  warrior0.components.combat:SetRetargetFunction(100, nil )
			   end
			   if GetPlayer().components.health.currenthealth <= 51 then
				  warrior0.components.locomotor:Stop()
				  warrior0:SetBrain(nil)
				  warrior0:AddTag("noplay")
				  warrior0.components.combat:SetTarget(nil)
				  warrior0.components.combat:SetRetargetFunction(100, nil )
				  warrior0.components.health:SetInvincible(true)
				  warrior0.AnimState:PlayAnimation("idle_onemanband1_loop",true)
				  GetPlayer().SoundEmitter:PlaySound("dontstarve/HUD/get_gold")
				  gamehost:DoTaskInTime(3, function()
					  warrior0:Remove()
					  GetPlayer().components.locomotor:Stop()
					  GetPlayer().Transform:SetPosition(pt.x-1, 0, pt.z+1)
					  if gamehost.task then gamehost.task:Cancel() gamehost.task = nil end
					  gamehost:RemoveTag("startgame")
				  end )
			   end
			end
		end )
		warrior0:ListenForEvent("death", function()
			GetPlayer().SoundEmitter:PlaySound("dontstarve/HUD/get_gold")
			gamehost:DoTaskInTime(3, function()
				GetPlayer().components.locomotor:Stop()
				GetPlayer().Transform:SetPosition(pt.x-1, 0, pt.z+1)
				for k = 1, 200 do
					local goldnugget = SpawnPrefab("goldnugget")
					GetPlayer().components.inventory:GiveItem(goldnugget)
				end
				if gamehost.task then gamehost.task:Cancel() gamehost.task = nil end
				gamehost:RemoveTag("startgame")
			end )
		end )
		warrior0:AddTag("candel")
		gamehost.task = gamehost:DoPeriodicTask(1, function(gamehost)
			local target = FindEntity(fountain, 13, function(guy) 
				return guy:HasTag("player")
			end )
			if not target then
			   GetPlayer().SoundEmitter:PlaySound("dontstarve/HUD/get_gold")
			   warrior0:Remove()
			   if gamehost.task then gamehost.task:Cancel() gamehost.task = nil end
			   gamehost:RemoveTag("startgame")
			end
		end )
	end
	gamehost.components.inspectable.getstatus = function(gamehost)
		if not gamehost:HasTag("startgame") then
		   if GetPlayer().components.inventory:Has("goldnugget", 20) then
			  GetPlayer().components.inventory:ConsumeByName("goldnugget", 20)
			  GetPlayer().SoundEmitter:PlaySound("dontstarve/common/horn_beefalo")
			  gamehost:AddTag("startgame")
			  local warrior1 = SpawnPrefab("thulecite")
			  warrior1.Transform:SetPosition(pt.x-11+5, 0, pt.z-11-5)
			  warrior1.AnimState:SetBank("wilson")
			  local names = {"wilson","wendy","wes","wickerbottom","willow","wolfgang","wx78"}
			  local buildname = names[math.random(#names)]
			  warrior1.AnimState:SetBuild(buildname)
			  local hats = {"hat_beefalo","hat_feather","hat_football","hat_ruins","hat_slurper","hat_slurtle","hat_spider"}
			  local hat = hats[math.random(#hats)]
			  warrior1.AnimState:OverrideSymbol("swap_hat", hat, "swap_hat")
			  local armors = {"armor_grass","armor_marble","armor_ruins","armor_sanity","armor_slurper","armor_wood"}
			  local armor = armors[math.random(#armors)]
			  warrior1.AnimState:OverrideSymbol("swap_body", armor, "swap_body")
			  warrior1.AnimState:Show("HAT")
			  warrior1.AnimState:Show("HAT_HAIR")
			  warrior1.AnimState:Hide("HAIR_NOHAT")
			  warrior1.AnimState:Hide("HAIR")
			  warrior1.AnimState:Hide("ARM_carry")
			  warrior1.AnimState:Show("ARM_normal")
			  warrior1.AnimState:PlayAnimation("idle")
			  warrior1.Transform:SetFourFaced()
			  local sound = warrior1.entity:AddSoundEmitter()
			  local shadow = warrior1.entity:AddDynamicShadow()
			  shadow:SetSize( 1.3, .6 )
			  local brain = require "brains/frogbrain"
			  warrior1:SetBrain(brain)
			  warrior1:AddComponent("locomotor")
			  warrior1.components.locomotor.walkspeed = 5
			  warrior1.components.locomotor.runspeed = 10
			  warrior1:SetStateGraph("SGshadowwaxwell")
			  MakeCharacterPhysics(warrior1, 75, .5)
			  warrior1:RemoveComponent("repairer")
			  warrior1:RemoveComponent("edible")
			  warrior1:RemoveComponent("tradable")
			  warrior1:RemoveComponent("inventoryitem")
			  warrior1:RemoveComponent("stackable")
			  warrior1:RemoveComponent("deployable")
			  warrior1:RemoveComponent("bait")
			  warrior1:RemoveTag("molebait")
			  warrior1:AddComponent("inventory")
			  warrior1:AddComponent("knownlocations")
			  warrior1:AddComponent("health")
			  warrior1.components.health:SetMaxHealth(math.random(200,500))
			  warrior1:AddComponent("combat")
			  warrior1.components.combat:SetDefaultDamage(math.random(25,100))
			  warrior1.components.combat:SetAttackPeriod(3)
			  warrior1.components.combat:SetRetargetFunction(1, function(warrior1)
				  if not warrior1.components.health:IsDead() then
					  return FindEntity(warrior1, 30, function(guy)
						  return guy:HasTag("warrior2")
					  end )
				  end
			  end )
			  warrior1:AddTag("warrior1")
			  warrior1:AddTag("candel")
			  local warrior2 = SpawnPrefab("thulecite")
			  warrior2.Transform:SetPosition(pt.x-11-5, 0, pt.z-11+5)
			  warrior2.AnimState:SetBank("wilson")
			  local names = {"wilson","wendy","wes","wickerbottom","willow","wolfgang","wx78"}
			  local buildname = names[math.random(#names)]
			  warrior2.AnimState:SetBuild(buildname)
			  local hats = {"hat_beefalo","hat_feather","hat_football","hat_ruins","hat_slurper","hat_slurtle","hat_spider"}
			  local hat = hats[math.random(#hats)]
			  warrior2.AnimState:OverrideSymbol("swap_hat", hat, "swap_hat")
			  local armors = {"armor_grass","armor_marble","armor_ruins","armor_sanity","armor_slurper","armor_wood"}
			  local armor = armors[math.random(#armors)]
			  warrior2.AnimState:OverrideSymbol("swap_body", armor, "swap_body")
			  warrior2.AnimState:Show("HAT")
			  warrior2.AnimState:Show("HAT_HAIR")
			  warrior2.AnimState:Hide("HAIR_NOHAT")
			  warrior2.AnimState:Hide("HAIR")
			  warrior2.AnimState:Hide("ARM_carry")
			  warrior2.AnimState:Show("ARM_normal")
			  warrior2.AnimState:PlayAnimation("idle")
			  warrior2.Transform:SetFourFaced()
			  local sound = warrior2.entity:AddSoundEmitter()
			  local shadow = warrior2.entity:AddDynamicShadow()
			  shadow:SetSize( 1.3, .6 )
			  local brain = require "brains/frogbrain"
			  warrior2:SetBrain(brain)
			  warrior2:AddComponent("locomotor")
			  warrior2.components.locomotor.walkspeed = 5
			  warrior2.components.locomotor.runspeed = 10
			  warrior2:SetStateGraph("SGshadowwaxwell")
			  MakeCharacterPhysics(warrior2, 75, .5)
			  warrior2:RemoveComponent("repairer")
			  warrior2:RemoveComponent("edible")
			  warrior2:RemoveComponent("tradable")
			  warrior2:RemoveComponent("inventoryitem")
			  warrior2:RemoveComponent("stackable")
			  warrior2:RemoveComponent("deployable")
			  warrior2:RemoveComponent("bait")
			  warrior2:RemoveTag("molebait")
			  warrior2:AddComponent("inventory")
			  warrior2:AddComponent("knownlocations")
			  warrior2:AddComponent("health")
			  warrior2.components.health:SetMaxHealth(math.random(200,500))
			  warrior2:AddComponent("combat")
			  warrior2.components.combat:SetDefaultDamage(math.random(25,100))
			  warrior2.components.combat:SetAttackPeriod(3)
			  warrior2.components.combat:SetRetargetFunction(1, function(warrior2)
				  if not warrior2.components.health:IsDead() then
					  return FindEntity(warrior2, 30, function(guy)
						  return guy:HasTag("warrior1")
					  end )
				  end
			  end )
			  warrior2:AddTag("warrior2")
			  warrior2:AddTag("candel")
			  warrior1:DoPeriodicTask(1, function(warrior1)
				  if not warrior1:HasTag("noplay") and not warrior2:HasTag("noplay") then
					 if warrior1.components.health.currenthealth <= 100 then
						warrior1:AddTag("noplay")
						warrior1.components.combat:SetTarget(nil)
						warrior1.components.combat:SetRetargetFunction(100, nil )
					 end
				  end
			  end )
			  warrior2:DoPeriodicTask(1, function(warrior2)
				  if not warrior2:HasTag("noplay") and not warrior1:HasTag("noplay") then
					 if warrior2.components.health.currenthealth <= 100 then
						warrior2:AddTag("noplay")
						warrior2.components.combat:SetTarget(nil)
						warrior2.components.combat:SetRetargetFunction(100, nil )
					 end
				  end
			  end )
			  warrior1:ListenForEvent("death", function()
				  GetPlayer().SoundEmitter:PlaySound("dontstarve/HUD/get_gold")
				  warrior2.components.locomotor:Stop()
				  warrior2:SetBrain(nil)
				  warrior2.AnimState:PlayAnimation("idle_onemanband1_loop",true)
				  gamehost:DoTaskInTime(3, function() warrior2:Remove() gamehost:RemoveTag("startgame") end )
			  end )
			  warrior2:ListenForEvent("death", function()
				  GetPlayer().SoundEmitter:PlaySound("dontstarve/HUD/get_gold")
				  warrior1.components.locomotor:Stop()
				  warrior1:SetBrain(nil)
				  warrior1.AnimState:PlayAnimation("idle_onemanband1_loop",true)
				  gamehost:DoTaskInTime(3, function() warrior1:Remove() gamehost:RemoveTag("startgame") end )
			  end )
		   end
		end
	end
end
local function OnDeploy (inst, pt)
	fightgame(inst)
	inst.components.stackable:Get():Remove()
end
	inst:AddComponent("deployable")
	inst.components.deployable.ondeploy = OnDeploy
local function onsave(inst, data)
	if inst:HasTag("candel") then
		data.candel = true
	end
	if inst:HasTag("gamehost") then
		data.gamehost = true
	end
end
local function onload(inst, data)
	if data and data.candel then
	   inst:Remove()
	end
	if data and data.gamehost then
	   fightgame(inst)
	   inst:Remove()
	end
end
	inst.OnSave = onsave
	inst.OnLoad = onload

	即可在开阔的空地上,用铥矿石种角斗场,(拿着1个铥矿石对地面点鼠标右键,如果拿着多个铥矿石,则不会种出来)。当身上有20个黄金时,鼠标左键点老板,可以观看一场角斗。如果想参加角斗,就给老板100个黄金(拿着黄金对老板点鼠标左键),你将进入角斗场与其他角斗士对战。如果击败对手,将获得本金加奖金共200个黄金;如果你的血量小于50,则判定你失败,对手会饶你不死,但本金将不会退回;如果你逃出围墙,同样判定你失败。每次与你对战的对手都不同,如果上一次失败,不代表下次不会胜利哦,作个职业的角斗士吧