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

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



二九0.逝者的赌局(绳子种人骨,用黄金下注猪拳击手生死战)

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

local function OnDeploy (inst, pt)
	local skeleton = SpawnPrefab("skeleton")
	if skeleton then
		skeleton:PushEvent("growfromrope")
		skeleton.Transform:SetPosition(pt.x, pt.y, pt.z)
		inst.components.stackable:Get():Remove()
	end
end
	inst:AddComponent("deployable")
	inst.components.deployable.ondeploy = OnDeploy


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

local function game(inst)
	local light = inst.entity:AddLight()
	light:Enable(true)
	local num_found = 0
	for k,v in pairs(inst.components.container.slots) do
		if v and v.prefab == "goldnugget" then
		   num_found = num_found + v.components.stackable:StackSize()
		end
	end
	inst.components.container:Close(GetPlayer())
	inst.components.container.canbeopened = false
	GetPlayer().components.playercontroller:Enable(false)
	local bonuspoint1 = math.random(5)
	local bonuspoint2 = math.random(5)
	local pt = Vector3(inst.Transform:GetWorldPosition())
	local red = SpawnPrefab("pigman")
	red.Transform:SetPosition(pt.x+4+3, 0, pt.z+4-3)
	red.components.health:SetMaxHealth(100 * bonuspoint1)
	red.components.health:DoDelta(200 * bonuspoint1)
	red.AnimState:SetMultColour(255/255,0/255,0/255,1)
	red.AnimState:OverrideSymbol("swap_hat", "hat_football", "swap_hat")
	red.AnimState:Show("hat")
	local blue = SpawnPrefab("pigman")
	blue.Transform:SetPosition(pt.x+4-3, 0, pt.z+4+3)
	blue.components.health:SetMaxHealth(100 * bonuspoint2)
	blue.components.health:DoDelta(200 * bonuspoint2)
	blue.AnimState:SetMultColour(0/255,100/255,255/255,1)
	blue.AnimState:OverrideSymbol("swap_hat", "hat_football", "swap_hat")
	blue.AnimState:Show("hat")
	red.components.combat.target = blue
	blue.components.combat.target = red
	TheCamera:SetTarget(red)
	red:ListenForEvent("death", function()
		inst:DoTaskInTime(3, function() blue:Remove()
		   GetPlayer().components.sanity:DoDelta(-10)
		   GetPlayer().AnimState:PlayAnimation("hit")
		   GetPlayer().SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
		   inst.components.container:DestroyContents()
		   inst.components.container.canbeopened = true
		   GetPlayer().components.playercontroller:Enable(true)
		   TheCamera:SetTarget(GetPlayer())
		   light:Enable(false)
		end )
	end )
	blue:ListenForEvent("death", function()
		inst:DoTaskInTime(3, function() red:Remove()
		   GetPlayer().components.sanity:DoDelta(10)
		   for k = 1, num_found do
			   inst.components.container:ConsumeByName("goldnugget", -1)
		   end
		   GetPlayer().SoundEmitter:PlaySound("dontstarve/HUD/get_gold")
		   inst.components.container.canbeopened = true
		   GetPlayer().components.playercontroller:Enable(true)
		   TheCamera:SetTarget(GetPlayer())
		   light:Enable(false)
		end )
	end )
end
local slotpos = { Vector3(0,-75,0)}
local widgetbuttoninfo = { text = "GO",
	  position = Vector3(0, -165, 0),
	  fn = function(inst) if not inst.components.container:IsEmpty() then game(inst) end
end }
local function itemtest(inst, item, slot)
	if item.prefab == "goldnugget" then
	   return true
	end
	return false
end
	inst:AddComponent("container")
	inst.components.container:SetNumSlots(#slotpos)
	inst.components.container.widgetslotpos = slotpos
	inst.components.container.widgetpos = Vector3(0,200,0)
	inst.components.container.side_align_tip = 160
	inst.components.container.itemtestfn = itemtest
	inst.components.container.widgetbuttoninfo = widgetbuttoninfo
	local light = inst.entity:AddLight()
	light:SetFalloff(1)
	light:SetIntensity(.8)
	light:SetRadius(50)
	light:Enable(false)
	light:SetColour(180/255, 195/255, 50/255)
	MakeMediumBurnable(inst)

	即可用绳子种人骨头,鼠标左键点人骨,出现1个格子及GO按钮,在格子中放入黄金后(赌金随意)按GO按钮,红、蓝两个猪拳手出击对战,如果红方获胜,你就赢得1倍奖金(在人骨的格子里领取),并增加10点脑。如果蓝方获胜,格子里的赌金将被收走(逝者获胜),同时减10点脑。平局(双方同时死)判定为逝者获胜。比赛中主角无法走动及攻击(防止作弊),但可以边吃东西边看比赛。人骨最好种在远离猪房、兔房的空旷处,以免干扰比赛。不想要人骨了,烧掉即可。逝者的赌局全天开放,不要沉迷赌博哦