Advertisement
Dowuer

Untitled

Jan 3rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  2. local Player,Mouse,mouse,UserInputService,ContextActionService = owner
  3. local RealPlayer = Player
  4. do print("FE Compatibility code by Mokiros")local a=RealPlayer;script.Parent=a.Character;local b=Instance.new("RemoteEvent")b.Name="UserInput_Event"local function c()local d={_fakeEvent=true,Functions={},Connect=function(self,e)table.insert(self.Functions,e)end}d.connect=d.Connect;return d end;local f={Target=nil,Hit=CFrame.new(),KeyUp=c(),KeyDown=c(),Button1Up=c(),Button1Down=c()}local g={InputBegan=c(),InputEnded=c()}local CAS={Actions={},BindAction=function(self,h,i,j,...)CAS.Actions[h]=i and{Name=h,Function=i,Keys={...}}or nil end}CAS.UnbindAction=CAS.BindAction;local function k(self,l,...)local d=f[l]if d and d._fakeEvent then for m,e in pairs(d.Functions)do e(...)end end end;f.TrigEvent=k;g.TrigEvent=k;b.OnServerEvent:Connect(function(n,o)if n~=a then return end;f.Target=o.Target;f.Hit=o.Hit;if not o.isMouse then local p=o.UserInputState==Enum.UserInputState.Begin;if o.UserInputType==Enum.UserInputType.MouseButton1 then return f:TrigEvent(p and"Button1Down"or"Button1Up")end;for m,d in pairs(CAS.Actions)do for m,q in pairs(d.Keys)do if q==o.KeyCode then d.Function(d.Name,o.UserInputState,o)end end end;f:TrigEvent(p and"KeyDown"or"KeyUp",o.KeyCode.Name:lower())g:TrigEvent(p and"InputBegan"or"InputEnded",o,false)end end)b.Parent=NLS([==[local a=game:GetService("Players").LocalPlayer;local b=script:WaitForChild("UserInput_Event")local c=a:GetMouse()local d=game:GetService("UserInputService")local e=function(f,g)if g then return end;b:FireServer({KeyCode=f.KeyCode,UserInputType=f.UserInputType,UserInputState=f.UserInputState,Hit=c.Hit,Target=c.Target})end;d.InputBegan:Connect(e)d.InputEnded:Connect(e)local h,i;while wait(1/30)do if h~=c.Hit or i~=c.Target then h,i=c.Hit,c.Target;b:FireServer({isMouse=true,Target=i,Hit=h})end end]==],Player.Character)local r=game;local s={__index=function(self,q)local t=rawget(self,"_RealService")if t then return t[q]end end,__newindex=function(self,q,u)local t=rawget(self,"_RealService")if t then t[q]=u end end,__call=function(self,...)local t=rawget(self,"_RealService")if t then return t(...)end end}local function v(d,w)d._RealService=typeof(w)=="string"and r:GetService(w)or w;return setmetatable(d,s)end;local x={GetService=function(self,t)return self[t]end,Players=v({LocalPlayer=v({GetMouse=function(self)return f end},Player)},"Players"),UserInputService=v(g,"UserInputService"),ContextActionService=v(CAS,"ContextActionService")}rawset(x.Players,"localPlayer",x.Players.LocalPlayer)x.service=x.GetService;x.RunService=v({RenderStepped=r:GetService("RunService").Heartbeat,BindToRenderStep=function(self,h,m,i)self._btrs[h]=self.Heartbeat:Connect(i)end,UnbindFromRenderStep=function(self,h)self._btrs[h]:Disconnect()end},"RunService")setmetatable(x,{__index=function(self,t)return r:GetService(t)or typeof(r[t])=="function"and function(m,...)return r[t](r,...)end or r[t]end,__newindex=s.__newindex,__call=s.__call})game,owner=x,x.Players.LocalPlayer end
  5.  
  6. local NodesPerStep = 30
  7.  
  8. plr = owner
  9. char = plr.Character
  10. human = char.Humanoid
  11. torso = char.Torso
  12. root = char.HumanoidRootPart
  13. lleg = char["Left Leg"]
  14. rleg = char["Right Leg"]
  15. larm = char["Left Arm"]
  16. rarm = char["Right Arm"]
  17. head = char.Head
  18. lshold = torso["Left Shoulder"]
  19. rshold = torso["Right Shoulder"]
  20. neck = torso.Neck
  21. lhip = torso["Left Hip"]
  22. rhip = torso["Right Hip"]
  23. lscf = lshold.C0
  24. rscf = rshold.C0
  25. ncf = neck.C0
  26. lhcf = lhip.C0
  27. rhcf = rhip.C0
  28. rad = math.rad
  29. random = math.random
  30. sin = math.sin
  31. cos = math.cos
  32. hurt = false
  33.  
  34. local Maze = {}
  35. function Maze:New(xSize, ySize)
  36. local Cells = {}
  37. local IDs = {}
  38. local ID = 1
  39. for x = 0, xSize+1 do
  40. Cells[x] = {}
  41. for y = 0, ySize+1 do
  42. Cells[x][y] = {
  43. ID = ID;
  44. X = x;
  45. Y = y;
  46. Edge = (x == 0 or y == 0 or x==xSize+1 or y == ySize+1)
  47. }
  48. IDs[ID] = Cells[x][y]
  49. ID = ID + 1
  50. end
  51. end
  52. local NewMaze = {
  53. Cells = Cells;
  54. IDs = IDs;
  55. }
  56. setmetatable(NewMaze, {
  57. __index = Maze;
  58. })
  59. return NewMaze
  60. end
  61. function Maze:NewWalls(x, y)
  62. local Walls = {}
  63. if (x == self.Finish.X and y == self.Finish.Y) or
  64. (x == self.Start.X and y == self.Start.Y) then
  65. if x == #self.Cells then
  66. Walls[1] = {self.Cells[x][y].ID, self.Cells[x-1][y].ID}
  67. Walls[2] = {self.Cells[x][y].ID, false}
  68. else
  69. Walls[1] = {self.Cells[x][y].ID, self.Cells[x+1][y].ID}
  70. Walls[2] = {self.Cells[x][y].ID, false}
  71. end
  72. if y == #self.Cells[x] then
  73. Walls[3] = {self.Cells[x][y].ID, self.Cells[x][y-1].ID}
  74. Walls[4] = {self.Cells[x][y].ID, false}
  75. else
  76. Walls[3] = {self.Cells[x][y].ID, self.Cells[x][y+1].ID}
  77. Walls[4] = {self.Cells[x][y].ID, false}
  78. end
  79. else
  80. Walls[1] = {self.Cells[x][y].ID, self.Cells[x-1][y].ID}
  81. Walls[2] = {self.Cells[x][y].ID, self.Cells[x+1][y].ID}
  82. Walls[3] = {self.Cells[x][y].ID, self.Cells[x][y-1].ID}
  83. Walls[4] = {self.Cells[x][y].ID, self.Cells[x][y+1].ID}
  84. end
  85. return Walls
  86. end
  87. function Maze:Generate(start, finish, scale, height)
  88. self.Finish = finish
  89. self.Start = start
  90. self.Scale = scale
  91. self.Height = height
  92. self.Model = Instance.new("Model")
  93. self.Model.Name = "Maze"
  94. local Walls = self:NewWalls(start.X, start.Y)
  95. local PermWalls = {}
  96. local PermCells = {[self.Cells[start.X][start.Y].ID] = true}
  97. local Rand = math.random
  98. local function MainLoop()
  99. while wait() do
  100. for i = 1, NodesPerStep do
  101. if not next(Walls, Key) then
  102. return nil
  103. end
  104. local Key = Rand(1, #Walls)
  105. local w = Walls[Key]
  106. table.remove(Walls,Key)
  107. local Other
  108. local Self
  109. if PermCells[w[1]] then
  110. if PermCells[w[2]] then
  111. PermWalls[#PermWalls+1] = w
  112. else
  113. Other = w[2]
  114. Self = w[1]
  115. end
  116. else
  117. Other = w[1]
  118. Self = w[2]
  119. end
  120. if Other then
  121. PermCells[Other] = true
  122. if self.IDs[Other].Edge then
  123. PermWalls[#PermWalls+1] = w
  124. else
  125. for _, Wall in pairs(self:NewWalls(self.IDs[Other].X, self.IDs[Other].Y)) do
  126. if Wall[2] ~= Self then
  127. Walls[#Walls+1] = Wall
  128. end
  129. end
  130. end
  131. end
  132. end
  133. end
  134. end
  135. MainLoop()
  136. for _, Wall in pairs(PermWalls) do
  137. self:CreateWall(Wall[1], Wall[2])
  138. end
  139. local xMax = ((#self.Cells - 1))*scale
  140. local yMax = ((#self.Cells[1] - 1))*scale
  141. local Floor = Instance.new("Part")
  142. Floor.Anchored = true
  143. Floor.BrickColor = BrickColor.new('Bright green')
  144. Floor.Material = "Grass"
  145. Floor.Name = "MainBase"
  146. Floor.Size = Vector3.new(xMax+2, 1.2, yMax+2)
  147. Floor.Position = Vector3.new(xMax/2+scale/2,-0.4,yMax/2+scale/2)
  148. Floor.Parent = self.Model
  149. end
  150. function Maze:CreateWall(id1, id2)
  151. local Wall = Instance.new "Part"
  152. Wall.Anchored = true
  153. Wall.Name = "Walls"
  154. Wall.Size = Vector3.new(self.Scale, self.Height, 2)
  155. local n1 = self.IDs[id1]
  156. local n2 = self.IDs[id2]
  157. Wall.CFrame = CFrame.new(
  158. Vector3.new(n1.X, self.Height/2, n1.Y),
  159. Vector3.new(n2.X, self.Height/2, n2.Y)
  160. )
  161. Wall.Position = Vector3.new((n1.X + n2.X)*self.Scale/2, self.Height/2, (n1.Y + n2.Y)*self.Scale/2)
  162. Wall.Parent = self.Model
  163. end
  164.  
  165. local m = Maze:New(25,25)
  166. m:Generate(Vector2.new(1,25), Vector2.new(50,50), 20, 25)
  167. m.Model.Parent = workspace
  168. m.Model:MoveTo(workspace:FindFirstChild('Base').Position + Vector3.new(0,65,0))
  169.  
  170. for _,c in pairs(m.Model:GetChildren()) do
  171. if c:IsA('Part') then
  172. if c.Name == "Walls" then
  173. c.Anchored = true
  174. c.CanCollide = false
  175. c.Name ="Walls"
  176. c.Transparency = 1
  177. c.TopSurface = 0
  178. c.BottomSurface = 0
  179. c.BrickColor = BrickColor.new('Daisy orange')
  180. c.Material = "Cobblestone"
  181. end
  182. end
  183. end
  184.  
  185. thing = Instance.new('Part', char.Torso)
  186. thing.Anchored = false
  187. thing.CanCollide = false
  188. thing.Transparency = 1
  189. thing.Name = "Trigger"
  190. thing.Size = Vector3.new(225, 0, 225)
  191.  
  192. thing.Touched:connect(function(hit)
  193. if hit.Name == "Walls" then
  194. hit.CanCollide = true
  195. hit.Transparency = 0
  196. local s = Instance.new("SelectionBox", char)
  197. local lasso = Instance.new("SelectionPartLasso",s)
  198. lasso.Humanoid = char.Humanoid
  199. lasso.Part = hit
  200. end
  201. end)
  202.  
  203. thing.TouchEnded:connect(function(unhit)
  204. if unhit.Name == "Walls" then
  205. unhit.CanCollide = false
  206. unhit.Transparency = 1
  207. for _,c in pairs(char:GetChildren()) do
  208. if c:IsA('SelectionBox') then
  209. c:Destroy()
  210. end
  211. end
  212. end
  213. end)
  214.  
  215. char.Torso.CFrame = CFrame.new(0,125,0)
  216. char.Archivable = true
  217.  
  218. game:GetService("RunService").RenderStepped:connect(function()
  219. thing.CFrame = char.Torso.CFrame
  220. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement