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

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



一六四.高爆地雷(指南针放在地上作地雷)

	用MT管理器打开游戏目录/assets/scripts/prefabs/compass.lua文件,在inst:AddComponent("inventoryitem")的下一行插入以下内容

	inst.components.inventoryitem:SetOnDroppedFn(function()
		inst:RemoveTag("startkill")
		if inst.task then inst.task:Cancel() inst.task = nil end
	end )
	inst.components.inventoryitem:SetOnPickupFn(function()
		inst:RemoveTag("startkill")
		if inst.task then inst.task:Cancel() inst.task = nil end
	end )
	inst.components.inventoryitem:SetOnPutInInventoryFn(function()
		inst:RemoveTag("startkill")
		if inst.task then inst.task:Cancel() inst.task = nil end
	end )
local function OnDeploy (inst, pt)
	inst:AddTag("startkill")
	inst.Physics:Teleport(pt:Get())
	inst.task = inst:DoPeriodicTask(0.1, function(inst)
		local target = FindEntity(inst, 2, function(guy) 
			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")
		end )
		if target then
		   GetPlayer().SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
		   SpawnPrefab("collapse_small").Transform:SetPosition(inst.Transform:GetWorldPosition())
		   SpawnPrefab("explode_small").Transform:SetPosition(inst.Transform:GetWorldPosition())
		   local pos = Vector3(inst.Transform:GetWorldPosition())
		   GetClock():DoLightningLighting()
		   GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 0.7, 0.02, .5, 40)
		   target.components.health:DoDelta(-3000)
		   inst:Remove()
		end
	end )
end
	inst:AddComponent("deployable")
	inst.components.deployable.ondeploy = OnDeploy
	inst.components.deployable.min_spacing = 2
	inst:AddComponent("stackable")
	inst.components.stackable.maxsize = 999
local function onsave(inst, data)
	if inst:HasTag("startkill") then
		data.startkill = true
	end
end
local function onload(inst, data)
  if data and data.startkill then
	inst:AddTag("startkill")
	inst.task = inst:DoPeriodicTask(0.1, function(inst)
		local target = FindEntity(inst, 2, function(guy) 
			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")
		end )
		if target then
		   GetPlayer().SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
		   SpawnPrefab("collapse_small").Transform:SetPosition(inst.Transform:GetWorldPosition())
		   SpawnPrefab("explode_small").Transform:SetPosition(inst.Transform:GetWorldPosition())
		   local pos = Vector3(inst.Transform:GetWorldPosition())
		   GetClock():DoLightningLighting()
		   GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 0.7, 0.02, .5, 40)
		   target.components.health:DoDelta(-3000)
		   inst:Remove()
		end
	end )
  end
end
	inst.OnSave = onsave
	inst.OnLoad = onload

	即可拿起指南针用鼠标右键部署在空地上,敌人踩上后会爆炸,主角、自养高鸟、狗箱不会触发。指南针在生存选项(画着绳套)下,用1个黄金、1张纸制造