代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二一三.红胡子强盗团(强盗团通过冒险之门入侵,烧杀抢掠,打死强盗可得黄金、武器)
3
4 1.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/forest.lua文件,在"puppet_wes",的下一行插入"puppet_woodie",
5
6
7 2.用MT管理器打开游戏目录/assets/scripts/prefabs/adventure_portal.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
8
9local function createbandit(inst)
10 for k = 1,math.random(20,35) do
11 local pt = inst:GetPosition()
12 local bandit = SpawnPrefab("beardhair")
13 bandit.Transform:SetPosition(pt.x+(math.random(50)-math.random(50)), 0, pt.z+(math.random(50)-math.random(50)))
14 bandit.AnimState:SetBank("wilson")
15 bandit.AnimState:SetBuild("woodie")
16 bandit.AnimState:OverrideSymbol("swap_hat", "hat_feather", "swap_hat")
17 bandit.AnimState:OverrideSymbol("swap_body", "armor_slurper", "swap_body")
18 bandit.AnimState:Show("HAT")
19 bandit.AnimState:Show("HAT_HAIR")
20 bandit.AnimState:Hide("HAIR_NOHAT")
21 bandit.AnimState:Hide("HAIR")
22 bandit.AnimState:Hide("ARM_carry")
23 bandit.AnimState:Show("ARM_normal")
24 bandit.AnimState:PlayAnimation("idle")
25 local sound = bandit.entity:AddSoundEmitter()
26 local shadow = bandit.entity:AddDynamicShadow()
27 shadow:SetSize( 1.3, .6 )
28 bandit.Transform:SetFourFaced()
29 local brain = require "brains/frogbrain"
30 bandit:SetBrain(brain)
31 bandit:AddComponent("locomotor")
32 bandit.components.locomotor.walkspeed = 5
33 bandit.components.locomotor.runspeed = 10
34 bandit:SetStateGraph("SGshadowwaxwell")
35 MakeCharacterPhysics(bandit, 75, .5)
36 bandit:RemoveComponent("inventoryitem")
37 bandit:RemoveComponent("stackable")
38 bandit:RemoveComponent("fuel")
39 bandit:RemoveComponent("burnable")
40 bandit:RemoveComponent("propagator")
41 bandit:AddComponent("inventory")
42 bandit:AddComponent("thief")
43 bandit:AddComponent("knownlocations")
44 bandit:AddComponent("health")
45 bandit.components.health:SetMaxHealth(1500)
46 bandit:ListenForEvent("death", function()
47 local pt1 = bandit:GetPosition()
48 for k = 1,math.random(15,25) do
49 local gold = SpawnPrefab("goldnugget")
50 gold.Transform:SetPosition(pt1.x+(math.random(3)-math.random(3)), 0, pt1.z+(math.random(3)-math.random(3)))
51 end
52 if math.random() < 0.1 then
53 local weapons = {"goldenaxe","spear","tentaclespike","batbat","ruins_bat"}
54 local weapon = weapons[math.random(#weapons)]
55 SpawnPrefab(weapon).Transform:SetPosition(pt1.x, 0, pt1.z)
56 end
57 end )
58 bandit:AddComponent("combat")
59 bandit.components.combat:SetDefaultDamage(20)
60 bandit.components.combat:SetAttackPeriod(1)
61 bandit.components.combat:SetRetargetFunction(2, function(bandit)
62 if not bandit.components.health:IsDead() then
63 return FindEntity(bandit, 20, function(guy)
64 return bandit.components.combat:CanTarget(guy) and not guy:HasTag("bandits")
65 end )
66 end
67 end )
68 bandit.components.combat.onhitotherfn = function(bandit, other, damage) bandit.components.thief:StealItem(other) end
69 bandit:ListenForEvent("attacked", function(bandit, data)
70 bandit.components.combat:SetTarget(data.attacker)
71 bandit.components.combat:ShareTarget(data.attacker, 30, function(dude) return dude:HasTag("bandits") and not dude.components.health:IsDead() end, 5)
72 end )
73 bandit.Physics:SetCollisionCallback(function(bandit, other)
74 if other and other.components.workable and other.components.workable.workleft > 0 then
75 other.components.workable:Destroy(bandit)
76 end
77 end)
78 bandit:DoPeriodicTask(1, function(bandit)
79 local pos = Vector3(bandit.Transform:GetWorldPosition())
80 local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, 3)
81 for k,v in pairs(ents) do
82 if v.components.pickable and v.components.pickable:CanBePicked() then
83 v.components.pickable:Pick(bandit)
84 end
85 if v.components.crop then
86 v.components.crop:Harvest(bandit)
87 end
88 end
89 end )
90 local minimap = bandit.entity:AddMiniMapEntity()
91 minimap:SetIcon( "lucy_axe.png" )
92 bandit:AddTag("monster")
93 bandit:AddTag("bandits")
94 end
95end
96local function delbandit(inst)
97 local range = 3000
98 local pos = Vector3(inst.Transform:GetWorldPosition())
99 local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, range)
100 for k,v in pairs(ents) do
101 if v:HasTag("bandits") then
102 v:Remove()
103 end
104 end
105end
106 inst:ListenForEvent( "daytime", function() createbandit(inst) end , GetWorld())
107 inst:ListenForEvent( "nighttime", function() delbandit(inst) end , GetWorld())
108
109
110 3.用MT管理器打开游戏目录/assets/scripts/prefabs/beardhair.lua文件,在Asset("ANIM", "anim/beardhair.zip"),的下一行插入以下内容:
111
112 Asset("ANIM", "anim/woodie.zip"),
113 Asset("SOUND", "sound/woodie.fsb"),
114
115
116 4.在inst:AddComponent("inspectable")的下一行插入以下内容:
117
118local names = {"swap_goldenaxe","swap_spear","swap_spike","swap_batbat","swap_ruins_bat"}
119local weapon = names[math.random(#names)]
120local items = { SWORD = weapon }
121local function EquipItem(inst, item)
122 if item then
123 inst.AnimState:OverrideSymbol("swap_object", item, item)
124 inst.AnimState:Show("ARM_carry")
125 inst.AnimState:Hide("ARM_normal")
126 end
127end
128 inst.items = items
129 inst.equipfn = EquipItem
130 EquipItem(inst)
131local function onsave(inst, data)
132 if inst:HasTag("bandits") then
133 data.bandits = true
134 end
135end
136local function onload(inst, data)
137 if data and data.bandits then
138 inst.AnimState:SetBank("wilson")
139 inst.AnimState:SetBuild("woodie")
140 inst.AnimState:OverrideSymbol("swap_hat", "hat_feather", "swap_hat")
141 inst.AnimState:OverrideSymbol("swap_body", "armor_slurper", "swap_body")
142 inst.AnimState:Show("HAT")
143 inst.AnimState:Show("HAT_HAIR")
144 inst.AnimState:Hide("HAIR_NOHAT")
145 inst.AnimState:Hide("HAIR")
146 inst.AnimState:Hide("ARM_carry")
147 inst.AnimState:Show("ARM_normal")
148 inst.AnimState:PlayAnimation("idle")
149 local sound = inst.entity:AddSoundEmitter()
150 local shadow = inst.entity:AddDynamicShadow()
151 shadow:SetSize( 1.3, .6 )
152 inst.Transform:SetFourFaced()
153 local brain = require "brains/frogbrain"
154 inst:SetBrain(brain)
155 inst:AddComponent("locomotor")
156 inst.components.locomotor.walkspeed = 5
157 inst.components.locomotor.runspeed = 10
158 inst:SetStateGraph("SGshadowwaxwell")
159 MakeCharacterPhysics(inst, 75, .5)
160 inst:RemoveComponent("inventoryitem")
161 inst:RemoveComponent("stackable")
162 inst:RemoveComponent("fuel")
163 inst:RemoveComponent("burnable")
164 inst:RemoveComponent("propagator")
165 inst:AddComponent("inventory")
166 inst:AddComponent("thief")
167 inst:AddComponent("knownlocations")
168 inst:AddComponent("health")
169 inst.components.health:SetMaxHealth(1500)
170 inst:ListenForEvent("death", function()
171 local pt1 = inst:GetPosition()
172 for k = 1,math.random(15,25) do
173 local gold = SpawnPrefab("goldnugget")
174 gold.Transform:SetPosition(pt1.x+(math.random(3)-math.random(3)), 0, pt1.z+(math.random(3)-math.random(3)))
175 end
176 if math.random() < 0.1 then
177 local weapons = {"goldenaxe","spear","tentaclespike","batbat","ruins_bat"}
178 local weapon = weapons[math.random(#weapons)]
179 SpawnPrefab(weapon).Transform:SetPosition(pt1.x, 0, pt1.z)
180 end
181 end )
182 inst:AddComponent("combat")
183 inst.components.combat:SetDefaultDamage(20)
184 inst.components.combat:SetAttackPeriod(1)
185 inst.components.combat:SetRetargetFunction(2, function(inst)
186 if not inst.components.health:IsDead() then
187 return FindEntity(inst, 20, function(guy)
188 return inst.components.combat:CanTarget(guy) and not guy:HasTag("bandits")
189 end )
190 end
191 end )
192 inst.components.combat.onhitotherfn = function(inst, other, damage) inst.components.thief:StealItem(other) end
193 inst:ListenForEvent("attacked", function(inst, data)
194 inst.components.combat:SetTarget(data.attacker)
195 inst.components.combat:ShareTarget(data.attacker, 30, function(dude) return dude:HasTag("bandits") and not dude.components.health:IsDead() end, 5)
196 end )
197 inst.Physics:SetCollisionCallback(function(inst, other)
198 if other and other.components.workable and other.components.workable.workleft > 0 then
199 other.components.workable:Destroy(inst)
200 end
201 end)
202 inst:DoPeriodicTask(1, function(inst)
203 local pos = Vector3(inst.Transform:GetWorldPosition())
204 local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, 3)
205 for k,v in pairs(ents) do
206 if v.components.pickable and v.components.pickable:CanBePicked() then
207 v.components.pickable:Pick(inst)
208 end
209 if v.components.crop then
210 v.components.crop:Harvest(inst)
211 end
212 end
213 end )
214 local minimap = inst.entity:AddMiniMapEntity()
215 minimap:SetIcon( "lucy_axe.png" )
216 inst:AddTag("monster")
217 inst:AddTag("bandits")
218 end
219end
220 inst.OnSave = onsave
221 inst.OnLoad = onload
222
223 即可有红胡子强盗通过冒险之门入侵你的大陆(修改后第2天早晨出现),他们将盘踞在冒险之门附近,毁坏森林、拆毁建筑、抢掠农作物,所到之处没有活口。通过小地图可查询强盗所在位置,显示为红斧子图标。与强盗交战时,他们会抢掠你身上的物品,并且附近的强盗将一起来围攻你,蛮干无异于送死,争取各个击破吧。从此在冒险之门周围,白天和傍晚都是危险的,只有漆黑的夜里,才是你可以喘息之际。打死强盗可获得战利品(不菲的黄金和他们抢来的赃物),还有一定概率掉落武器。如果同时修改了“雇佣兵工厂”,你的铁甲战团终于有了用武之地。同胞们,饥荒世界正遭遇重大危机,亿万苍生期盼着你,起兵去攻打强盗吧,这是旷日持久的反抗,也是正义而光荣的战争,用你的每一滴鲜血去证明,新一代的救世主,从此诞生了