Advertisement
eea

maze generation

eea
May 7th, 2022 (edited)
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.91 KB | None | 0 0
  1. local x = 30
  2. local z = 30
  3. local espeed = 17
  4. local wall_size = Vector3.new(10, 2047, 1)
  5. local grid_size = Vector3.new(10, 2047/2, 10)
  6. local b_wall_counter = 0
  7. local offset = Vector3.new(0, 0, 20)
  8. local dist = wall_size.X/2
  9. local roof = Instance.new("Part", script)
  10. local balls = Instance.new("Folder", script)
  11. balls.Name = "balls"
  12. local maze = Instance.new("Folder", script)
  13. maze.Name = "maze"
  14. local mazemaze = script.maze
  15. local pfs = game:GetService("PathfindingService")
  16.  
  17. local params = {
  18.     AgentRadius = 8;
  19.     AgentHeight = 4;
  20.     AgentCanJump = true;
  21.     WaypointSpacing = 2;
  22. }
  23.  
  24. local p = game:GetService("Players")
  25. local rs = game:GetService("RunService")
  26. local stuff = {}
  27. roof.Anchored = true
  28. roof.Size = Vector3.new(1,1,1)
  29. roof.Position = offset + Vector3.new(0, wall_size.Y+2.5, 0)
  30. roof.Size = Vector3.new(x*grid_size.X+wall_size.X+1, 5, z*grid_size.Z+wall_size.X+1)
  31. roof.Position += Vector3.new(x*grid_size.X/2, 0, z*grid_size.Z/2)
  32. roof.Material = "Concrete"
  33. roof.Color = Color3.new(.3, .3, .3)
  34. roof.Locked = true
  35. stuff[1] = roof
  36.  
  37. local enemies = {}
  38.  
  39. local chats = {
  40.     "haha",
  41.     "l bozo",
  42.     "get good",
  43.     "skill issue",
  44.     "gg ez no re",
  45.     "imagine dying to a ball :skull:"
  46. }
  47.  
  48. function getpathpoints(start, en)
  49.     local path = pfs:CreatePath()
  50.     path:ComputeAsync(start, en)
  51.     return path:GetWaypoints()
  52. end
  53.  
  54. function whentouch(p, e)
  55.     if p.Parent:FindFirstChild("Humanoid") and (not p:IsDescendantOf(balls)) then
  56.         local hum = p.Parent.Humanoid
  57.         hum:TakeDamage(e:GetAttribute("atk"))
  58.         hum.Died:Connect(function() game:GetService("Chat"):Chat(e, chats[math.random(#chats)]) end)
  59.     end
  60. end
  61.  
  62. function findclosest(pos)
  63.     local poss = {}
  64.     local closest = 6^90
  65.     local target = nil
  66.     local overlapparams = OverlapParams.new()
  67.     overlapparams.FilterDescendantsInstances = script:GetChildren()
  68.     overlapparams.FilterType = Enum.RaycastFilterType.Exclude
  69.     local entities = workspace:GetPartBoundsInRadius(pos, 4000, overlapparams)
  70.     for i = 1,#entities do
  71.         local hum = entities[i].Parent:FindFirstChild("Humanoid")
  72.         local head = entities[i].Parent:FindFirstChild("Head")
  73.         if hum and head then
  74.             if entities[i].Name == "Head" then
  75.                 --print(entities[i])
  76.                 if (head.Position - pos).Magnitude < closest then
  77.                     target = head
  78.                     closest = (head.Position - pos).Magnitude
  79.                 end
  80.             end
  81.         end
  82.     end
  83.     return target
  84. end
  85.  
  86. local floor = roof:Clone()
  87. floor.Parent = script
  88. floor.Position -= Vector3.new(0, wall_size.Y + 4.99/2, 0)
  89. floor.Size += Vector3.new(0, -4.99, 0)
  90. floor.Locked = true
  91. stuff[2] = floor
  92.  
  93. function enemy(xp, zp)
  94.     local model = Instance.new("Model", balls)
  95.     local ene = Instance.new("Part", model)
  96.     ene.Shape = "Ball"
  97.     ene.Position = Vector3.new(xp, 2, zp)
  98.     ene.Velocity = Vector3.new(math.random(), math.random(), math.random())
  99.     ene.Name = "HumanoidRootPart"
  100.     local humanoid = Instance.new("Humanoid", model)
  101.     humanoid.WalkSpeed = espeed
  102.     ene:SetAttribute("atk", .5)
  103.     if math.random() < (1/30) then
  104.         ene.Color = Color3.new(1,0,0)
  105.         humanoid.MaxHealth = 500
  106.         humanoid.Health = 500
  107.         ene:SetAttribute("atk",3)
  108.     end
  109.     return ene
  110. end
  111. local coros = {}
  112. owner.Chatted:Connect(function(msg)
  113.     if string.sub(msg, 1, 3) == "*sp" then
  114.         local amoun = tonumber(string.sub(msg, 4)) or 1
  115.         for i = 1, amoun do
  116.             local enemyd = enemy(math.random() * x * grid_size.X, math.random() * z * grid_size.Z)
  117.             table.insert(enemies, enemyd)
  118.             enemyd.Parent.Humanoid.Died:Connect(function()
  119.                 table.remove(enemies, table.find(enemies, enemyd))
  120.                 enemyd.Parent:Destroy()
  121.             end)
  122.             enemyd.Touched:Connect(function(touched) whentouch(touched, enemyd) end)
  123.             local IOP = coroutine.wrap(function()
  124.                 while task.wait() do
  125.                     if enemyd ~= nil then
  126.                         local enem = enemyd
  127.                         pcall(function() enem:SetNetworkOwner(nil) end)
  128.                         local closest = findclosest(enem.Position)
  129.                         local rayparams = RaycastParams.new()
  130.                         rayparams.FilterDescendantsInstances = { script.balls }
  131.                         local points = getpathpoints(enem.Position, closest.Position)
  132.                         table.remove(points, 1)
  133.                         local coro = coroutine.create(function()
  134.                             for j = 1, #points do
  135.                                 local pointpos = points[j].Position
  136.                                 local vis = Instance.new("Part", enem)
  137.                                 vis.Size = Vector3.one
  138.                                 vis.Position = pointpos
  139.                                 vis.Anchored = true
  140.                                 vis.CanCollide = false
  141.                                 if enem.Parent then
  142.                                     local dist = (pointpos - enem.Position).Magnitude
  143.                                     enem.Parent.Humanoid:MoveTo(pointpos)
  144.                                     enem.Parent.Humanoid.MoveToFinished:Wait()
  145.                                 end
  146.                             end
  147.                         end)
  148.                         local rtoclosest = workspace:Raycast(enem.Position, (closest.Position - enem.Position), rayparams)
  149.                         if rtoclosest and enem.Parent then
  150.                             if not rtoclosest.Instance:IsDescendantOf(closest.Parent) then
  151.                                 local coroscoro = coros[i + #enemies]
  152.                                 if coroscoro then
  153.                                     if coroutine.status(coroscoro) == "dead" then
  154.                                         coroutine.resume(coro)
  155.                                         --print(coros[i + #enemies] == coro)
  156.                                     end
  157.                                 else
  158.                                     coroutine.resume(coro)
  159.                                     --print(coros[i + #enemies] == coro)
  160.                                 end
  161.                             else
  162.                                 coroutine.close(coros[i + #enemies] or coroutine.create(function() end))
  163.                                 coroutine.wrap(function() enem.Parent.Humanoid:MoveTo(closest.Position) end)()
  164.                             end
  165.                         else
  166.                             if enem.Parent then
  167.                                 coroutine.close(coros[i + #enemies] or coroutine.create(function() end))
  168.                                 coroutine.wrap(function() enem.Parent.Humanoid:MoveTo(closest.Position) end)()
  169.                             end
  170.                         end
  171.                         coros[i + #enemies] = coro
  172.                     end
  173.                 end
  174.             end)
  175.             IOP()
  176.             task.wait()
  177.         end
  178.         print("d")
  179.     end
  180.  
  181.     if string.sub(msg, 1, 2) == "*h" then
  182.         for i = 1, #enemies do
  183.             local enemi = enemies[i]
  184.             if enemi:FindFirstChild("Highlight") == nil then
  185.                 local hi = Instance.new("Highlight", enemi)
  186.                 task.wait()
  187.             end
  188.         end
  189.         print("dh")
  190.     end
  191.  
  192.     if string.sub(msg, 1, 2) == "*r" then
  193.         for i = 1, #enemies do
  194.             local enemi = enemies[i]
  195.             if enemi:FindFirstChild("Highlight") then
  196.                 enemi.Highlight:Destroy()
  197.                 task.wait()
  198.             end
  199.         end
  200.         print("dr")
  201.     end
  202.  
  203.     if string.sub(msg, 1, 3) == "*ce" then
  204.         for i = #enemies, 1, -1 do
  205.             local enemi = enemies[i]
  206.             enemi:Destroy()
  207.             table.remove(enemies, i)
  208.             task.wait()
  209.         end
  210.         print("dc")
  211.     end
  212.     if msg == "*nm" then
  213.         mazemaze.Parent = game:GetService("ReplicatedStorage")
  214.     end
  215.  
  216.     if msg == "*ym" then
  217.          mazemaze.Parent = script
  218.     end
  219. end)
  220.  
  221. for xpos = 0, x do
  222.     for zpos = 0, z do
  223.         --local random = math.round(math.noise(xpos/5, zpos/5)*2)
  224.         local random = math.random(1, 4)
  225.         local wall = Instance.new("SpawnLocation", maze)
  226.         wall.Enabled = false
  227.         wall.Orientation = Vector3.new(0, random*90, 0)
  228.         wall.Size = wall_size
  229.         wall.Material = "Concrete"
  230.         wall.Position = Vector3.new(xpos, 1, zpos)*grid_size+offset
  231.         wall.Position += wall.CFrame.LookVector*dist
  232.         wall.Anchored = true
  233.         wall.Locked = true
  234.         if math.random() < 1/300 then
  235.             wall.Color = Color3.new()
  236.             wall.Transparency = .4
  237.             b_wall_counter += 1
  238.         end
  239.         stuff[#stuff+1] = wall
  240.        
  241.         if (xpos % 8 == 0) and (zpos % 8 == 0) then
  242.             local lightbulb = Instance.new("Part", maze)
  243.             lightbulb.Size = Vector3.new(2, 1, 2)
  244.             lightbulb.Position = Vector3.new(xpos, 2, zpos)*grid_size+offset-Vector3.new(0, 1, 0)
  245.             lightbulb.Anchored = true
  246.             lightbulb.Color = Color3.new(1, .6, .3)
  247.             lightbulb.Material = "Neon"
  248.             lightbulb.Locked = true
  249.             stuff[#stuff+1] = lightbulb
  250.             local light = Instance.new("SpotLight", lightbulb)
  251.             light.Range = 35
  252.             light.Face = "Bottom"
  253.             light.Angle = 45
  254.             light.Brightness = 1
  255.             light.Color = Color3.new(1, 1, .8)
  256.         end
  257.     end
  258. end
  259.  
  260. for i = 1,#game:GetService("Players"):GetChildren() do
  261.     if p:children()[i].Character:FindFirstChild("Head") then
  262.     if not p:children()[i].Character.Head:FindFirstChild("NLS") then
  263.     NLS([[
  264.         game:GetService("Lighting").Ambient = Color3.new(.119, .119, .119)
  265.         game:GetService("Lighting").OutdoorAmbient = Color3.new()
  266.     ]], game:GetService("Players"):children()[i].Character.Head)
  267.     end
  268.     end
  269. end
  270.  
  271.  
  272. print(b_wall_counter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement