代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。

原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html


 1
 2一六四.高爆地雷(指南针放在地上作地雷)
 3
 4	MT管理器打开游戏目录/assets/scripts/prefabs/compass.lua文件,在inst:AddComponent("inventoryitem")的下一行插入以下内容
 5
 6	inst.components.inventoryitem:SetOnDroppedFn(function()
 7		inst:RemoveTag("startkill")
 8		if inst.task then inst.task:Cancel() inst.task = nil end
 9	end )
10	inst.components.inventoryitem:SetOnPickupFn(function()
11		inst:RemoveTag("startkill")
12		if inst.task then inst.task:Cancel() inst.task = nil end
13	end )
14	inst.components.inventoryitem:SetOnPutInInventoryFn(function()
15		inst:RemoveTag("startkill")
16		if inst.task then inst.task:Cancel() inst.task = nil end
17	end )
18local function OnDeploy (inst, pt)
19	inst:AddTag("startkill")
20	inst.Physics:Teleport(pt:Get())
21	inst.task = inst:DoPeriodicTask(0.1, function(inst)
22		local target = FindEntity(inst, 2, function(guy) 
23			return guy.components.combat and guy.components.health and not guy.components.health:IsDead() and not guy:HasTag("player") and not guy:HasTag("smallbird") and not guy:HasTag("chester")
24		end )
25		if target then
26		   GetPlayer().SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
27		   SpawnPrefab("collapse_small").Transform:SetPosition(inst.Transform:GetWorldPosition())
28		   SpawnPrefab("explode_small").Transform:SetPosition(inst.Transform:GetWorldPosition())
29		   local pos = Vector3(inst.Transform:GetWorldPosition())
30		   GetClock():DoLightningLighting()
31		   GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 0.7, 0.02, .5, 40)
32		   target.components.health:DoDelta(-3000)
33		   inst:Remove()
34		end
35	end )
36end
37	inst:AddComponent("deployable")
38	inst.components.deployable.ondeploy = OnDeploy
39	inst.components.deployable.min_spacing = 2
40	inst:AddComponent("stackable")
41	inst.components.stackable.maxsize = 999
42local function onsave(inst, data)
43	if inst:HasTag("startkill") then
44		data.startkill = true
45	end
46end
47local function onload(inst, data)
48  if data and data.startkill then
49	inst:AddTag("startkill")
50	inst.task = inst:DoPeriodicTask(0.1, function(inst)
51		local target = FindEntity(inst, 2, function(guy) 
52			return guy.components.combat and guy.components.health and not guy.components.health:IsDead() and not guy:HasTag("player") and not guy:HasTag("smallbird") and not guy:HasTag("chester")
53		end )
54		if target then
55		   GetPlayer().SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
56		   SpawnPrefab("collapse_small").Transform:SetPosition(inst.Transform:GetWorldPosition())
57		   SpawnPrefab("explode_small").Transform:SetPosition(inst.Transform:GetWorldPosition())
58		   local pos = Vector3(inst.Transform:GetWorldPosition())
59		   GetClock():DoLightningLighting()
60		   GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 0.7, 0.02, .5, 40)
61		   target.components.health:DoDelta(-3000)
62		   inst:Remove()
63		end
64	end )
65  end
66end
67	inst.OnSave = onsave
68	inst.OnLoad = onload
69
70	即可拿起指南针用鼠标右键部署在空地上,敌人踩上后会爆炸,主角、自养高鸟、狗箱不会触发。指南针在生存选项(画着绳套)下,用1个黄金、1张纸制造