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

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


  1
  2一九五.口袋猴子(用蜂蜜绷带种猴子,帮你活捉兔子、鸟、鼹鼠等小动物)
  3
  4	MT管理器打开游戏目录/assets/scripts/prefabs/bandage.lua文件,在inst:AddComponent("inventoryitem")的下一行插入以下内容:
  5
  6local function OnDeploy (inst, pt)
  7	local helper = SpawnPrefab("bandage")
  8	helper.Transform:SetPosition(pt.x, pt.y, pt.z)
  9	helper.AnimState:SetBank("kiki")
 10	helper.AnimState:SetBuild("kiki_basic")
 11	helper.AnimState:PlayAnimation("idle_loop", true)
 12	helper.Transform:SetFourFaced()
 13	helper.Transform:SetScale(0.8, 0.8, 0.8)
 14	helper:RemoveComponent("stackable")
 15	helper:RemoveComponent("healer")
 16	local sound = helper.entity:AddSoundEmitter()	
 17	helper.soundtype = ""
 18	local brain = require "brains/abigailbrain"
 19	helper:SetBrain(brain)
 20	helper:AddComponent("locomotor")
 21	helper.components.locomotor:SetTriggersCreep(false)
 22	helper.components.locomotor.pathcaps = { ignorecreep = false }
 23	helper.components.locomotor.walkspeed = 12
 24	helper:SetStateGraph("SGmonkey")
 25	helper:AddComponent("follower")
 26	GetPlayer().components.leader:AddFollower(helper)
 27	helper:AddComponent("combat")
 28	helper.components.combat.hiteffectsymbol = "torso"
 29	helper.components.combat:SetRetargetFunction(1, function(helper)
 30		if not helper.components.health:IsDead() then
 31			return FindEntity(helper, 20, function(guy)
 32				if guy.components.health and not guy.components.health:IsDead() then
 33				   return guy.prefab == "crow" or guy.prefab == "robin" or guy.prefab == "robin_winter" or guy.prefab == "bee" or guy.prefab == "killerbee" or guy.prefab == "rabbit" or guy.prefab == "butterfly" or guy.prefab == "mole"
 34				end
 35			end)
 36		end
 37	end )
 38	helper.components.combat:SetKeepTargetFunction(function(helper, target) return target and target:IsValid() end )
 39	helper.components.combat:SetAttackPeriod(1)
 40	helper.components.combat:SetRange(1, 2)
 41	helper.components.combat:SetDefaultDamage(1)
 42	helper.components.combat.onhitotherfn = function(helper, other, damage)
 43		if other.prefab == "crow" then
 44		   local prey = SpawnPrefab("crow")
 45		   GetPlayer().components.inventory:GiveItem(prey)
 46		end
 47		if other.prefab == "robin" then
 48		   local prey = SpawnPrefab("robin")
 49		   GetPlayer().components.inventory:GiveItem(prey)
 50		end
 51		if other.prefab == "robin_winter" then
 52		   local prey = SpawnPrefab("robin_winter")
 53		   GetPlayer().components.inventory:GiveItem(prey)
 54		end
 55		if other.prefab == "bee" then
 56		   local prey = SpawnPrefab("bee")
 57		   GetPlayer().components.inventory:GiveItem(prey)
 58		end
 59		if other.prefab == "killerbee" then
 60		   local prey = SpawnPrefab("killerbee")
 61		   GetPlayer().components.inventory:GiveItem(prey)
 62		end
 63		if other.prefab == "rabbit" then
 64		   local prey = SpawnPrefab("rabbit")
 65		   GetPlayer().components.inventory:GiveItem(prey)
 66		end
 67		if other.prefab == "butterfly" then
 68		   local prey = SpawnPrefab("butterfly")
 69		   GetPlayer().components.inventory:GiveItem(prey)
 70		end
 71		if other.prefab == "mole" then
 72		   local prey = SpawnPrefab("mole")
 73		   GetPlayer().components.inventory:GiveItem(prey)
 74		end
 75		other:Remove()
 76	end
 77	helper:AddComponent("health")
 78	helper.components.health:SetMaxHealth(1000)
 79	helper.components.health:SetInvincible(true)
 80	helper.components.health.nofadeout = true
 81	helper.components.inventoryitem:ChangeImageName("cave_banana")
 82	helper:AddComponent( "playerprox" )
 83	helper.components.playerprox:SetDist(3,5)
 84	helper.components.playerprox:SetOnPlayerNear(function(helper) helper.components.locomotor.walkspeed = 5 end )
 85	helper.components.playerprox:SetOnPlayerFar(function(helper) helper.components.locomotor.walkspeed = 12 end )
 86	helper:AddTag("helpers")
 87	inst.components.stackable:Get():Remove()
 88end
 89	inst:AddComponent("deployable")
 90	inst.components.deployable.ondeploy = OnDeploy
 91
 92local function onsave(inst, data)
 93	if inst:HasTag("helpers") then
 94		data.helpers = true
 95	end
 96end
 97local function onload(inst, data)
 98  if data and data.helpers then
 99	inst.AnimState:SetBank("kiki")
100	inst.AnimState:SetBuild("kiki_basic")
101	inst.AnimState:PlayAnimation("idle_loop", true)
102	inst.Transform:SetFourFaced()
103	inst.Transform:SetScale(0.8, 0.8, 0.8)
104	inst:RemoveComponent("stackable")
105	inst:RemoveComponent("healer")
106	local sound = inst.entity:AddSoundEmitter()	
107	inst.soundtype = ""
108	local brain = require "brains/abigailbrain"
109	inst:SetBrain(brain)
110	inst:AddComponent("locomotor")
111	inst.components.locomotor:SetTriggersCreep(false)
112	inst.components.locomotor.pathcaps = { ignorecreep = false }
113	inst.components.locomotor.walkspeed = 12
114	inst:SetStateGraph("SGmonkey")
115	inst:AddComponent("follower")
116	GetPlayer().components.leader:AddFollower(inst)
117	inst:AddComponent("combat")
118	inst.components.combat.hiteffectsymbol = "torso"
119	inst.components.combat:SetRetargetFunction(1, function(inst)
120		if not inst.components.health:IsDead() then
121			return FindEntity(inst, 20, function(guy)
122				if guy.components.health and not guy.components.health:IsDead() then
123				   return guy.prefab == "crow" or guy.prefab == "robin" or guy.prefab == "robin_winter" or guy.prefab == "bee" or guy.prefab == "killerbee" or guy.prefab == "rabbit" or guy.prefab == "butterfly" or guy.prefab == "mole"
124				end
125			end)
126		end
127	end )
128	inst.components.combat:SetKeepTargetFunction(function(inst, target) return target and target:IsValid() end )
129	inst.components.combat:SetAttackPeriod(1)
130	inst.components.combat:SetRange(1, 2)
131	inst.components.combat:SetDefaultDamage(1)
132	inst.components.combat.onhitotherfn = function(inst, other, damage)
133		if other.prefab == "crow" then
134		   local prey = SpawnPrefab("crow")
135		   GetPlayer().components.inventory:GiveItem(prey)
136		end
137		if other.prefab == "robin" then
138		   local prey = SpawnPrefab("robin")
139		   GetPlayer().components.inventory:GiveItem(prey)
140		end
141		if other.prefab == "robin_winter" then
142		   local prey = SpawnPrefab("robin_winter")
143		   GetPlayer().components.inventory:GiveItem(prey)
144		end
145		if other.prefab == "bee" then
146		   local prey = SpawnPrefab("bee")
147		   GetPlayer().components.inventory:GiveItem(prey)
148		end
149		if other.prefab == "killerbee" then
150		   local prey = SpawnPrefab("killerbee")
151		   GetPlayer().components.inventory:GiveItem(prey)
152		end
153		if other.prefab == "rabbit" then
154		   local prey = SpawnPrefab("rabbit")
155		   GetPlayer().components.inventory:GiveItem(prey)
156		end
157		if other.prefab == "butterfly" then
158		   local prey = SpawnPrefab("butterfly")
159		   GetPlayer().components.inventory:GiveItem(prey)
160		end
161		if other.prefab == "mole" then
162		   local prey = SpawnPrefab("mole")
163		   GetPlayer().components.inventory:GiveItem(prey)
164		end
165		other:Remove()
166	end
167	inst:AddComponent("health")
168	inst.components.health:SetMaxHealth(1000)
169	inst.components.health:SetInvincible(true)
170	inst.components.health.nofadeout = true
171	inst.components.inventoryitem:ChangeImageName("cave_banana")
172	inst:AddComponent( "playerprox" )
173	inst.components.playerprox:SetDist(3,5)
174	inst.components.playerprox:SetOnPlayerNear(function(inst) inst.components.locomotor.walkspeed = 5 end )
175	inst.components.playerprox:SetOnPlayerFar(function(inst) inst.components.locomotor.walkspeed = 12 end )
176	inst:AddTag("helpers")
177  end
178end
179	inst.OnSave = onsave
180	inst.OnLoad = onload
181
182	即可用蜂蜜绷带种猴子,鼠标左键点猴子,可将其放入物品栏(显示为香蕉的图标)。在附近有兔子、鸟、蜜蜂、杀人蜂、蝴蝶、鼹鼠等小动物时,可将猴子放在地上,会为你捕捉小动物,如果同时修改了“网上宠宠店”,就可以将捉到的小动物卖掉换黄金。如果不想要猴子了,在物品栏中对其按鼠标右键即可。蜂蜜绷带在生存选项(画着绳套)下,用1张纸、2个蜂蜜制造