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

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



九十五.游牧生涯(带牛毛帽让牛群跟随,牛不集体攻击主角)

	1.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/hats.lua文件,将下列内容:

	local function beefalo_equip(inst, owner)
		onequip(inst, owner)
		owner:AddTag("beefalo")
	end
	local function beefalo_unequip(inst, owner)
		onunequip(inst, owner)
		owner:RemoveTag("beefalo")
	end
	local function beefalo()
		local inst = simple()
		inst.components.equippable:SetOnEquip( beefalo_equip )
		inst.components.equippable:SetOnUnequip( beefalo_unequip )

		inst:AddComponent("insulator")
		inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)

		inst:AddComponent("waterproofer")
		inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_SMALL)
		
		inst:AddComponent("fueled")
		inst.components.fueled.fueltype = "USAGE"
		inst.components.fueled:InitializeFuelLevel(TUNING.BEEFALOHAT_PERISHTIME)
		inst.components.fueled:SetDepletedFn(generic_perish)
		
		
		return inst
	end

	替换为:

	local function beefalo_disable(inst)
		if inst.updatetask then
			inst.updatetask:Cancel()
			inst.updatetask = nil
		end
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner
			owner.components.leader:RemoveFollowersByTag("beefalo")
	end
	local function beefalo_update(inst)
		local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner
		if owner and owner.components.leader then
			local x,y,z = owner.Transform:GetWorldPosition()
			local ents = TheSim:FindEntities(x,y,z, TUNING.SPIDERHAT_RANGE, {"beefalo"})
			for k,v in pairs(ents) do
				if v.components.follower and not v.components.follower.leader and not owner.components.leader:IsFollower(v) and owner.components.leader.numfollowers < 50 then
					owner.components.leader:AddFollower(v)
				end
			end
		end
	end
	local function beefalo_enable(inst)
		inst.updatetask = inst:DoPeriodicTask(0.5, beefalo_update, 1)
	end
	local function beefalo_equip(inst, owner)
		onequip(inst, owner)
		beefalo_enable(inst)
		owner:AddTag("beefalo")
	end
	local function beefalo_unequip(inst, owner)
		onunequip(inst, owner)
		beefalo_disable(inst)
		owner:RemoveTag("beefalo")
	end
	local function beefalo_perish(inst)
		beefalo_disable(inst)
		inst:Remove()
	end
	local function beefalo()
		local inst = simple()
		inst.components.equippable:SetOnEquip( beefalo_equip )
		inst.components.equippable:SetOnUnequip( beefalo_unequip )
		inst:AddComponent("insulator")
		inst.components.insulator.insulation = TUNING.INSULATION_LARGE
		inst:AddComponent("waterproofer")
		inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_SMALL)
		inst:AddComponent("fueled")
		inst.components.fueled.fueltype = "USAGE"
		inst.components.fueled:InitializeFuelLevel(TUNING.BEEFALOHAT_PERISHTIME)
		inst.components.fueled:SetDepletedFn(beefalo_perish)
		return inst
	end


	2.用MT管理器打开游戏目录/assets/scripts/prefabs/beefalo.lua文件,将return not guy:HasTag("beefalo") and替换为return not guy:HasTag("beefalo") and not guy:HasTag("player") and


	3.return dude:HasTag("beefalo") and not dude:HasTag("player") and not dude.components.health:IsDead()替换为return dude:HasTag("beefalo") and dude:HasTag("player") and not dude.components.health:IsDead()


	4.将inst.components.locomotor.walkspeed = 1.5替换为inst.components.locomotor.walkspeed = 3

	即可带牛毛帽让牛群跟随,杀牛它们不会集体反击,也提高了牛走路的速度。加上“牛产便便速度增加1倍”、“喂牛蔬菜无限产黄油”、“牛醒着也可剪牛毛”的修改(见本修改技巧),就可以烧着便便取暖,吃牛肉、黄油,经营自己的牛群吧