代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二一四.饥饿的儿童(不时有孤儿向你乞讨,施舍黄金后离开,否则跟随你直到午夜冻饿而死)
3
4 1.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/forest.lua文件,在inst:AddComponent("clock")的下一行插入以下内容:
5
6local function createbeggar(inst)
7 for k = 1,math.random(3,7) do
8 local pt = GetPlayer():GetPosition()
9 local beggar = SpawnPrefab("foliage")
10 beggar.Transform:SetPosition(pt.x+(math.random(50)-math.random(50)), 0, pt.z+(math.random(50)-math.random(50)))
11 beggar.AnimState:SetBank("wilson")
12 local names = {"wilson","wendy","wes","wickerbottom","willow","wolfgang","wx78"}
13 local buildname = names[math.random(#names)]
14 beggar.AnimState:SetBuild(buildname)
15 beggar.Transform:SetScale(0.8, 0.8, 0.8)
16 beggar.AnimState:OverrideSymbol("swap_body", "armor_grass", "swap_body")
17 beggar.AnimState:Hide("ARM_carry")
18 beggar.AnimState:Show("ARM_normal")
19 beggar.AnimState:PlayAnimation("idle")
20 local sound = beggar.entity:AddSoundEmitter()
21 local shadow = beggar.entity:AddDynamicShadow()
22 shadow:SetSize( 1.3, .6 )
23 beggar.Transform:SetFourFaced()
24 local brain = require "brains/chesterbrain"
25 beggar:SetBrain(brain)
26 beggar:AddComponent("knownlocations")
27 beggar:AddComponent("locomotor")
28 beggar.components.locomotor.walkspeed = 5
29 beggar.components.locomotor.runspeed = 15
30 beggar:SetStateGraph("SGshadowwaxwell")
31 MakeCharacterPhysics(beggar, 50, .5)
32 beggar:RemoveComponent("stackable")
33 beggar:RemoveComponent("tradable")
34 beggar:RemoveComponent("fuel")
35 beggar:RemoveComponent("inventoryitem")
36 beggar:RemoveComponent("edible")
37 beggar:RemoveComponent("perishable")
38 beggar:RemoveComponent("burnable")
39 beggar:RemoveComponent("propagator")
40 beggar:RemoveTag("cattoy")
41 beggar:AddComponent("follower")
42 beggar.components.follower:SetLeader(GetPlayer())
43 beggar:AddComponent("health")
44 beggar.components.health:SetMaxHealth(500)
45 beggar.components.health:SetInvincible(true)
46 beggar.components.health.nofadeout = true
47 beggar:AddComponent("combat")
48 beggar:DoPeriodicTask(math.random(10,60), function(beggar)
49 beggar.SoundEmitter:PlaySound("dontstarve/characters/willow/hurt")
50 beggar.AnimState:PlayAnimation("hungry")
51 end )
52 beggar:AddComponent("trader")
53 beggar.components.trader:SetAcceptTest(function(beggar, item)
54 if GetPlayer().components.inventory:Has("goldnugget", 10) then
55 if item.prefab == "goldnugget" then
56 return true
57 end
58 end
59 return false
60 end )
61 beggar.components.trader.onaccept = function(beggar, giver, item)
62 GetPlayer().components.inventory:ConsumeByName("goldnugget", 9)
63 GetPlayer().components.sanity:DoDelta(5)
64 beggar.components.locomotor:Stop()
65 beggar:SetBrain(nil)
66 beggar.components.follower:SetLeader(nil)
67 beggar.AnimState:PlayAnimation("idle_onemanband1_loop",true)
68 beggar:DoTaskInTime(5, function() beggar:Remove() end )
69 end
70 beggar:ListenForEvent( "nighttime", function()
71 beggar.components.locomotor:Stop()
72 beggar:SetBrain(nil)
73 beggar.components.follower:SetLeader(nil)
74 beggar.AnimState:PlayAnimation("idle_shiver_pre")
75 beggar.AnimState:PushAnimation("idle_shiver_loop")
76 beggar.AnimState:PushAnimation("idle_shiver_pst", false)
77 beggar:RemoveComponent("trader")
78 beggar:DoTaskInTime(math.random(1,6), function()
79 beggar.components.health:SetInvincible(false)
80 beggar.components.health:Kill()
81 end )
82 end, GetWorld())
83 beggar:ListenForEvent("death", function()
84 GetPlayer():DoTaskInTime(2, function()
85 GetPlayer().components.sanity:DoDelta(-10)
86 end )
87 end )
88 beggar:AddTag("beggars")
89 end
90end
91 inst:ListenForEvent( "daytime", function() if math.random()<.3 then createbeggar(inst) end end , GetWorld())
92
93
94 2.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/foliage.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
95
96local function onsave(inst, data)
97 if inst:HasTag("beggars") then
98 data.beggars = true
99 end
100end
101local function onload(inst, data)
102 if data and data.beggars then
103 inst.AnimState:SetBank("wilson")
104 local names = {"wilson","wendy","wes","wickerbottom","willow","wolfgang","wx78"}
105 local buildname = names[math.random(#names)]
106 inst.AnimState:SetBuild(buildname)
107 inst.Transform:SetScale(0.8, 0.8, 0.8)
108 inst.AnimState:OverrideSymbol("swap_body", "armor_grass", "swap_body")
109 inst.AnimState:Hide("ARM_carry")
110 inst.AnimState:Show("ARM_normal")
111 inst.AnimState:PlayAnimation("idle")
112 local sound = inst.entity:AddSoundEmitter()
113 local shadow = inst.entity:AddDynamicShadow()
114 shadow:SetSize( 1.3, .6 )
115 inst.Transform:SetFourFaced()
116 local brain = require "brains/chesterbrain"
117 inst:SetBrain(brain)
118 inst:AddComponent("knownlocations")
119 inst:AddComponent("locomotor")
120 inst.components.locomotor.walkspeed = 5
121 inst.components.locomotor.runspeed = 15
122 inst:SetStateGraph("SGshadowwaxwell")
123 MakeCharacterPhysics(inst, 50, .5)
124 inst:RemoveComponent("stackable")
125 inst:RemoveComponent("tradable")
126 inst:RemoveComponent("fuel")
127 inst:RemoveComponent("inventoryitem")
128 inst:RemoveComponent("edible")
129 inst:RemoveComponent("perishable")
130 inst:RemoveComponent("burnable")
131 inst:RemoveComponent("propagator")
132 inst:RemoveTag("cattoy")
133 inst:AddComponent("follower")
134 inst.components.follower:SetLeader(GetPlayer())
135 inst:AddComponent("health")
136 inst.components.health:SetMaxHealth(500)
137 inst.components.health:SetInvincible(true)
138 inst.components.health.nofadeout = true
139 inst:AddComponent("combat")
140 inst:DoPeriodicTask(math.random(10,60), function(inst)
141 inst.SoundEmitter:PlaySound("dontstarve/characters/willow/hurt")
142 inst.AnimState:PlayAnimation("hungry")
143 end )
144 inst:AddComponent("trader")
145 inst.components.trader:SetAcceptTest(function(inst, item)
146 if GetPlayer().components.inventory:Has("goldnugget", 10) then
147 if item.prefab == "goldnugget" then
148 return true
149 end
150 end
151 return false
152 end )
153 inst.components.trader.onaccept = function(inst, giver, item)
154 GetPlayer().components.inventory:ConsumeByName("goldnugget", 9)
155 GetPlayer().components.sanity:DoDelta(5)
156 inst.components.locomotor:Stop()
157 inst:SetBrain(nil)
158 inst.components.follower:SetLeader(nil)
159 inst.AnimState:PlayAnimation("idle_onemanband1_loop",true)
160 inst:DoTaskInTime(5, function() inst:Remove() end )
161 end
162 inst:ListenForEvent( "nighttime", function()
163 inst.components.locomotor:Stop()
164 inst:SetBrain(nil)
165 inst.components.follower:SetLeader(nil)
166 inst.AnimState:PlayAnimation("idle_shiver_pre")
167 inst.AnimState:PushAnimation("idle_shiver_loop")
168 inst.AnimState:PushAnimation("idle_shiver_pst", false)
169 inst:RemoveComponent("trader")
170 inst:DoTaskInTime(math.random(1,6), function()
171 inst.components.health:SetInvincible(false)
172 inst.components.health:Kill()
173 end )
174 end, GetWorld())
175 inst:ListenForEvent("death", function()
176 GetPlayer():DoTaskInTime(2, function()
177 GetPlayer().components.sanity:DoDelta(-10)
178 end )
179 end )
180 inst:AddTag("beggars")
181 end
182end
183 inst.OnSave = onsave
184 inst.OnLoad = onload
185
186 即可开启一个独特的游戏模式,在饥荒世界这苦寒之地,有许多失去亲人的儿童正在忍饥挨饿,已经站稳脚跟的你,有责任帮助他们。不时会有孤儿向你乞讨,只要10个黄金(拿着黄金对儿童点鼠标左键),就能给予他们几天的温饱(儿童将离开),你也会获得心灵的宁静(补5点脑)。如果你不愿付出,他们也不会给你添任何麻烦,只是默默地跟随,期盼着一点点施舍。当黑夜来临时,他们将在你眼前冻饿而死,苍天为之动容(你将降10点脑),痛惜一个幼小生命的逝去。何去何从,由你自己决定。不要与“荒野之狼”一同修改