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

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



二二五.荒野之狼(吃蜗牛龟粘液变成狼,打败别的狼成为领袖)

	用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/slurtleslime.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:

local function item_oneaten(inst, eater)
	if eater:HasTag("player") then
		local pos = GetPlayer():GetPosition()
		GetSeasonManager():DoLightningStrike(pos)
		eater.components.locomotor:Stop()
		eater.components.playercontroller:Enable(false)
		eater:DoTaskInTime(1, function() 
			eater.AnimState:SetBank("hound")
			eater.AnimState:SetBuild("hound_red")
			eater.AnimState:PlayAnimation("idle")
			eater:SetStateGraph("SGhound")
			eater:RemoveTag("scarytoprey")
			eater:AddTag("monster")
			local light = eater.entity:AddLight()
			light:SetFalloff(1)
			light:SetIntensity(.8)
			light:SetRadius(20)
			light:Enable(true)
			light:SetColour(0/255, 255/255, 0/255)
			eater:ListenForEvent("attacked", function(eater)
				local pt = eater:GetPosition()
				eater.Transform:SetPosition(pt.x+(math.random(5)-math.random(5)), 0, pt.z+(math.random(5)-math.random(5)))
			end )
			eater.components.locomotor.runspeed = 25
			eater.components.sanity:DoDelta(eater.components.sanity.max)
			eater.components.sanity.ignore = true
			eater.components.health:StartRegen(100, 10)
			eater.components.combat:SetDefaultDamage(500)
			eater.components.combat:SetAttackPeriod(0.1)
			eater.components.eater:SetCarnivore()
			eater.components.temperature:SetTemp(20)
			eater.components.playercontroller:Enable(true)
			GetPlayer().HUD.controls.crafttabs:Hide()
			GetPlayer().HUD.controls.inv:Hide()
			GetPlayer().HUD.controls.mapcontrols.minimapBtn:Hide()
			local head = GetPlayer().components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)
			GetPlayer().components.inventory:DropItem(head)
			local hands = GetPlayer().components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
			GetPlayer().components.inventory:DropItem(hands)
			local body = GetPlayer().components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)
			GetPlayer().components.inventory:DropItem(body)
			eater.components.playeractionpicker.leftclickoverride = function(eater, target_ent, pos)
				if eater.components.combat:CanTarget(target_ent) then
				   return eater.components.playeractionpicker:SortActionList({ACTIONS.ATTACK}, target_ent, nil)
				end
				if target_ent and target_ent.components.edible and eater.components.eater:CanEat(target_ent) then
				   return eater.components.playeractionpicker:SortActionList({ACTIONS.EAT}, target_ent, nil)
				end
			end
			eater:DoPeriodicTask(3, function(eater)
			  if math.random() < 0.05 then
				if eater.components.hunger:GetPercent() > 0.995 then
				   local pt1 = eater:GetPosition()
				   local wolf = SpawnPrefab("slurtleslime")
				   wolf.Transform:SetPosition(pt1.x+(math.random(10)-math.random(10)), 0, pt1.z+(math.random(10)-math.random(10)))
				   wolf.AnimState:SetBank("hound")
				   wolf.AnimState:SetBuild("hound")
				   wolf.AnimState:PlayAnimation("idle")
				   wolf.Transform:SetFourFaced()
				   local sound = wolf.entity:AddSoundEmitter()
				   local shadow = wolf.entity:AddDynamicShadow()
				   shadow:SetSize( 2.5, 1.5 )
				   MakeCharacterPhysics(wolf, 10, .5)
				   wolf:AddComponent("locomotor")
				   wolf.components.locomotor.runspeed = 25
				   wolf:SetStateGraph("SGhound")
				   local brain = require "brains/frogbrain"
				   wolf:SetBrain(brain)
				   wolf:RemoveComponent("stackable")
				   wolf:RemoveComponent("fuel")
				   wolf:RemoveComponent("inventoryitem")
				   wolf:RemoveComponent("explosive")
				   wolf:RemoveComponent("burnable")
				   wolf:RemoveComponent("propagator")
				   wolf:RemoveComponent("edible")
				   wolf:AddComponent("follower")
				   wolf:AddComponent("knownlocations")
				   wolf:AddComponent("lootdropper")
				   wolf.components.lootdropper:SetLoot({"meat", "meat"})
				   wolf:AddComponent("health")
				   wolf.components.health:SetMaxHealth(2000)
				   wolf.components.health:StartRegen(100, 10)
				   wolf:AddComponent("combat")
				   wolf.components.combat:SetDefaultDamage(20)
				   wolf.components.combat:SetAttackPeriod(0.1)
				   wolf.components.combat:SetTarget(eater)
				   wolf.AnimState:SetMultColour(255/255,0/255,0/255,1)
				   wolf.components.combat:SetRetargetFunction(1, function(wolf)
					   if not wolf.components.health:IsDead() then
						  return FindEntity(wolf, 300, function(guy)
								 return guy:HasTag("player")
						  end )
					   end
				   end )
				   wolf.components.combat:SetKeepTargetFunction(function(wolf, target) return target and target:IsValid() end )
				   wolf.task = wolf:DoPeriodicTask(1, function(customer)
					   if wolf.components.health.currenthealth < 1000 then
						  wolf.components.combat:SetTarget(nil)
						  wolf:RemoveTag("goodbye")
						  local brain = require "brains/abigailbrain"
						  wolf:SetBrain(brain)
						  wolf:RestartBrain()
						  wolf.components.follower:SetLeader(GetPlayer())
						  wolf.AnimState:SetMultColour(255/255,255/255,255/255,1)
						  wolf.components.combat:SetRetargetFunction(2, function(wolf)
							  if not wolf.components.health:IsDead() then
								 return FindEntity(wolf, 20, function(guy)
									 if guy.components.health and not guy.components.health:IsDead() and not guy:HasTag("wolfs") then
										return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy
									 end
								 end )
							  end
						  end )
						  wolf.components.combat:SetKeepTargetFunction(function(wolf, target) return target and target:IsValid() end )
						  if wolf.task then wolf.task:Cancel() wolf.task = nil end
					   end
				   end )
				   wolf:AddTag("monster")
				   wolf:AddTag("wolfs")
				   wolf:AddTag("goodbye")
				end
			  end
			end )
		end )
	end
end
	inst:AddComponent("edible")
	inst.components.edible:SetOnEatenFn(item_oneaten)
	inst.components.edible.hungervalue = 1
	inst.components.edible.foodtype = "VEGGIE"
local function onsave(inst, data)
	if inst:HasTag("wolfs") then
		data.wolfs = true
	end
	if inst:HasTag("goodbye") then
		data.goodbye = true
	end
end
local function onload(inst, data)
	if data and data.goodbye then
	   inst:Remove()
	end
	if data and data.wolfs then
	   inst.AnimState:SetBank("hound")
	   inst.AnimState:SetBuild("hound")
	   inst.AnimState:PlayAnimation("idle")
	   inst.Transform:SetFourFaced()
	   local sound = inst.entity:AddSoundEmitter()
	   local shadow = inst.entity:AddDynamicShadow()
	   shadow:SetSize( 2.5, 1.5 )
	   MakeCharacterPhysics(inst, 10, .5)
	   inst:AddComponent("locomotor")
	   inst.components.locomotor.runspeed = 25
	   inst:SetStateGraph("SGhound")
	   inst:RemoveComponent("stackable")
	   inst:RemoveComponent("fuel")
	   inst:RemoveComponent("inventoryitem")
	   inst:RemoveComponent("explosive")
	   inst:RemoveComponent("burnable")
	   inst:RemoveComponent("propagator")
	   inst:RemoveComponent("edible")
	   inst:AddComponent("follower")
	   inst:AddComponent("knownlocations")
	   inst:AddComponent("lootdropper")
	   inst.components.lootdropper:SetLoot({"meat", "meat"})
	   inst:AddComponent("health")
	   inst.components.health:SetMaxHealth(2000)
	   inst.components.health:StartRegen(100, 10)
	   inst:AddComponent("combat")
	   inst.components.combat:SetDefaultDamage(20)
	   inst.components.combat:SetAttackPeriod(0.1)
	   local brain = require "brains/abigailbrain"
	   inst:SetBrain(brain)
	   inst.components.follower:SetLeader(GetPlayer())
	   inst.components.combat:SetRetargetFunction(2, function(inst)
		   if not inst.components.health:IsDead() then
			  return FindEntity(inst, 20, function(guy)
				  if guy.components.health and not guy.components.health:IsDead() and not guy:HasTag("wolfs") then
					 return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy
				  end
			  end )
		   end
	   end )
	   inst.components.combat:SetKeepTargetFunction(function(inst, target) return target and target:IsValid() end )
	   inst:AddTag("monster")
	   inst:AddTag("wolfs")
	end
end
	inst.OnSave = onsave
	inst.OnLoad = onload

	即可吃蜗牛龟粘液让主角变成狼,体验野生动物的生活。可喜的是,你将拥有强大的生命力(自动回血),超快的跑动速度和恐怖的咬合能力,黑夜也不会影响你看清前方,甚至由于没有了人的味道,一些小动物将无法躲避你。可悲的是,你必须告别之前所有的伙伴,连“新移民”都会主动攻击你,离开人类的生活,流浪在荒郊野外。战斗中,由于你的体重变轻,被打时会被甩出去,因此要学会扬长避短,发挥速度和攻击力的优势,跑过去咬上一口就躲,千万不要与敌人原地肉搏。当你进食到最饱时,有一定概率出现别的狼(全身红色)挑战你,打败它(它身上不再呈红色),则将成为你的小弟,用锋利的牙齿发展起你的狼群吧。如果实在受不了荒野的生活了,存档退出再读档,即可变回人,但狼小弟将继续跟随你。使用大力士、伍迪作主角时,不适用此项,不要与“变身传奇”、“饥饿的儿童”一同修改。蜗牛龟粘液可打蜗牛龟和蜗牛窝获得