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

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


  1
  2二五二.鲜果龙树(用蝙蝠棒种龙树,每天掉落水果,可上树)
  3
  4	MT管理器打开游戏目录/assets/scripts/prefabs/batbat.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
  5
  6local colours=
  7{
  8	{198/255,43/255,43/255},
  9	{0/255,255/255,0/255},
 10	{0/255,0/255,255/255},
 11	{255/255,255/255,0/255},
 12	{109/255,50/255,163/255},
 13	{255/255,0/255,0/255},
 14	{255/255,255/255,255/255},
 15}
 16local function createtree(inst)
 17	local pt = inst:GetPosition()
 18	local phantom = SpawnPrefab("batbat")
 19	phantom.Transform:SetPosition(pt.x, pt.y, pt.z)
 20	phantom.AnimState:SetBank("firepit")
 21	phantom.AnimState:SetBuild("firepit")
 22	phantom.AnimState:PlayAnimation("idle",false)
 23	phantom.Transform:SetScale(0.8, 0.8, 0.8)
 24	phantom:RemoveComponent("weapon")
 25	phantom:RemoveComponent("finiteuses")
 26	phantom:RemoveComponent("inventoryitem")
 27	phantom:RemoveComponent("equippable")
 28	phantom:RemoveComponent("deployable")
 29	phantom:RemoveTag("dull")
 30	phantom:AddTag("NOCLICK")
 31	local light = phantom.entity:AddLight()
 32	phantom.Light:SetFalloff(0.6)
 33	phantom.Light:SetIntensity(.8)
 34	phantom.Light:SetRadius(5)
 35	phantom.colour_idx = math.random(#colours)
 36	phantom.Light:SetColour(colours[phantom.colour_idx][1],colours[phantom.colour_idx][2],colours[phantom.colour_idx][3])
 37	phantom.Light:Enable(true)
 38	phantom:DoPeriodicTask(15, function()
 39		phantom.colour_idx = math.random(#colours)
 40		phantom.Light:SetColour(colours[phantom.colour_idx][1],colours[phantom.colour_idx][2],colours[phantom.colour_idx][3])
 41	end )
 42	phantom:ListenForEvent( "daytime", function()
 43		local pos = Vector3(phantom.Transform:GetWorldPosition())
 44		local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, 5)
 45		for k,v in pairs(ents) do
 46			if v.components.inventoryitem and not v.components.inventoryitem:IsHeld() then
 47			   if v.prefab == "durian" or v.prefab == "pomegranate" or v.prefab == "dragonfruit" then
 48				  v:Remove()
 49			   end
 50			end
 51		end
 52		phantom:DoTaskInTime(0.3, function(phantom)
 53			phantom:StartThread(function()
 54				for k = 1,math.random(3,7) do
 55					local pt1 = phantom:GetPosition()
 56					local names = {"durian","pomegranate","dragonfruit"}
 57					local name = names[math.random(#names)]
 58					local fruit = SpawnPrefab(name)
 59					fruit.Transform:SetPosition(pt1.x+(math.random(5)-math.random(5)), 5, pt1.z+(math.random(5)-math.random(5)))
 60					Sleep(0.3)
 61				end
 62			end )
 63		end )
 64	end , GetWorld() )
 65	phantom:AddTag("phantom")
 66	phantom.long = SpawnPrefab("batbat")
 67	phantom.long.AnimState:SetBank("worm")
 68	phantom.long.AnimState:SetBuild("worm")
 69	phantom.long.AnimState:SetPercent("atk", 0.40)
 70	phantom.long.Transform:SetScale(1.5, 1.5, 1.5)
 71	phantom.long.Physics:SetActive(false)
 72	phantom.long:RemoveComponent("weapon")
 73	phantom.long:RemoveComponent("finiteuses")
 74	phantom.long:RemoveComponent("inventoryitem")
 75	phantom.long:RemoveComponent("equippable")
 76	phantom.long:RemoveComponent("deployable")
 77	phantom.long:RemoveTag("dull")
 78	local follower = phantom.long.entity:AddFollower()
 79	follower:FollowSymbol( phantom.GUID, "swap_object", 10, -90, 0 )
 80	phantom.long.components.inspectable.getstatus = function()
 81		if not GetPlayer():HasTag("climbtree") then
 82		   GetPlayer():AddTag("climbtree")
 83		   GetPlayer().components.playercontroller:Enable(false)
 84		   local pt0 = phantom:GetPosition()
 85		   GetPlayer().Transform:SetPosition(pt0.x, 10.2, pt0.z)
 86		   GetPlayer():DoTaskInTime(5, function()
 87			   GetPlayer().Transform:SetPosition(pt0.x, 0, pt0.z)
 88			   GetPlayer():RemoveTag("climbtree")
 89			   GetPlayer().components.playercontroller:Enable(true)
 90		   end )
 91		end
 92	end
 93	phantom.long:AddTag("lightningrod")
 94	phantom.long:ListenForEvent("lightningstrike", function()
 95		phantom.long.AnimState:SetBloomEffectHandle( "shaders/anim.ksh" )
 96		phantom.long:DoTaskInTime(60, function()
 97			phantom.long.AnimState:SetBloomEffectHandle("")
 98		end )
 99	end )
100	phantom.long:AddComponent("sanityaura")
101	phantom.long.components.sanityaura.aura = TUNING.SANITYAURA_MED
102	phantom.long:AddTag("goodbye")
103	phantom.guo1 = SpawnPrefab("batbat")
104	phantom.guo1.AnimState:SetBank("durian")
105	phantom.guo1.AnimState:SetBuild("durian")
106	phantom.guo1.AnimState:PlayAnimation("idle")
107	phantom.guo1.Transform:SetScale(1.5, 1.5, 1.5)
108	phantom.guo1.Physics:SetActive(false)
109	phantom.guo1:RemoveComponent("weapon")
110	phantom.guo1:RemoveComponent("finiteuses")
111	phantom.guo1:RemoveComponent("inventoryitem")
112	phantom.guo1:RemoveComponent("equippable")
113	phantom.guo1:RemoveComponent("deployable")
114	phantom.guo1:RemoveTag("dull")
115	local follower = phantom.guo1.entity:AddFollower()
116	follower:FollowSymbol( phantom.GUID, "swap_object", -550, -580, 0 )
117	phantom.guo1:AddTag("NOCLICK")
118	phantom.guo1:AddTag("goodbye")
119	phantom.guo2 = SpawnPrefab("batbat")
120	phantom.guo2.AnimState:SetBank("pomegranate")
121	phantom.guo2.AnimState:SetBuild("pomegranate")
122	phantom.guo2.AnimState:PlayAnimation("idle")
123	phantom.guo2.Transform:SetScale(1.5, 1.5, 1.5)
124	phantom.guo2.Physics:SetActive(false)
125	phantom.guo2:RemoveComponent("weapon")
126	phantom.guo2:RemoveComponent("finiteuses")
127	phantom.guo2:RemoveComponent("inventoryitem")
128	phantom.guo2:RemoveComponent("equippable")
129	phantom.guo2:RemoveComponent("deployable")
130	phantom.guo2:RemoveTag("dull")
131	local follower = phantom.guo2.entity:AddFollower()
132	follower:FollowSymbol( phantom.GUID, "swap_object", 610, -690, 0 )
133	phantom.guo2:AddTag("NOCLICK")
134	phantom.guo2:AddTag("goodbye")
135	phantom.guo3 = SpawnPrefab("batbat")
136	phantom.guo3.AnimState:SetBank("dragonfruit")
137	phantom.guo3.AnimState:SetBuild("dragonfruit")
138	phantom.guo3.AnimState:PlayAnimation("idle")
139	phantom.guo3.Transform:SetScale(1.5, 1.5, 1.5)
140	phantom.guo3.Physics:SetActive(false)
141	phantom.guo3:RemoveComponent("weapon")
142	phantom.guo3:RemoveComponent("finiteuses")
143	phantom.guo3:RemoveComponent("inventoryitem")
144	phantom.guo3:RemoveComponent("equippable")
145	phantom.guo3:RemoveComponent("deployable")
146	phantom.guo3:RemoveTag("dull")
147	local follower = phantom.guo3.entity:AddFollower()
148	follower:FollowSymbol( phantom.GUID, "swap_object", -290, -1385, 0 )
149	phantom.guo3:AddTag("NOCLICK")
150	phantom.guo3:AddTag("goodbye")
151end
152local function OnDeploy (inst, pt)
153	createtree(inst)
154	inst:Remove()
155end
156	inst:AddComponent("deployable")
157	inst.components.deployable.ondeploy = OnDeploy
158local function onsave(inst, data)
159	if inst:HasTag("goodbye") then
160		data.goodbye = true
161	end
162	if inst:HasTag("phantom") then
163		data.phantom = true
164	end
165end
166local function onload(inst, data)
167	if data and data.goodbye then
168	   inst:Remove()
169	end
170	if data and data.phantom then
171	   createtree(inst)
172	   inst:Remove()
173	end
174end
175	inst.OnSave = onsave
176	inst.OnLoad = onload
177MakeLargeBurnable(inst)
178MakeLargePropagator(inst)
179
180	即可用蝙蝠棒种龙树,靠近可补脑,每天会掉落各种水果。龙树可吸收闪电,起到避雷针的作用。鼠标左键点龙树,会爬上树顶眺望风景,5秒后滑下。龙树会不断变化七彩光,夜晚可照明。不想要龙树时,烧掉即可。蝙蝠棒在魔法选项(画着红骷髅)下,用5个蝙蝠翅膀、2个活木头、1个紫宝石制造