代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二五0.小油灯(用蜘蛛腺体种小油灯,放在地上自动点燃,无限燃烧,可烧炭、烤食物、取暖、照明)
3
4 1.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/log.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
5
6 inst:AddComponent("cookable")
7 inst.components.cookable.product = "charcoal"
8
9
10 2.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/spidergland.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
11
12local colours=
13{
14 {198/255,43/255,43/255},
15 {79/255,153/255,68/255},
16 {35/255,105/255,235/255},
17 {233/255,208/255,69/255},
18 {109/255,50/255,163/255},
19 {222/255,126/255,39/255},
20}
21local function OnDeploy (inst, pt)
22 local lamp = SpawnPrefab("spidergland")
23 lamp.Transform:SetPosition(pt.x, pt.y, pt.z)
24 lamp.AnimState:SetBank("trinkets")
25 lamp.AnimState:SetBuild("trinkets")
26 lamp.AnimState:PlayAnimation(tostring(2))
27 lamp.components.inventoryitem:ChangeImageName("trinket_2")
28 lamp.entity:AddSoundEmitter()
29 lamp.Transform:SetScale(1.2,1.2,1.2)
30 lamp.colour_idx = math.random(#colours)
31 lamp.AnimState:SetMultColour(colours[lamp.colour_idx][1],colours[lamp.colour_idx][2],colours[lamp.colour_idx][3],1)
32 lamp:RemoveComponent("stackable")
33 lamp:RemoveComponent("tradable")
34 lamp:RemoveComponent("healer")
35 lamp:RemoveComponent("burnable")
36 lamp:RemoveComponent("propagator")
37 lamp:RemoveComponent("deployable")
38 lamp:RemoveTag("cattoy")
39 lamp:AddComponent("cooker")
40 lamp:AddComponent("burnable")
41 lamp.components.burnable:SetFXLevel(3)
42 lamp.components.burnable:AddBurnFX("campfirefire", Vector3(0,0.5,0) )
43 lamp.components.burnable:Ignite(true)
44 lamp.components.inventoryitem:SetOnDroppedFn(function() lamp.components.burnable:Ignite(true) lamp:AddTag("ontheground") end )
45 lamp.components.inventoryitem:SetOnPickupFn(function() lamp.components.burnable:Extinguish() lamp:RemoveTag("ontheground") end )
46 lamp.components.inventoryitem:SetOnPutInInventoryFn(function() lamp.components.burnable:Extinguish() lamp:RemoveTag("ontheground") end )
47 lamp:ListenForEvent("onignite", function()
48 if not lamp.components.cooker then lamp:AddComponent("cooker") end
49 end )
50 lamp:ListenForEvent("onextinguish", function()
51 lamp.SoundEmitter:PlaySound("dontstarve/common/fireOut")
52 if lamp.components.cooker then lamp:RemoveComponent("cooker") end
53 end )
54 lamp:AddComponent("workable")
55 lamp.components.workable:SetWorkAction(ACTIONS.HAMMER)
56 lamp.components.workable:SetWorkLeft(3)
57 lamp.components.workable:SetOnFinishCallback(function(lamp)
58 SpawnPrefab("ground_chunks_breaking").Transform:SetPosition(lamp.Transform:GetWorldPosition())
59 lamp:Remove()
60 end )
61 lamp:AddTag("ontheground")
62 lamp:AddTag("light")
63 lamp:AddTag("lamps")
64 inst.components.stackable:Get():Remove()
65end
66 inst:AddComponent("deployable")
67 inst.components.deployable.ondeploy = OnDeploy
68
69local function onsave(inst, data)
70 if inst:HasTag("lamps") then
71 data.lamps = true
72 end
73 if inst:HasTag("ontheground") then
74 data.ontheground = true
75 end
76 data.colour_idx = inst.colour_idx
77end
78local function onload(inst, data)
79 if data and data.lamps then
80 inst.AnimState:SetBank("trinkets")
81 inst.AnimState:SetBuild("trinkets")
82 inst.AnimState:PlayAnimation(tostring(2))
83 inst.components.inventoryitem:ChangeImageName("trinket_2")
84 inst.entity:AddSoundEmitter()
85 inst.Transform:SetScale(1.2,1.2,1.2)
86 inst.colour_idx = math.random(#colours)
87 inst.AnimState:SetMultColour(colours[inst.colour_idx][1],colours[inst.colour_idx][2],colours[inst.colour_idx][3],1)
88 inst:RemoveComponent("stackable")
89 inst:RemoveComponent("tradable")
90 inst:RemoveComponent("healer")
91 inst:RemoveComponent("burnable")
92 inst:RemoveComponent("propagator")
93 inst:RemoveComponent("deployable")
94 inst:RemoveTag("cattoy")
95 inst:AddComponent("burnable")
96 inst.components.burnable:SetFXLevel(3)
97 inst.components.burnable:AddBurnFX("campfirefire", Vector3(0,0.5,0) )
98 inst.components.inventoryitem:SetOnDroppedFn(function() inst.components.burnable:Ignite(true) inst:AddTag("ontheground") end )
99 inst.components.inventoryitem:SetOnPickupFn(function() inst.components.burnable:Extinguish() inst:RemoveTag("ontheground") end )
100 inst.components.inventoryitem:SetOnPutInInventoryFn(function() inst.components.burnable:Extinguish() inst:RemoveTag("ontheground") end )
101 inst:ListenForEvent("onignite", function()
102 if not inst.components.cooker then inst:AddComponent("cooker") end
103 end )
104 inst:ListenForEvent("onextinguish", function()
105 inst.SoundEmitter:PlaySound("dontstarve/common/fireOut")
106 if inst.components.cooker then inst:RemoveComponent("cooker") end
107 end )
108 inst:AddComponent("workable")
109 inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
110 inst.components.workable:SetWorkLeft(3)
111 inst.components.workable:SetOnFinishCallback(function(inst)
112 SpawnPrefab("ground_chunks_breaking").Transform:SetPosition(inst.Transform:GetWorldPosition())
113 inst:Remove()
114 end )
115 inst:AddTag("light")
116 inst:AddTag("lamps")
117 end
118 if data and data.ontheground then
119 inst.components.burnable:Ignite(true)
120 inst:AddComponent("cooker")
121 inst:AddTag("ontheground")
122 end
123 if data and data.colour_idx then
124 inst.colour_idx = math.min(#colours, data.colour_idx)
125 inst.AnimState:SetMultColour(colours[inst.colour_idx][1],colours[inst.colour_idx][2],colours[inst.colour_idx][3],1)
126 end
127end
128 inst.OnSave = onsave
129 inst.OnLoad = onload
130
131 即可用蜘蛛腺体种小油灯(颜色随机),无须任何燃料,放在地上自动点燃,拿起来自动熄灭。拿着木头对油灯按鼠标左键,可将木头烧成炭。也可烤食物、取暖、照明,出行必备。不想要小油灯时,用锤子砸掉即可