local j=game:GetService("\080\108\097\121\101\114\115")local F={}local I=require(script:WaitForChild("\082\111\116\097\116\101\100\082\101\103\105\111\110\051"))local function n(j,F)for j,I in pairs(j)do if I==F then return true end end return false end function F.createRegion3FromPart(j)return I.new(j.CFrame,j.Size)end function F.returnRegionFromPlayer(j,F)if j and(j.Character and j.Character:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116"))then for j,F in pairs(F)do local I=F:cast(nil,10000)if#I>=1 then return j,F end end end return nil end function F.getPlayersInRegion(F)local I={}local w={}for j,F in pairs(j:GetPlayers())do if F and F.Character then table.insert(w,F.Character)end end local W=F:castwhite(w,10000)for F,w in pairs(W)do if w.Name=="\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116"then local F=j:GetPlayerFromCharacter(w.Parent)if F and(F.Character and not n(I,F))then table.insert(I,F)end end end return I end return F
-- DrBaja/Braden_J
-- For BlueConX's use only. Unauthorized Redistribution is not allowed.
-- Please see the MAD Contract and Intellectual Property Rights for more information.

local players = game:GetService("Players")

local detectionAPI = {}

local rAPI = require(script:WaitForChild("RotatedRegion3"))

local function isValueInTable(tableToSearch, tableValue)
	for i, v in pairs(tableToSearch) do
		if v == tableValue then
			return true
		end
	end
	return false
end

function detectionAPI.createRegion3FromPart(part)
	return rAPI.new(part.CFrame, part.Size)
end

function detectionAPI.returnRegionFromPlayer(player, regionList)
	if player and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
		for regionName, region in pairs(regionList) do
			local partsInRegion = region:cast(nil, 10000)
			if #partsInRegion >= 1 then
				return regionName, region
			end
		end
	end
	return nil
end

function detectionAPI.getPlayersInRegion(region)
	local playersInRegion = {}

	local playersa = {}
	for _, v in pairs(players:GetPlayers()) do
		if v and v.Character then
			table.insert(playersa, v.Character)
		end
	end

	local parts = region:castwhite(playersa, 10000)
	for _, part in pairs(parts) do
		if part.Name == "HumanoidRootPart" then
			local player = players:GetPlayerFromCharacter(part.Parent)
			if player and player.Character and not isValueInTable(playersInRegion, player) then
				table.insert(playersInRegion, player)
			end
		end
	end
	return playersInRegion
end

return detectionAPI
