Advertisement
DropSquad

Untitled

Nov 21st, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 KB | None | 0 0
  1.  
  2. --
  3. -- @ JimmyChance
  4. --
  5. local playerName = "JimmyChance"
  6. local maze_size = {10, 10, 10} -- square maze
  7. local cell_size = 10
  8.  
  9. cellStack = {}
  10. rService = game:GetService("RunService")
  11. directions = {
  12. ["0, 1"] = 1,
  13. ["0, -1"] = 3,
  14. ["1, 0"] = 2,
  15. ["-1, 0"] = 4,
  16. } -- L,R,D,U
  17. -- W: LDRU
  18. map = {}
  19. count = 0
  20.  
  21. local maze = Instance.new("Model", workspace)
  22. maze.Name = "Maze"
  23.  
  24. function makeBrick(c, h, s)
  25. print("Makewallz")
  26. local walls = c[3]
  27. local ch = Instance.new("Model", maze)
  28. ch.Name = "Cell"
  29. local cellpos = c[2]
  30. local p = Instance.new("Part", ch)
  31. p.Anchored = true
  32. p.Name = "Base"
  33. p.CFrame = CFrame.new(cellpos) * CFrame.new(0, -h/2, 0)
  34. p.Size = Vector3.new(cell_size, 1, cell_size)
  35. p.FormFactor = "Custom"
  36. for i = 1, 4 do
  37. local sb = Instance.new("Part", ch)
  38. sb.Anchored = true
  39. sb.FormFactor = "Custom"
  40. sb.Name = "Support Beam"
  41. sb.Size = Vector3.new(1, h, 1)
  42. local basepos = p.Position
  43. local sX = p.Size.X/2 - 0.5
  44. local sZ = p.Size.Z/2 - 0.5
  45. if i == 1 then
  46. sb.Position = basepos + Vector3.new(sX, h/2, sZ)
  47. elseif i == 2 then
  48. sb.Position = cellpos - Vector3.new(sX, 0, sZ)
  49. elseif i == 3 then
  50. sb.Position = cellpos + Vector3.new(sX, 0, -sZ)
  51. elseif i == 4 then
  52. sb.Position = cellpos - Vector3.new(sX, 0, -sZ)
  53. end
  54. end
  55. for i = 1, 4 do
  56. if walls[i] then
  57. local part = Instance.new("Part", ch)
  58. part.Name = "Wall"
  59. part.Anchored = true
  60. part.FormFactor = "Custom"
  61. local basepos = p.Position
  62. local sX = p.Size.X/2 - 0.5
  63. local sZ = p.Size.Z/2 - 0.5
  64. if i == 1 then
  65. part.Size = Vector3.new(cell_size - 2, h, 1)
  66. part.Position = cellpos + Vector3.new(0, 0, -sZ)
  67. elseif i == 2 then
  68. part.Size = Vector3.new(1, h, cell_size - 2)
  69. part.Position = cellpos + Vector3.new(-sX, 0, 0)
  70. elseif i == 3 then
  71. part.Size = Vector3.new(cell_size - 2, h, 1)
  72. part.Position = cellpos + Vector3.new(0, 0, sZ)
  73. elseif i == 4 then
  74. part.Size = Vector3.new(1, h, cell_size - 2)
  75. part.Position = cellpos + Vector3.new(sX, 0, 0)
  76. end
  77. end
  78. end
  79. end
  80.  
  81. function createPositions(startPos, cellSize, mazeSize)
  82. local pos = startPos
  83. local xSize = mazeSize[1]
  84. local zSize = mazeSize[2]
  85. local height = mazeSize[3]
  86. for x = 1, xSize do
  87. map[x] = {}
  88. for z = 1, zSize do
  89. local posY = (startPos + Vector3.new(0, height/2, 0)).Y
  90. local p = Vector3.new((x - 1) * cellSize + startPos.X, posY, (z - 1) * cellSize + startPos.Z)
  91. map[x][z] = {{x, z}, p, {true, true, true, true}, false}
  92. end
  93. end
  94. return map
  95. end
  96.  
  97. function getNearby(cell, tab)
  98. local v = Vector2.new(cell[1][1], cell[1][2])
  99. local n = {}
  100. for i = 1, #tab do
  101. for h = 1, #tab[i] do
  102. local current = tab[i][h]
  103. local v2 = Vector2.new(current[1][1], current[1][2])
  104. local l = (v - v2).magnitude
  105. if l == 1 and not current[4] then
  106. local dir = (v - v2).unit
  107. local num = directions[tostring(dir)]
  108. n[#n + 1] = {current, num}
  109. end
  110. end
  111. end
  112. return n
  113. end
  114.  
  115. function generateMaze(exitEnabled)
  116. print"Generating"
  117. local playex = workspace:FindFirstChild("JimmyChance")
  118. local px = Vector3.new(0, 0, 0)
  119. if playex then
  120. px = playex.Torso.Position
  121. end
  122. local m = createPositions(px, cell_size, maze_size)
  123. local xSize = maze_size[1]
  124. local zSize = maze_size[2]
  125. if exitEnabled[1] then
  126. local choice = exitEnabled[2]
  127. if choice == 0 then
  128. choice = math.random(zSize)
  129. end
  130. m[1][choice][3][2] = false
  131. choice = exitEnabled[3]
  132. if choice == 0 then
  133. choice = math.random(zSize)
  134. end
  135. m[xSize][choice][3][4] = false
  136. end
  137.  
  138. cellStack[1] = {m[1][1], nil}
  139. while count < (xSize * zSize) do
  140. local rand = math.random(100)
  141. if rand > 70 then
  142. wait()
  143. print("Yus")
  144. end
  145. local ncells = getNearby(cellStack[#cellStack][1], m)
  146. if #ncells > 0 then
  147. local ccell = ncells[math.random(#ncells)]
  148. local d = ccell[2]
  149. local q = d + 2
  150. if q > 4 then
  151. q = q - 4
  152. end
  153. ccell[1][4] = true
  154. ccell[1][3][q] = false
  155. cellStack[#cellStack + 1] = ccell
  156. local old = cellStack[#cellStack - 1]
  157. old[1][3][d] = false
  158. count = count + 1
  159. print(count)
  160. else
  161. table.remove(cellStack, #cellStack)
  162. end
  163. end
  164. print("Done")
  165. for x = 1, xSize do
  166. print("Hello " .. x)
  167. if m[x] then
  168. print("Yes!!")
  169. for z = 1, zSize do
  170. wait()
  171. makeBrick(m[x][z], maze_size[3], cell_size)
  172. end
  173. end
  174. end
  175. end
  176.  
  177. local x;
  178. local z;
  179. local h;
  180. local c;
  181.  
  182. code = 0
  183. function onChat(p, message)
  184. local user = p
  185. print("Chat event", code)
  186. if message:sub(1, 4):lower() == "gen:" then -- {10, 10, 10, 10}
  187. local num = tonumber(message:sub(5))
  188. print("Engage")
  189. if workspace:FindFirstChild("Maze") then
  190. workspace:FindFirstChild("Maze"):Destroy()
  191. local maze = Instance.new("Model", workspace)
  192. maze.Name = "Maze"
  193. end
  194. maze_size = {num, num, 20}
  195. cell_size = num
  196. print(1)
  197. generateMaze({true, 0, 0})
  198. end
  199. end
  200.  
  201. wait(2)
  202. local player = game.Players[playerName]
  203. player.Character.Humanoid.WalkSpeed = 50
  204. player.Chatted:connect(function(msg) onChat(player, msg) end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement