代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二九0.逝者的赌局(绳子种人骨,用黄金下注猪拳击手生死战)
3
4 1.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/rope.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
5
6local function OnDeploy (inst, pt)
7 local skeleton = SpawnPrefab("skeleton")
8 if skeleton then
9 skeleton:PushEvent("growfromrope")
10 skeleton.Transform:SetPosition(pt.x, pt.y, pt.z)
11 inst.components.stackable:Get():Remove()
12 end
13end
14 inst:AddComponent("deployable")
15 inst.components.deployable.ondeploy = OnDeploy
16
17
18 2.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/skeleton.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
19
20local function game(inst)
21 local light = inst.entity:AddLight()
22 light:Enable(true)
23 local num_found = 0
24 for k,v in pairs(inst.components.container.slots) do
25 if v and v.prefab == "goldnugget" then
26 num_found = num_found + v.components.stackable:StackSize()
27 end
28 end
29 inst.components.container:Close(GetPlayer())
30 inst.components.container.canbeopened = false
31 GetPlayer().components.playercontroller:Enable(false)
32 local bonuspoint1 = math.random(5)
33 local bonuspoint2 = math.random(5)
34 local pt = Vector3(inst.Transform:GetWorldPosition())
35 local red = SpawnPrefab("pigman")
36 red.Transform:SetPosition(pt.x+4+3, 0, pt.z+4-3)
37 red.components.health:SetMaxHealth(100 * bonuspoint1)
38 red.components.health:DoDelta(200 * bonuspoint1)
39 red.AnimState:SetMultColour(255/255,0/255,0/255,1)
40 red.AnimState:OverrideSymbol("swap_hat", "hat_football", "swap_hat")
41 red.AnimState:Show("hat")
42 local blue = SpawnPrefab("pigman")
43 blue.Transform:SetPosition(pt.x+4-3, 0, pt.z+4+3)
44 blue.components.health:SetMaxHealth(100 * bonuspoint2)
45 blue.components.health:DoDelta(200 * bonuspoint2)
46 blue.AnimState:SetMultColour(0/255,100/255,255/255,1)
47 blue.AnimState:OverrideSymbol("swap_hat", "hat_football", "swap_hat")
48 blue.AnimState:Show("hat")
49 red.components.combat.target = blue
50 blue.components.combat.target = red
51 TheCamera:SetTarget(red)
52 red:ListenForEvent("death", function()
53 inst:DoTaskInTime(3, function() blue:Remove()
54 GetPlayer().components.sanity:DoDelta(-10)
55 GetPlayer().AnimState:PlayAnimation("hit")
56 GetPlayer().SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
57 inst.components.container:DestroyContents()
58 inst.components.container.canbeopened = true
59 GetPlayer().components.playercontroller:Enable(true)
60 TheCamera:SetTarget(GetPlayer())
61 light:Enable(false)
62 end )
63 end )
64 blue:ListenForEvent("death", function()
65 inst:DoTaskInTime(3, function() red:Remove()
66 GetPlayer().components.sanity:DoDelta(10)
67 for k = 1, num_found do
68 inst.components.container:ConsumeByName("goldnugget", -1)
69 end
70 GetPlayer().SoundEmitter:PlaySound("dontstarve/HUD/get_gold")
71 inst.components.container.canbeopened = true
72 GetPlayer().components.playercontroller:Enable(true)
73 TheCamera:SetTarget(GetPlayer())
74 light:Enable(false)
75 end )
76 end )
77end
78local slotpos = { Vector3(0,-75,0)}
79local widgetbuttoninfo = { text = "GO",
80 position = Vector3(0, -165, 0),
81 fn = function(inst) if not inst.components.container:IsEmpty() then game(inst) end
82end }
83local function itemtest(inst, item, slot)
84 if item.prefab == "goldnugget" then
85 return true
86 end
87 return false
88end
89 inst:AddComponent("container")
90 inst.components.container:SetNumSlots(#slotpos)
91 inst.components.container.widgetslotpos = slotpos
92 inst.components.container.widgetpos = Vector3(0,200,0)
93 inst.components.container.side_align_tip = 160
94 inst.components.container.itemtestfn = itemtest
95 inst.components.container.widgetbuttoninfo = widgetbuttoninfo
96 local light = inst.entity:AddLight()
97 light:SetFalloff(1)
98 light:SetIntensity(.8)
99 light:SetRadius(50)
100 light:Enable(false)
101 light:SetColour(180/255, 195/255, 50/255)
102 MakeMediumBurnable(inst)
103
104 即可用绳子种人骨头,鼠标左键点人骨,出现1个格子及GO按钮,在格子中放入黄金后(赌金随意)按GO按钮,红、蓝两个猪拳手出击对战,如果红方获胜,你就赢得1倍奖金(在人骨的格子里领取),并增加10点脑。如果蓝方获胜,格子里的赌金将被收走(逝者获胜),同时减10点脑。平局(双方同时死)判定为逝者获胜。比赛中主角无法走动及攻击(防止作弊),但可以边吃东西边看比赛。人骨最好种在远离猪房、兔房的空旷处,以免干扰比赛。不想要人骨了,烧掉即可。逝者的赌局全天开放,不要沉迷赌博哦