代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二七二.智能播种机器人(将独奏乐器扔在地上自动种100棵香蕉树)
3
4 用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/onemanband.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
5
6local function ondropped(inst)
7 local player = GetPlayer()
8 if player.components.inventory:Has("goldnugget", 50) then
9 player.components.inventory:ConsumeByName("goldnugget", 50)
10 RemovePhysicsColliders(inst)
11 inst.name = "cave_banana_tree"
12 inst.components.inventoryitem.canbepickedup = false
13 inst:DoTaskInTime(1, function()
14 inst.task = inst:DoPeriodicTask(.5, function()
15 inst.Physics:SetMotorVelOverride(2,0,2)
16 inst.Physics:ClearMotorVelOverride()
17 player.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
18 SpawnPrefab(inst.name).Transform:SetPosition(inst.Transform:GetWorldPosition())
19 end)
20 end)
21 inst:DoTaskInTime(11, function()
22 if inst.task then inst.task:Cancel() inst.task = nil end
23 player.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
24 inst.Physics:SetMotorVelOverride(-3,0,3)
25 inst.Physics:ClearMotorVelOverride()
26 end)
27 inst:DoTaskInTime(12, function()
28 inst.task = inst:DoPeriodicTask(.5, function()
29 inst.Physics:SetMotorVelOverride(-2,0,-2)
30 inst.Physics:ClearMotorVelOverride()
31 player.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
32 SpawnPrefab(inst.name).Transform:SetPosition(inst.Transform:GetWorldPosition())
33 end)
34 end)
35 inst:DoTaskInTime(22, function()
36 if inst.task then inst.task:Cancel() inst.task = nil end
37 player.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
38 inst.Physics:SetMotorVelOverride(-3,0,3)
39 inst.Physics:ClearMotorVelOverride()
40 end)
41 inst:DoTaskInTime(23, function()
42 inst.task = inst:DoPeriodicTask(.5, function()
43 inst.Physics:SetMotorVelOverride(2,0,2)
44 inst.Physics:ClearMotorVelOverride()
45 player.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
46 SpawnPrefab(inst.name).Transform:SetPosition(inst.Transform:GetWorldPosition())
47 end)
48 end)
49 inst:DoTaskInTime(33, function()
50 if inst.task then inst.task:Cancel() inst.task = nil end
51 player.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
52 inst.Physics:SetMotorVelOverride(-3,0,3)
53 inst.Physics:ClearMotorVelOverride()
54 end)
55 inst:DoTaskInTime(34, function()
56 inst.task = inst:DoPeriodicTask(.5, function()
57 inst.Physics:SetMotorVelOverride(-2,0,-2)
58 inst.Physics:ClearMotorVelOverride()
59 player.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
60 SpawnPrefab(inst.name).Transform:SetPosition(inst.Transform:GetWorldPosition())
61 end)
62 end)
63 inst:DoTaskInTime(44, function()
64 if inst.task then inst.task:Cancel() inst.task = nil end
65 player.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
66 inst.Physics:SetMotorVelOverride(-3,0,3)
67 inst.Physics:ClearMotorVelOverride()
68 end)
69 inst:DoTaskInTime(45, function()
70 inst.task = inst:DoPeriodicTask(.5, function()
71 inst.Physics:SetMotorVelOverride(2,0,2)
72 inst.Physics:ClearMotorVelOverride()
73 player.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
74 SpawnPrefab(inst.name).Transform:SetPosition(inst.Transform:GetWorldPosition())
75 end)
76 end)
77 inst:DoTaskInTime(55, function()
78 if inst.task then inst.task:Cancel() inst.task = nil end
79 player.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
80 inst.Physics:SetMotorVelOverride(-3,0,3)
81 inst.Physics:ClearMotorVelOverride()
82 inst.components.inventoryitem.canbepickedup = true
83 end)
84 end
85end
86 inst:ListenForEvent("ondropped", ondropped)
87
88 即可将独奏乐器扔在开阔的空地上,它会自动行驶种下100棵香蕉树(5行,每行20棵),同时收取主角50个黄金,身上黄金不足时不会干活。将其中的cave_banana_tree(洞穴香蕉树)改为其他植物,如flower_cave_triple(三朵洞穴花)等,就可以种其他植物了(见本修改技巧“常用物品中英文名称”)。独奏乐器在魔法选项(画着红骷髅)下,用2个黄金、4个噩梦燃料、2个猪皮制造