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