代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二七五.电动镐(拿黄金镐自动凿开身边的石头)
3
4 1.用MT管理器打开游戏目录/assets/scripts/prefabs/pickaxe.lua文件,将下列内容:
5
6local function onequipgold(inst, owner)
7 owner.AnimState:OverrideSymbol("swap_object", "swap_goldenpickaxe", "swap_goldenpickaxe")
8 owner.SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold")
9 owner.AnimState:Show("ARM_carry")
10 owner.AnimState:Hide("ARM_normal")
11end
12
13 替换为:
14
15local function pickup(inst, owner)
16 local range = 3
17 local pos = Vector3(owner.Transform:GetWorldPosition())
18 local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, range)
19 for k,v in pairs(ents) do
20 if v.components.workable and v.components.workable.action == ACTIONS.MINE and v.components.workable.workleft > 0 then
21 v.components.workable:Destroy(GetPlayer())
22 end
23 end
24 inst.SoundEmitter:PlaySound("dontstarve/wilson/rock_break")
25end
26local function onequipgold(inst, owner)
27 if owner.components.inventory:Has("lightbulb", 1) then
28 inst.task = inst:DoPeriodicTask(.033, function() pickup(inst, owner) end)
29 owner.components.inventory:ConsumeByName("lightbulb", 1)
30 end
31 owner.AnimState:OverrideSymbol("swap_object", "swap_goldenpickaxe", "swap_goldenpickaxe")
32 owner.SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold")
33 owner.AnimState:Show("ARM_carry")
34 owner.AnimState:Hide("ARM_normal")
35end
36local function onunequipgold(inst, owner)
37 owner.AnimState:Hide("ARM_carry")
38 owner.AnimState:Show("ARM_normal")
39 if inst.task then inst.task:Cancel() inst.task = nil end
40end
41
42
43 2.在inst.components.equippable:SetOnEquip( onequipgold )的下一行插入inst.components.equippable:SetOnUnequip( onunequipgold )
44
45 即可拿黄金镐自动凿开身边的石头,效率极高,连大理石树、蜘蛛洞、远古雕像都可轻松凿平。电动镐需要能源,每次装备时自动开启,会消耗1个荧光果,如果身上没有荧光果,则不会开启电动功能,只能手动开矿了