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

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



一九六.口袋浣熊(用纸种口袋浣熊,捕猎、战斗好帮手,喂鱼变身超级浣熊)

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

local function OnDeploy (inst, pt)
	local coon = SpawnPrefab("papyrus")
	coon.Transform:SetPosition(pt.x, pt.y, pt.z)
	coon.AnimState:SetBank("catcoon")
	coon.AnimState:SetBuild("catcoon_build")
	coon.AnimState:PlayAnimation("idle_loop")
	coon.Transform:SetFourFaced()
	coon.Transform:SetScale(0.8, 0.8, 0.8)
	coon.entity:AddSoundEmitter()
	local shadow = coon.entity:AddDynamicShadow()
	shadow:SetSize(2,0.75)
	coon:RemoveComponent("stackable")
	coon:RemoveComponent("fuel")
	coon:RemoveComponent("tradable")
	coon:RemoveComponent("burnable")
	coon:RemoveComponent("propagator")
	coon:RemoveComponent("deployable")
	coon:RemoveTag("cattoy")
	coon.components.inventoryitem:ChangeImageName("catcoonhat")
	coon:AddComponent("named")
	coon.components.named:SetName("Catcoon")
	coon:AddComponent("follower")
	coon.components.follower:SetLeader(GetPlayer())
	coon:AddComponent("locomotor")
	coon.components.locomotor.walkspeed = 12
	coon:SetStateGraph("SGcatcoon")
	local brain = require "brains/abigailbrain"
	coon:SetBrain(brain)
	coon:AddComponent("health")
	coon.components.health:SetMaxHealth(3000)
	coon:AddComponent("lootdropper")
	coon.components.lootdropper:SetLoot({"smallmeat"})
	coon:AddComponent("combat")
	coon.components.combat:SetDefaultDamage(50)
	coon.components.combat:SetRange(4)
	coon.components.combat:SetAttackPeriod(0.5)
	coon.components.combat:SetHurtSound("dontstarve_DLC001/creatures/catcoon/hurt")
	coon.components.combat.battlecryinterval = 20
	coon.components.combat:SetRetargetFunction(1, function(coon)
		if not coon.components.health:IsDead() then
			return FindEntity(GetPlayer(), 20, function(guy)
				if 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") or guy:HasTag("smallcreature")
				end
			end)
		end
	end )
	coon.components.combat:SetKeepTargetFunction(function(coon, target) return target and target:IsValid() end )
	coon:ListenForEvent("attacked", function(coon, data)
		if data.attacker ~= GetPlayer() then
		   coon.components.combat:SetTarget(data.attacker)
		else
		   coon.components.health:Kill()
		end
	end )
	coon:AddComponent( "playerprox" )
	coon.components.playerprox:SetDist(3,5)
	coon.components.playerprox:SetOnPlayerNear(function(coon) coon.components.locomotor.walkspeed = 5 end )
	coon.components.playerprox:SetOnPlayerFar(function(coon) coon.components.locomotor.walkspeed = 12 end )
	coon:AddComponent("trader")
	coon.components.trader:SetAcceptTest(function(coon, item)
		if not coon:HasTag("supercoon") then
		   if item.prefab == "fish" then
			  return true
		   end
		   if item.prefab == "smallmeat" then
			  return coon.components.health:GetPercent() < 1
		   end
		end
		return false
	end )
	coon.components.trader.onaccept = function(coon, giver, item)
		if item.prefab == "fish" then
		   coon:AddTag("supercoon")
		   coon.components.named:SetName("SuperCatcoon")
		   SpawnPrefab("collapse_big").Transform:SetPosition(coon.Transform:GetWorldPosition())
		   coon.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
		   coon.Transform:SetScale(1.3, 1.3, 1.3)
		   coon.components.inventoryitem.canbepickedup = false
		   coon.components.health:SetInvincible(true)
		   coon.components.combat:SetDefaultDamage(500)
		   coon:DoTaskInTime(60, function(coon)
			   coon:RemoveTag("supercoon")
			   coon.components.named:SetName("Catcoon")
			   SpawnPrefab("collapse_big").Transform:SetPosition(coon.Transform:GetWorldPosition())
			   coon.AnimState:SetBloomEffectHandle("")
			   coon.Transform:SetScale(0.8, 0.8, 0.8)
			   coon.components.inventoryitem.canbepickedup = true
			   coon.components.health:SetInvincible(false)
			   coon.components.combat:SetDefaultDamage(50)
		   end )
		end
		if item.prefab == "smallmeat" then
		   coon.components.health:DoDelta(1000)
		end
	end
	coon:AddTag("coons")
	inst.components.stackable:Get():Remove()
end
	inst:AddComponent("deployable")
	inst.components.deployable.ondeploy = OnDeploy
local function onsave(inst, data)
	if inst:HasTag("coons") then
		data.coons = true
	end
end
local function onload(inst, data)
  if data and data.coons then
	inst.AnimState:SetBank("catcoon")
	inst.AnimState:SetBuild("catcoon_build")
	inst.AnimState:PlayAnimation("idle_loop")
	inst.Transform:SetFourFaced()
	inst.Transform:SetScale(0.8, 0.8, 0.8)
	inst.entity:AddSoundEmitter()
	local shadow = inst.entity:AddDynamicShadow()
	shadow:SetSize(2,0.75)
	inst:RemoveComponent("stackable")
	inst:RemoveComponent("fuel")
	inst:RemoveComponent("tradable")
	inst:RemoveComponent("burnable")
	inst:RemoveComponent("propagator")
	inst:RemoveComponent("deployable")
	inst:RemoveTag("cattoy")
	inst.components.inventoryitem:ChangeImageName("catcoonhat")
	inst:AddComponent("named")
	inst.components.named:SetName("Catcoon")
	inst:AddComponent("follower")
	inst.components.follower:SetLeader(GetPlayer())
	inst:AddComponent("locomotor")
	inst.components.locomotor.walkspeed = 12
	inst:SetStateGraph("SGcatcoon")
	local brain = require "brains/abigailbrain"
	inst:SetBrain(brain)
	inst:AddComponent("health")
	inst.components.health:SetMaxHealth(3000)
	inst:AddComponent("lootdropper")
	inst.components.lootdropper:SetLoot({"smallmeat"})
	inst:AddComponent("combat")
	inst.components.combat:SetDefaultDamage(50)
	inst.components.combat:SetRange(4)
	inst.components.combat:SetAttackPeriod(0.5)
	inst.components.combat:SetHurtSound("dontstarve_DLC001/creatures/catcoon/hurt")
	inst.components.combat.battlecryinterval = 20
	inst.components.combat:SetRetargetFunction(1, function(inst)
		if not inst.components.health:IsDead() then
			return FindEntity(GetPlayer(), 20, function(guy)
				if 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") or guy:HasTag("smallcreature")
				end
			end)
		end
	end )
	inst.components.combat:SetKeepTargetFunction(function(inst, target) return target and target:IsValid() end )
	inst:ListenForEvent("attacked", function(inst, data)
		if data.attacker ~= GetPlayer() then
		   inst.components.combat:SetTarget(data.attacker)
		else
		   inst.components.health:Kill()
		end
	end )
	inst:AddComponent( "playerprox" )
	inst.components.playerprox:SetDist(3,5)
	inst.components.playerprox:SetOnPlayerNear(function(inst) inst.components.locomotor.walkspeed = 5 end )
	inst.components.playerprox:SetOnPlayerFar(function(inst) inst.components.locomotor.walkspeed = 12 end )
	inst:AddComponent("trader")
	inst.components.trader:SetAcceptTest(function(inst, item)
		if not inst:HasTag("supercoon") then
		   if item.prefab == "fish" then
			  return true
		   end
		   if item.prefab == "smallmeat" then
			  return inst.components.health:GetPercent() < 1
		   end
		end
		return false
	end )
	inst.components.trader.onaccept = function(inst, giver, item)
		if item.prefab == "fish" then
		   inst:AddTag("supercoon")
		   inst.components.named:SetName("SuperCatcoon")
		   SpawnPrefab("collapse_big").Transform:SetPosition(inst.Transform:GetWorldPosition())
		   inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
		   inst.Transform:SetScale(1.3, 1.3, 1.3)
		   inst.components.inventoryitem.canbepickedup = false
		   inst.components.health:SetInvincible(true)
		   inst.components.combat:SetDefaultDamage(500)
		   inst:DoTaskInTime(60, function(inst)
			   inst:RemoveTag("supercoon")
			   inst.components.named:SetName("Catcoon")
			   SpawnPrefab("collapse_big").Transform:SetPosition(inst.Transform:GetWorldPosition())
			   inst.AnimState:SetBloomEffectHandle("")
			   inst.Transform:SetScale(0.8, 0.8, 0.8)
			   inst.components.inventoryitem.canbepickedup = true
			   inst.components.health:SetInvincible(false)
			   inst.components.combat:SetDefaultDamage(50)
		   end )
		end
		if item.prefab == "smallmeat" then
		   inst.components.health:DoDelta(1000)
		end
	end
	inst:AddTag("coons")
  end
end
	inst.OnSave = onsave
	inst.OnLoad = onload

	即可用纸种口袋浣熊,帮你捕猎、战斗。鼠标左键点浣熊,可将其放入物品栏(显示为浣熊帽的图标)。喂浣熊小肉,可为其补血(3块可补满),如果喂浣熊鱼,则变身超级浣熊,不会受伤,攻击力提高10倍,60秒后变回来。在超级浣熊状态下,口袋浣熊无法被拿起,也不接受食物。不想要口袋浣熊了,在物品栏中对其按鼠标右键即可。纸在精炼选项(画着白色宝石)下,用4个芦苇制造