function gadget:GetInfo()
	return {
		name = "Call P.O.P.S.",
		desc = "Fancy P.O.P.S. effects of all kinds, called from BOS / Lua",
		author = "Argh, thanks to Kloot, jK",
		date = "February 10, 2010",
		license = "GPL, v. 2 or later, 2009,2010",
		layer = 2,  --Layer assignment is critical!
		enabled = true,
	}
end

local PB = {frothParticles = {},dustParticles = {},dirtParticles = {}, smokeParticles = {}, flameParticles = {}, sparkParticles = {}, junkParticles = {}} --PB stands for "pre-built"
local sunR, sunG, sunB
if (gadgetHandler:IsSyncedCode()) then
--------------------------------------------------------------------------------
--  SYNCED
--------------------------------------------------------------------------------

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

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,10000 do
			color1R = 1.0
			color1G = 1.0
			color1B = 1.0
			color1A = 0.3

			color2R = 1.0
			color2G = 1.0
			color2B = 1.0
			color2A = 0.5

			color3R = 1.0
			color3G = 1.0
			color3B = 1.0
			color3A = 1.0

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

			size = math.random(7.5,15) / distScale

			myType = math_random(9,16) / distScale

			drag = 0.07 / distScale
			gravity = math_random(1,4) / distScale

			velX = 0
			velY = 1.0
			velZ = 0

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

			myVelocity = math_random(2500,5000) * 8 /1000 -- VELOCITY MIN/MAX!
			startTime = 0 -- shrink enough to fit into color space
			finishTime = math_random(300,750) / 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 BuildSmokeParticles()
	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,10000 do
			drag = 0.1 / distScale
			gravity = (math_random(5,10) / distScale) + 0.5 --negative

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

			color2R = 0.25 * sunR
			color2G = 0.25 * sunG
			color2B = 0.25 * 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,50) / 1000 / distScale
			if sizeGrowth < 0 then sizeGrowth = sizeGrowth * -1 + 0.5 end

			myVelocity = math_random(1,5) -- VELOCITY MIN/MAX!
			startTime = 0 -- shrink enough to fit into color space
			finishTime = math_random(3000,7000) / 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.smokeParticles[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 BuildFrothParticles()
	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,10000 do
			color1R = 0.8 * sunR
			color1G = 0.9 * sunG
			color1B = 1.0 * sunB
			color1A = 1.0

			color2R = 0.8 * sunR
			color2G = 0.9 * sunG
			color2B = 1.0 * sunB
			color2A = 1.0

			color3R = 0.8 * sunR
			color3G = 0.9 * sunG
			color3B = 1.0 * sunB
			color3A = 1.0

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

			size = math_random(1,2) / 10  / distScale

			myType = math_random(1,4) / distScale

			drag = 0.9 / distScale
			gravity = 10 / distScale

			velX = math_random(-1000,1000)/1000
			velY = 1.0
			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(2,5) -- VELOCITY MIN/MAX!
			startTime = 0 -- shrink enough to fit into color space
			finishTime = math_random(1500,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(-45000,45000)/1000 -- cone value, like CEG, 9000 == 90 degrees

			PB.frothParticles[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
end

local function BuildSparkParticles()
	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,10000 do

			color1R = 1.0
			color1G = 1.0
			color1B = 1.0
			color1A = 1.0

			color2R = 1.0
			color2G = 1.0
			color2B = 0.1
			color2A = 1.0

			color3R = 1.0
			color3G = 0.3 
			color3B = 0.1
			color3A = 1.0

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

			drag = 0.01 / distScale
			gravity = math_random(30,60) / distScale 

			size = math_random(500,700)/1000 / distScale

			myType = 64 / distScale

			velX = 0
			velY = 1.0
			velZ = 0

			sizeGrowth = math_random(-5,-1) / 10000 / distScale
			if sizeGrowth < 0 then sizeGrowth = sizeGrowth * -1 + 0.5 end

			myVelocity = math_random(20000,25000) * 8 / 1000 -- 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.sparkParticles[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 BuildJunkParticles()
	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,10000 do

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

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

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

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

			drag = 0.05 / distScale
			gravity = math_random(30,60) / distScale 

			size = math_random(1500,3000)/1000 / distScale

			myType = math_random(41,48) / distScale

			velX = 0
			velY = 1.0
			velZ = 0

			sizeGrowth = math_random(-5,-1) / 10000 / distScale
			if sizeGrowth < 0 then sizeGrowth = sizeGrowth * -1 + 0.5 end

			myVelocity = math_random(10000,15000) * 8 / 1000 -- 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.junkParticles[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 BuildDustParticles()
	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.8 * sunR
			color1G = 0.8 * sunG
			color1B = 0.8 * sunB
			color1A = 1.0

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

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

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

			size = math_random(3,5) / 10  / distScale
			sizeGrowth = math_random(25,50) / 1000 / distScale

			myType = math_random(5,6) / distScale

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

			velX = 0
			velY = 1.0
			velZ = 0
	
			myVelocity = math_random(2,5) -- VELOCITY MIN/MAX!
			startTime = 0 -- shrink enough to fit into color space
			finishTime = math_random(1500,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(-45000,45000)/1000 -- cone value, like CEG, 9000 == 90 degrees

			PB.dustParticles[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
end

local function BuildDirtParticles()
	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.05 * sunG
			color1B = 0.05 * sunB
			color1A = 1.0

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

			color3R = 0.2 * 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 = math_random(1,5) / distScale
			sizeGrowth = math_random(25,50) / 1000 /distScale

			myType = math_random(5,6) / distScale

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

			velX = 0
			velY = 1.0
			velZ = 0
	
			myVelocity = math_random(4,10) -- VELOCITY MIN/MAX!
			startTime = 0 -- shrink enough to fit into color space
			finishTime = math_random(1500,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(-45000,45000)/1000 -- cone value, like CEG, 9000 == 90 degrees

			PB.dirtParticles[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
end

function CallPOPS(unitID, ud, team, pieceID, popsType, popsPercent)
	local myPiece = Spring.GetUnitScriptPiece(unitID, pieceID)
	local pX, pY, pZ, vecX, vecY, vecZ = Spring.GetUnitPiecePosDir(unitID,myPiece)
	local realX, realY, realZ = pX, pY, pZ

	if popsPercent == nil then popsPercent = 1.0 else popsPercent = popsPercent / 100 end

	local math_abs = math.abs
	local math_random = math.random
	local distScale = 1000000
	local index

	pX = pX / distScale
	if pX < 0 then pX = -pX + 0.5 end
	pY = pY / distScale
	if pY < 0 then pY = -pY + 0.5 end
	pZ = pZ / distScale
	if pZ < 0 then pZ = -pZ + 0.5 end


------------------------------------------CUSTOM UNIT WATER FROTH
	if popsType == 1 then
		for i = 1,5 do
			index = math_random(1,1000)

			SendToUnsynced("pops_event", pX, pY, pZ,PB.frothParticles[index].gravity,PB.frothParticles[index].velX,PB.frothParticles[index].velY,PB.frothParticles[index].velZ,PB.frothParticles[index].size * popsPercent,PB.frothParticles[index].drag * popsPercent,PB.frothParticles[index].sizeGrowth * popsPercent,PB.frothParticles[index].myVelocity * popsPercent,PB.frothParticles[index].startTime,PB.frothParticles[index].finishTime,PB.frothParticles[index].myRand,PB.frothParticles[index].myType,PB.frothParticles[index].myCone,PB.frothParticles[index].color1R, PB.frothParticles[index].color1G, PB.frothParticles[index].color1B, PB.frothParticles[index].color1A, PB.frothParticles[index].color2R, PB.frothParticles[index].color2G, PB.frothParticles[index].color2B, PB.frothParticles[index].color2A, PB.frothParticles[index].color3R, PB.frothParticles[index].color3G, PB.frothParticles[index].color3B, PB.frothParticles[index].color3A, PB.frothParticles[index].color4R, PB.frothParticles[index].color4G, PB.frothParticles[index].color4B, PB.frothParticles[index].color4A)
		end

	end

------------------------------------------CUSTOM UNIT DUST TRAILS
	if popsType == 2 then
		local x,y,z = Spring.GetUnitPosition(unitID)
		local type = Spring.GetGroundInfo(x,z)
		local height = Spring.GetGroundHeight(x,z)

		if height <= 0 then
			for i = 1,3 do
				index = math_random(1,1000)

				SendToUnsynced("pops_event",pX, pY, pZ,PB.frothParticles[index].gravity,PB.frothParticles[index].velX,PB.frothParticles[index].velY,PB.frothParticles[index].velZ,PB.frothParticles[index].size * popsPercent,PB.frothParticles[index].drag * popsPercent,PB.frothParticles[index].sizeGrowth * popsPercent,PB.frothParticles[index].myVelocity * popsPercent,PB.frothParticles[index].startTime,PB.frothParticles[index].finishTime,PB.frothParticles[index].myRand,PB.frothParticles[index].myType,PB.frothParticles[index].myCone,PB.frothParticles[index].color1R, PB.frothParticles[index].color1G, PB.frothParticles[index].color1B, PB.frothParticles[index].color1A, PB.frothParticles[index].color2R, PB.frothParticles[index].color2G, PB.frothParticles[index].color2B, PB.frothParticles[index].color2A, PB.frothParticles[index].color3R, PB.frothParticles[index].color3G, PB.frothParticles[index].color3B, PB.frothParticles[index].color3A, PB.frothParticles[index].color4R, PB.frothParticles[index].color4G, PB.frothParticles[index].color4B, PB.frothParticles[index].color4A)
			end
		else
			if type == "sand" then
				for i = 1,3 do
					index = math_random(1,1000)

					SendToUnsynced("pops_event",pX, pY, pZ,PB.dustParticles[index].gravity,PB.dustParticles[index].velX,PB.dustParticles[index].velY,PB.dustParticles[index].velZ,PB.dustParticles[index].size * popsPercent,PB.dustParticles[index].drag * popsPercent,PB.dustParticles[index].sizeGrowth * popsPercent,PB.dustParticles[index].myVelocity * popsPercent,PB.dustParticles[index].startTime,PB.dustParticles[index].finishTime,PB.dustParticles[index].myRand,PB.dustParticles[index].myType,PB.dustParticles[index].myCone,PB.dustParticles[index].color1R, PB.dustParticles[index].color1G, PB.dustParticles[index].color1B, PB.dustParticles[index].color1A, PB.dustParticles[index].color2R, PB.dustParticles[index].color2G, PB.dustParticles[index].color2B, PB.dustParticles[index].color2A, PB.dustParticles[index].color3R, PB.dustParticles[index].color3G, PB.dustParticles[index].color3B, PB.dustParticles[index].color3A, PB.dustParticles[index].color4R, PB.dustParticles[index].color4G, PB.dustParticles[index].color4B, PB.dustParticles[index].color4A)
				end
			end

			if type == "ground" or type == "default" then
				for i = 1,1 do
					index = math_random(1,1000)

					SendToUnsynced("pops_event",pX, pY, pZ,PB.dustParticles[index].gravity,PB.dustParticles[index].velX,PB.dustParticles[index].velY,PB.dustParticles[index].velZ,PB.dustParticles[index].size * popsPercent,PB.dustParticles[index].drag * popsPercent,PB.dustParticles[index].sizeGrowth * popsPercent,PB.dustParticles[index].myVelocity * popsPercent,PB.dustParticles[index].startTime,PB.dustParticles[index].finishTime,PB.dustParticles[index].myRand,PB.dustParticles[index].myType,PB.dustParticles[index].myCone,PB.dustParticles[index].color1R, PB.dustParticles[index].color1G, PB.dustParticles[index].color1B, PB.dustParticles[index].color1A, PB.dustParticles[index].color2R, PB.dustParticles[index].color2G, PB.dustParticles[index].color2B, PB.dustParticles[index].color2A, PB.dustParticles[index].color3R, PB.dustParticles[index].color3G, PB.dustParticles[index].color3B, PB.dustParticles[index].color3A, PB.dustParticles[index].color4R, PB.dustParticles[index].color4G, PB.dustParticles[index].color4B, PB.dustParticles[index].color4A)
				end

				for i = 1,2 do
					index = math_random(1,1000)

					SendToUnsynced("pops_event", pX, pY, pZ,PB.dirtParticles[index].gravity,PB.dirtParticles[index].velX,PB.dirtParticles[index].velY,PB.dirtParticles[index].velZ,PB.dirtParticles[index].size * popsPercent,PB.dirtParticles[index].drag * popsPercent,PB.dirtParticles[index].sizeGrowth * popsPercent,PB.dirtParticles[index].myVelocity * popsPercent,PB.dirtParticles[index].startTime,PB.dirtParticles[index].finishTime,PB.dirtParticles[index].myRand,PB.dirtParticles[index].myType,PB.dirtParticles[index].myCone,PB.dirtParticles[index].color1R, PB.dirtParticles[index].color1G, PB.dirtParticles[index].color1B, PB.dirtParticles[index].color1A, PB.dirtParticles[index].color2R, PB.dirtParticles[index].color2G, PB.dirtParticles[index].color2B, PB.dirtParticles[index].color2A, PB.dirtParticles[index].color3R, PB.dirtParticles[index].color3G, PB.dirtParticles[index].color3B, PB.dirtParticles[index].color3A, PB.dirtParticles[index].color4R, PB.dirtParticles[index].color4G, PB.dirtParticles[index].color4B, PB.dirtParticles[index].color4A)
				end
			end

		end
	end


------------------------------------------CUSTOM UNIT EXPLOSIONS
	if popsType == 3 then

	events = math_abs(popsPercent * 100 / 3)

		if popsPercent < 0.85 then
			Spring.SpawnCEG('small_explosion_fx',realX,realY,realZ, 0, 1.0, 0,0,0)
		elseif popsPercent < 1.5 and popsPercent >= 0.85 then
			Spring.SpawnCEG('big_explosion_fx',realX,realY,realZ, 0, 1.0, 0,0,0)
		else
			Spring.SpawnCEG('huge_explosion_fx',realX,realY,realZ, 0, 1.0, 0,0,0)
		end

		for i = 1,(events / 2) do
			index = math_random(1,10000)

			SendToUnsynced("pops_event", pX, pY, pZ,PB.flameParticles[index].gravity,PB.flameParticles[index].velX,PB.flameParticles[index].velY,PB.flameParticles[index].velZ,PB.flameParticles[index].size * popsPercent,PB.flameParticles[index].drag * popsPercent,PB.flameParticles[index].sizeGrowth * popsPercent,PB.flameParticles[index].myVelocity * popsPercent,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)

SendToUnsynced("pops_event", pX, pY, pZ,PB.smokeParticles[index].gravity,PB.smokeParticles[index].velX,PB.smokeParticles[index].velY,PB.smokeParticles[index].velZ,PB.smokeParticles[index].size * popsPercent,PB.smokeParticles[index].drag * popsPercent,PB.smokeParticles[index].sizeGrowth * popsPercent,PB.smokeParticles[index].myVelocity * popsPercent,PB.smokeParticles[index].startTime,PB.smokeParticles[index].finishTime,PB.smokeParticles[index].myRand,PB.smokeParticles[index].myType,PB.smokeParticles[index].myCone,PB.smokeParticles[index].color1R, PB.smokeParticles[index].color1G, PB.smokeParticles[index].color1B, PB.smokeParticles[index].color1A, PB.smokeParticles[index].color2R, PB.smokeParticles[index].color2G, PB.smokeParticles[index].color2B, PB.smokeParticles[index].color2A, PB.smokeParticles[index].color3R, PB.smokeParticles[index].color3G, PB.smokeParticles[index].color3B, PB.smokeParticles[index].color3A, PB.smokeParticles[index].color4R, PB.smokeParticles[index].color4G, PB.smokeParticles[index].color4B, PB.smokeParticles[index].color4A)
		end

		for i = 1,events do
			index = math_random(1,10000)

SendToUnsynced("pops_event", pX, pY, pZ,PB.sparkParticles[index].gravity,PB.sparkParticles[index].velX,PB.sparkParticles[index].velY,PB.sparkParticles[index].velZ,PB.sparkParticles[index].size,PB.sparkParticles[index].drag * popsPercent,PB.sparkParticles[index].sizeGrowth,PB.sparkParticles[index].myVelocity * popsPercent,PB.sparkParticles[index].startTime,PB.sparkParticles[index].finishTime,PB.sparkParticles[index].myRand,PB.sparkParticles[index].myType,PB.sparkParticles[index].myCone,PB.sparkParticles[index].color1R, PB.sparkParticles[index].color1G, PB.sparkParticles[index].color1B, PB.sparkParticles[index].color1A, PB.sparkParticles[index].color2R, PB.sparkParticles[index].color2G, PB.sparkParticles[index].color2B, PB.sparkParticles[index].color2A, PB.sparkParticles[index].color3R, PB.sparkParticles[index].color3G, PB.sparkParticles[index].color3B, PB.sparkParticles[index].color3A, PB.sparkParticles[index].color4R, PB.sparkParticles[index].color4G, PB.sparkParticles[index].color4B, PB.sparkParticles[index].color4A)

SendToUnsynced("pops_event", pX, pY, pZ,PB.junkParticles[index].gravity,PB.junkParticles[index].velX,PB.junkParticles[index].velY,PB.junkParticles[index].velZ,PB.junkParticles[index].size,PB.junkParticles[index].drag * popsPercent,PB.junkParticles[index].sizeGrowth,PB.junkParticles[index].myVelocity * popsPercent,PB.junkParticles[index].startTime,PB.junkParticles[index].finishTime,PB.junkParticles[index].myRand,PB.junkParticles[index].myType,PB.junkParticles[index].myCone,PB.junkParticles[index].color1R, PB.junkParticles[index].color1G, PB.junkParticles[index].color1B, PB.junkParticles[index].color1A, PB.junkParticles[index].color2R, PB.junkParticles[index].color2G, PB.junkParticles[index].color2B, PB.junkParticles[index].color2A, PB.junkParticles[index].color3R, PB.junkParticles[index].color3G, PB.junkParticles[index].color3B, PB.junkParticles[index].color3A, PB.junkParticles[index].color4R, PB.junkParticles[index].color4G, PB.junkParticles[index].color4B, PB.junkParticles[index].color4A)
		end
	end
	return true
end
gadgetHandler:RegisterGlobal("CallPOPS", CallPOPS)

function GameStart()
	if sunR == nil then
		sunR = 1.0
		sunG = 1.0
		sunB = 1.0
		return
	end

	BuildFrothParticles()

	BuildDustParticles()

	BuildDirtParticles()

	BuildSmokeParticles()

	BuildFlameParticles()

	BuildSparkParticles()

	BuildJunkParticles()

	--gadgetHandler:RemoveCallIn("GameFrame")
end

end --END OF SYNCED