代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。
原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html
1
2一八七.高压电避难所(按小键盘加号键筑一圈带高压电的玄武岩墙,按减号键消失)
3
4 1.用MT管理器打开游戏目录/assets/scripts/prefabs/basalt.lua文件,在inst:AddComponent("inspectable")的下一行插入以下内容:
5
6local function OnExplode(inst, target)
7 if target and not target:HasTag("smallbird") and not target:HasTag("chester") then
8 SpawnPrefab("lightning_rod_fx").Transform:SetPosition(inst.Transform:GetWorldPosition())
9 SpawnPrefab("lightning_rod_fx").Transform:SetPosition(target.Transform:GetWorldPosition())
10 inst.SoundEmitter:PlaySound("dontstarve/common/lightningrod")
11 target.components.health:DoDelta(-3000)
12 end
13 inst:DoTaskInTime(.1, function() inst.components.mine:Reset() end )
14end
15 inst:AddComponent("mine")
16 inst.components.mine:SetRadius(4)
17 inst.components.mine:SetAlignment("player")
18 inst.components.mine:SetOnExplodeFn(OnExplode)
19 inst.components.mine:Reset()
20
21
22 2.用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/player_common.lua文件,在inst:AddComponent("catcher")的下一行插入以下内容:
23
24TheInput:AddKeyUpHandler(KEY_KP_PLUS, function()
25 local player = GetPlayer()
26 local pt = Vector3(player.Transform:GetWorldPosition())
27 for k = 1, 50 do
28 local theta = 1 * 2 * PI
29 local radius = 8
30 local result_offset = FindValidPositionByFan(theta, radius, 50, function(offset)
31 local x,y,z = (pt + offset):Get()
32 local ents = TheSim:FindEntities(x,y,z , 1)
33 return not next(ents)
34 end)
35 if result_offset then
36 local tentacle = SpawnPrefab("basalt_pillar")
37 tentacle.Transform:SetPosition((pt + result_offset):Get())
38 GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 0.2, 0.02, .25, 40)
39 local fx = SpawnPrefab("lightning_rod_fx")
40 local pos = pt + result_offset
41 fx.Transform:SetPosition(pos.x, pos.y, pos.z)
42 end
43 inst.SoundEmitter:PlaySound("dontstarve/common/lightningrod")
44 end
45end)
46TheInput:AddKeyUpHandler(KEY_KP_MINUS, function()
47 local player = GetPlayer()
48 local range = 15
49 local pos = Vector3(player.Transform:GetWorldPosition())
50 local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, range)
51 for k,v in pairs(ents) do
52 if v.prefab == "basalt_pillar" then
53 SpawnPrefab("lightning_rod_fx").Transform:SetPosition(v.Transform:GetWorldPosition())
54 v:Remove()
55 end
56 end
57 inst.SoundEmitter:PlaySound("dontstarve/common/lightningrod")
58end)
59
60 即可按小键盘加号键,在主角周围筑起一圈带高压电的玄武岩墙,怪物靠近会被电死,按小键盘减号键自动消失。注意不要离怪物太近时按加号键,会把怪物也圈进来或使墙有缺口。如果使用橙色魔杖或“瑞士手杖”(见本修改技巧),就可以自由出入各个避难所,把家具、农田放在里面,再也不怕狗和巨鹿了