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

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


  1
  2二六九.公车站(用草席卷种公车站,买票坐到下一站)
  3
  4	MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/bedroll_straw.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
  5
  6	inst.kind = ""
  7	inst.soundpath   = "dontstarve/creatures/rook/"
  8	inst.effortsound = "dontstarve/creatures/rook/steam"
  9local function OnDeploy (inst, pt)
 10	local busstation = SpawnPrefab("bedroll_straw")
 11	busstation.Transform:SetPosition(pt.x, pt.y, pt.z)
 12	busstation.AnimState:SetBank("sign_home")
 13	busstation.AnimState:SetBuild("sign_home")
 14	busstation.AnimState:PlayAnimation("idle")
 15	busstation.Transform:SetScale(1.5, 1.5, 1.5)
 16	busstation.AnimState:SetMultColour(255/255,105/255,0/255,0.8)
 17	local minimap = busstation.entity:AddMiniMapEntity()
 18	minimap:SetIcon( "sign.png" )
 19	busstation:RemoveComponent("inventoryitem")
 20	busstation:RemoveComponent("stackable")
 21	busstation:RemoveComponent("fuel")
 22	busstation:RemoveComponent("sleepingbag")
 23	busstation:RemoveComponent("burnable")
 24	busstation:RemoveComponent("propagator")
 25	busstation:RemoveComponent("deployable")
 26	busstation:AddTag("busstation")
 27	busstation:AddComponent("workable")
 28	busstation.components.workable:SetWorkAction(ACTIONS.HAMMER)
 29	busstation.components.workable:SetWorkLeft(3)
 30	busstation.components.workable:SetOnFinishCallback(function(busstation)
 31		SpawnPrefab("collapse_big").Transform:SetPosition(busstation.Transform:GetWorldPosition())
 32		GetPlayer().SoundEmitter:PlaySound("dontstarve/common/destroy_wood")
 33		busstation:Remove()
 34	end )
 35	busstation:AddComponent("trader")
 36	busstation.components.trader:SetAcceptTest(function(busstation, item) 
 37	   if item.prefab == "goldnugget" then
 38		  return true
 39	   end
 40	   return false
 41	end )
 42	busstation.components.trader.onaccept = function(busstation, giver, item)
 43		busstation:AddTag("startingpoint")
 44		local target = FindEntity(busstation, 3000, function(guy) 
 45			return guy:HasTag("busstation") and not guy:HasTag("startingpoint")
 46		end )
 47		if target then
 48		   GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold")
 49		   GetPlayer().components.playercontroller:Enable(false)
 50		   local pt1 = busstation:GetPosition()
 51		   local bus = SpawnPrefab("bedroll_straw")
 52		   bus.Transform:SetPosition(pt1.x+15+2, 0, pt1.z-15+2)
 53		   bus.AnimState:SetBank("rook")
 54		   bus.AnimState:SetBuild("rook_build")
 55		   bus.AnimState:PlayAnimation("idle", true)
 56		   bus.Transform:SetFourFaced()
 57		   bus.Transform:SetScale(1.2, 1.2, 1.2)
 58		   bus.AnimState:SetMultColour(255/255,105/255,0/255,1)
 59		   local sound = bus.entity:AddSoundEmitter()
 60		   bus:RemoveComponent("inventoryitem")
 61		   bus:RemoveComponent("stackable")
 62		   bus:RemoveComponent("fuel")
 63		   bus:RemoveComponent("sleepingbag")
 64		   bus:RemoveComponent("burnable")
 65		   bus:RemoveComponent("propagator")
 66		   bus:RemoveComponent("deployable")
 67		   bus:AddTag("goodbye")
 68		   bus:AddComponent("locomotor")
 69		   bus.components.locomotor.walkspeed = 5
 70		   bus.components.locomotor.runspeed =  10
 71		   bus:SetStateGraph("SGrook")
 72		   bus:AddComponent("health")
 73		   bus.components.health:SetMaxHealth(1000)
 74		   bus.components.health:SetInvincible(true)
 75		   bus:AddComponent("combat")
 76		   bus:AddComponent("follower")
 77		   bus:AddComponent("knownlocations")
 78		   bus:DoTaskInTime(1, function()
 79			   bus.components.locomotor:GoToPoint(Point(pt1.x+2, 0, pt1.z+2))
 80		   end )
 81		   bus:DoTaskInTime(9, function()
 82			   GetPlayer():Hide()
 83			   GetPlayer().components.health:SetInvincible(true)
 84			   local shadow = GetPlayer().entity:AddDynamicShadow()
 85			   shadow:SetSize( 0, 0 )
 86			   bus.components.locomotor:GoToPoint(Point(pt1.x-15+2, 0, pt1.z+15+2))
 87		   end )
 88		   GetPlayer():DoTaskInTime(15, function()
 89			   TheFrontEnd:Fade(false,1)
 90			   bus:Remove()
 91			   GetPlayer().Transform:SetPosition(target.Transform:GetWorldPosition())
 92			   GetPlayer():DoTaskInTime(2, function()
 93				   TheFrontEnd:Fade(true,1)
 94				   busstation:RemoveTag("startingpoint")
 95				   GetPlayer():Show()
 96				   GetPlayer().components.health:SetInvincible(false)
 97				   GetPlayer().components.playercontroller:Enable(true)
 98				   local shadow = GetPlayer().entity:AddDynamicShadow()
 99				   shadow:SetSize( 1.3, .6 )
100			   end )
101		   end )
102		else
103		   SpawnPrefab("goldnugget").Transform:SetPosition(GetPlayer().Transform:GetWorldPosition())
104		   busstation:RemoveTag("startingpoint")
105		end
106	end
107	inst.components.stackable:Get():Remove()
108end
109	inst:AddComponent("deployable")
110	inst.components.deployable.ondeploy = OnDeploy
111local function onsave(inst, data)
112	if inst:HasTag("goodbye") then
113		data.goodbye = true
114	end
115	if inst:HasTag("busstation") then
116		data.busstation = true
117	end
118end
119local function onload(inst, data)
120  if data and data.goodbye then
121	 inst:Remove()
122  end
123  if data and data.busstation then
124	inst.AnimState:SetBank("sign_home")
125	inst.AnimState:SetBuild("sign_home")
126	inst.AnimState:PlayAnimation("idle")
127	inst.Transform:SetScale(1.5, 1.5, 1.5)
128	inst.AnimState:SetMultColour(255/255,105/255,0/255,0.8)
129	local minimap = inst.entity:AddMiniMapEntity()
130	minimap:SetIcon( "sign.png" )
131	inst:RemoveComponent("inventoryitem")
132	inst:RemoveComponent("stackable")
133	inst:RemoveComponent("fuel")
134	inst:RemoveComponent("sleepingbag")
135	inst:RemoveComponent("burnable")
136	inst:RemoveComponent("propagator")
137	inst:RemoveComponent("deployable")
138	inst:AddTag("busstation")
139	inst:AddComponent("workable")
140	inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
141	inst.components.workable:SetWorkLeft(3)
142	inst.components.workable:SetOnFinishCallback(function(inst)
143		SpawnPrefab("collapse_big").Transform:SetPosition(inst.Transform:GetWorldPosition())
144		GetPlayer().SoundEmitter:PlaySound("dontstarve/common/destroy_wood")
145		inst:Remove()
146	end )
147	inst:AddComponent("trader")
148	inst.components.trader:SetAcceptTest(function(inst, item) 
149	   if item.prefab == "goldnugget" then
150		  return true
151	   end
152	   return false
153	end )
154	inst.components.trader.onaccept = function(inst, giver, item)
155		inst:AddTag("startingpoint")
156		local target = FindEntity(inst, 3000, function(guy) 
157			return guy:HasTag("busstation") and not guy:HasTag("startingpoint")
158		end )
159		if target then
160		   GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold")
161		   GetPlayer().components.playercontroller:Enable(false)
162		   local pt1 = inst:GetPosition()
163		   local bus = SpawnPrefab("bedroll_straw")
164		   bus.Transform:SetPosition(pt1.x+15+2, 0, pt1.z-15+2)
165		   bus.AnimState:SetBank("rook")
166		   bus.AnimState:SetBuild("rook_build")
167		   bus.AnimState:PlayAnimation("idle", true)
168		   bus.Transform:SetFourFaced()
169		   bus.Transform:SetScale(1.2, 1.2, 1.2)
170		   bus.AnimState:SetMultColour(255/255,105/255,0/255,1)
171		   local sound = bus.entity:AddSoundEmitter()
172		   bus:RemoveComponent("inventoryitem")
173		   bus:RemoveComponent("stackable")
174		   bus:RemoveComponent("fuel")
175		   bus:RemoveComponent("sleepingbag")
176		   bus:RemoveComponent("burnable")
177		   bus:RemoveComponent("propagator")
178		   bus:RemoveComponent("deployable")
179		   bus:AddTag("goodbye")
180		   bus:AddComponent("locomotor")
181		   bus.components.locomotor.walkspeed = 5
182		   bus.components.locomotor.runspeed =  10
183		   bus:SetStateGraph("SGrook")
184		   bus:AddComponent("health")
185		   bus.components.health:SetMaxHealth(1000)
186		   bus.components.health:SetInvincible(true)
187		   bus:AddComponent("combat")
188		   bus:AddComponent("follower")
189		   bus:AddComponent("knownlocations")
190		   bus:DoTaskInTime(1, function()
191			   bus.components.locomotor:GoToPoint(Point(pt1.x+2, 0, pt1.z+2))
192		   end )
193		   bus:DoTaskInTime(9, function()
194			   GetPlayer():Hide()
195			   GetPlayer().components.health:SetInvincible(true)
196			   local shadow = GetPlayer().entity:AddDynamicShadow()
197			   shadow:SetSize( 0, 0 )
198			   bus.components.locomotor:GoToPoint(Point(pt1.x-15+2, 0, pt1.z+15+2))
199		   end )
200		   GetPlayer():DoTaskInTime(15, function()
201			   TheFrontEnd:Fade(false,1)
202			   bus:Remove()
203			   GetPlayer().Transform:SetPosition(target.Transform:GetWorldPosition())
204			   GetPlayer():DoTaskInTime(2, function()
205				   TheFrontEnd:Fade(true,1)
206				   inst:RemoveTag("startingpoint")
207				   GetPlayer():Show()
208				   GetPlayer().components.health:SetInvincible(false)
209				   GetPlayer().components.playercontroller:Enable(true)
210				   local shadow = GetPlayer().entity:AddDynamicShadow()
211				   shadow:SetSize( 1.3, .6 )
212			   end )
213		   end )
214		else
215		   SpawnPrefab("goldnugget").Transform:SetPosition(GetPlayer().Transform:GetWorldPosition())
216		   inst:RemoveTag("startingpoint")
217		end
218	end
219  end
220end
221	inst.OnSave = onsave
222	inst.OnLoad = onload
223
224	即可在地图的任意两个地点,用草席卷种公车站,给站牌1个黄金(拿着黄金对站牌点鼠标左键),会来公共汽车送你到另一个站牌,方便在两点间快速移动。公车站须种在空旷的地方,以便公共汽车行驶。如果只种了一个公车站,则站牌不会接受你的黄金。公车站在小地图上显示为路牌的图标。不想要公车站时,用锤子砸掉即可。草席卷在生存选项下(画着绳套)下,用6个草、1个绳子制造