local M = {}

--Base code by Simon1234, for sBEVE, fireing order lua. Slightly repurposed by me

local function toggleFire()	
electrics.values.nosFireActive = 1 - (electrics.values.nosFireActive or 0)

	if electrics.values.nosFireActive == 1 then
		guihooks.message("NOS Fire deactivated!", 2, "vehicle.vertexNos.nosFireState", "whatshot")
	else
		guihooks.message("NOS Fire activated!", 2, "vehicle.vertexNos.nosFireState", "whatshot")
	end
end


local function onInit()	
	for v, node in pairs (v.data.nodes) do
		if node.name == "exh16" then e0=v  end	--most common exhaust nodes on focus
		if node.name == "exh14" then e1=v  end

		if node.name == "exh16r" then e2=v  end
		if node.name == "exh14r" then e3=v  end

		if node.name == "exh16rr" then e4=v  end
		if node.name == "exh14r" then e5=v  end

		if node.name == "exh16ll" then e6=v  end
		if node.name == "exh14l" then e7=v  end

		if node.name == "exh16l" then e8=v  end
		if node.name == "exh14l" then e9=v  end
	end
end


local function UpdateGFX(dt)

	local Intensify = math.random(2,4)
	local rnd = math.random(3,10)

	if electrics.values["nitrousOxideActive"] == 1 and electrics.values["nosFireActive"] == 0  then
		if e0 ~= nil then				--end node, start node, amount of particles, particle ID, unsure, start velocity?
			obj:addParticleByNodesRelative(e0, e1, -3 * Intensify, 67, rnd/100, 50)
		end	
		
		if e2 ~= nil then
			obj:addParticleByNodesRelative(e2, e3, -3 * Intensify, 67, rnd/100, 50)
		end	

		if e4 ~= nil then
			obj:addParticleByNodesRelative(e4, e5, -3 * Intensify, 67, rnd/100, 50)
		end	
		
		if e6 ~= nil then
			obj:addParticleByNodesRelative(e6, e7, -3 * Intensify, 67, rnd/100, 50)
		end	
		
		if e8 ~= nil then
			obj:addParticleByNodesRelative(e8, e9, -3 * Intensify, 67, rnd/100, 50)
		end	
	end
	
end

local function onReset()
	electrics.values["nosFireActive"] = 0
end
M.onReset   = onReset
M.updateGFX = UpdateGFX
M.onInit = onInit
M.toggleFire = toggleFire
return M