Advertisement
akitheone

Untitled

Nov 19th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. local gridWorldSizeX = 2048;
  2. local gridWorldSizeY = 2048;
  3. local nodeRadius = .65;
  4. local nodeDiameter = nodeRadius * 2;
  5. local gridSizeX = math.ceil(gridWorldSizeX / nodeDiameter)
  6. local gridSizeY = math.ceil(gridWorldSizeY / nodeDiameter)
  7. local MaxSize = gridSizeX * gridSizeY;
  8. local WalkableMask = "Walkable"
  9. local NodeClass = require(game.ServerScriptService.Map.Node)
  10. local obstaclePromityPenalty = 1
  11.  
  12. local part = workspace.Unwalkable.GridPart:Clone()
  13.  
  14.  
  15. local TerrainTypes = {
  16. {
  17. TerrainParentFolder = "Walkable",
  18. TerrainPenalty = 0,
  19. }
  20. }
  21. local walkableRegionList = {}
  22.  
  23.  
  24. function createFile(original)
  25. original.Parent = workspace.Exports
  26. return Instance.new("ModuleScript")
  27. end
  28. local makeGrid = true;
  29.  
  30. local modulescript = Instance.new("ModuleScript")
  31.  
  32. local worldBottomLeft = (Vector3.new(0,0,0) - Vector3.new(1,0, 0) * gridWorldSizeX / 2 - Vector3.new(0,0,1) * gridWorldSizeY / 2)
  33. local finalTable = {}
  34. local dataStuffTable = {}
  35. local Grid = {}
  36. if(makeGrid == true) then
  37. for x=1,gridSizeX, 1 do
  38. Grid[x] = {}
  39. for y=1,gridSizeY, 1 do
  40. local WorldPoint = worldBottomLeft + Vector3.new(1,0,0) * (x * nodeDiameter + nodeRadius) + Vector3.new(0,0,1) * (y * nodeDiameter + nodeRadius)
  41. local min = WorldPoint - (((nodeDiameter + nodeRadius)) * part.Size)
  42. local max = WorldPoint + (((nodeDiameter + nodeRadius)) * part.Size)
  43. local currentRegion = Region3.new(min, max)
  44. local notWalkableFound = false
  45. for _,Part in pairs(game.Workspace:FindPartsInRegion3(currentRegion,nil,5)) do
  46. if(Part.Parent.Name == "Unwalkable" == true) then
  47. notWalkableFound = true
  48. break;
  49. end
  50. end
  51.  
  52. local walkable = true
  53. if(notWalkableFound == true) then
  54. walkable = false
  55. end
  56. local penalty = 1
  57. if(walkable == false) then
  58. penalty = penalty + obstaclePromityPenalty
  59. end
  60.  
  61. if(string.len(modulescript.Source) > 197000) then
  62. modulescript = createFile(modulescript)
  63. end
  64. modulescript.Source = modulescript.Source.."\n".."GridStorage["..x.."]["..y.."] = NodeClass.new("..tostring(walkable)..", Vector3.new("..tostring(WorldPoint.X)..", 0, "..tostring(WorldPoint.Z).."), "..x..", "..y..", "..penalty..")"
  65.  
  66. --Grid[x][y] = NodeClass.new(walkable, Vector3.new(WorldPoint.X, 0, WorldPoint.Z), x, y, penalty)--]]
  67. --wait()
  68. end
  69. wait()
  70. end
  71. else
  72. print("load from datastore.")
  73. end
  74. Grid.CompletedLoad = true
  75. repeat wait() until Grid.CompletedLoad == true
  76. --modulescript.Source = Grid
  77.  
  78. modulescript.Parent = workspace.Exports
  79. --print("added to datastore.")
  80. --DrawBlocks()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement