代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二一九.铁血蛮族(蛮族霸占虫洞,打死可得肉类、装备,带瓦丝格雷斯帽不被攻击,用大肉收买蛮族做手下)
3
4 1.用MT管理器打开游戏目录/assets/scripts/prefabs/wormhole.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
5
6local function createsavage(inst)
7 for k = 1,math.random(10,15) do
8 local pt = inst:GetPosition()
9 local savage = SpawnPrefab("hammer")
10 savage.Transform:SetPosition(pt.x+(math.random(30)-math.random(30)), 0, pt.z+(math.random(30)-math.random(30)))
11 savage.AnimState:SetBank("wilson")
12 savage.AnimState:SetBuild("wolfgang")
13 savage.AnimState:OverrideSymbol("swap_hat", "hat_wathgrithr", "swap_hat")
14 savage.AnimState:OverrideSymbol("swap_body", "torso_rain", "swap_body")
15 savage.AnimState:OverrideSymbol("swap_object", "swap_spear_wathgrithr", "swap_spear_wathgrithr")
16 savage.AnimState:Show("HAT")
17 savage.AnimState:Show("HAT_HAIR")
18 savage.AnimState:Hide("HAIR_NOHAT")
19 savage.AnimState:Hide("HAIR")
20 savage.AnimState:Hide("ARM_normal")
21 savage.AnimState:Show("ARM_carry")
22 savage.AnimState:PlayAnimation("idle")
23 savage.Transform:SetScale(1.2, 1.2, 1.2)
24 local sound = savage.entity:AddSoundEmitter()
25 local shadow = savage.entity:AddDynamicShadow()
26 shadow:SetSize( 1.3, .6 )
27 savage.Transform:SetFourFaced()
28 MakeCharacterPhysics(savage, 100, .5)
29 local minimap = savage.entity:AddMiniMapEntity()
30 minimap:SetIcon( "wolfgang.png" )
31 savage:AddComponent("locomotor")
32 savage.components.locomotor.walkspeed = 4
33 savage.components.locomotor.runspeed = 8
34 savage:SetStateGraph("SGshadowwaxwell")
35 local brain = require "brains/leifbrain"
36 savage:SetBrain(brain)
37 savage:RemoveComponent("weapon")
38 savage:RemoveComponent("tool")
39 savage:RemoveComponent("finiteuses")
40 savage:RemoveComponent("inventoryitem")
41 savage:RemoveComponent("equippable")
42 savage:RemoveTag("hammer")
43 savage:AddComponent("inventory")
44 savage:AddComponent("health")
45 savage.components.health:SetMaxHealth(2000)
46 savage:ListenForEvent("death", function()
47 local pt1 = savage:GetPosition()
48 for k = 1,math.random(5,10) do
49 local meatnames = {"meat","smallmeat","drumstick"}
50 local meatname = meatnames[math.random(#meatnames)]
51 local meat = SpawnPrefab(meatname)
52 meat.Transform:SetPosition(pt1.x+(math.random(3)-math.random(3)), 0, pt1.z+(math.random(3)-math.random(3)))
53 end
54 if math.random() < 0.01 then
55 local lootnames = {"spear_wathgrithr","wathgrithrhat"}
56 local lootname = lootnames[math.random(#lootnames)]
57 local loot = SpawnPrefab(lootname)
58 loot.Transform:SetPosition(pt1.x, 0, pt1.z)
59 end
60 end )
61 savage:AddComponent("combat")
62 savage.components.combat:SetDefaultDamage(30)
63 savage.components.combat:SetAttackPeriod(1.5)
64 savage.components.combat:SetRetargetFunction(3, function(savage)
65 if not savage.components.health:IsDead() then
66 return FindEntity(savage, 20, function(guy)
67 return savage.components.combat:CanTarget(guy) and not guy:HasTag("savages") and not guy:HasTag("goodsavages")
68 end )
69 end
70 end )
71 savage.components.combat:SetKeepTargetFunction(function(savage, target) return target and target:IsValid() end )
72 savage:ListenForEvent("attacked", function(savage, data)
73 savage.components.combat:SetTarget(data.attacker)
74 savage.components.combat:ShareTarget(data.attacker, 30, function(dude) return dude:HasTag("savages") and not dude:HasTag("mysavage") and not dude.components.health:IsDead() end, 5)
75 end )
76 savage.Physics:SetCollisionCallback(function(savage, other)
77 if other and other.components.workable and other.components.workable.workleft > 0 then
78 other.components.workable:Destroy(savage)
79 end
80 end)
81 savage:ListenForEvent( "nighttime", function() savage:Remove() end , GetWorld())
82 savage:AddComponent("trader")
83 savage.components.trader:SetAcceptTest(function(savage, item)
84 if GetPlayer():HasTag("goodsavages") then
85 if GetPlayer().components.inventory:Has("meat", 10) then
86 if item.prefab == "meat" then
87 return true
88 end
89 end
90 end
91 return false
92 end )
93 savage.components.trader.onaccept = function(savage, giver, item)
94 GetPlayer().components.inventory:ConsumeByName("meat", 9)
95 savage:AddTag("mysavage")
96 savage.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
97 savage:AddComponent("follower")
98 savage.components.follower:SetLeader(GetPlayer())
99 local brain = require "brains/abigailbrain"
100 savage:SetBrain(brain)
101 savage:RestartBrain()
102 savage.components.combat:SetAttackPeriod(1)
103 savage.components.combat:SetRetargetFunction(1, function(savage)
104 if not savage.components.health:IsDead() then
105 return FindEntity(GetPlayer(), 20, function(guy)
106 if guy.components.combat and guy.components.health and not guy.components.health:IsDead() then
107 return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy or guy:HasTag("monster")
108 end
109 end )
110 end
111 end )
112 savage:RemoveAllEventCallbacks()
113 savage:RemoveComponent("trader")
114 savage:ListenForEvent( "daytime", function() savage.components.health:DoDelta(2000) end , GetWorld())
115 savage:ListenForEvent("attacked", function(savage, data)
116 savage.components.combat:SetTarget(data.attacker)
117 end )
118 savage.Physics:SetCollisionCallback( nil )
119 savage.components.inspectable.getstatus = function(savage)
120 if not savage:HasTag("stophere") then
121 savage:AddTag("stophere")
122 savage.components.locomotor:Stop()
123 savage:SetBrain(nil)
124 savage.components.follower:SetLeader(nil)
125 savage.AnimState:SetBloomEffectHandle("")
126 else
127 savage:RemoveTag("stophere")
128 local brain = require "brains/abigailbrain"
129 savage:SetBrain(brain)
130 savage:RestartBrain()
131 savage.components.follower:SetLeader(GetPlayer())
132 savage.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
133 end
134 end
135 end
136 savage:AddTag("savages")
137 end
138end
139 inst:ListenForEvent( "daytime", function() createsavage(inst) end , GetWorld())
140
141
142 2.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/hammer.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
143
144local items = { SWORD = "swap_spear_wathgrithr" }
145local function EquipItem(inst, item)
146 if item then
147 inst.AnimState:OverrideSymbol("swap_object", item, item)
148 inst.AnimState:Show("ARM_carry")
149 inst.AnimState:Hide("ARM_normal")
150 end
151end
152 inst.items = items
153 inst.equipfn = EquipItem
154 EquipItem(inst)
155local function onsave(inst, data)
156 if inst:HasTag("savages") then
157 data.savages = true
158 end
159 if inst:HasTag("mysavage") then
160 data.mysavage = true
161 end
162 if inst:HasTag("stophere") then
163 data.stophere = true
164 end
165end
166local function onload(inst, data)
167 if data and data.savages then
168 inst.AnimState:SetBank("wilson")
169 inst.AnimState:SetBuild("wolfgang")
170 inst.AnimState:OverrideSymbol("swap_hat", "hat_wathgrithr", "swap_hat")
171 inst.AnimState:OverrideSymbol("swap_body", "torso_rain", "swap_body")
172 inst.AnimState:OverrideSymbol("swap_object", "swap_spear_wathgrithr", "swap_spear_wathgrithr")
173 inst.AnimState:Show("HAT")
174 inst.AnimState:Show("HAT_HAIR")
175 inst.AnimState:Hide("HAIR_NOHAT")
176 inst.AnimState:Hide("HAIR")
177 inst.AnimState:Hide("ARM_normal")
178 inst.AnimState:Show("ARM_carry")
179 inst.AnimState:PlayAnimation("idle")
180 inst.Transform:SetScale(1.2, 1.2, 1.2)
181 local sound = inst.entity:AddSoundEmitter()
182 local shadow = inst.entity:AddDynamicShadow()
183 shadow:SetSize( 1.3, .6 )
184 inst.Transform:SetFourFaced()
185 MakeCharacterPhysics(inst, 100, .5)
186 local minimap = inst.entity:AddMiniMapEntity()
187 minimap:SetIcon( "wolfgang.png" )
188 inst:AddComponent("locomotor")
189 inst.components.locomotor.walkspeed = 4
190 inst.components.locomotor.runspeed = 8
191 inst:SetStateGraph("SGshadowwaxwell")
192 local brain = require "brains/leifbrain"
193 inst:SetBrain(brain)
194 inst:RemoveComponent("weapon")
195 inst:RemoveComponent("tool")
196 inst:RemoveComponent("finiteuses")
197 inst:RemoveComponent("inventoryitem")
198 inst:RemoveComponent("equippable")
199 inst:RemoveTag("hammer")
200 inst:AddComponent("inventory")
201 inst:AddComponent("health")
202 inst.components.health:SetMaxHealth(2000)
203 inst:ListenForEvent("death", function()
204 local pt1 = inst:GetPosition()
205 for k = 1,math.random(5,10) do
206 local meatnames = {"meat","smallmeat","drumstick"}
207 local meatname = meatnames[math.random(#meatnames)]
208 local meat = SpawnPrefab(meatname)
209 meat.Transform:SetPosition(pt1.x+(math.random(3)-math.random(3)), 0, pt1.z+(math.random(3)-math.random(3)))
210 end
211 if math.random() < 0.01 then
212 local lootnames = {"spear_wathgrithr","wathgrithrhat"}
213 local lootname = lootnames[math.random(#lootnames)]
214 local loot = SpawnPrefab(lootname)
215 loot.Transform:SetPosition(pt1.x, 0, pt1.z)
216 end
217 end )
218 inst:AddComponent("combat")
219 inst.components.combat:SetDefaultDamage(30)
220 inst.components.combat:SetAttackPeriod(1.5)
221 inst.components.combat:SetRetargetFunction(3, function(inst)
222 if not inst.components.health:IsDead() then
223 return FindEntity(inst, 20, function(guy)
224 return inst.components.combat:CanTarget(guy) and not guy:HasTag("savages") and not guy:HasTag("goodsavages")
225 end )
226 end
227 end )
228 inst.components.combat:SetKeepTargetFunction(function(inst, target) return target and target:IsValid() end )
229 inst:ListenForEvent("attacked", function(inst, data)
230 inst.components.combat:SetTarget(data.attacker)
231 inst.components.combat:ShareTarget(data.attacker, 30, function(dude) return dude:HasTag("savages") and not dude:HasTag("mysavage") and not dude.components.health:IsDead() end, 5)
232 end )
233 inst.Physics:SetCollisionCallback(function(inst, other)
234 if other and other.components.workable and other.components.workable.workleft > 0 then
235 other.components.workable:Destroy(inst)
236 end
237 end)
238 inst:ListenForEvent( "nighttime", function() inst:Remove() end , GetWorld())
239 inst:AddComponent("trader")
240 inst.components.trader:SetAcceptTest(function(inst, item)
241 if GetPlayer():HasTag("goodsavages") then
242 if GetPlayer().components.inventory:Has("meat", 10) then
243 if item.prefab == "meat" then
244 return true
245 end
246 end
247 end
248 return false
249 end )
250 inst.components.trader.onaccept = function(inst, giver, item)
251 GetPlayer().components.inventory:ConsumeByName("meat", 9)
252 inst:AddTag("mysavage")
253 inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
254 inst:AddComponent("follower")
255 inst.components.follower:SetLeader(GetPlayer())
256 local brain = require "brains/abigailbrain"
257 inst:SetBrain(brain)
258 inst:RestartBrain()
259 inst.components.combat:SetAttackPeriod(1)
260 inst.components.combat:SetRetargetFunction(1, function(inst)
261 if not inst.components.health:IsDead() then
262 return FindEntity(GetPlayer(), 20, function(guy)
263 if guy.components.combat and guy.components.health and not guy.components.health:IsDead() then
264 return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy or guy:HasTag("monster")
265 end
266 end )
267 end
268 end )
269 inst:RemoveAllEventCallbacks()
270 inst:RemoveComponent("trader")
271 inst:ListenForEvent( "daytime", function() inst.components.health:DoDelta(2000) end , GetWorld())
272 inst:ListenForEvent("attacked", function(inst, data)
273 inst.components.combat:SetTarget(data.attacker)
274 end )
275 inst.Physics:SetCollisionCallback( nil )
276 inst.components.inspectable.getstatus = function(inst)
277 if not inst:HasTag("stophere") then
278 inst:AddTag("stophere")
279 inst.components.locomotor:Stop()
280 inst:SetBrain(nil)
281 inst.components.follower:SetLeader(nil)
282 inst.AnimState:SetBloomEffectHandle("")
283 else
284 inst:RemoveTag("stophere")
285 local brain = require "brains/abigailbrain"
286 inst:SetBrain(brain)
287 inst:RestartBrain()
288 inst.components.follower:SetLeader(GetPlayer())
289 inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
290 end
291 end
292 end
293 inst:AddTag("savages")
294 end
295 if data and data.mysavage then
296 inst:AddTag("mysavage")
297 inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
298 inst:AddComponent("follower")
299 inst.components.follower:SetLeader(GetPlayer())
300 local brain = require "brains/abigailbrain"
301 inst:SetBrain(brain)
302 inst:RestartBrain()
303 inst.components.combat:SetAttackPeriod(1)
304 inst.components.combat:SetRetargetFunction(1, function(inst)
305 if not inst.components.health:IsDead() then
306 return FindEntity(GetPlayer(), 20, function(guy)
307 if guy.components.combat and guy.components.health and not guy.components.health:IsDead() then
308 return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy or guy:HasTag("monster")
309 end
310 end )
311 end
312 end )
313 inst:RemoveAllEventCallbacks()
314 inst:RemoveComponent("trader")
315 inst:ListenForEvent( "daytime", function() inst.components.health:DoDelta(2000) end , GetWorld())
316 inst:ListenForEvent("attacked", function(inst, data)
317 inst.components.combat:SetTarget(data.attacker)
318 end )
319 inst.Physics:SetCollisionCallback( nil )
320 inst.components.inspectable.getstatus = function(inst)
321 if not inst:HasTag("stophere") then
322 inst:AddTag("stophere")
323 inst.components.locomotor:Stop()
324 inst:SetBrain(nil)
325 inst.components.follower:SetLeader(nil)
326 inst.AnimState:SetBloomEffectHandle("")
327 else
328 inst:RemoveTag("stophere")
329 local brain = require "brains/abigailbrain"
330 inst:SetBrain(brain)
331 inst:RestartBrain()
332 inst.components.follower:SetLeader(GetPlayer())
333 inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
334 end
335 end
336 end
337 if data and data.stophere then
338 inst:AddTag("stophere")
339 inst.components.locomotor:Stop()
340 inst:SetBrain(nil)
341 inst.components.follower:SetLeader(nil)
342 inst.AnimState:SetBloomEffectHandle("")
343 end
344end
345 inst.OnSave = onsave
346 inst.OnLoad = onload
347
348
349 3.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/hats.lua文件,在inst.components.armor:InitCondition(TUNING.ARMOR_WATHGRITHRHAT, TUNING.ARMOR_WATHGRITHRHAT_ABSORPTION)的下一行插入以下内容:
350
351 inst.components.equippable:SetOnEquip(function(inst, owner)
352 onequip(inst, owner)
353 if owner == GetPlayer() then
354 owner:AddTag("goodsavages")
355 end
356 end )
357 inst.components.equippable:SetOnUnequip(function(inst, owner)
358 onunequip(inst, owner)
359 owner:RemoveTag("goodsavages")
360 end )
361
362 即可有蛮族霸占虫洞附近的区域,白天和傍晚活动,黑夜消失。他们会攻击一切生物,拆毁建筑,通过小地图可查询蛮族所在位置,显示为沃尔夫冈图标。与蛮族对战时,他们会围攻你,打死蛮族可获得他们携带的肉类,还有一定概率获得瓦丝格雷斯帽和瓦丝格雷斯矛。装备瓦丝格雷斯帽,将被蛮族视为同类,从而免受攻击,并可以用10个大肉收买蛮族作手下(拿着大肉对蛮族点鼠标左键)。蛮族手下不会破坏建筑,无论受多重的伤,每天清晨都会恢复健康,鼠标左键点击(不要拿武器)蛮族手下可让其停留在原地,再次点击可继续跟随。从此开启与铁血蛮族共处的时代,作他们望而生畏的敌人,或带领他们征霸天下吧