projectileParentElement = createElement("projectileParentElement", "projectileParentElement")
projectileUpdateBuffer = {}

function destroyProjectileByTimer(projectileElement)
	if isElement (projectileElement) then
		local projectileData = findProjectileData (projectileElement)
		if projectileData then
			projectileData.timer = nil
			detonateProjectile(projectileData)
		end
		
	end
end

addEvent("onServerCustomProjectileDestroy", true)
addEventHandler("onServerCustomProjectileDestroy", projectileParentElement, 
function (x, y, z, updateVersion, hitElement)
	if isElement(source) then
		local projectileData = findProjectileData (source)
		if projectileData and projectileData.updateVersion <= updateVersion + 3 then -- only accept a maximum of 3 updates in the past, it a player is on a timed-out state, de-synced explosion positions can occur.
			if not x then
				detonateProjectile(projectileData, nil, nil, nil, hitElement)
			else
				detonateProjectile(projectileData, x, y, z, hitElement)
			end
		end
	end
end)

function validateProjectileSyncers (projectileData)
	local syncers = projectileData.syncers
	for i=#syncers, 1, -1 do
		local player = syncers[i]
		if not isElement(player) then
			table.remove(syncers, 1)
		end
	end
end