代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。

原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html


  1
  2.统御战狼(按键盘X键召唤战狼,誓死护卫你,给5块疯肉升级为金刚战狼)
  3
  4	1.MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/player_common.lua文件,在inst:AddComponent("playercontroller")的下一行插入以下内容:
  5
  6TheInput:AddKeyUpHandler(KEY_X, function()
  7	if inst.components.inventory:Has("goldnugget", 20) then
  8	   inst.components.inventory:ConsumeByName("goldnugget", 20)
  9	   inst.AnimState:PlayAnimation("give")
 10	   inst.SoundEmitter:PlaySound("dontstarve/common/horn_beefalo")
 11	   local mywolf = SpawnPrefab("greenamulet")
 12	   local pt = GetPlayer():GetPosition()
 13	   mywolf.Transform:SetPosition(pt.x+(math.random(3)-math.random(3)), 0, pt.z+(math.random(3)-math.random(3)))
 14	   mywolf.AnimState:SetBank("warg")
 15	   mywolf.AnimState:SetBuild("warg_build")
 16	   mywolf.AnimState:PlayAnimation("idle")
 17	   mywolf.Transform:SetScale(0.6, 0.6, 0.6)
 18	   mywolf.Transform:SetFourFaced()
 19	   local sound = mywolf.entity:AddSoundEmitter()
 20	   local shadow = mywolf.entity:AddDynamicShadow()
 21	   shadow:SetSize(1.2, 0.7)
 22	   MakeCharacterPhysics(mywolf, 100, 1)
 23	   mywolf:RemoveComponent("equippable")
 24	   mywolf:RemoveComponent("inventoryitem")
 25	   mywolf:RemoveComponent("finiteuses")
 26	   mywolf:RemoveComponent("deployable")
 27	   mywolf:AddComponent("named")
 28	   mywolf.components.named:SetName("Wolf")
 29	   mywolf:AddComponent("follower")
 30	   mywolf.components.follower:SetLeader(GetPlayer())
 31	   mywolf:AddComponent("lootdropper")
 32	   mywolf.components.lootdropper:SetLoot({"monstermeat", "houndstooth"})
 33	   mywolf:AddComponent("health")
 34	   mywolf.components.health:SetMaxHealth(1000)
 35	   mywolf.components.health:StartRegen(50, 10)
 36	   mywolf:AddComponent("combat")
 37	   mywolf.components.combat:SetDefaultDamage(50)
 38	   mywolf.components.combat:SetAttackPeriod(0.5)
 39	   mywolf.components.combat:SetRange(3)
 40	   mywolf.components.combat:SetRetargetFunction(1, function(mywolf)
 41		   if not mywolf.components.health:IsDead() then
 42			   return FindEntity(mywolf, 25, function(guy)
 43				   if guy.components.combat then
 44					  return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy or guy:HasTag("monster")
 45				   end
 46			   end )
 47		   end
 48	   end )
 49	   mywolf.components.combat:SetKeepTargetFunction(function(mywolf, target) return target and target:IsValid() end )
 50	   mywolf:ListenForEvent("attacked", function(mywolf, data)
 51		   if data.attacker ~= GetPlayer() then
 52			  mywolf.components.combat:SetTarget(data.attacker)
 53			  mywolf.components.combat:ShareTarget(data.attacker, 30, function(dude) return dude:HasTag("mywolfs") and not dude.components.health:IsDead() end, 10)
 54		   else
 55			  mywolf.components.health:Kill()
 56		   end
 57	   end )
 58	   mywolf:AddComponent("locomotor")
 59	   mywolf.components.locomotor.runspeed = 18
 60	   mywolf.components.locomotor:SetShouldRun(true)
 61	   mywolf:SetStateGraph("SGwarg")
 62	   local brain = require "brains/abigailbrain"
 63	   mywolf:SetBrain(brain)
 64	   mywolf:AddComponent("trader")
 65	   mywolf.components.trader:SetAcceptTest(function(mywolf, item)
 66		   if GetPlayer().components.inventory:Has("monstermeat", 5) then
 67			  if item.prefab == "monstermeat" then
 68				 if not mywolf:HasTag("superwolf") then
 69					return true
 70				 end
 71			  end
 72		   end
 73		   return false
 74	   end )
 75	   mywolf.components.trader.onaccept = function(mywolf, giver, item)
 76		   if item.prefab == "monstermeat" then
 77			  giver.components.inventory:ConsumeByName("monstermeat", 4)
 78			  mywolf:AddTag("superwolf")
 79			  mywolf.components.named:SetName("Super Wolf")
 80			  mywolf.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
 81			  mywolf.Transform:SetScale(0.7, 0.7, 0.7)
 82			  mywolf.components.health:SetMaxHealth(2000)
 83			  mywolf.components.health:DoDelta(2000)
 84			  mywolf.components.combat:SetDefaultDamage(100)
 85			  mywolf.components.locomotor.runspeed = 25
 86		   end
 87	   end
 88	   mywolf.components.inspectable.getstatus = function(mywolf)
 89		   if not mywolf:HasTag("stophere") then
 90			  mywolf:AddTag("stophere")
 91			  mywolf.components.locomotor:Stop()
 92			  mywolf:SetBrain(nil)
 93			  mywolf.components.follower:SetLeader(nil)
 94		   else
 95			  mywolf:RemoveTag("stophere")
 96			  local brain = require "brains/abigailbrain"
 97			  mywolf:SetBrain(brain)
 98			  mywolf:RestartBrain()
 99			  mywolf.components.follower:SetLeader(GetPlayer())
100		   end
101	   end
102	   mywolf:AddTag("companion")
103	   mywolf:AddTag("mywolfs")
104	end
105end )
106
107
108	2.MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/amulet.lua文件,在inst.AnimState:PlayAnimation("greenamulet")的下一行插入以下内容:
109
110local function onsave(inst, data)
111	if inst:HasTag("mywolfs") then
112		data.mywolfs = true
113	end
114	if inst:HasTag("superwolf") then
115		data.superwolf = true
116	end
117	if inst:HasTag("stophere") then
118		data.stophere = true
119	end
120end
121local function onload(inst, data)
122	if data and data.mywolfs then
123	   inst.AnimState:SetBank("warg")
124	   inst.AnimState:SetBuild("warg_build")
125	   inst.AnimState:PlayAnimation("idle")
126	   inst.Transform:SetScale(0.6, 0.6, 0.6)
127	   inst.Transform:SetFourFaced()
128	   local sound = inst.entity:AddSoundEmitter()
129	   local shadow = inst.entity:AddDynamicShadow()
130	   shadow:SetSize(1.2, 0.7)
131	   MakeCharacterPhysics(inst, 100, 1)
132	   inst:RemoveComponent("equippable")
133	   inst:RemoveComponent("inventoryitem")
134	   inst:RemoveComponent("finiteuses")
135	   inst:RemoveComponent("deployable")
136	   inst:AddComponent("named")
137	   inst.components.named:SetName("Wolf")
138	   inst:AddComponent("follower")
139	   inst.components.follower:SetLeader(GetPlayer())
140	   inst:AddComponent("lootdropper")
141	   inst.components.lootdropper:SetLoot({"monstermeat", "houndstooth"})
142	   inst:AddComponent("health")
143	   inst.components.health:SetMaxHealth(1000)
144	   inst.components.health:StartRegen(50, 10)
145	   inst:AddComponent("combat")
146	   inst.components.combat:SetDefaultDamage(50)
147	   inst.components.combat:SetAttackPeriod(0.5)
148	   inst.components.combat:SetRange(3)
149	   inst.components.combat:SetRetargetFunction(1, function(inst)
150		   if not inst.components.health:IsDead() then
151			   return FindEntity(inst, 25, function(guy)
152				   if guy.components.combat then
153					  return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy or guy:HasTag("monster")
154				   end
155			   end )
156		   end
157	   end )
158	   inst.components.combat:SetKeepTargetFunction(function(inst, target) return target and target:IsValid() end )
159	   inst:ListenForEvent("attacked", function(inst, data)
160		   if data.attacker ~= GetPlayer() then
161			  inst.components.combat:SetTarget(data.attacker)
162			  inst.components.combat:ShareTarget(data.attacker, 30, function(dude) return dude:HasTag("mywolfs") and not dude.components.health:IsDead() end, 10)
163		   else
164			  inst.components.health:Kill()
165		   end
166	   end )
167	   inst:AddComponent("locomotor")
168	   inst.components.locomotor.runspeed = 18
169	   inst.components.locomotor:SetShouldRun(true)
170	   inst:SetStateGraph("SGwarg")
171	   local brain = require "brains/abigailbrain"
172	   inst:SetBrain(brain)
173	   inst:AddComponent("trader")
174	   inst.components.trader:SetAcceptTest(function(inst, item)
175		   if GetPlayer().components.inventory:Has("monstermeat", 5) then
176			  if item.prefab == "monstermeat" then
177				 if not inst:HasTag("superwolf") then
178					return true
179				 end
180			  end
181		   end
182		   return false
183	   end )
184	   inst.components.trader.onaccept = function(inst, giver, item)
185		   if item.prefab == "monstermeat" then
186			  giver.components.inventory:ConsumeByName("monstermeat", 4)
187			  inst:AddTag("superwolf")
188			  inst.components.named:SetName("Super Wolf")
189			  inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
190			  inst.Transform:SetScale(0.7, 0.7, 0.7)
191			  inst.components.health:SetMaxHealth(2000)
192			  inst.components.health:DoDelta(2000)
193			  inst.components.combat:SetDefaultDamage(100)
194			  inst.components.locomotor.runspeed = 25
195		   end
196	   end
197	   inst.components.inspectable.getstatus = function(inst)
198		   if not inst:HasTag("stophere") then
199			  inst:AddTag("stophere")
200			  inst.components.locomotor:Stop()
201			  inst:SetBrain(nil)
202			  inst.components.follower:SetLeader(nil)
203		   else
204			  inst:RemoveTag("stophere")
205			  local brain = require "brains/abigailbrain"
206			  inst:SetBrain(brain)
207			  inst:RestartBrain()
208			  inst.components.follower:SetLeader(GetPlayer())
209		   end
210	   end
211	   inst:AddTag("companion")
212	   inst:AddTag("mywolfs")
213	end
214	if data and data.superwolf then
215	   inst:AddTag("superwolf")
216	   inst.components.named:SetName("Super Wolf")
217	   inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
218	   inst.Transform:SetScale(0.7, 0.7, 0.7)
219	   inst.components.health:SetMaxHealth(2000)
220	   inst.components.health:DoDelta(2000)
221	   inst.components.combat:SetDefaultDamage(100)
222	   inst.components.locomotor.runspeed = 25
223	end
224	if data and data.stophere then
225	  inst:AddTag("stophere")
226	  inst.components.locomotor:Stop()
227	  inst:SetBrain(nil)
228	  inst.components.follower:SetLeader(nil)
229	end
230end
231	inst.OnSave = onsave
232	inst.OnLoad = onload
233
234	即可按键盘X键召唤战狼,每只花费20个黄金,身上黄金数不足时无法召唤。战狼极其忠诚,会誓死护卫你,鼠标左键点击可停在原地,再次点击则继续跟随。如果想赐战狼死,用任何武器打击一下即可(按Ctrl + 鼠标左键攻击),它不会还击。战狼生命力顽强,会自动回血。当一只战狼遭到攻击时,其他战狼会围攻敌人。给战狼5块疯肉(拿着疯肉对战狼点鼠标左键),可将其升级为金刚战狼,生命值、攻击力、速度会大幅提升。统御你的战狼部队,横扫大陆吧