代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2九十五.游牧生涯(带牛毛帽让牛群跟随,牛不集体攻击主角)
3
4 1.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/hats.lua文件,将下列内容:
5
6 local function beefalo_equip(inst, owner)
7 onequip(inst, owner)
8 owner:AddTag("beefalo")
9 end
10 local function beefalo_unequip(inst, owner)
11 onunequip(inst, owner)
12 owner:RemoveTag("beefalo")
13 end
14 local function beefalo()
15 local inst = simple()
16 inst.components.equippable:SetOnEquip( beefalo_equip )
17 inst.components.equippable:SetOnUnequip( beefalo_unequip )
18
19 inst:AddComponent("insulator")
20 inst.components.insulator:SetInsulation(TUNING.INSULATION_LARGE)
21
22 inst:AddComponent("waterproofer")
23 inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_SMALL)
24
25 inst:AddComponent("fueled")
26 inst.components.fueled.fueltype = "USAGE"
27 inst.components.fueled:InitializeFuelLevel(TUNING.BEEFALOHAT_PERISHTIME)
28 inst.components.fueled:SetDepletedFn(generic_perish)
29
30
31 return inst
32 end
33
34 替换为:
35
36 local function beefalo_disable(inst)
37 if inst.updatetask then
38 inst.updatetask:Cancel()
39 inst.updatetask = nil
40 end
41 local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner
42 owner.components.leader:RemoveFollowersByTag("beefalo")
43 end
44 local function beefalo_update(inst)
45 local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner
46 if owner and owner.components.leader then
47 local x,y,z = owner.Transform:GetWorldPosition()
48 local ents = TheSim:FindEntities(x,y,z, TUNING.SPIDERHAT_RANGE, {"beefalo"})
49 for k,v in pairs(ents) do
50 if v.components.follower and not v.components.follower.leader and not owner.components.leader:IsFollower(v) and owner.components.leader.numfollowers < 50 then
51 owner.components.leader:AddFollower(v)
52 end
53 end
54 end
55 end
56 local function beefalo_enable(inst)
57 inst.updatetask = inst:DoPeriodicTask(0.5, beefalo_update, 1)
58 end
59 local function beefalo_equip(inst, owner)
60 onequip(inst, owner)
61 beefalo_enable(inst)
62 owner:AddTag("beefalo")
63 end
64 local function beefalo_unequip(inst, owner)
65 onunequip(inst, owner)
66 beefalo_disable(inst)
67 owner:RemoveTag("beefalo")
68 end
69 local function beefalo_perish(inst)
70 beefalo_disable(inst)
71 inst:Remove()
72 end
73 local function beefalo()
74 local inst = simple()
75 inst.components.equippable:SetOnEquip( beefalo_equip )
76 inst.components.equippable:SetOnUnequip( beefalo_unequip )
77 inst:AddComponent("insulator")
78 inst.components.insulator.insulation = TUNING.INSULATION_LARGE
79 inst:AddComponent("waterproofer")
80 inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_SMALL)
81 inst:AddComponent("fueled")
82 inst.components.fueled.fueltype = "USAGE"
83 inst.components.fueled:InitializeFuelLevel(TUNING.BEEFALOHAT_PERISHTIME)
84 inst.components.fueled:SetDepletedFn(beefalo_perish)
85 return inst
86 end
87
88
89 2.用MT管理器打开游戏目录/assets/scripts/prefabs/beefalo.lua文件,将return not guy:HasTag("beefalo") and替换为return not guy:HasTag("beefalo") and not guy:HasTag("player") and
90
91
92 3.将return dude:HasTag("beefalo") and not dude:HasTag("player") and not dude.components.health:IsDead()替换为return dude:HasTag("beefalo") and dude:HasTag("player") and not dude.components.health:IsDead()
93
94
95 4.将inst.components.locomotor.walkspeed = 1.5替换为inst.components.locomotor.walkspeed = 3
96
97 即可带牛毛帽让牛群跟随,杀牛它们不会集体反击,也提高了牛走路的速度。加上“牛产便便速度增加1倍”、“喂牛蔬菜无限产黄油”、“牛醒着也可剪牛毛”的修改(见本修改技巧),就可以烧着便便取暖,吃牛肉、黄油,经营自己的牛群吧