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

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



二五四.噩梦草(用鸟粪种噩梦草,可采噩梦燃料,有一定概率出现地下巨人)

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

local items = { SWORD = "swap_ham_bat" }
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 OnDeploy (inst, pt)
	local darkgrass = SpawnPrefab("guano")
	darkgrass.Transform:SetPosition(pt.x, pt.y, pt.z)
	darkgrass.AnimState:SetBank("marsh_plant")
	darkgrass.AnimState:SetBuild("marsh_plant")
	darkgrass.AnimState:PlayAnimation("idle")
	darkgrass.Transform:SetScale(1.8, 1.8, 1.8)
	darkgrass.AnimState:SetMultColour(255/255,255/255,0/255,1)
	darkgrass:RemoveComponent("stackable")
	darkgrass:RemoveComponent("inventoryitem")
	darkgrass:RemoveComponent("fertilizer")
	darkgrass:RemoveComponent("smotherer")
	darkgrass:RemoveComponent("fuel")
	darkgrass:RemoveComponent("burnable")
	darkgrass:RemoveComponent("propagator")
	darkgrass:RemoveComponent("deployable")
	MakeMediumBurnable(darkgrass)
	MakeSmallPropagator(darkgrass)
	if darkgrass.flies then darkgrass.flies:Remove() darkgrass.flies = nil end
	darkgrass:AddComponent("workable")
	darkgrass.components.workable:SetWorkAction(ACTIONS.DIG)
	darkgrass.components.workable:SetWorkLeft(1)
	darkgrass.components.workable:SetOnFinishCallback(function(darkgrass)
		SpawnPrefab("nightmarefuel").Transform:SetPosition(darkgrass.Transform:GetWorldPosition())
		darkgrass:Remove()
	end )
	darkgrass:AddComponent("pickable")
	darkgrass.components.pickable:SetUp("nightmarefuel", 480)
	darkgrass.components.pickable:SetOnRegenFn(function(darkgrass) darkgrass.AnimState:SetMultColour(255/255,255/255,0/255,1) end )
	darkgrass.components.pickable:SetOnPickedFn(function(darkgrass)
		darkgrass.AnimState:SetMultColour(255/255,255/255,255/255,1)
		if math.random()<0.05 then
		   GetPlayer().components.playercontroller:ShakeCamera(darkgrass, "FULL", 1.5, 0.03, 2, 30)
		   GetPlayer().SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
		   SpawnPrefab("collapse_big").Transform:SetPosition(darkgrass.Transform:GetWorldPosition())
		   local giant = SpawnPrefab("guano")
		   giant.Transform:SetPosition(darkgrass.Transform:GetWorldPosition())
		   giant.entity:AddSoundEmitter()
		   giant.AnimState:SetBank("wilson")
		   giant.AnimState:SetBuild("wolfgang")
		   giant.AnimState:PlayAnimation("idle")
		   giant.AnimState:OverrideSymbol("swap_object", "swap_ham_bat", "swap_ham_bat")
		   giant.AnimState:OverrideSymbol("swap_body", "armor_slurper", "swap_body")
		   giant.AnimState:Show("ARM_carry") 
		   giant.AnimState:Hide("ARM_normal")
		   giant.Transform:SetFourFaced()
		   giant.Transform:SetScale(3.5,3.5,3.5)
		   local sound = giant.entity:AddSoundEmitter()
		   local shadow = giant.entity:AddDynamicShadow()
		   shadow:SetSize( 6, 3.5 )
		   MakeCharacterPhysics(giant, 200, 1)
		   local minimap = giant.entity:AddMiniMapEntity()
		   minimap:SetIcon("wolfgang.png")
		   local brain = require "brains/leifbrain"
		   giant:SetBrain(brain)
		   giant:AddComponent("locomotor")
		   giant.components.locomotor.walkspeed = 1
		   giant.components.locomotor.runspeed = 2
		   giant:SetStateGraph("SGshadowwaxwell")
		   giant:RemoveComponent("stackable")
		   giant:RemoveComponent("inventoryitem")
		   giant:RemoveComponent("fertilizer")
		   giant:RemoveComponent("smotherer")
		   giant:RemoveComponent("fuel")
		   giant:RemoveComponent("burnable")
		   giant:RemoveComponent("propagator")
		   giant:RemoveComponent("deployable")
		   if giant.flies then giant.flies:Remove() giant.flies = nil end
		   giant:AddComponent("follower")
		   giant:AddComponent("inventory")
		   giant:AddComponent("combat")
		   giant.components.combat.hiteffectsymbol = "torso"
		   giant.components.combat:SetDefaultDamage(70)
		   giant.components.combat:SetAttackPeriod(3)
		   giant.components.combat.onhitotherfn = function()
			   giant.SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
			   GetPlayer().components.playercontroller:ShakeCamera(giant, "FULL", 0.5, 0.05, 2, 40)
		   end
		   giant.components.combat:SetAreaDamage(5, 0.8)
		   giant.components.combat:SetRetargetFunction(3, function(giant)
			   if not giant.components.health:IsDead() then
				  return FindEntity(giant, 20, function(guy)
					  return giant.components.combat:CanTarget(guy) and not guy:HasTag("giant")
				  end )
			   end
		   end )
		   giant:ListenForEvent("attacked", function(giant, data)
			   giant.components.combat:SetTarget(data.attacker)
		   end )
		   giant.Physics:SetCollisionCallback(function(giant, other)
			   if other and other.components.workable and other.components.workable.workleft > 0 then
				  other.components.workable:Destroy(giant)
			   end
		   end )
		   giant:AddComponent("health")
		   giant.components.health:SetMaxHealth(8000)
		   giant.components.health.nofadeout = true
		   giant:AddComponent("sanityaura")
		   giant.components.sanityaura.aura = -TUNING.SANITYAURA_LARGE
		   giant:ListenForEvent("death", function()
			   local pt1 = giant:GetPosition()
			   for k = 1,math.random(20,35) do
				   local gold = SpawnPrefab("goldnugget")
				   gold.Transform:SetPosition(pt1.x+(math.random(3)-math.random(3)), 0, pt1.z+(math.random(3)-math.random(3)))
			   end
			   local rewards = {"walrus_tusk","trunk_summer","trunk_winter","deerclops_eyeball","minotaurhorn"}
			   local reward = rewards[math.random(#rewards)]
			   SpawnPrefab(reward).Transform:SetPosition(pt1.x, 0, pt1.z)
		   end )
		   giant:DoTaskInTime(480, function(giant)
			   giant:Remove()
		   end )
		   giant:AddTag("monster")
		   giant:AddTag("giant")
		end
	end )
	darkgrass:AddTag("darkgrass")
	inst.components.stackable:Get():Remove()
end
	inst:AddComponent("deployable")
	inst.components.deployable.ondeploy = OnDeploy
local function onsave(inst, data)
	if inst:HasTag("darkgrass") then
	   data.darkgrass = true
	end
	if inst:HasTag("giant") then
	   data.giant = true
	end
end
local function onload(inst, data)
	if data and data.darkgrass then
	   inst.AnimState:SetBank("marsh_plant")
	   inst.AnimState:SetBuild("marsh_plant")
	   inst.AnimState:PlayAnimation("idle")
	   inst.Transform:SetScale(1.8, 1.8, 1.8)
	   inst.AnimState:SetMultColour(255/255,255/255,0/255,1)
	   inst:RemoveComponent("stackable")
	   inst:RemoveComponent("inventoryitem")
	   inst:RemoveComponent("fertilizer")
	   inst:RemoveComponent("smotherer")
	   inst:RemoveComponent("fuel")
	   inst:RemoveComponent("burnable")
	   inst:RemoveComponent("propagator")
	   inst:RemoveComponent("deployable")
	   MakeMediumBurnable(inst)
	   MakeSmallPropagator(inst)
	   if inst.flies then inst.flies:Remove() inst.flies = nil end
	   inst:AddComponent("workable")
	   inst.components.workable:SetWorkAction(ACTIONS.DIG)
	   inst.components.workable:SetWorkLeft(1)
	   inst.components.workable:SetOnFinishCallback(function(inst)
		   SpawnPrefab("nightmarefuel").Transform:SetPosition(inst.Transform:GetWorldPosition())
		   inst:Remove()
	   end )
	   inst:AddComponent("pickable")
	   inst.components.pickable:SetUp("nightmarefuel", 480)
	   inst.components.pickable:SetOnRegenFn(function(inst) inst.AnimState:SetMultColour(255/255,255/255,0/255,1) end )
	   inst.components.pickable:SetOnPickedFn(function(inst)
		   inst.AnimState:SetMultColour(255/255,255/255,255/255,1)
		   if math.random()<0.05 then
			  GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 1.5, 0.03, 2, 30)
			  GetPlayer().SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
			  SpawnPrefab("collapse_big").Transform:SetPosition(inst.Transform:GetWorldPosition())
			  local giant = SpawnPrefab("guano")
			  giant.Transform:SetPosition(inst.Transform:GetWorldPosition())
			  giant.entity:AddSoundEmitter()
			  giant.AnimState:SetBank("wilson")
			  giant.AnimState:SetBuild("wolfgang")
			  giant.AnimState:PlayAnimation("idle")
			  giant.AnimState:OverrideSymbol("swap_object", "swap_ham_bat", "swap_ham_bat")
			  giant.AnimState:OverrideSymbol("swap_body", "armor_slurper", "swap_body")
			  giant.AnimState:Show("ARM_carry") 
			  giant.AnimState:Hide("ARM_normal")
			  giant.Transform:SetFourFaced()
			  giant.Transform:SetScale(3.5,3.5,3.5)
			  local sound = giant.entity:AddSoundEmitter()
			  local shadow = giant.entity:AddDynamicShadow()
			  shadow:SetSize( 6, 3.5 )
			  MakeCharacterPhysics(giant, 200, 1)
			  local minimap = giant.entity:AddMiniMapEntity()
			  minimap:SetIcon("wolfgang.png")
			  local brain = require "brains/leifbrain"
			  giant:SetBrain(brain)
			  giant:AddComponent("locomotor")
			  giant.components.locomotor.walkspeed = 1
			  giant.components.locomotor.runspeed = 2
			  giant:SetStateGraph("SGshadowwaxwell")
			  giant:RemoveComponent("stackable")
			  giant:RemoveComponent("inventoryitem")
			  giant:RemoveComponent("fertilizer")
			  giant:RemoveComponent("smotherer")
			  giant:RemoveComponent("fuel")
			  giant:RemoveComponent("burnable")
			  giant:RemoveComponent("propagator")
			  giant:RemoveComponent("deployable")
			  if giant.flies then giant.flies:Remove() giant.flies = nil end
			  giant:AddComponent("follower")
			  giant:AddComponent("inventory")
			  giant:AddComponent("combat")
			  giant.components.combat.hiteffectsymbol = "torso"
			  giant.components.combat:SetDefaultDamage(70)
			  giant.components.combat:SetAttackPeriod(3)
			  giant.components.combat.onhitotherfn = function()
				  giant.SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
				  GetPlayer().components.playercontroller:ShakeCamera(giant, "FULL", 0.5, 0.05, 2, 40)
			  end
			  giant.components.combat:SetAreaDamage(5, 0.8)
			  giant.components.combat:SetRetargetFunction(3, function(giant)
				  if not giant.components.health:IsDead() then
					 return FindEntity(giant, 20, function(guy)
						 return giant.components.combat:CanTarget(guy) and not guy:HasTag("giant")
					 end )
				  end
			  end )
			  giant:ListenForEvent("attacked", function(giant, data)
				  giant.components.combat:SetTarget(data.attacker)
			  end )
			  giant.Physics:SetCollisionCallback(function(giant, other)
				  if other and other.components.workable and other.components.workable.workleft > 0 then
					 other.components.workable:Destroy(giant)
				  end
			  end )
			  giant:AddComponent("health")
			  giant.components.health:SetMaxHealth(8000)
			  giant.components.health.nofadeout = true
			  giant:AddComponent("sanityaura")
			  giant.components.sanityaura.aura = -TUNING.SANITYAURA_LARGE
			  giant:ListenForEvent("death", function()
				  local pt1 = giant:GetPosition()
				  for k = 1,math.random(20,35) do
					  local gold = SpawnPrefab("goldnugget")
					  gold.Transform:SetPosition(pt1.x+(math.random(3)-math.random(3)), 0, pt1.z+(math.random(3)-math.random(3)))
				  end
				  local rewards = {"walrus_tusk","trunk_summer","trunk_winter","deerclops_eyeball","minotaurhorn"}
				  local reward = rewards[math.random(#rewards)]
				  SpawnPrefab(reward).Transform:SetPosition(pt1.x, 0, pt1.z)
			  end )
			  giant:DoTaskInTime(480, function(giant)
				  giant:Remove()
			  end )
			  giant:AddTag("monster")
			  giant:AddTag("giant")
		   end
	   end )
	   inst:AddTag("darkgrass")
	 end
	if data and data.giant then
	   inst.entity:AddSoundEmitter()
	   inst.AnimState:SetBank("wilson")
	   inst.AnimState:SetBuild("wolfgang")
	   inst.AnimState:PlayAnimation("idle")
	   inst.AnimState:OverrideSymbol("swap_object", "swap_ham_bat", "swap_ham_bat")
	   inst.AnimState:OverrideSymbol("swap_body", "armor_slurper", "swap_body")
	   inst.AnimState:Show("ARM_carry") 
	   inst.AnimState:Hide("ARM_normal")
	   inst.Transform:SetFourFaced()
	   inst.Transform:SetScale(3.5,3.5,3.5)
	   local sound = inst.entity:AddSoundEmitter()
	   local shadow = inst.entity:AddDynamicShadow()
	   shadow:SetSize( 6, 3.5 )
	   MakeCharacterPhysics(inst, 200, 1)
	   local minimap = inst.entity:AddMiniMapEntity()
	   minimap:SetIcon("wolfgang.png")
	   local brain = require "brains/leifbrain"
	   inst:SetBrain(brain)
	   inst:AddComponent("locomotor")
	   inst.components.locomotor.walkspeed = 1
	   inst.components.locomotor.runspeed = 2
	   inst:SetStateGraph("SGshadowwaxwell")
	   inst:RemoveComponent("stackable")
	   inst:RemoveComponent("inventoryitem")
	   inst:RemoveComponent("fertilizer")
	   inst:RemoveComponent("smotherer")
	   inst:RemoveComponent("fuel")
	   inst:RemoveComponent("burnable")
	   inst:RemoveComponent("propagator")
	   inst:RemoveComponent("deployable")
	   if inst.flies then inst.flies:Remove() inst.flies = nil end
	   inst:AddComponent("follower")
	   inst:AddComponent("inventory")
	   inst:AddComponent("combat")
	   inst.components.combat.hiteffectsymbol = "torso"
	   inst.components.combat:SetDefaultDamage(70)
	   inst.components.combat:SetAttackPeriod(3)
	   inst.components.combat.onhitotherfn = function()
		   inst.SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
		   GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 0.5, 0.05, 2, 40)
	   end
	   inst.components.combat:SetAreaDamage(5, 0.8)
	   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("giant")
			  end )
		   end
	   end )
	   inst:ListenForEvent("attacked", function(inst, data)
		   inst.components.combat:SetTarget(data.attacker)
	   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:AddComponent("health")
	   inst.components.health:SetMaxHealth(8000)
	   inst.components.health.nofadeout = true
	   inst:AddComponent("sanityaura")
	   inst.components.sanityaura.aura = -TUNING.SANITYAURA_LARGE
	   inst:ListenForEvent("death", function()
		   local pt1 = inst:GetPosition()
		   for k = 1,math.random(20,35) do
			   local gold = SpawnPrefab("goldnugget")
			   gold.Transform:SetPosition(pt1.x+(math.random(3)-math.random(3)), 0, pt1.z+(math.random(3)-math.random(3)))
		   end
		   local rewards = {"walrus_tusk","trunk_summer","trunk_winter","deerclops_eyeball","minotaurhorn"}
		   local reward = rewards[math.random(#rewards)]
		   SpawnPrefab(reward).Transform:SetPosition(pt1.x, 0, pt1.z)
	   end )
	   inst:DoTaskInTime(480, function(inst)
		   inst:Remove()
	   end )
	   inst:AddTag("monster")
	   inst:AddTag("giant")
	end
end
	inst.OnSave = onsave
	inst.OnLoad = onload

	即可用鸟粪(白色便便)种噩梦草(请远离基地种植),可采摘噩梦燃料,每天都能采一次。采摘时有一定概率出现地下巨人,将攻击你,消灭巨人可获得黄金、巨鹿眼球、远古守护者角、海象牙等宝物。巨人的血量及攻击力都很强,如果打不过,就先逃跑避避风头,一天后巨人将回到地下。巨人在小地图上显示为大力士的图标,绕着点走吧