function gadget:GetInfo()
	return {
		name = "P.O.P.S. Projectile Trail Effects",
		desc = "Fancy Projectile Trails",
		author = "Argh, thanks to Kloot, jK",
		date = "December 21, 2009",
		license = "GPL, v. 2 or later, 2009",
		layer = 4,--Layer assignment is critical!
		enabled = true,
	}
end



local TL = {projID,trailType,createdPos = {x,y,z}, updatePos = {x,y,z}} -- TL stands for "trail list"
local PB = {flameParticles = {},fireParticles = {},rocketFlameParticles = {}, smRocketFlameParticles = {}} --PB stands for "pre-built"

if (gadgetHandler:IsSyncedCode()) then
--------------------------------------------------------------------------------
--  SYNCED
--------------------------------------------------------------------------------
local sunR, sunG, sunB

function gadget:RecvLuaMsg(msg, playerID)
	--Spring.Echo("message received, "..msg)
	if string.find(msg,"sunvalueR") then
		msg = msg:gsub("sunvalueR","")
		sunR = tonumber(msg)
	end
	if string.find(msg,"sunvalueG") then
		msg = msg:gsub("sunvalueG","")
		sunG = tonumber(msg)
	end
	if string.find(msg,"sunvalueB") then
		msg = msg:gsub("sunvalueB","")
		sunB = tonumber(msg)
	end
end

function gadget:ProjectileCreated(pid, proOwnerID)
	local width,size,colorR,colorG,colorB,colorA,layer
	local GetProjectilePosition = Spring.GetProjectilePosition
	local GetProjectileName = Spring.GetProjectileName
	local GetProjectileType = Spring.GetProjectileType
	local tInsert = table.insert

	local isWeapon,isPiece = GetProjectileType(pid)
	if isWeapon == true then
		
		local name = GetProjectileName(pid)
		local wd = WeaponDefNames[name]
		if wd.customParams.trail == "yes" then
			local tType = tonumber(wd.customParams.trail_type)

			--STOCK BASIC FLAME / SMOKE
			if tType == 0 then
				--Particle trails via P.O.P.S.
				local cX,cY,cZ = GetProjectilePosition(pid)
				TL[pid] = {projID = pid,trailType = tType, updatePos = {x = cX, y = cY, z = cZ}}
			end
			
			--STOCK MISSILE TRAIL
			if tType == 1 then
				--Particle trails via P.O.P.S.
				local cX,cY,cZ = GetProjectilePosition(pid)
				TL[pid] = {projID = pid,trailType = 1, updatePos = {x = cX, y = cY, z = cZ}}
				--Particle trails via LUPS
				width = 0.5
				layer = -16
				colorR = 1.0
				colorG = 0.5
				colorB = 0.0
				colorA = 1.0
				size = 5
				searchradius = 10
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
			end

			--STRATEGICPLASMACANNON
			if tType == 2 then
				--Particle trails via LUPS only
				width = 2
				layer = -32
				colorR = 0.0
				colorG = 0.7
				colorB = 1.0
				colorA = 1.0
				size = 120
				searchradius = 240
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
				width = 5
				layer = -16
				colorR = 0
				colorG = 0.2
				colorB = 1.0
				colorA = 0.5
				size = 360
				searchradius = 720
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
			end

			--ARTILLERY SHELL
			if tType == 3 then
				--Particle trails via LUPS only
				width = 0.5
				layer = -32
				colorR = 0.0
				colorG = 0.7
				colorB = 1.0
				colorA = 1.0
				size = 60
				searchradius = 120
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
				width = 3
				layer = -16
				colorR = 0
				colorG = 0.2
				colorB = 1.0
				colorA = 0.5
				size = 250
				searchradius = 500
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
			end	

			--BIG CONVENTIONAL ARTY
			if tType == 4 then
				--Particle trails via P.O.P.S.
				--tInsert(TL,pid,{projID = pid,trailType = tType})
				--Particle trails via LUPS
				width = 1.5
				layer = -32
				colorR = 1.0
				colorG = 1.0
				colorB = 0.5
				colorA = 1.0
				size = 120
				searchradius = 240
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
				width = 4
				layer = -16
				colorR = 1.0
				colorG = 0.3
				colorB = 0.0
				colorA = 0.5
				size = 250
				searchradius = 500
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
			end

			--SMALL CONVENTIONAL ARTY
			if tType == 5 then
				--Particle trails via P.O.P.S.
				--tInsert(TL,pid,{projID = pid,trailType = tType})
				--Particle trails via LUPS
				width = 0.75
				layer = -32
				colorR = 1.0
				colorG = 1.0
				colorB = 0.5
				colorA = 1.0
				size = 60
				searchradius = 120
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
				width = 3
				layer = -16
				colorR = 1.0
				colorG = 0.3
				colorB = 0.0
				colorA = 0.5
				size = 200
				searchradius = 400
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
			end	

			--FLAMETHROWER
			if tType == 6 then
				--Particle trails via P.O.P.S.
				local cX,cY,cZ = GetProjectilePosition(pid)
				TL[pid] = {projID = pid,trailType = tType, updatePos = {x = cX, y = cY, z = cZ}, createdPos = {x = cX, y = cY, z = cZ}}
				width = 1
				layer = -16
				colorR = 1.0
				colorG = 0.3
				colorB = 0.0
				colorA = 1.0
				size = 60
				searchradius = 120
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
			end	

			--CHICKEN BASIC ARTY
			if tType == 7 then
				--Particle trails via P.O.P.S.
				--tInsert(TL,pid,{projID = pid,trailType = tType})
				--Particle trails via LUPS
				width = 0.75
				layer = -32
				colorR = 0.5
				colorG = 1.0
				colorB = 0.0
				colorA = 1.0
				size = 60
				searchradius = 120
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
				width = 3
				layer = -16
				colorR = 0.3
				colorG = 1.0
				colorB = 0.0
				colorA = 0.5
				size = 200
				searchradius = 400
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
			end

			--CHICKEN BLOB MISSILE PURPLE TRAIL
			if tType == 8 then
				--Particle trails via P.O.P.S.
				--tInsert(TL,pid,{projID = pid,trailType = tType})
				--Particle trails via LUPS
				width = 1.25
				layer = -32
				colorR = 0.5
				colorG = 0.0
				colorB = 1.0
				colorA = 1.0
				size = 90
				searchradius = 180
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
				width = 4
				layer = -16
				colorR = 0.2
				colorG = 0.0
				colorB = 1.0
				colorA = 0.5
				size = 300
				searchradius = 600
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
			end

			--ROCKETTANK / ROCKETTURRET
			if tType == 9 then
				--Particle trails via P.O.P.S.
				local cX,cY,cZ = GetProjectilePosition(pid)
				TL[pid] = {projID = pid,trailType = tType, updatePos = {x = cX, y = cY, z = cZ}}
				--Particle trails via LUPS
				width = 0.5
				layer = -16
				colorR = 1.0
				colorG = 0.5
				colorB = 0.0
				colorA = 1.0
				size = 30
				searchradius = 60
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
			end

			--MAXIM ARTY
			if tType == 10 then
				width = 1
				layer = -32
				colorR = 1.0
				colorG = 0.3
				colorB = 0.0
				colorA = 1.0
				size = 45
				searchradius = 90
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
				width = 4
				layer = -16
				colorR = 0.3
				colorG = 1.0
				colorB = 0.0
				colorA = 0.5
				size = 180
				searchradius = 360
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
			end

			--LIGHTMECH ROCKET, OTHER SPAMMERS
			if tType == 11 then
				width = 0.5
				layer = -16
				colorR = 1.0
				colorG = 0.7
				colorB = 0.0
				colorA = 0.3
				size = 5
				searchradius = 10
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
				width = 1
				layer = -32
				colorR = 1.0
				colorG = 0.3
				colorB = 0.0
				colorA = 0.5
				size = 10
				searchradius = 20
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius)
				width = 2
				layer = -48
				colorR = 0.2
				colorG = 0.2
				colorB = 0.2
				colorA = 0.5
				size = 90
				searchradius = 180
				saturate = 1
				SendToUnsynced("particleTrail",pid,width,size,colorR,colorG,colorB,colorA,layer,searchradius,saturate)
			end						
		end
	end
	if isPiece == true then
		local name = GetProjectileName(pid)
		local sFind = string.find
		if sFind(name,"explode_point") or sFind(name,"base") then 
			local cX,cY,cZ = GetProjectilePosition(pid)
			TL[pid] = {projID = pid,trailType = 0, updatePos = {x = cX, y = cY, z = cZ}}
		end
	end
end

function gadget:ProjectileDestroyed(pid, proOwnerID)
	local GetProjectilePosition = Spring.GetProjectilePosition
	local GetProjectileName = Spring.GetProjectileName
	local GetProjectileType = Spring.GetProjectileType
	local tRemove = table.remove
	local name = GetProjectileName(pid)

	isWeapon,isPiece = GetProjectileType(pid)
	if isWeapon == true then
		
		local wd = WeaponDefNames[name]

		if wd.customParams.trail == "yes" then
			TL[pid] = {}
		end

	end-- END WEAPON CHECK

	if isPiece == true then
		TL[pid] = {}
	end
end

local function BuildFlameParticles()
	local myType, gravity, velX, velY, velZ, size, drag, color1R, color1G, color1B, color1A, color2R, color2G, color2B, color2A, color3R, color3G, color3B, color3A, color4R, color4G, color4B, color4A
	local math_random = math.random
	local distScale = 1000000

	for i = 1,1000 do
			drag = 0.1 / distScale
			gravity = (math_random(1,30) / distScale) + 0.5 --negative

			color1R = 1.0
			color1G = math_random(1,7)/10
			color1B = 0.0
			color1A = 0.1

			color2R = 0.3 * sunR
			color2G = 0.3 * sunG
			color2B = 0.3 * sunB
			color2A = 1.0

			color3R = 0.2 * sunR
			color3G = 0.2 * sunG
			color3B = 0.2 * sunB
			color3A = 1.0

			color4R = 0.0
			color4G = 0.0
			color4B = 0.0
			color4A = 0.0

			size = math_random(750,2000)/1000 / distScale

			myType = math_random(1,4) / distScale

			velX = math_random(-1000,1000)/1000
			velY = math_random(-1000,1000)/1000
			velZ = math_random(-1000,1000)/1000

			sizeGrowth = math_random(25,150) / 1000 / distScale
			if sizeGrowth < 0 then sizeGrowth = sizeGrowth * -1 + 0.5 end

			myVelocity = math_random(0,1) -- VELOCITY MIN/MAX!
			startTime = 0 -- shrink enough to fit into color space
			finishTime = math_random(1000,3500) / 1000 -- shrink enough to fit into color space
			myRand = math_random() -- should be left alone, unless you really need to change this.
			myCone = math_random(-90000,90000)/1000 -- cone value, like CEG, 9000 == 90 degrees

			PB.flameParticles[i] = {gravity = gravity,velX = velX,velY = velY,velZ = velZ,size = size,drag = drag,sizeGrowth = sizeGrowth,myVelocity = myVelocity,startTime = startTime, finishTime = finishTime,myRand = myRand,myType = myType, myCone = myCone, color1R = color1R, color1G = color1G, color1B = color1B, color1A = color1A, color2R = color2R, color2G = color2G, color2B = color2B, color2A = color2A, color3R = color3R, color3G = color3G, color3B = color3B, color3A = color3A, color4R = color4R, color4G = color4G, color4B = color4B, color4A = color4A}
	end
	return
end

local function BuildFireParticles()
	local myType, gravity, velX, velY, velZ, size, drag, color1R, color1G, color1B, color1A, color2R, color2G, color2B, color2A, color3R, color3G, color3B, color3A, color4R, color4G, color4B, color4A
	local math_random = math.random
	local distScale = 1000000

	for i = 1,1000 do
			color1R = 1.0
			color1G = 1.0
			color1B = 1.0
			color1A = 0.3

			color2R = 1.0
			color2G = 1.0
			color2B = 1.0
			color2A = 0.7

			color3R = 0.05 * sunR
			color3G = 0.05 * sunG
			color3B = 0.05 * sunB
			color3A = 1.0

			color4R = 0.0
			color4G = 0.0
			color4B = 0.0
			color4A = 0.0

			size = 0.25 / distScale

			myType = math_random(9,16) / distScale

			drag = 0.01 / distScale
			gravity = (math_random(1,30) / distScale) + 0.5 --negative

			velX = math_random(-1000,1000)/1000
			velY = math_random(-1000,1000)/1000
			velZ = math_random(-1000,1000)/1000

			sizeGrowth = math_random(25,50) / 1000 / distScale
			if sizeGrowth < 0 then sizeGrowth = sizeGrowth * -1 + 0.5 end

			myVelocity = math_random(0,1) -- VELOCITY MIN/MAX!
			startTime = 0 -- shrink enough to fit into color space
			finishTime = math_random(1500,2500) / 1000 -- shrink enough to fit into color space
			myRand = math_random() -- should be left alone, unless you really need to change this.
			myCone = math_random(-90000,90000)/1000 -- cone value, like CEG, 9000 == 90 degrees

			PB.fireParticles[i] = {gravity = gravity,velX = velX,velY = velY,velZ = velZ,size = size,drag = drag,sizeGrowth = sizeGrowth,myVelocity = myVelocity,startTime = startTime, finishTime = finishTime,myRand = myRand,myType = myType, myCone = myCone, color1R = color1R, color1G = color1G, color1B = color1B, color1A = color1A, color2R = color2R, color2G = color2G, color2B = color2B, color2A = color2A, color3R = color3R, color3G = color3G, color3B = color3B, color3A = color3A, color4R = color4R, color4G = color4G, color4B = color4B, color4A = color4A}
	end
	return
end

local function BuildRocketFlameParticles()
	local myType, gravity, velX, velY, velZ, size, drag, color1R, color1G, color1B, color1A, color2R, color2G, color2B, color2A, color3R, color3G, color3B, color3A, color4R, color4G, color4B, color4A
	local math_random = math.random
	local distScale = 1000000

	for i = 1,1000 do

			color1R = 0.2 * sunR
			color1G = 0.2 * sunG
			color1B = 0.2 * sunG
			color1A = 1.0

			color2R = 0.3 * sunR
			color2G = 0.3 * sunG
			color2B = 0.3 * sunB
			color2A = 1.0

			color3R = 0.4 * sunR
			color3G = 0.4 * sunG
			color3B = 0.4 * sunB
			color3A = 1.0

			color4R = 0.0
			color4G = 0.0
			color4B = 0.0
			color4A = 0.0

			drag = 0.5 / distScale
			gravity = (math_random(1,15) / distScale) + 0.5 --negative

			size = math_random(2000,2350)/1000 / distScale

			myType = (math_random(1,4) -1) / distScale

			velX = math_random(-1000,1000)/1000
			velY = math_random(-1000,1000)/1000
			velZ = math_random(-1000,1000)/1000

			sizeGrowth = math_random(50,150) / 1000 / distScale
			if sizeGrowth < 0 then sizeGrowth = sizeGrowth * -1 + 0.5 end

			myVelocity = math_random(0,1) -- VELOCITY MIN/MAX!
			startTime = 0 -- shrink enough to fit into color space
			finishTime = math_random(1000,3500) / 1000 -- shrink enough to fit into color space
			myRand = math_random() -- should be left alone, unless you really need to change this.
			myCone = math_random(-90000,90000)/1000 -- cone value, like CEG, 90000 == 90 degrees

			PB.rocketFlameParticles[i] = {gravity = gravity,velX = velX,velY = velY,velZ = velZ,size = size,drag = drag,sizeGrowth = sizeGrowth,myVelocity = myVelocity,startTime = startTime, finishTime = finishTime,myRand = myRand,myType = myType, myCone = myCone, color1R = color1R, color1G = color1G, color1B = color1B, color1A = color1A, color2R = color2R, color2G = color2G, color2B = color2B, color2A = color2A, color3R = color3R, color3G = color3G, color3B = color3B, color3A = color3A, color4R = color4R, color4G = color4G, color4B = color4B, color4A = color4A}
	end
	return
end

local function BuildSmallRocketFlameParticles()
	local myType, gravity, velX, velY, velZ, size, drag, color1R, color1G, color1B, color1A, color2R, color2G, color2B, color2A, color3R, color3G, color3B, color3A, color4R, color4G, color4B, color4A
	local math_random = math.random
	local distScale = 1000000

	for i = 1,1000 do

			color1R = 0.15 * sunR
			color1G = 0.15 * sunG
			color1B = 0.15 * sunB
			color1A = 1.0

			color2R = 0.2 * sunR
			color2G = 0.2 * sunG
			color2B = 0.2 * sunB
			color2A = 1.0

			color3R = 0.25 * sunR
			color3G = 0.25 * sunG
			color3B = 0.25 * sunB
			color3A = 1.0

			color4R = 0.0
			color4G = 0.0
			color4B = 0.0
			color4A = 0.0

			drag = 0.6 / distScale
			gravity = (math_random(1,15) / distScale) + 0.5 --negative

			size = math_random(2500,3500)/1000 / distScale

			myType = math_random(1,4) / distScale

			velX = math_random(-1000,1000)/1000
			velY = math_random(-1000,1000)/1000
			velZ = math_random(-1000,1000)/1000

			sizeGrowth = math_random(200,300) / 1000 / distScale
			if sizeGrowth < 0 then sizeGrowth = sizeGrowth * -1 + 0.5 end

			myVelocity = math_random(1,2) -- VELOCITY MIN/MAX!
			startTime = 0 -- shrink enough to fit into color space
			finishTime = math_random(1000,3500) / 1000 -- shrink enough to fit into color space
			myRand = math_random() -- should be left alone, unless you really need to change this.
			myCone = math_random(-90000,90000)/1000 -- cone value, like CEG, 90000 == 90 degrees

			PB.smRocketFlameParticles[i] = {gravity = gravity,velX = velX,velY = velY,velZ = velZ,size = size,drag = drag,sizeGrowth = sizeGrowth,myVelocity = myVelocity,startTime = startTime, finishTime = finishTime,myRand = myRand,myType = myType, myCone = myCone, color1R = color1R, color1G = color1G, color1B = color1B, color1A = color1A, color2R = color2R, color2G = color2G, color2B = color2B, color2A = color2A, color3R = color3R, color3G = color3G, color3B = color3B, color3A = color3A, color4R = color4R, color4G = color4G, color4B = color4B, color4A = color4A}
	end
	return
end

function gadget:GameFrame(f)

	if f == 1 then
		if sunR == nil then
			sunR = 1.0
			sunG = 1.0
			sunB = 1.0
		end
	
		BuildFlameParticles()

		BuildRocketFlameParticles()

		BuildSmallRocketFlameParticles()

		BuildFireParticles()
	end

	local projID
	local projX, projY, projZ
	local GetProjectilePosition = Spring.GetProjectilePosition
	local GetProjectileVelocity = Spring.GetProjectileVelocity
	--local tList = TL
	local distScale = 1000000
	local index = 0
	local math_random = math.random
	local math_abs = math.abs

	--if tList[1] ~= nil then
	--if #TL > 1 then
	for i,k in pairs(TL) do
		--Spring.Echo(i,k.projID,k.trailType)
		projID = k.projID
		if projID ~= nil then
		projX, projY, projZ = GetProjectilePosition(projID)
		if projX ~= nil then
			if k.trailType == 0 then
				local distX = (projX  - k.updatePos.x) / 5
				local distY = (projY  - k.updatePos.y) / 5
				local distZ = (projZ  - k.updatePos.z) / 5

				for i = 1,3 do
					index = math_random(1,1000)
					local x = (k.updatePos.x + (distX * i)) / distScale
					if x < 0 then x = -x + 0.5 end
					local y = (k.updatePos.y + (distY * i)) / distScale
					if y < 0 then y = -y + 0.5 end
					local z = (k.updatePos.z + (distZ * i)) / distScale
					if z < 0 then z = -z + 0.5 end
SendToUnsynced("pops_event",x,y,z, PB.flameParticles[index].gravity,PB.flameParticles[index].velX,PB.flameParticles[index].velY,PB.flameParticles[index].velZ,PB.flameParticles[index].size,PB.flameParticles[index].drag,PB.flameParticles[index].sizeGrowth,PB.flameParticles[index].myVelocity,PB.flameParticles[index].startTime,PB.flameParticles[index].finishTime,PB.flameParticles[index].myRand,PB.flameParticles[index].myType,PB.flameParticles[index].myCone,PB.flameParticles[index].color1R, PB.flameParticles[index].color1G, PB.flameParticles[index].color1B, PB.flameParticles[index].color1A, PB.flameParticles[index].color2R, PB.flameParticles[index].color2G, PB.flameParticles[index].color2B, PB.flameParticles[index].color2A, PB.flameParticles[index].color3R, PB.flameParticles[index].color3G, PB.flameParticles[index].color3B, PB.flameParticles[index].color3A, PB.flameParticles[index].color4R, PB.flameParticles[index].color4G, PB.flameParticles[index].color4B, PB.flameParticles[index].color4A)
				end
				k.updatePos.x = projX
				k.updatePos.y = projY
				k.updatePos.z = projZ
			--end
			elseif k.trailType == 1 then
				local distX = (projX  - k.updatePos.x) / 3
				local distY = (projY  - k.updatePos.y) / 3
				local distZ = (projZ  - k.updatePos.z) / 3

				for i = 1,3 do
					index = math_random(1,1000)
					local x = (k.updatePos.x + (distX * i)) / distScale
					if x < 0 then x = -x + 0.5 end
					local y = (k.updatePos.y + (distY * i)) / distScale
					if y < 0 then y = -y + 0.5 end
					local z = (k.updatePos.z + (distZ * i)) / distScale
					if z < 0 then z = -z + 0.5 end
SendToUnsynced("pops_event",x,y,z,PB.rocketFlameParticles[index].gravity,PB.rocketFlameParticles[index].velX,PB.rocketFlameParticles[index].velY,PB.rocketFlameParticles[index].velZ,PB.rocketFlameParticles[index].size,PB.rocketFlameParticles[index].drag,PB.rocketFlameParticles[index].sizeGrowth,PB.rocketFlameParticles[index].myVelocity,PB.rocketFlameParticles[index].startTime,PB.rocketFlameParticles[index].finishTime,PB.rocketFlameParticles[index].myRand,PB.rocketFlameParticles[index].myType,PB.rocketFlameParticles[index].myCone,PB.rocketFlameParticles[index].color1R, PB.rocketFlameParticles[index].color1G, PB.rocketFlameParticles[index].color1B, PB.rocketFlameParticles[index].color1A, PB.rocketFlameParticles[index].color2R, PB.rocketFlameParticles[index].color2G, PB.rocketFlameParticles[index].color2B, PB.rocketFlameParticles[index].color2A, PB.rocketFlameParticles[index].color3R, PB.rocketFlameParticles[index].color3G, PB.rocketFlameParticles[index].color3B, PB.rocketFlameParticles[index].color3A, PB.rocketFlameParticles[index].color4R, PB.rocketFlameParticles[index].color4G, PB.rocketFlameParticles[index].color4B, PB.rocketFlameParticles[index].color4A)
				end
				k.updatePos.x = projX
				k.updatePos.y = projY
				k.updatePos.z = projZ
			--end
			elseif k.trailType == 6 then
				local distX,distY,distZ = 0,0,0
				if math_abs(projX) > math_abs(k.createdPos.x) then
					distX = projX - k.createdPos.x
				else
					distX = k.createdPos.x - projX
				end
				if math_abs(projY) > math_abs(k.createdPos.y) then
					distY = projY - k.createdPos.y
				else
					distY = k.createdPos.y - projY
				end
				if math_abs(projZ) > math_abs(k.createdPos.z) then
					distZ = projZ - k.createdPos.z
				else
					distZ = k.createdPos.z - projZ
				end

				local dist = math_abs((distX + distY + distZ)/3 / 20) / distScale

				for i = 1,5 do
					distX = (projX  - k.updatePos.x) / 5
					distY = (projY  - k.updatePos.y) / 5
					distZ = (projZ  - k.updatePos.z) / 5

					local x = (k.updatePos.x + (distX * i)) / distScale
					if x < 0 then x = -x + 0.5 end
					local y = (k.updatePos.y + (distY * i)) / distScale
					if y < 0 then y = -y + 0.5 end
					local z = (k.updatePos.z + (distZ * i)) / distScale
					if z < 0 then z = -z + 0.5 end

					index = math_random(1,1000)
SendToUnsynced("pops_event",x,y,z,PB.fireParticles[index].gravity,PB.fireParticles[index].velX,PB.fireParticles[index].velY,PB.fireParticles[index].velZ,PB.fireParticles[index].size + dist,PB.fireParticles[index].drag,PB.fireParticles[index].sizeGrowth,PB.fireParticles[index].myVelocity,PB.fireParticles[index].startTime,PB.fireParticles[index].finishTime,PB.fireParticles[index].myRand,PB.fireParticles[index].myType,PB.fireParticles[index].myCone,PB.fireParticles[index].color1R, PB.fireParticles[index].color1G, PB.fireParticles[index].color1B, PB.fireParticles[index].color1A, PB.fireParticles[index].color2R, PB.fireParticles[index].color2G, PB.fireParticles[index].color2B, PB.fireParticles[index].color2A, PB.fireParticles[index].color3R, PB.fireParticles[index].color3G, PB.fireParticles[index].color3B, PB.fireParticles[index].color3A, PB.fireParticles[index].color4R, PB.fireParticles[index].color4G, PB.fireParticles[index].color4B, PB.fireParticles[index].color4A)
					k.updatePos.x = projX
					k.updatePos.y = projY
					k.updatePos.z = projZ
				end
			--end
			elseif k.trailType == 9 then
				local distX = (projX  - k.updatePos.x) / 3
				local distY = (projY  - k.updatePos.y) / 3
				local distZ = (projZ  - k.updatePos.z) / 3

				for i = 1,3 do
					index = math_random(1,1000)
					local x = (k.updatePos.x + (distX * i)) / distScale
					if x < 0 then x = -x + 0.5 end
					local y = (k.updatePos.y + (distY * i)) / distScale
					if y < 0 then y = -y + 0.5 end
					local z = (k.updatePos.z + (distZ * i)) / distScale
					if z < 0 then z = -z + 0.5 end
SendToUnsynced("pops_event",x, y, z,PB.smRocketFlameParticles[index].gravity,PB.smRocketFlameParticles[index].velX,PB.smRocketFlameParticles[index].velY,PB.smRocketFlameParticles[index].velZ,PB.smRocketFlameParticles[index].size,PB.smRocketFlameParticles[index].drag,PB.smRocketFlameParticles[index].sizeGrowth,PB.smRocketFlameParticles[index].myVelocity,PB.smRocketFlameParticles[index].startTime,PB.smRocketFlameParticles[index].finishTime,PB.smRocketFlameParticles[index].myRand,PB.rocketFlameParticles[index].myType,PB.smRocketFlameParticles[index].myCone,PB.smRocketFlameParticles[index].color1R, PB.smRocketFlameParticles[index].color1G, PB.smRocketFlameParticles[index].color1B, PB.smRocketFlameParticles[index].color1A, PB.smRocketFlameParticles[index].color2R, PB.smRocketFlameParticles[index].color2G, PB.smRocketFlameParticles[index].color2B, PB.smRocketFlameParticles[index].color2A, PB.smRocketFlameParticles[index].color3R, PB.smRocketFlameParticles[index].color3G, PB.smRocketFlameParticles[index].color3B, PB.smRocketFlameParticles[index].color3A, PB.smRocketFlameParticles[index].color4R, PB.smRocketFlameParticles[index].color4G, PB.smRocketFlameParticles[index].color4B, PB.smRocketFlameParticles[index].color4A)
				end
				k.updatePos.x = projX
				k.updatePos.y = projY
				k.updatePos.z = projZ
				--return				
			end
		end
		end
	--return
	end
	--end
end

-------------------------------------------------------------------------------------------------UNSYNC
else

local function BuildProjectileTrail(_,projID,width,size,colorR,colorG,colorB,colorA,layer,searchradius, saturate)
	local Lups = GG['Lups']
	if saturate ~= 1 then saturate = false else saturate = true end
	Lups.AddParticles('ProjectileRibbon',{projectile = projID, layer = layer, color = {colorR,colorG,colorB,colorA},width= width, size= size,searchradius = searchradius, saturate = saturate})
end


function gadget:Initialize()
	gadgetHandler:AddSyncAction("particleTrail", BuildProjectileTrail)
end

end