function rnd(mi, ma)
	local v = math.random(0, 1000) / 1000
	return mi + (ma - mi) * v
end

function rndVec(length)
	return Vec(rnd(-length, length), rnd(-length, length), rnd(-length, length))
end

function init()
	dynamiteStick = FindBody("dynamite_stick")

	light = FindLight("light")

	sound = LoadLoop("tools/blowtorch-hit-loop.ogg", 5.0)
	local d = VecAdd(Vec(0, 50 , -190), rndVec(10))
	ApplyBodyImpulse(dynamiteStick, GetBodyTransform(dynamiteStick).pos, TransformToParentVec(GetPlayerCameraTransform(), d))
end

local lifeTimer = 0.0
local explosionTimer = 1.5

function tick(dt)
	if not IsHandleValid(dynamiteStick) then
		return
	end

	local dynamiteStickT = GetBodyTransform(dynamiteStick)

	lifeTimer = lifeTimer + dt
	if lifeTimer >= explosionTimer then
		Explosion(dynamiteStickT.pos, GetFloat("game.tool.dynamite_stick.damage"))
		Delete(dynamiteStick)
	end

	local sparksPos = GetLightTransform(light).pos

	ParticleReset()
	ParticleTile(6)
	ParticleColor(1, 0.5, 0, 1, 0.1, 0)
	ParticleRadius(0.01)
	ParticleEmissive(1, 0.1)
	local x = math.random(-2, 2)
	local y = math.random(3)
	local z = math.random(-2, 2)
	local sparksDir = QuatRotateVec(dynamiteStickT.rot, Vec(x, y, z))
	SpawnParticle(sparksPos, sparksDir, 1.0)

	PlayLoop(sound)
end