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

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



二七七.电动铺路铲(拿黄金铲自动将脚下的空地皮铺成路)

	用MT管理器打开游戏目录/assets/scripts/prefabs/shovel.lua文件,

	1.将下列内容:

local function onequipgold(inst, owner) 
	owner.AnimState:OverrideSymbol("swap_object", "swap_goldenshovel", "swap_goldenshovel")
	owner.SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold")	 
	owner.AnimState:Show("ARM_carry") 
	owner.AnimState:Hide("ARM_normal") 
end

	替换为:

local function pickup(inst, owner)
	inst.name = GROUND.ROAD
	local pt = owner:GetPosition()
	local ground = GetWorld()
	local tile = ground.Map:GetTileAtPoint(pt.x, pt.y, pt.z)
	if ground and tile == GROUND.DIRT then
	   local original_tile_type = ground.Map:GetTileAtPoint(pt.x, pt.y, pt.z)
	   local x, y = ground.Map:GetTileCoordsAtPoint(pt.x, pt.y, pt.z)
	   if x and y then
		  ground.Map:SetTile(x,y, inst.name)
		  ground.Map:RebuildLayer( original_tile_type, x, y )
		  ground.Map:RebuildLayer( inst.name, x, y )
	   end
	   local minimap = TheSim:FindFirstEntityWithTag("minimap")
	   if minimap then
		  minimap.MiniMap:RebuildLayer( original_tile_type, x, y )
		  minimap.MiniMap:RebuildLayer( inst.name, x, y )
	   end
	end
	inst.SoundEmitter:PlaySound("dontstarve/wilson/dig")
end
local function onequipgold(inst, owner) 
	if owner.components.inventory:Has("lightbulb", 1) then
	   inst.task = inst:DoPeriodicTask(.033, function() pickup(inst, owner) end)
	   owner.components.inventory:ConsumeByName("lightbulb", 1)
	end
	owner.AnimState:OverrideSymbol("swap_object", "swap_goldenshovel", "swap_goldenshovel")
	owner.SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold")	 
	owner.AnimState:Show("ARM_carry") 
	owner.AnimState:Hide("ARM_normal") 
end
local function onunequipgold(inst, owner) 
	owner.AnimState:Hide("ARM_carry") 
	owner.AnimState:Show("ARM_normal") 
	if inst.task then inst.task:Cancel() inst.task = nil end
end


	2.在inst.components.equippable:SetOnEquip( onequipgold )的下一行插入inst.components.equippable:SetOnUnequip( onunequipgold )

	即可拿黄金铲自动将脚下的空地皮铺成路,效率极高,铺路的速度只取决于你走多快。电动铺路铲需要能源,每次装备时自动开启,会消耗1个荧光果,如果身上没有荧光果,则不会开启电动功能。将其中GROUND.ROAD(卵石路)替换为其他地皮名称,如GROUND.ROCKY(岩石地皮)、GROUND.DIRT(污垢地皮)、GROUND.SAVANNA(热带草原地皮)、GROUND.GRASS(长草地皮)、GROUND.FOREST(森林地皮)、GROUND.MARSH(沼泽地皮)、GROUND.WOODFLOOR(木质地板)、GROUND.CARPET(地毯地板)、GROUND.CHECKER(棋盘地板)、GROUND.CAVE(鸟粪地皮)、GROUND.FUNGUS(菌类地皮)、GROUND.FUNGUSRED(红菌类地皮)、GROUND.FUNGUSGREEN(绿菌类地皮)、GROUND.SINKHOLE(粘滑地皮)、GROUND.UNDERROCK(洞穴石地地皮)、GROUND.MUD(泥泞地皮),就可以自动铺其他地皮