代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2二二0.象之树(用紫色护身符种象之树,白天周围有巨象群活动,狩猎它们吧)
3
4 用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/amulet.lua文件,在inst.AnimState:PlayAnimation("purpleamulet")的下一行插入以下内容:
5
6local function makebananatree(inst)
7 local pt = inst:GetPosition()
8 local bananatree = SpawnPrefab("purpleamulet")
9 bananatree.Transform:SetPosition(pt.x, pt.y, pt.z)
10 bananatree.AnimState:SetBank("cave_banana_tree")
11 bananatree.AnimState:SetBuild("cave_banana_tree")
12 bananatree.AnimState:PlayAnimation("idle_loop",true)
13 bananatree.Transform:SetScale(1.5, 1.5, 1.5)
14 bananatree:AddComponent("named")
15 bananatree.components.named:SetName("Banana Tree")
16 bananatree:RemoveComponent("equippable")
17 bananatree:RemoveComponent("inventoryitem")
18 bananatree:RemoveComponent("fueled")
19 bananatree:RemoveComponent("deployable")
20 bananatree:AddComponent("workable")
21 bananatree.components.workable:SetWorkAction(ACTIONS.CHOP)
22 bananatree.components.workable:SetWorkLeft(10)
23 bananatree.components.workable:SetOnFinishCallback(function()
24 SpawnPrefab("collapse_big").Transform:SetPosition(bananatree.Transform:GetWorldPosition())
25 GetPlayer().SoundEmitter:PlaySound("dontstarve/common/destroy_wood")
26 bananatree:Remove()
27 end )
28 bananatree:ListenForEvent( "daytime", function()
29 local pos = Vector3(bananatree.Transform:GetWorldPosition())
30 local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, 5)
31 for k,v in pairs(ents) do
32 if v.components.inventoryitem and not v.components.inventoryitem:IsHeld() then
33 if v.prefab == "cave_banana" then
34 v:Remove()
35 end
36 end
37 end
38 bananatree:DoTaskInTime(0.3, function(bananatree)
39 bananatree:StartThread(function()
40 for k = 1,math.random(4,8) do
41 local pt1 = bananatree:GetPosition()
42 local banana = SpawnPrefab("cave_banana")
43 banana.Transform:SetPosition(pt1.x+(math.random(5)-math.random(5)), 5, pt1.z+(math.random(5)-math.random(5)))
44 Sleep(0.3)
45 end
46 end )
47 end )
48 for k = 1,math.random(5,10) do
49 local elephant = SpawnPrefab("purpleamulet")
50 elephant.Transform:SetPosition(pt.x+(math.random(30)-math.random(30)), 0, pt.z+(math.random(30)-math.random(30)))
51 elephant.AnimState:SetBank("koalefant")
52 elephant.AnimState:SetBuild("koalefant_winter_build")
53 elephant.AnimState:PlayAnimation("idle_loop", true)
54 local sound = elephant.entity:AddSoundEmitter()
55 local shadow = elephant.entity:AddDynamicShadow()
56 shadow:SetSize( 4.5, 2 )
57 elephant.Transform:SetFourFaced()
58 MakeCharacterPhysics(elephant, 500, 1.5)
59 elephant:AddComponent("named")
60 elephant.components.named:SetName("Elephant")
61 elephant.Transform:SetScale(1.5, 1.5, 1.5)
62 local minimap = elephant.entity:AddMiniMapEntity()
63 minimap:SetIcon( "cave_banana_tree.png" )
64 elephant:RemoveComponent("equippable")
65 elephant:RemoveComponent("inventoryitem")
66 elephant:RemoveComponent("fueled")
67 elephant:RemoveComponent("deployable")
68 elephant:AddComponent("knownlocations")
69 elephant:AddComponent("health")
70 elephant.components.health:SetMaxHealth(1000)
71 elephant:AddComponent("combat")
72 elephant.components.combat.hiteffectsymbol = "beefalo_body"
73 elephant.components.combat:SetDefaultDamage(30)
74 elephant.components.combat:SetAttackPeriod(2)
75 elephant.components.combat:SetRetargetFunction(3, function(elephant)
76 if not elephant.components.health:IsDead() then
77 return FindEntity(elephant, 25, function(guy)
78 return guy:HasTag("monster")
79 end )
80 end
81 end )
82 elephant.components.combat:SetKeepTargetFunction(function(elephant, target) return target and target:IsValid() end )
83 elephant:ListenForEvent("attacked", function(elephant, data)
84 elephant.components.combat:SetTarget(data.attacker)
85 elephant.components.combat:ShareTarget(data.attacker, 10, function(dude) return dude:HasTag("elephants") and not dude.components.health:IsDead() end, 1)
86 end )
87 elephant:AddComponent("lootdropper")
88 elephant.components.lootdropper:SetLoot({"meat","meat","meat","meat","meat","meat","meat","meat","meat","meat","trunk_winter"})
89 elephant:AddComponent("locomotor")
90 elephant.components.locomotor.walkspeed = 2
91 elephant.components.locomotor.runspeed = 4
92 elephant:SetStateGraph("SGkoalefant")
93 local brain = require "brains/frogbrain"
94 elephant:SetBrain(brain)
95 elephant:ListenForEvent( "nighttime", function() elephant:Remove() end , GetWorld())
96 elephant:DoPeriodicTask(math.random(30, 60), function(elephant)
97 if not elephant.components.combat.target then
98 local sgnames = {"bellow","graze","alert","shake"}
99 local sgname = sgnames[math.random(#sgnames)]
100 elephant.sg:GoToState(sgname)
101 end
102 end )
103 elephant:DoPeriodicTask(math.random(120, 240), function(inst)
104 SpawnPrefab("poop").Transform:SetPosition(elephant.Transform:GetWorldPosition())
105 end )
106 if math.random() < 0.5 then
107 elephant:AddTag("redelephants")
108 elephant.AnimState:SetBuild("koalefant_summer_build")
109 elephant.components.lootdropper:SetLoot({"meat","meat","meat","meat","meat","meat","meat","meat","meat","meat","trunk_summer"})
110 end
111 elephant:AddTag("elephants")
112 end
113 end , GetWorld())
114 bananatree:AddTag("bananatree")
115end
116local function OnDeploy (inst, pt)
117 makebananatree(inst)
118 inst:Remove()
119end
120 inst:AddComponent("deployable")
121 inst.components.deployable.ondeploy = OnDeploy
122local function onsave(inst, data)
123 if inst:HasTag("bananatree") then
124 data.bananatree = true
125 end
126 if inst:HasTag("elephants") then
127 data.elephants = true
128 end
129 if inst:HasTag("redelephants") then
130 data.redelephants = true
131 end
132end
133local function onload(inst, data)
134 if data and data.bananatree then
135 makebananatree(inst)
136 inst:Remove()
137 end
138 if data and data.elephants then
139 inst.AnimState:SetBank("koalefant")
140 inst.AnimState:SetBuild("koalefant_winter_build")
141 inst.AnimState:PlayAnimation("idle_loop", true)
142 local sound = inst.entity:AddSoundEmitter()
143 local shadow = inst.entity:AddDynamicShadow()
144 shadow:SetSize( 4.5, 2 )
145 inst.Transform:SetFourFaced()
146 MakeCharacterPhysics(inst, 500, 1.5)
147 inst:AddComponent("named")
148 inst.components.named:SetName("Elephant")
149 inst.Transform:SetScale(1.5, 1.5, 1.5)
150 local minimap = inst.entity:AddMiniMapEntity()
151 minimap:SetIcon( "cave_banana_tree.png" )
152 inst:RemoveComponent("equippable")
153 inst:RemoveComponent("inventoryitem")
154 inst:RemoveComponent("fueled")
155 inst:RemoveComponent("deployable")
156 inst:AddComponent("knownlocations")
157 inst:AddComponent("health")
158 inst.components.health:SetMaxHealth(1000)
159 inst:AddComponent("combat")
160 inst.components.combat.hiteffectsymbol = "beefalo_body"
161 inst.components.combat:SetDefaultDamage(30)
162 inst.components.combat:SetAttackPeriod(2)
163 inst.components.combat:SetRetargetFunction(3, function(inst)
164 if not inst.components.health:IsDead() then
165 return FindEntity(inst, 25, function(guy)
166 return guy:HasTag("monster")
167 end )
168 end
169 end )
170 inst.components.combat:SetKeepTargetFunction(function(inst, target) return target and target:IsValid() end )
171 inst:ListenForEvent("attacked", function(inst, data)
172 inst.components.combat:SetTarget(data.attacker)
173 inst.components.combat:ShareTarget(data.attacker, 10, function(dude) return dude:HasTag("elephants") and not dude.components.health:IsDead() end, 1)
174 end )
175 inst:AddComponent("lootdropper")
176 inst.components.lootdropper:SetLoot({"meat","meat","meat","meat","meat","meat","meat","meat","meat","meat","trunk_winter"})
177 inst:AddComponent("locomotor")
178 inst.components.locomotor.walkspeed = 2
179 inst.components.locomotor.runspeed = 4
180 inst:SetStateGraph("SGkoalefant")
181 local brain = require "brains/frogbrain"
182 inst:SetBrain(brain)
183 inst:ListenForEvent( "nighttime", function() inst:Remove() end , GetWorld())
184 inst:DoPeriodicTask(math.random(30, 60), function(inst)
185 if not inst.components.combat.target then
186 local sgnames = {"bellow","graze","alert","shake"}
187 local sgname = sgnames[math.random(#sgnames)]
188 inst.sg:GoToState(sgname)
189 end
190 end )
191 inst:DoPeriodicTask(math.random(120, 240), function(inst)
192 SpawnPrefab("poop").Transform:SetPosition(inst.Transform:GetWorldPosition())
193 end )
194 inst:AddTag("elephants")
195 end
196 if data and data.redelephants then
197 inst:AddTag("redelephants")
198 inst.AnimState:SetBuild("koalefant_summer_build")
199 inst.components.lootdropper:SetLoot({"meat","meat","meat","meat","meat","meat","meat","meat","meat","meat","trunk_summer"})
200 end
201end
202 inst.OnSave = onsave
203 inst.OnLoad = onload
204
205 即可用紫色护身符种象之树,白天会掉落香蕉,并有巨象群在周围活动,夜晚离开。巨象不会主动攻击你,想狩猎它们时,尽量选择落单的巨象,否则其他巨象会一起反击。巨象在小地图上显示为香蕉图标,它们是天然的肉库,杀死一只可获得10块大肉及象鼻,并且会不断产便便,缺少肥料的话,可以在象之树附近拾取。不想要象之树了,砍掉即可,象群会在黑夜离去。紫色护身符在魔法选项(画着红骷髅)下,用6个黄金、4个噩梦燃料、2个紫宝石制造