代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二二五.荒野之狼(吃蜗牛龟粘液变成狼,打败别的狼成为领袖)
3
4 用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/slurtleslime.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
5
6local function item_oneaten(inst, eater)
7 if eater:HasTag("player") then
8 local pos = GetPlayer():GetPosition()
9 GetSeasonManager():DoLightningStrike(pos)
10 eater.components.locomotor:Stop()
11 eater.components.playercontroller:Enable(false)
12 eater:DoTaskInTime(1, function()
13 eater.AnimState:SetBank("hound")
14 eater.AnimState:SetBuild("hound_red")
15 eater.AnimState:PlayAnimation("idle")
16 eater:SetStateGraph("SGhound")
17 eater:RemoveTag("scarytoprey")
18 eater:AddTag("monster")
19 local light = eater.entity:AddLight()
20 light:SetFalloff(1)
21 light:SetIntensity(.8)
22 light:SetRadius(20)
23 light:Enable(true)
24 light:SetColour(0/255, 255/255, 0/255)
25 eater:ListenForEvent("attacked", function(eater)
26 local pt = eater:GetPosition()
27 eater.Transform:SetPosition(pt.x+(math.random(5)-math.random(5)), 0, pt.z+(math.random(5)-math.random(5)))
28 end )
29 eater.components.locomotor.runspeed = 25
30 eater.components.sanity:DoDelta(eater.components.sanity.max)
31 eater.components.sanity.ignore = true
32 eater.components.health:StartRegen(100, 10)
33 eater.components.combat:SetDefaultDamage(500)
34 eater.components.combat:SetAttackPeriod(0.1)
35 eater.components.eater:SetCarnivore()
36 eater.components.temperature:SetTemp(20)
37 eater.components.playercontroller:Enable(true)
38 GetPlayer().HUD.controls.crafttabs:Hide()
39 GetPlayer().HUD.controls.inv:Hide()
40 GetPlayer().HUD.controls.mapcontrols.minimapBtn:Hide()
41 local head = GetPlayer().components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)
42 GetPlayer().components.inventory:DropItem(head)
43 local hands = GetPlayer().components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
44 GetPlayer().components.inventory:DropItem(hands)
45 local body = GetPlayer().components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)
46 GetPlayer().components.inventory:DropItem(body)
47 eater.components.playeractionpicker.leftclickoverride = function(eater, target_ent, pos)
48 if eater.components.combat:CanTarget(target_ent) then
49 return eater.components.playeractionpicker:SortActionList({ACTIONS.ATTACK}, target_ent, nil)
50 end
51 if target_ent and target_ent.components.edible and eater.components.eater:CanEat(target_ent) then
52 return eater.components.playeractionpicker:SortActionList({ACTIONS.EAT}, target_ent, nil)
53 end
54 end
55 eater:DoPeriodicTask(3, function(eater)
56 if math.random() < 0.05 then
57 if eater.components.hunger:GetPercent() > 0.995 then
58 local pt1 = eater:GetPosition()
59 local wolf = SpawnPrefab("slurtleslime")
60 wolf.Transform:SetPosition(pt1.x+(math.random(10)-math.random(10)), 0, pt1.z+(math.random(10)-math.random(10)))
61 wolf.AnimState:SetBank("hound")
62 wolf.AnimState:SetBuild("hound")
63 wolf.AnimState:PlayAnimation("idle")
64 wolf.Transform:SetFourFaced()
65 local sound = wolf.entity:AddSoundEmitter()
66 local shadow = wolf.entity:AddDynamicShadow()
67 shadow:SetSize( 2.5, 1.5 )
68 MakeCharacterPhysics(wolf, 10, .5)
69 wolf:AddComponent("locomotor")
70 wolf.components.locomotor.runspeed = 25
71 wolf:SetStateGraph("SGhound")
72 local brain = require "brains/frogbrain"
73 wolf:SetBrain(brain)
74 wolf:RemoveComponent("stackable")
75 wolf:RemoveComponent("fuel")
76 wolf:RemoveComponent("inventoryitem")
77 wolf:RemoveComponent("explosive")
78 wolf:RemoveComponent("burnable")
79 wolf:RemoveComponent("propagator")
80 wolf:RemoveComponent("edible")
81 wolf:AddComponent("follower")
82 wolf:AddComponent("knownlocations")
83 wolf:AddComponent("lootdropper")
84 wolf.components.lootdropper:SetLoot({"meat", "meat"})
85 wolf:AddComponent("health")
86 wolf.components.health:SetMaxHealth(2000)
87 wolf.components.health:StartRegen(100, 10)
88 wolf:AddComponent("combat")
89 wolf.components.combat:SetDefaultDamage(20)
90 wolf.components.combat:SetAttackPeriod(0.1)
91 wolf.components.combat:SetTarget(eater)
92 wolf.AnimState:SetMultColour(255/255,0/255,0/255,1)
93 wolf.components.combat:SetRetargetFunction(1, function(wolf)
94 if not wolf.components.health:IsDead() then
95 return FindEntity(wolf, 300, function(guy)
96 return guy:HasTag("player")
97 end )
98 end
99 end )
100 wolf.components.combat:SetKeepTargetFunction(function(wolf, target) return target and target:IsValid() end )
101 wolf.task = wolf:DoPeriodicTask(1, function(customer)
102 if wolf.components.health.currenthealth < 1000 then
103 wolf.components.combat:SetTarget(nil)
104 wolf:RemoveTag("goodbye")
105 local brain = require "brains/abigailbrain"
106 wolf:SetBrain(brain)
107 wolf:RestartBrain()
108 wolf.components.follower:SetLeader(GetPlayer())
109 wolf.AnimState:SetMultColour(255/255,255/255,255/255,1)
110 wolf.components.combat:SetRetargetFunction(2, function(wolf)
111 if not wolf.components.health:IsDead() then
112 return FindEntity(wolf, 20, function(guy)
113 if guy.components.health and not guy.components.health:IsDead() and not guy:HasTag("wolfs") then
114 return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy
115 end
116 end )
117 end
118 end )
119 wolf.components.combat:SetKeepTargetFunction(function(wolf, target) return target and target:IsValid() end )
120 if wolf.task then wolf.task:Cancel() wolf.task = nil end
121 end
122 end )
123 wolf:AddTag("monster")
124 wolf:AddTag("wolfs")
125 wolf:AddTag("goodbye")
126 end
127 end
128 end )
129 end )
130 end
131end
132 inst:AddComponent("edible")
133 inst.components.edible:SetOnEatenFn(item_oneaten)
134 inst.components.edible.hungervalue = 1
135 inst.components.edible.foodtype = "VEGGIE"
136local function onsave(inst, data)
137 if inst:HasTag("wolfs") then
138 data.wolfs = true
139 end
140 if inst:HasTag("goodbye") then
141 data.goodbye = true
142 end
143end
144local function onload(inst, data)
145 if data and data.goodbye then
146 inst:Remove()
147 end
148 if data and data.wolfs then
149 inst.AnimState:SetBank("hound")
150 inst.AnimState:SetBuild("hound")
151 inst.AnimState:PlayAnimation("idle")
152 inst.Transform:SetFourFaced()
153 local sound = inst.entity:AddSoundEmitter()
154 local shadow = inst.entity:AddDynamicShadow()
155 shadow:SetSize( 2.5, 1.5 )
156 MakeCharacterPhysics(inst, 10, .5)
157 inst:AddComponent("locomotor")
158 inst.components.locomotor.runspeed = 25
159 inst:SetStateGraph("SGhound")
160 inst:RemoveComponent("stackable")
161 inst:RemoveComponent("fuel")
162 inst:RemoveComponent("inventoryitem")
163 inst:RemoveComponent("explosive")
164 inst:RemoveComponent("burnable")
165 inst:RemoveComponent("propagator")
166 inst:RemoveComponent("edible")
167 inst:AddComponent("follower")
168 inst:AddComponent("knownlocations")
169 inst:AddComponent("lootdropper")
170 inst.components.lootdropper:SetLoot({"meat", "meat"})
171 inst:AddComponent("health")
172 inst.components.health:SetMaxHealth(2000)
173 inst.components.health:StartRegen(100, 10)
174 inst:AddComponent("combat")
175 inst.components.combat:SetDefaultDamage(20)
176 inst.components.combat:SetAttackPeriod(0.1)
177 local brain = require "brains/abigailbrain"
178 inst:SetBrain(brain)
179 inst.components.follower:SetLeader(GetPlayer())
180 inst.components.combat:SetRetargetFunction(2, function(inst)
181 if not inst.components.health:IsDead() then
182 return FindEntity(inst, 20, function(guy)
183 if guy.components.health and not guy.components.health:IsDead() and not guy:HasTag("wolfs") then
184 return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy
185 end
186 end )
187 end
188 end )
189 inst.components.combat:SetKeepTargetFunction(function(inst, target) return target and target:IsValid() end )
190 inst:AddTag("monster")
191 inst:AddTag("wolfs")
192 end
193end
194 inst.OnSave = onsave
195 inst.OnLoad = onload
196
197 即可吃蜗牛龟粘液让主角变成狼,体验野生动物的生活。可喜的是,你将拥有强大的生命力(自动回血),超快的跑动速度和恐怖的咬合能力,黑夜也不会影响你看清前方,甚至由于没有了人的味道,一些小动物将无法躲避你。可悲的是,你必须告别之前所有的伙伴,连“新移民”都会主动攻击你,离开人类的生活,流浪在荒郊野外。战斗中,由于你的体重变轻,被打时会被甩出去,因此要学会扬长避短,发挥速度和攻击力的优势,跑过去咬上一口就躲,千万不要与敌人原地肉搏。当你进食到最饱时,有一定概率出现别的狼(全身红色)挑战你,打败它(它身上不再呈红色),则将成为你的小弟,用锋利的牙齿发展起你的狼群吧。如果实在受不了荒野的生活了,存档退出再读档,即可变回人,但狼小弟将继续跟随你。使用大力士、伍迪作主角时,不适用此项,不要与“变身传奇”、“饥饿的儿童”一同修改。蜗牛龟粘液可打蜗牛龟和蜗牛窝获得