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

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



二八四.杂货收购行(将料理、帽子、绳子等杂货卖给帐篷换黄金)

	1.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/rope.lua文件,在inst:AddComponent("inspectable")的下一行插入inst:AddComponent("tradable")


	2.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/boards.lua文件,在inst:AddComponent("inspectable")的下一行插入inst:AddComponent("tradable")


	3.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/cutstone.lua文件,在inst:AddComponent("inspectable")的下一行插入inst:AddComponent("tradable")


	4.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/tent.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:

local function ShouldAcceptItem(inst, item)
	if item:HasTag("hat") then
	   return true
	end
	if item:HasTag("preparedfood") and item.prefab ~= "wetgoop" then
	   return true
	end
	if item.prefab == "rope" or item.prefab == "boards" or item.prefab == "cutstone" or item.prefab == "foliage" or item.prefab == "honey" or item.prefab == "lightbulb" or item.prefab == "manrabbit_tail" or item.prefab == "pigskin" or item.prefab == "petals" or item.prefab == "petals_evil" or item.prefab == "slurper_pelt" or item.prefab == "wormlight" then
	   return true
	end
	return false
end
local function OnGetItemFromPlayer(inst, giver, item)
	if item:HasTag("hat") then
	   for k = 1, 3 do
		   local goldnugget = SpawnPrefab("goldnugget")
		   giver.components.inventory:GiveItem(goldnugget)
	   end
	end
	if item:HasTag("preparedfood") and item.prefab ~= "wetgoop" then
	   for k = 1, 5 do
		   local goldnugget = SpawnPrefab("goldnugget")
		   giver.components.inventory:GiveItem(goldnugget)
	   end
	end
	if item.prefab == "rope" or item.prefab == "boards" or item.prefab == "cutstone" or item.prefab == "foliage" or item.prefab == "honey" or item.prefab == "lightbulb" or item.prefab == "manrabbit_tail" or item.prefab == "pigskin" or item.prefab == "petals" or item.prefab == "petals_evil" or item.prefab == "slurper_pelt" or item.prefab == "wormlight" then
	   local goldnugget = SpawnPrefab("goldnugget")
	   giver.components.inventory:GiveItem(goldnugget)
	end
end
	inst:AddComponent("trader")
	inst.components.trader.onaccept = OnGetItemFromPlayer
	inst.components.trader:SetAcceptTest(ShouldAcceptItem)

	即可将杂货卖给帐篷换黄金(拿着物品对帐篷点鼠标左键),其中料理收购价5个黄金,帽子3个黄金,绳子、木板、石砖、叶子、蜂蜜、荧光果、兔人尾巴、猪皮、花瓣、噩梦花瓣、啜食者皮、虫子果都是1个黄金