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

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



二一九.铁血蛮族(蛮族霸占虫洞,打死可得肉类、装备,带瓦丝格雷斯帽不被攻击,用大肉收买蛮族做手下)

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

local function createsavage(inst)
  for k = 1,math.random(10,15) do
	local pt = inst:GetPosition()
	local savage = SpawnPrefab("hammer")
	savage.Transform:SetPosition(pt.x+(math.random(30)-math.random(30)), 0, pt.z+(math.random(30)-math.random(30)))
	savage.AnimState:SetBank("wilson")
	savage.AnimState:SetBuild("wolfgang")
	savage.AnimState:OverrideSymbol("swap_hat", "hat_wathgrithr", "swap_hat")
	savage.AnimState:OverrideSymbol("swap_body", "torso_rain", "swap_body")
	savage.AnimState:OverrideSymbol("swap_object", "swap_spear_wathgrithr", "swap_spear_wathgrithr")
	savage.AnimState:Show("HAT")
	savage.AnimState:Show("HAT_HAIR")
	savage.AnimState:Hide("HAIR_NOHAT")
	savage.AnimState:Hide("HAIR")
	savage.AnimState:Hide("ARM_normal")
	savage.AnimState:Show("ARM_carry")
	savage.AnimState:PlayAnimation("idle")
	savage.Transform:SetScale(1.2, 1.2, 1.2)
	local sound = savage.entity:AddSoundEmitter()
	local shadow = savage.entity:AddDynamicShadow()
	shadow:SetSize( 1.3, .6 )
	savage.Transform:SetFourFaced()
	MakeCharacterPhysics(savage, 100, .5)
	local minimap = savage.entity:AddMiniMapEntity()
	minimap:SetIcon( "wolfgang.png" )
	savage:AddComponent("locomotor")
	savage.components.locomotor.walkspeed = 4
	savage.components.locomotor.runspeed = 8
	savage:SetStateGraph("SGshadowwaxwell")
	local brain = require "brains/leifbrain"
	savage:SetBrain(brain)
	savage:RemoveComponent("weapon")
	savage:RemoveComponent("tool")
	savage:RemoveComponent("finiteuses")
	savage:RemoveComponent("inventoryitem")
	savage:RemoveComponent("equippable")
	savage:RemoveTag("hammer")
	savage:AddComponent("inventory")
	savage:AddComponent("health")
	savage.components.health:SetMaxHealth(2000)
	savage:ListenForEvent("death", function()
		local pt1 = savage:GetPosition()
		for k = 1,math.random(5,10) do
			local meatnames = {"meat","smallmeat","drumstick"}
			local meatname = meatnames[math.random(#meatnames)]
			local meat = SpawnPrefab(meatname)
			meat.Transform:SetPosition(pt1.x+(math.random(3)-math.random(3)), 0, pt1.z+(math.random(3)-math.random(3)))
		end
		if math.random() < 0.01 then
			local lootnames = {"spear_wathgrithr","wathgrithrhat"}
			local lootname = lootnames[math.random(#lootnames)]
			local loot = SpawnPrefab(lootname)
			loot.Transform:SetPosition(pt1.x, 0, pt1.z)
		end
	end )
	savage:AddComponent("combat")
	savage.components.combat:SetDefaultDamage(30)
	savage.components.combat:SetAttackPeriod(1.5)
	savage.components.combat:SetRetargetFunction(3, function(savage)
		if not savage.components.health:IsDead() then
			return FindEntity(savage, 20, function(guy)
				return savage.components.combat:CanTarget(guy) and not guy:HasTag("savages") and not guy:HasTag("goodsavages")
			end )
		end
	end )
	savage.components.combat:SetKeepTargetFunction(function(savage, target) return target and target:IsValid() end )
	savage:ListenForEvent("attacked", function(savage, data)
		savage.components.combat:SetTarget(data.attacker)
		savage.components.combat:ShareTarget(data.attacker, 30, function(dude) return dude:HasTag("savages") and not dude:HasTag("mysavage") and not dude.components.health:IsDead() end, 5)
	end )
	savage.Physics:SetCollisionCallback(function(savage, other)
		if other and other.components.workable and other.components.workable.workleft > 0 then
		   other.components.workable:Destroy(savage)
		end
	end)
	savage:ListenForEvent( "nighttime", function() savage:Remove() end , GetWorld())
	savage:AddComponent("trader")
	savage.components.trader:SetAcceptTest(function(savage, item) 
		if GetPlayer():HasTag("goodsavages") then
		   if GetPlayer().components.inventory:Has("meat", 10) then
			  if item.prefab == "meat" then
				 return true
			  end
		   end
		end
		return false
	end )
	savage.components.trader.onaccept = function(savage, giver, item)
		GetPlayer().components.inventory:ConsumeByName("meat", 9)
		savage:AddTag("mysavage")
		savage.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
		savage:AddComponent("follower")
		savage.components.follower:SetLeader(GetPlayer())
		local brain = require "brains/abigailbrain"
		savage:SetBrain(brain)
		savage:RestartBrain()
		savage.components.combat:SetAttackPeriod(1)
		savage.components.combat:SetRetargetFunction(1, function(savage)
			if not savage.components.health:IsDead() then
			   return FindEntity(GetPlayer(), 20, function(guy)
				   if guy.components.combat and guy.components.health and not guy.components.health:IsDead() then
					  return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy or guy:HasTag("monster")
				   end
			   end )
			end
		end )
		savage:RemoveAllEventCallbacks()
		savage:RemoveComponent("trader")
		savage:ListenForEvent( "daytime", function() savage.components.health:DoDelta(2000) end , GetWorld())
		savage:ListenForEvent("attacked", function(savage, data)
			savage.components.combat:SetTarget(data.attacker)
		end )
		savage.Physics:SetCollisionCallback( nil )
		savage.components.inspectable.getstatus = function(savage)
			if not savage:HasTag("stophere") then
			   savage:AddTag("stophere")
			   savage.components.locomotor:Stop()
			   savage:SetBrain(nil)
			   savage.components.follower:SetLeader(nil)
			   savage.AnimState:SetBloomEffectHandle("")
			else
			   savage:RemoveTag("stophere")
			   local brain = require "brains/abigailbrain"
			   savage:SetBrain(brain)
			   savage:RestartBrain()
			   savage.components.follower:SetLeader(GetPlayer())
			   savage.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
			end
		end
	end
	savage:AddTag("savages")
  end
end
	inst:ListenForEvent( "daytime", function() createsavage(inst) end , GetWorld())


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

local items = { SWORD = "swap_spear_wathgrithr" }
local function EquipItem(inst, item)
	if item then
	   inst.AnimState:OverrideSymbol("swap_object", item, item)
	   inst.AnimState:Show("ARM_carry") 
	   inst.AnimState:Hide("ARM_normal")
	end
end
	inst.items = items
	inst.equipfn = EquipItem
	EquipItem(inst)
local function onsave(inst, data)
	if inst:HasTag("savages") then
		data.savages = true
	end
	if inst:HasTag("mysavage") then
		data.mysavage = true
	end
	if inst:HasTag("stophere") then
		data.stophere = true
	end
end
local function onload(inst, data)
  if data and data.savages then
	inst.AnimState:SetBank("wilson")
	inst.AnimState:SetBuild("wolfgang")
	inst.AnimState:OverrideSymbol("swap_hat", "hat_wathgrithr", "swap_hat")
	inst.AnimState:OverrideSymbol("swap_body", "torso_rain", "swap_body")
	inst.AnimState:OverrideSymbol("swap_object", "swap_spear_wathgrithr", "swap_spear_wathgrithr")
	inst.AnimState:Show("HAT")
	inst.AnimState:Show("HAT_HAIR")
	inst.AnimState:Hide("HAIR_NOHAT")
	inst.AnimState:Hide("HAIR")
	inst.AnimState:Hide("ARM_normal")
	inst.AnimState:Show("ARM_carry")
	inst.AnimState:PlayAnimation("idle")
	inst.Transform:SetScale(1.2, 1.2, 1.2)
	local sound = inst.entity:AddSoundEmitter()
	local shadow = inst.entity:AddDynamicShadow()
	shadow:SetSize( 1.3, .6 )
	inst.Transform:SetFourFaced()
	MakeCharacterPhysics(inst, 100, .5)
	local minimap = inst.entity:AddMiniMapEntity()
	minimap:SetIcon( "wolfgang.png" )
	inst:AddComponent("locomotor")
	inst.components.locomotor.walkspeed = 4
	inst.components.locomotor.runspeed = 8
	inst:SetStateGraph("SGshadowwaxwell")
	local brain = require "brains/leifbrain"
	inst:SetBrain(brain)
	inst:RemoveComponent("weapon")
	inst:RemoveComponent("tool")
	inst:RemoveComponent("finiteuses")
	inst:RemoveComponent("inventoryitem")
	inst:RemoveComponent("equippable")
	inst:RemoveTag("hammer")
	inst:AddComponent("inventory")
	inst:AddComponent("health")
	inst.components.health:SetMaxHealth(2000)
	inst:ListenForEvent("death", function()
		local pt1 = inst:GetPosition()
		for k = 1,math.random(5,10) do
			local meatnames = {"meat","smallmeat","drumstick"}
			local meatname = meatnames[math.random(#meatnames)]
			local meat = SpawnPrefab(meatname)
			meat.Transform:SetPosition(pt1.x+(math.random(3)-math.random(3)), 0, pt1.z+(math.random(3)-math.random(3)))
		end
		if math.random() < 0.01 then
			local lootnames = {"spear_wathgrithr","wathgrithrhat"}
			local lootname = lootnames[math.random(#lootnames)]
			local loot = SpawnPrefab(lootname)
			loot.Transform:SetPosition(pt1.x, 0, pt1.z)
		end
	end )
	inst:AddComponent("combat")
	inst.components.combat:SetDefaultDamage(30)
	inst.components.combat:SetAttackPeriod(1.5)
	inst.components.combat:SetRetargetFunction(3, function(inst)
		if not inst.components.health:IsDead() then
			return FindEntity(inst, 20, function(guy)
				return inst.components.combat:CanTarget(guy) and not guy:HasTag("savages") and not guy:HasTag("goodsavages")
			end )
		end
	end )
	inst.components.combat:SetKeepTargetFunction(function(inst, target) return target and target:IsValid() end )
	inst:ListenForEvent("attacked", function(inst, data)
		inst.components.combat:SetTarget(data.attacker)
		inst.components.combat:ShareTarget(data.attacker, 30, function(dude) return dude:HasTag("savages") and not dude:HasTag("mysavage") and not dude.components.health:IsDead() end, 5)
	end )
	inst.Physics:SetCollisionCallback(function(inst, other)
		if other and other.components.workable and other.components.workable.workleft > 0 then
		   other.components.workable:Destroy(inst)
		end
	end)
	inst:ListenForEvent( "nighttime", function() inst:Remove() end , GetWorld())
	inst:AddComponent("trader")
	inst.components.trader:SetAcceptTest(function(inst, item) 
		if GetPlayer():HasTag("goodsavages") then
		   if GetPlayer().components.inventory:Has("meat", 10) then
			  if item.prefab == "meat" then
				 return true
			  end
		   end
		end
		return false
	end )
	inst.components.trader.onaccept = function(inst, giver, item)
		GetPlayer().components.inventory:ConsumeByName("meat", 9)
		inst:AddTag("mysavage")
		inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
		inst:AddComponent("follower")
		inst.components.follower:SetLeader(GetPlayer())
		local brain = require "brains/abigailbrain"
		inst:SetBrain(brain)
		inst:RestartBrain()
		inst.components.combat:SetAttackPeriod(1)
		inst.components.combat:SetRetargetFunction(1, function(inst)
			if not inst.components.health:IsDead() then
			   return FindEntity(GetPlayer(), 20, function(guy)
				   if guy.components.combat and guy.components.health and not guy.components.health:IsDead() then
					  return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy or guy:HasTag("monster")
				   end
			   end )
			end
		end )
		inst:RemoveAllEventCallbacks()
		inst:RemoveComponent("trader")
		inst:ListenForEvent( "daytime", function() inst.components.health:DoDelta(2000) end , GetWorld())
		inst:ListenForEvent("attacked", function(inst, data)
			inst.components.combat:SetTarget(data.attacker)
		end )
		inst.Physics:SetCollisionCallback( nil )
		inst.components.inspectable.getstatus = function(inst)
			if not inst:HasTag("stophere") then
			   inst:AddTag("stophere")
			   inst.components.locomotor:Stop()
			   inst:SetBrain(nil)
			   inst.components.follower:SetLeader(nil)
			   inst.AnimState:SetBloomEffectHandle("")
			else
			   inst:RemoveTag("stophere")
			   local brain = require "brains/abigailbrain"
			   inst:SetBrain(brain)
			   inst:RestartBrain()
			   inst.components.follower:SetLeader(GetPlayer())
			   inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
			end
		end
	end
	inst:AddTag("savages")
  end
  if data and data.mysavage then
	 inst:AddTag("mysavage")
	 inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
	 inst:AddComponent("follower")
	 inst.components.follower:SetLeader(GetPlayer())
	 local brain = require "brains/abigailbrain"
	 inst:SetBrain(brain)
	 inst:RestartBrain()
	 inst.components.combat:SetAttackPeriod(1)
	 inst.components.combat:SetRetargetFunction(1, function(inst)
		 if not inst.components.health:IsDead() then
			return FindEntity(GetPlayer(), 20, function(guy)
				if guy.components.combat and guy.components.health and not guy.components.health:IsDead() then
				   return guy.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == guy or guy:HasTag("monster")
				end
			end )
		 end
	 end )
	 inst:RemoveAllEventCallbacks()
	 inst:RemoveComponent("trader")
	 inst:ListenForEvent( "daytime", function() inst.components.health:DoDelta(2000) end , GetWorld())
	 inst:ListenForEvent("attacked", function(inst, data)
		 inst.components.combat:SetTarget(data.attacker)
	 end )
	 inst.Physics:SetCollisionCallback( nil )
	 inst.components.inspectable.getstatus = function(inst)
		 if not inst:HasTag("stophere") then
			inst:AddTag("stophere")
			inst.components.locomotor:Stop()
			inst:SetBrain(nil)
			inst.components.follower:SetLeader(nil)
			inst.AnimState:SetBloomEffectHandle("")
		 else
			inst:RemoveTag("stophere")
			local brain = require "brains/abigailbrain"
			inst:SetBrain(brain)
			inst:RestartBrain()
			inst.components.follower:SetLeader(GetPlayer())
			inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
		 end
	 end
  end
  if data and data.stophere then
	 inst:AddTag("stophere")
	 inst.components.locomotor:Stop()
	 inst:SetBrain(nil)
	 inst.components.follower:SetLeader(nil)
	 inst.AnimState:SetBloomEffectHandle("")
  end
end
	inst.OnSave = onsave
	inst.OnLoad = onload


	3.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/hats.lua文件,在inst.components.armor:InitCondition(TUNING.ARMOR_WATHGRITHRHAT, TUNING.ARMOR_WATHGRITHRHAT_ABSORPTION)的下一行插入以下内容:

	inst.components.equippable:SetOnEquip(function(inst, owner)
		onequip(inst, owner)
		if owner == GetPlayer() then
		   owner:AddTag("goodsavages")
		end
	end )
	inst.components.equippable:SetOnUnequip(function(inst, owner)
		onunequip(inst, owner)
		owner:RemoveTag("goodsavages")
	end )

	即可有蛮族霸占虫洞附近的区域,白天和傍晚活动,黑夜消失。他们会攻击一切生物,拆毁建筑,通过小地图可查询蛮族所在位置,显示为沃尔夫冈图标。与蛮族对战时,他们会围攻你,打死蛮族可获得他们携带的肉类,还有一定概率获得瓦丝格雷斯帽和瓦丝格雷斯矛。装备瓦丝格雷斯帽,将被蛮族视为同类,从而免受攻击,并可以用10个大肉收买蛮族作手下(拿着大肉对蛮族点鼠标左键)。蛮族手下不会破坏建筑,无论受多重的伤,每天清晨都会恢复健康,鼠标左键点击(不要拿武器)蛮族手下可让其停留在原地,再次点击可继续跟随。从此开启与铁血蛮族共处的时代,作他们望而生畏的敌人,或带领他们征霸天下吧