代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二00.养育孩子(主角逝去则孩子接班,一代一代生存下去)
3
4 1.用MT管理器打开游戏目录/assets/scripts/prefabs/minotaurhorn.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
5
6local function getson (inst)
7 TheFrontEnd:Fade(false,1)
8 GetPlayer():DoTaskInTime(1.5, function()
9 TheFrontEnd:Fade(true,1)
10 local pt = GetPlayer():GetPosition()
11 local son = SpawnPrefab("resurrectionstatue")
12 son.Transform:SetPosition(pt.x, pt.y, pt.z)
13 son.AnimState:SetBank("wilson")
14 if GetPlayer().prefab == "wilson" then son.AnimState:SetBuild("wilson") end
15 if GetPlayer().prefab == "wendy" then son.AnimState:SetBuild("wendy") end
16 if GetPlayer().prefab == "wes" then son.AnimState:SetBuild("wes") end
17 if GetPlayer().prefab == "wickerbottom" then son.AnimState:SetBuild("wickerbottom") end
18 if GetPlayer().prefab == "willow" then son.AnimState:SetBuild("willow") end
19 if GetPlayer().prefab == "wolfgang" then son.AnimState:SetBuild("wolfgang_skinny") end
20 if GetPlayer().prefab == "wx78" then son.AnimState:SetBuild("wx78") end
21 if GetPlayer().prefab == "woodie" then son.AnimState:SetBuild("woodie") end
22 if GetPlayer().prefab == "waxwell" then son.AnimState:SetBuild("waxwell") end
23 if GetPlayer().prefab == "wathgrithr" then son.AnimState:SetBuild("wathgrithr") end
24 if GetPlayer().prefab == "webber" then son.AnimState:SetBuild("webber") end
25 local hats = {"hat_beefalo","hat_feather","hat_flower","hat_top","hat_walrus","hat_winter"}
26 local hat = hats[math.random(#hats)]
27 son.AnimState:OverrideSymbol("swap_hat", hat, "swap_hat")
28 local armors = {"armor_sanity","armor_slurper","armor_sweatervest","armor_trunkvest_summer","armor_trunkvest_winter"}
29 local armor = armors[math.random(#armors)]
30 son.AnimState:OverrideSymbol("swap_body", armor, "swap_body")
31 son.AnimState:Show("HAT")
32 son.AnimState:Show("HAT_HAIR")
33 son.AnimState:Hide("HAIR_NOHAT")
34 son.AnimState:Hide("HAIR")
35 son.AnimState:Hide("ARM_carry")
36 son.AnimState:Show("ARM_normal")
37 son.AnimState:PlayAnimation("idle")
38 son.AnimState:Hide("snow")
39 son.Transform:SetFourFaced()
40 son.Transform:SetScale(0.8,0.8,0.8)
41 son:AddComponent("combat")
42 son.components.combat.hiteffectsymbol = "torso"
43 son.components.combat:SetRetargetFunction(3, function(son)
44 if not son.components.health:IsDead() then
45 return FindEntity(son, 20, function(guy)
46 if guy.components.health and not guy.components.health:IsDead() then
47 return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy
48 end
49 end)
50 end
51 end )
52 son.components.combat:SetKeepTargetFunction(function(son, target) return target and target:IsValid() end )
53 son.components.combat:SetAttackPeriod(1)
54 son.components.combat:SetRange(2, 3)
55 son.components.combat:SetDefaultDamage(10)
56 son:AddComponent("health")
57 son.components.health:SetMaxHealth(1000)
58 son.components.health.nofadeout = true
59 son:AddComponent("inventory")
60 son.components.inventory.dropondeath = false
61 son:AddComponent("locomotor")
62 son.components.locomotor.pathcaps = { ignorecreep = true }
63 son.components.locomotor.runspeed = 12
64 local brain = require"brains/shadowwaxwellbrain"
65 son:SetBrain(brain)
66 son:SetStateGraph("SGshadowwaxwell")
67 son:RemoveComponent("lootdropper")
68 son:RemoveComponent("workable")
69 son:RemoveComponent("burnable")
70 son:RemoveComponent("propagator")
71 MakeCharacterPhysics(son, 75, .5)
72 son:RemoveTag("structure")
73 son:AddComponent("follower")
74 son.components.follower.leader = GetPlayer()
75 son:AddComponent("trader")
76 son.components.trader:SetAcceptTest(function(son, item)
77 if GetPlayer().components.inventory:Has("goldnugget", 5) then
78 if item.prefab == "goldnugget" and son.components.health and not son.components.health:IsDead() then
79 return son.components.health:GetPercent() < .99
80 end
81 end
82 return false
83 end )
84 son.components.trader.onaccept = function(son, giver, item)
85 GetPlayer().components.inventory:ConsumeByName("goldnugget", 4)
86 son.components.health:DoDelta(1000)
87 end
88 son:AddComponent("machine")
89 son.components.machine.turnonfn = function() son.components.locomotor:Stop() son.brain:Stop() end
90 son.components.machine.turnofffn = function() son.brain:Start() end
91 son:ListenForEvent("death", function()
92 GetPlayer().components.sanity:DoDelta(-100)
93 SpawnPrefab("trinket_1").Transform:SetPosition(son.Transform:GetWorldPosition())
94 end )
95 son:AddTag("companion")
96 son:AddTag("sons")
97 inst:Remove()
98 end )
99end
100local function OnDeploy (inst, pt)
101 if GetPlayer().components.inventory:Has("goldnugget", 100) then
102 GetPlayer().components.inventory:ConsumeByName("goldnugget", 100)
103 local egg1 = SpawnPrefab("minotaurhorn")
104 egg1.AnimState:SetBuild("tallbird_egg")
105 egg1.AnimState:SetBank("egg")
106 egg1.AnimState:PlayAnimation("egg")
107 egg1.Transform:SetPosition(pt.x+2+3, pt.y, pt.z+2-3)
108 egg1.AnimState:SetMultColour(0/255,255/255,0/255,1)
109 egg1.Transform:SetScale(1.5,1.5,1.5)
110 egg1:AddComponent("health")
111 egg1.components.health:SetMaxHealth(1)
112 egg1:AddComponent("combat")
113 egg1:RemoveComponent("edible")
114 egg1.components.inventoryitem.canbepickedup = false
115 local egg2 = SpawnPrefab("minotaurhorn")
116 egg2.AnimState:SetBuild("tallbird_egg")
117 egg2.AnimState:SetBank("egg")
118 egg2.AnimState:PlayAnimation("egg")
119 egg2.Transform:SetPosition(pt.x+2-3, pt.y, pt.z+2+3)
120 egg2.AnimState:SetMultColour(0/255,255/255,0/255,1)
121 egg2.Transform:SetScale(1.5,1.5,1.5)
122 egg2:AddComponent("health")
123 egg2.components.health:SetMaxHealth(1)
124 egg2:AddComponent("combat")
125 egg2:RemoveComponent("edible")
126 egg2.components.inventoryitem.canbepickedup = false
127 egg1:ListenForEvent("death", function() egg1.AnimState:PlayAnimation("crack") egg2:Remove()
128 if math.random()<.5 then
129 local pt = GetPlayer():GetPosition()
130 GetSeasonManager():DoLightningStrike(pt)
131 inst:DoTaskInTime(1, function() getson(inst) end )
132 else
133 SpawnPrefab("collapse_small").Transform:SetPosition(egg1.Transform:GetWorldPosition())
134 GetPlayer().SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
135 end
136 end )
137 egg2:ListenForEvent("death", function() egg2.AnimState:PlayAnimation("crack") egg1:Remove()
138 if math.random()<.5 then
139 local pt = GetPlayer():GetPosition()
140 GetSeasonManager():DoLightningStrike(pt)
141 inst:DoTaskInTime(2, function() getson(inst) end )
142 else
143 SpawnPrefab("collapse_small").Transform:SetPosition(egg2.Transform:GetWorldPosition())
144 GetPlayer().SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
145 end
146 end )
147 end
148end
149 inst:AddComponent("deployable")
150 inst.components.deployable.ondeploy = OnDeploy
151
152
153 2.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/resurrectionstatue.lua文件,将下列内容:
154
155 inst.OnSave = onsave
156 inst.OnLoad = onload
157
158 替换为:
159
160local items = { AXE = "swap_axe", PICK = "swap_pickaxe", SWORD = "swap_spear" }
161local function EquipItem(inst, item)
162 if item then
163 inst.AnimState:OverrideSymbol("swap_object", item, item)
164 inst.AnimState:Show("ARM_carry")
165 inst.AnimState:Hide("ARM_normal")
166 end
167end
168 inst.items = items
169 inst.equipfn = EquipItem
170 EquipItem(inst)
171local function onsave2(inst, data)
172 if inst:HasTag("sons") then
173 data.sons = true
174 end
175end
176local function onload2(inst, data)
177 if data and data.sons then
178 inst.AnimState:SetBank("wilson")
179 if GetPlayer().prefab == "wilson" then inst.AnimState:SetBuild("wilson") end
180 if GetPlayer().prefab == "wendy" then inst.AnimState:SetBuild("wendy") end
181 if GetPlayer().prefab == "wes" then inst.AnimState:SetBuild("wes") end
182 if GetPlayer().prefab == "wickerbottom" then inst.AnimState:SetBuild("wickerbottom") end
183 if GetPlayer().prefab == "willow" then inst.AnimState:SetBuild("willow") end
184 if GetPlayer().prefab == "wolfgang" then inst.AnimState:SetBuild("wolfgang_skinny") end
185 if GetPlayer().prefab == "wx78" then inst.AnimState:SetBuild("wx78") end
186 if GetPlayer().prefab == "woodie" then inst.AnimState:SetBuild("woodie") end
187 if GetPlayer().prefab == "waxwell" then inst.AnimState:SetBuild("waxwell") end
188 if GetPlayer().prefab == "wathgrithr" then inst.AnimState:SetBuild("wathgrithr") end
189 if GetPlayer().prefab == "webber" then inst.AnimState:SetBuild("webber") end
190 local hats = {"hat_beefalo","hat_feather","hat_flower","hat_top","hat_walrus","hat_winter"}
191 local hat = hats[math.random(#hats)]
192 inst.AnimState:OverrideSymbol("swap_hat", hat, "swap_hat")
193 local armors = {"armor_sanity","armor_slurper","armor_sweatervest","armor_trunkvest_summer","armor_trunkvest_winter"}
194 local armor = armors[math.random(#armors)]
195 inst.AnimState:OverrideSymbol("swap_body", armor, "swap_body")
196 inst.AnimState:Show("HAT")
197 inst.AnimState:Show("HAT_HAIR")
198 inst.AnimState:Hide("HAIR_NOHAT")
199 inst.AnimState:Hide("HAIR")
200 inst.AnimState:Hide("ARM_carry")
201 inst.AnimState:Show("ARM_normal")
202 inst.AnimState:PlayAnimation("idle")
203 inst.AnimState:Hide("snow")
204 inst.Transform:SetFourFaced()
205 inst.Transform:SetScale(0.8,0.8,0.8)
206 inst:AddComponent("combat")
207 inst.components.combat.hiteffectsymbol = "torso"
208 inst.components.combat:SetRetargetFunction(3, function(inst)
209 if not inst.components.health:IsDead() then
210 return FindEntity(inst, 20, function(guy)
211 if guy.components.health and not guy.components.health:IsDead() then
212 return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy
213 end
214 end)
215 end
216 end )
217 inst.components.combat:SetKeepTargetFunction(function(inst, target) return target and target:IsValid() end )
218 inst.components.combat:SetAttackPeriod(1)
219 inst.components.combat:SetRange(2, 3)
220 inst.components.combat:SetDefaultDamage(10)
221 inst:AddComponent("health")
222 inst.components.health:SetMaxHealth(1000)
223 inst.components.health.nofadeout = true
224 inst:AddComponent("inventory")
225 inst.components.inventory.dropondeath = false
226 inst:AddComponent("locomotor")
227 inst.components.locomotor.pathcaps = { ignorecreep = true }
228 inst.components.locomotor.runspeed = 12
229 local brain = require"brains/shadowwaxwellbrain"
230 inst:SetBrain(brain)
231 inst:SetStateGraph("SGshadowwaxwell")
232 inst:RemoveComponent("lootdropper")
233 inst:RemoveComponent("workable")
234 inst:RemoveComponent("burnable")
235 inst:RemoveComponent("propagator")
236 MakeCharacterPhysics(inst, 75, .5)
237 inst:RemoveTag("structure")
238 inst:AddComponent("follower")
239 inst.components.follower.leader = GetPlayer()
240 inst:AddComponent("trader")
241 inst.components.trader:SetAcceptTest(function(inst, item)
242 if GetPlayer().components.inventory:Has("goldnugget", 5) then
243 if item.prefab == "goldnugget" and inst.components.health and not inst.components.health:IsDead() then
244 return inst.components.health:GetPercent() < .99
245 end
246 end
247 return false
248 end )
249 inst.components.trader.onaccept = function(inst, giver, item)
250 GetPlayer().components.inventory:ConsumeByName("goldnugget", 4)
251 inst.components.health:DoDelta(1000)
252 end
253 inst:AddComponent("machine")
254 inst.components.machine.turnonfn = function() inst.components.locomotor:Stop() inst.brain:Stop() end
255 inst.components.machine.turnofffn = function() inst.brain:Start() end
256 inst:ListenForEvent("death", function()
257 GetPlayer().components.sanity:DoDelta(-100)
258 SpawnPrefab("trinket_1").Transform:SetPosition(inst.Transform:GetWorldPosition())
259 end )
260 inst:AddTag("companion")
261 inst:AddTag("sons")
262 end
263end
264 inst.OnSave = onsave2
265 inst.OnLoad = onload2
266
267 即可在你攒够100个黄金时,将远古守护者角种在地上,向上天求子,会赐予你2个蛋(身上黄金数不足时,只收走远古守护者角,不给蛋),选一个打破,如果中了(屏幕黑一下),就会获得孩子,如果没中(生一团烟),就只能下次再试了。使用不同主角,将获得不同的孩子,可以带着他打仗、砍树、开矿。如果你死了,他将长大成人,继承你的事业,一代一代在饥荒世界里生存下去。如果他不幸夭折了,对你而言无疑是晴天霹雳(减100点脑),他将为你留下一件小小的遗物,让你永远不要忘记他。当遇到危险时,可以对他点鼠标右键,让他停留在原地,等危险排除了,再对他按右键,即可继续跟随。可以通过给零花钱为他补血(拿着黄金对他点鼠标左键),一次5个黄金,身上黄金数不足或孩子满血时拒收。注意未成年人是不会跟着你下地洞的,把他安顿好后再去刷怪吧