代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二八四.杂货收购行(将料理、帽子、绳子等杂货卖给帐篷换黄金)
3
4 1.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/rope.lua文件,在inst:AddComponent("inspectable")的下一行插入inst:AddComponent("tradable")
5
6
7 2.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/boards.lua文件,在inst:AddComponent("inspectable")的下一行插入inst:AddComponent("tradable")
8
9
10 3.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/cutstone.lua文件,在inst:AddComponent("inspectable")的下一行插入inst:AddComponent("tradable")
11
12
13 4.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/tent.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
14
15local function ShouldAcceptItem(inst, item)
16 if item:HasTag("hat") then
17 return true
18 end
19 if item:HasTag("preparedfood") and item.prefab ~= "wetgoop" then
20 return true
21 end
22 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
23 return true
24 end
25 return false
26end
27local function OnGetItemFromPlayer(inst, giver, item)
28 if item:HasTag("hat") then
29 for k = 1, 3 do
30 local goldnugget = SpawnPrefab("goldnugget")
31 giver.components.inventory:GiveItem(goldnugget)
32 end
33 end
34 if item:HasTag("preparedfood") and item.prefab ~= "wetgoop" then
35 for k = 1, 5 do
36 local goldnugget = SpawnPrefab("goldnugget")
37 giver.components.inventory:GiveItem(goldnugget)
38 end
39 end
40 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
41 local goldnugget = SpawnPrefab("goldnugget")
42 giver.components.inventory:GiveItem(goldnugget)
43 end
44end
45 inst:AddComponent("trader")
46 inst.components.trader.onaccept = OnGetItemFromPlayer
47 inst.components.trader:SetAcceptTest(ShouldAcceptItem)
48
49 即可将杂货卖给帐篷换黄金(拿着物品对帐篷点鼠标左键),其中料理收购价5个黄金,帽子3个黄金,绳子、木板、石砖、叶子、蜂蜜、荧光果、兔人尾巴、猪皮、花瓣、噩梦花瓣、啜食者皮、虫子果都是1个黄金