local tableRemove = table.remove


--[[
	Get elements based on distance from point
]]

-- Non mutation variant
function reduceElementsBasedOnDistanceFromPoint (elements, x1, y1, z1, distance)
	local newElementList = {}
	for i=1, #elements do
		local element = elements[i]
		local x2, y2, z2 = getElementPosition(element)
		if getDistanceBetweenPoints3D(x1, y1, z1, x2, y2, z2) < distance then
			newElementList[#newElementList + 1] = element
		end
	end
	return newElementList
end

-- Mutation variant
function filterElementsBasedOnDistanceFromPoint(elements, x1, y1, z1, distance)
	for i=#elements, 1, -1  do
		local x2, y2, z2 = getElementPosition(elements[i])
		if getDistanceBetweenPoints3D(x1, y1, z1, x2, y2, z2) > distance then
			tableRemove(elements, i)
		end
	end
	return elements
end

--//////////////////////////--

--[[
	Get elements based on dimension
]]

-- Non mutation variant
function reduceElementsBasedOnDimension (elements, dimension)
	local newElementList = {}
	for i=1, #elements do
		local element = elements[i]
		if getElementDimension(element) == dimension then
			newElementList[#newElementList + 1] = element
		end
	end
	return newElementList
end

-- Mutation variant
function filterElementsBasedOnDimension (elements, dimension)
	for i=#elements, 1, -1  do
		if getElementDimension(elements[i]) ~= dimension then
			tableRemove(elements, i)
		end
	end
	return elements
end


--//////////////////////////--


function filterPlayersBasedOnDeadStatus (players, status)
	for i=#players, 1, -1  do
		if isPedDead(players[i]) ~= status then
			tableRemove(players, i)
		end
	end
	return players
end

function outputStatusMessage (...)
	
	local status, message, receiver
	if clientSide then
		status, message = arg[1], arg[2]
	else
		receiver, status, message = arg[1], arg[2], arg[3]
	end
	message = tostring(message)

	if status then
		if clientSide then
			outputChatBox(message, 0, 200, 0, true )
		else
			outputChatBox(receiver, message, 0, 200, 0, true )
		end
	else
		if clientSide then
			outputChatBox(message, 200, 0, 0, true )
		else
			outputChatBox(receiver, message, 200, 0, 0, true )
		end
	end
end

function tableToVector (theTable)
	return Vector3(theTable.x, theTable.y, theTable.z)
end

function vectorToTable(theVector)
	return {x = theVector.x, y = theVector.y, z = theVector.z}
end