local c=10 local r=game:GetService("\080\097\116\104\102\105\110\100\105\110\103\083\101\114\118\105\099\101")local function p(c)local r={}local p=1 while p<#c do local n=c[p]table.insert(r,n)if p<#c then local r=c[p+1]local x,A,d=r.x-n.x,r.y-n.y,r.z-n.z for r=p+1,#c,1 do p=r local n=c[p-1]local y=c[p]local z,P,R=y.x-n.x,y.y-n.y,y.z-n.z if x~=z or A~=P or d~=R then p=p-1 break end end end end table.insert(r,c[#c])return r end local function n(c)local r={}local p=3 while p<#c do local n=c[p-2]local x=c[p-1]local A=c[p]local d=(n-x).magnitude local y=(x-A).magnitude local z=(n-A).magnitude table.insert(r,n)if d==y then p=p+2 else p=p+1 end end table.insert(r,c[#c])return r end function CreatePathObject(c,r,p)local n={}local x={}x.Status=p function x.GetPointCoordinates(c)return r end function x.CheckOcclusionAsync(p,r)local n=0 local x=1 for c,p in pairs(c)do local A=#p:GetPointCoordinates()n=n+A if n>=r then x=c+1 local d=p:CheckOcclusionAsync((n-A)+r)if d~=-1 then return(n-A)+d end break end end for r=x,#c,1 do local p=c[r]local x=#p:GetPointCoordinates()n=n+x if x>0 then local c=p:CheckOcclusionAsync(1)if c~=-1 then return(n-x)+c end end end return-1 end return setmetatable(n,{__metatable=true;__index=x,__newindex=function()error("\067\097\110\110\111\116 \101\100\105\116 \080\097\116\104")end})end


local MAX_PATHS = 10

local pathfindingService = game:GetService("PathfindingService")


local function SimplifyPointsStraight(points)
	local simplified = {}
	local i = 1
	while (i < #points) do
		local pt = points[i]
		table.insert(simplified, pt)
		if (i < #points) then
			local ptNext = points[i + 1]
			local dx, dy, dz = (ptNext.x - pt.x), (ptNext.y - pt.y), (ptNext.z - pt.z)
			for j = i+1, #points do
				i = j
				local ptLast = points[i - 1]
				local pt2 = points[i]
				local dx2, dy2, dz2 = (pt2.x - ptLast.x), (pt2.y - ptLast.y), (pt2.z - ptLast.z)
				if (dx ~= dx2 or dy ~= dy2 or dz ~= dz2) then
					i = (i - 1)
					break
				end
			end
		end
	end
	table.insert(simplified, points[#points])
	return simplified
end


local function SimplifyPointsDiagonal(points)
	local simplified = {}
	local i = 3
	while (i < #points) do
		local p1 = points[i - 2]
		local p2 = points[i - 1]
		local p3 = points[i]
		local a = (p1 - p2).magnitude
		local b = (p2 - p3).magnitude
		local c = (p1 - p3).magnitude
		table.insert(simplified, p1)
		if (a == b) then
			i = (i + 2)
		else
			i = (i + 1)
		end
	end
	table.insert(simplified, points[#points])
	return simplified
end


function CreatePathObject(paths, points, finalStatus)
	local path = {}
	local api = {}
	api.Status = finalStatus
	function api:GetPointCoordinates()
		return points
	end
	function api:CheckOcclusionAsync(start)
		local n = 0
		local startIndex = 1
		for i,p in pairs(paths) do
			local numPoints = #p:GetPointCoordinates()
			n = (n + numPoints)
			if (n >= start) then
				startIndex = i + 1
				local test = p:CheckOcclusionAsync(n - numPoints + start)
				if (test ~= -1) then
					return (n - numPoints + test)
				end
				break
			end
		end
		for i = startIndex, #paths do
			local p = paths[i]
			local numPoints = #p:GetPointCoordinates()
			n = (n + numPoints)
			if (numPoints > 0) then
				local test = p:CheckOcclusionAsync(1)
				if (test ~= -1) then
					return (n - numPoints + test)
				end
			end
		end
		return -1
	end
	return setmetatable(path, {
		__metatable = true;
		__index = api;
		__newindex = function()
			error("Cannot edit Path")
		end;
	})
end

