We have a folder called path.
Each path is a number or waypoint.
The paths can split into different choices.
The idea is to create multiple paths
local PatrolIndex = 1
local PatrolSubIndex = 1 -- probably for each path
local PatrolPaths = {}
local tins = table.insert
local function MakePath(pathpart, Level)
local amtpaths = 0
for i,v in pathpart:GetChildren() do
amtpaths+=1
local index = #PatrolPaths
tins(PatrolPaths, {v})
MakePath( v, Level + 1 )
end
end
local Level = 1
for i,v in npc.Path:GetChildren() do
MakePath(v, 1)
end
print(PatrolPaths)
-- format we want
PatrolPaths = { {},{} }
we are trying to get all the children from the single ancestor in order to form paths. The picture here
Would show 3 paths for example.
There will be 3 paths and 2 will share the same branch and 1 will branch off from the 2nd one.
It’s complex logic but chatGPT did it
local function ReturnPaths(part)
local AllPaths = {}
local function FindPaths(currentPath, currentPart)
local children = currentPart:GetChildren()
if #children > 0 then
for _, child in ipairs(children) do
local newPath = {unpack(currentPath)}
table.insert(newPath, currentPart)
FindPaths(newPath, child)
end
else
-- reached end of path
table.insert(currentPath, currentPart) -- Include the last part in the path
table.insert(AllPaths, currentPath)
end
end
FindPaths({}, part)
for i, path in ipairs(AllPaths) do
print("Path "..i.." for "..part..":")
for j, node in ipairs(path) do
print(j, node)
end
end
end
ReturnPaths(npc.Path["1"])