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

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


  1
  2二七八.地皮改造机(用排箫种地皮改造机,一次铺70块地皮)
  3
  4	MT管理器打开游戏目录/assets/scripts/prefabs/panflute.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
  5
  6local function itemtest(inst, item, slot)
  7	if item.prefab == "turf_road" or item.prefab == "turf_rocky" or item.prefab == "turf_forest" or item.prefab == "turf_marsh" or item.prefab == "turf_grass" or item.prefab == "turf_savanna" or item.prefab == "turf_dirt" or item.prefab == "turf_woodfloor" or item.prefab == "turf_carpetfloor" or item.prefab == "turf_checkerfloor" or item.prefab == "turf_cave" or item.prefab == "turf_fungus" or item.prefab == "turf_fungus_red" or item.prefab == "turf_fungus_green" or item.prefab == "turf_sinkhole" or item.prefab == "turf_underrock" or item.prefab == "turf_mud" then
  8	   return true
  9	end
 10	return false
 11end
 12local slotpos = { Vector3(0,-75,0)}
 13local widgetbuttoninfo = {
 14	text = "Do",
 15	position = Vector3(0, -135, 0),
 16	fn = function(inst)
 17		if inst:HasTag("turfmachines") then
 18		   if not inst.components.container:IsEmpty() then
 19			  for k,v in pairs(inst.components.container.slots) do
 20				  if v and v.prefab == "turf_road" then inst.rug = GROUND.ROAD end
 21				  if v and v.prefab == "turf_rocky" then inst.rug = GROUND.ROCKY end
 22				  if v and v.prefab == "turf_forest" then inst.rug = GROUND.FOREST end
 23				  if v and v.prefab == "turf_marsh" then inst.rug = GROUND.MARSH end
 24				  if v and v.prefab == "turf_grass" then inst.rug = GROUND.GRASS end
 25				  if v and v.prefab == "turf_savanna" then inst.rug = GROUND.SAVANNA end
 26				  if v and v.prefab == "turf_dirt" then inst.rug = GROUND.DIRT end
 27				  if v and v.prefab == "turf_woodfloor" then inst.rug = GROUND.WOODFLOOR end
 28				  if v and v.prefab == "turf_carpetfloor" then inst.rug = GROUND.CARPET end
 29				  if v and v.prefab == "turf_checkerfloor" then inst.rug = GROUND.CHECKER end
 30				  if v and v.prefab == "turf_cave" then inst.rug = GROUND.CAVE end
 31				  if v and v.prefab == "turf_fungus" then inst.rug = GROUND.FUNGUS end
 32				  if v and v.prefab == "turf_fungus_red" then inst.rug = GROUND.FUNGUSRED end
 33				  if v and v.prefab == "turf_fungus_green" then inst.rug = GROUND.FUNGUSGREEN end
 34				  if v and v.prefab == "turf_sinkhole" then inst.rug = GROUND.SINKHOLE end
 35				  if v and v.prefab == "turf_underrock" then inst.rug = GROUND.UNDERROCK end
 36				  if v and v.prefab == "turf_mud" then inst.rug = GROUND.MUD end
 37				  v:Remove()
 38			  end
 39			  local pt = GetPlayer():GetPosition()
 40			  for y = 10, 0, -1 do
 41				  for x = 0, 10 do
 42					  local tile = GetWorld().Map:GetTileAtPoint(pt.x-2.1*x+2.1*y-10.5+10.5, pt.y, pt.z+2.1*x+2.1*y-10.5-10.5)
 43					  if tile ~= GROUND.IMPASSABLE then
 44						 local original_tile_type = GetWorld().Map:GetTileAtPoint(pt.x-2.1*x+2.1*y-10.5+10.5, pt.y, pt.z+2.1*x+2.1*y-10.5-10.5)
 45						 local x, y = GetWorld().Map:GetTileCoordsAtPoint(pt.x-2.1*x+2.1*y-10.5+10.5, pt.y, pt.z+2.1*x+2.1*y-10.5-10.5)
 46						 GetWorld().Map:SetTile(x,y, inst.rug)
 47						 GetWorld().Map:RebuildLayer( original_tile_type, x, y )
 48						 GetWorld().Map:RebuildLayer( inst.rug, x, y )
 49						 local minimap = TheSim:FindFirstEntityWithTag("minimap")
 50						 minimap.MiniMap:RebuildLayer( original_tile_type, x, y )
 51						 minimap.MiniMap:RebuildLayer( inst.rug, x, y )
 52					  end
 53				  end
 54			  end
 55		   end
 56		end
 57	end }
 58local function OnDeploy (inst, pt)
 59	local turfmachine = SpawnPrefab("panflute")
 60	turfmachine.Transform:SetPosition(pt.x, pt.y, pt.z)
 61	turfmachine.AnimState:SetBank("researchlab3")
 62	turfmachine.AnimState:SetBuild("researchlab3")
 63	turfmachine.AnimState:PlayAnimation("idle")
 64	turfmachine.Transform:SetScale(0.5, 0.5, 0.5)
 65	turfmachine:RemoveComponent("instrument")
 66	turfmachine:RemoveComponent("tool")
 67	if turfmachine.components.finiteuses then turfmachine:RemoveComponent("finiteuses") end
 68	turfmachine:RemoveComponent("deployable")
 69	turfmachine.components.container.canbeopened = true
 70	turfmachine.components.inventoryitem:ChangeImageName("researchlab3")
 71	turfmachine:AddComponent("equippable")
 72	turfmachine.components.equippable.equipslot = EQUIPSLOTS.BODY
 73	turfmachine.components.equippable:SetOnEquip( function(turfmachine)
 74		GetPlayer().components.inventory:SetOverflow(turfmachine)
 75		turfmachine.components.container:Open(GetPlayer())
 76		GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/backpack_open", "open")
 77	end )
 78	turfmachine.components.equippable:SetOnUnequip( function(turfmachine)
 79		turfmachine.components.container:Close(GetPlayer())
 80		GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/backpack_close", "open")
 81	end )
 82	turfmachine:AddTag("turfmachines")
 83	inst:Remove()
 84end
 85	inst:AddComponent("deployable")
 86	inst.components.deployable.ondeploy = OnDeploy
 87local function onsave(inst, data)
 88	if inst:HasTag("turfmachines") then
 89	   data.turfmachines = true
 90	end
 91end
 92local function onload(inst, data)
 93  if data and data.turfmachines then
 94	inst.AnimState:SetBank("researchlab3")
 95	inst.AnimState:SetBuild("researchlab3")
 96	inst.AnimState:PlayAnimation("idle")
 97	inst.Transform:SetScale(0.5, 0.5, 0.5)
 98	inst:RemoveComponent("instrument")
 99	inst:RemoveComponent("tool")
100	if inst.components.finiteuses then inst:RemoveComponent("finiteuses") end
101	inst:RemoveComponent("deployable")
102	inst.components.container.canbeopened = true
103	inst.components.inventoryitem:ChangeImageName("researchlab3")
104	inst:AddComponent("equippable")
105	inst.components.equippable.equipslot = EQUIPSLOTS.BODY
106	inst.components.equippable:SetOnEquip( function(inst)
107		GetPlayer().components.inventory:SetOverflow(inst)
108		inst.components.container:Open(GetPlayer())
109		GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/backpack_open", "open")
110	end )
111	inst.components.equippable:SetOnUnequip( function(inst)
112		inst.components.container:Close(GetPlayer())
113		GetPlayer().SoundEmitter:PlaySound("dontstarve/wilson/backpack_close", "open")
114	end )
115	inst:AddTag("turfmachines")
116  end
117end
118	inst.OnSave = onsave
119	inst.OnLoad = onload
120	inst:AddComponent("container")
121	inst.components.container:SetNumSlots(#slotpos)
122	inst.components.container.widgetslotpos = slotpos
123	inst.components.container.widgetpos = Vector3(-80,150,0)
124	inst.components.container.side_widget = true
125	inst.components.container.itemtestfn = itemtest
126	inst.components.container.widgetbuttoninfo = widgetbuttoninfo
127	inst.components.container.acceptsstacks = false
128	inst.components.container.canbeopened = false
129
130	即可用排箫种地皮改造机,装备地皮改造机后,屏幕右侧将出现格子和按钮,在格子中放入1块地皮,按Do按钮,游戏会卡一下(5-10秒),70块地皮就铺好了,方便大面积改造地图。共支持17种地皮,只要可以放入格子的都可以铺。排箫在魔法选项(画着红骷髅)下用5个芦苇、1个曼德拉草、1个绳子制造