Advertisement
Dowuer

Untitled

Jan 3rd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --https://github.com/Mokiros/roblox-FE-compatibility
  2. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  3. local Player,game,owner = owner,game
  4. local RealPlayer = Player
  5. do
  6. print("FE Compatibility code by Mokiros")
  7. local rp = RealPlayer
  8. script.Parent = rp.Character
  9.  
  10. --RemoteEvent for communicating
  11. local Event = Instance.new("RemoteEvent")
  12. Event.Name = "UserInput_Event"
  13.  
  14. --Fake event to make stuff like Mouse.KeyDown work
  15. local function fakeEvent()
  16. local t = {_fakeEvent=true,Functions={},Connect=function(self,f)table.insert(self.Functions,f) end}
  17. t.connect = t.Connect
  18. return t
  19. end
  20.  
  21. --Creating fake input objects with fake variables
  22. local m = {Target=nil,Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent(),Button2Up=fakeEvent(),Button2Down=fakeEvent()}
  23. local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
  24. local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
  25. CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
  26. end}
  27. --Merged 2 functions into one by checking amount of arguments
  28. CAS.UnbindAction = CAS.BindAction
  29.  
  30. --This function will trigger the events that have been :Connect()'ed
  31. local function te(self,ev,...)
  32. local t = m[ev]
  33. if t and t._fakeEvent then
  34. for _,f in pairs(t.Functions) do
  35. f(...)
  36. end
  37. end
  38. end
  39. m.TrigEvent = te
  40. UIS.TrigEvent = te
  41.  
  42. Event.OnServerEvent:Connect(function(plr,io)
  43. if plr~=rp then return end
  44. m.Target = io.Target
  45. m.Hit = io.Hit
  46. if not io.isMouse then
  47. local b = io.UserInputState == Enum.UserInputState.Begin
  48. if io.UserInputType == Enum.UserInputType.MouseButton1 then
  49. return m:TrigEvent(b and "Button1Down" or "Button1Up")
  50. end
  51. if io.UserInputType == Enum.UserInputType.MouseButton2 then
  52. return m:TrigEvent(b and "Button2Down" or "Button2Up")
  53. end
  54. for _,t in pairs(CAS.Actions) do
  55. for _,k in pairs(t.Keys) do
  56. if k==io.KeyCode then
  57. t.Function(t.Name,io.UserInputState,io)
  58. end
  59. end
  60. end
  61. m:TrigEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
  62. UIS:TrigEvent(b and "InputBegan" or "InputEnded",io,false)
  63. end
  64. end)
  65. Event.Parent = NLS([==[
  66. local Player = game:GetService("Players").LocalPlayer
  67. local Event = script:WaitForChild("UserInput_Event")
  68.  
  69. local Mouse = Player:GetMouse()
  70. local UIS = game:GetService("UserInputService")
  71. local input = function(io,a)
  72. if a then return end
  73. --Since InputObject is a client-side instance, we create and pass table instead
  74. Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
  75. end
  76. UIS.InputBegan:Connect(input)
  77. UIS.InputEnded:Connect(input)
  78.  
  79. local h,t
  80. --Give the server mouse data 30 times every second, but only if the values changed
  81. --If player is not moving their mouse, client won't fire events
  82. while wait(1/30) do
  83. if h~=Mouse.Hit or t~=Mouse.Target then
  84. h,t=Mouse.Hit,Mouse.Target
  85. Event:FireServer({isMouse=true,Target=t,Hit=h})
  86. end
  87. end]==],Player.Character)
  88.  
  89. ----Sandboxed game object that allows the usage of client-side methods and services
  90. --Real game object
  91. local _rg = game
  92.  
  93. --Metatable for fake service
  94. local fsmt = {
  95. __index = function(self,k)
  96. local s = rawget(self,"_RealService")
  97. if s then
  98. return typeof(s[k])=="function"
  99. and function(_,...)return s[k](s,...)end or s[k]
  100. end
  101. end,
  102. __newindex = function(self,k,v)
  103. local s = rawget(self,"_RealService")
  104. if s then s[k]=v end
  105. end
  106. }
  107. local function FakeService(t,RealService)
  108. t._RealService = typeof(RealService)=="string" and _rg:GetService(RealService) or RealService
  109. return setmetatable(t,fsmt)
  110. end
  111.  
  112. --Fake game object
  113. local g = {
  114. GetService = function(self,s)
  115. return rawget(self,s) or _rg:GetService(s)
  116. end,
  117. Players = FakeService({
  118. LocalPlayer = FakeService({GetMouse=function(self)return m end},Player)
  119. },"Players"),
  120. UserInputService = FakeService(UIS,"UserInputService"),
  121. ContextActionService = FakeService(CAS,"ContextActionService"),
  122. RunService = FakeService({
  123. _btrs = {},
  124. RenderStepped = _rg:GetService("RunService").Heartbeat,
  125. BindToRenderStep = function(self,name,_,fun)
  126. self._btrs[name] = self.Heartbeat:Connect(fun)
  127. end,
  128. UnbindFromRenderStep = function(self,name)
  129. self._btrs[name]:Disconnect()
  130. end,
  131. },"RunService")
  132. }
  133. rawset(g.Players,"localPlayer",g.Players.LocalPlayer)
  134. g.service = g.GetService
  135. FakeService(g,game)
  136. --Changing owner to fake player object to support owner:GetMouse()
  137. game,owner = g,g.Players.LocalPlayer
  138. NodesPerStep = 30
  139.  
  140. plr = owner
  141. char = plr.Character
  142. human = char.Humanoid
  143. torso = char.Torso
  144. root = char.HumanoidRootPart
  145. lleg = char["Left Leg"]
  146. rleg = char["Right Leg"]
  147. larm = char["Left Arm"]
  148. rarm = char["Right Arm"]
  149. head = char.Head
  150. lshold = torso["Left Shoulder"]
  151. rshold = torso["Right Shoulder"]
  152. neck = torso.Neck
  153. lhip = torso["Left Hip"]
  154. rhip = torso["Right Hip"]
  155. lscf = lshold.C0
  156. rscf = rshold.C0
  157. ncf = neck.C0
  158. lhcf = lhip.C0
  159. rhcf = rhip.C0
  160. rad = math.rad
  161. random = math.random
  162. sin = math.sin
  163. cos = math.cos
  164. hurt = false
  165.  
  166. local Maze = {}
  167. function Maze:New(xSize, ySize)
  168. local Cells = {}
  169. local IDs = {}
  170. local ID = 1
  171. for x = 0, xSize+1 do
  172. Cells[x] = {}
  173. for y = 0, ySize+1 do
  174. Cells[x][y] = {
  175. ID = ID;
  176. X = x;
  177. Y = y;
  178. Edge = (x == 0 or y == 0 or x==xSize+1 or y == ySize+1)
  179. }
  180. IDs[ID] = Cells[x][y]
  181. ID = ID + 1
  182. end
  183. end
  184. local NewMaze = {
  185. Cells = Cells;
  186. IDs = IDs;
  187. }
  188. setmetatable(NewMaze, {
  189. __index = Maze;
  190. })
  191. return NewMaze
  192. end
  193. function Maze:NewWalls(x, y)
  194. local Walls = {}
  195. if (x == self.Finish.X and y == self.Finish.Y) or
  196. (x == self.Start.X and y == self.Start.Y) then
  197. if x == #self.Cells then
  198. Walls[1] = {self.Cells[x][y].ID, self.Cells[x-1][y].ID}
  199. Walls[2] = {self.Cells[x][y].ID, false}
  200. else
  201. Walls[1] = {self.Cells[x][y].ID, self.Cells[x+1][y].ID}
  202. Walls[2] = {self.Cells[x][y].ID, false}
  203. end
  204. if y == #self.Cells[x] then
  205. Walls[3] = {self.Cells[x][y].ID, self.Cells[x][y-1].ID}
  206. Walls[4] = {self.Cells[x][y].ID, false}
  207. else
  208. Walls[3] = {self.Cells[x][y].ID, self.Cells[x][y+1].ID}
  209. Walls[4] = {self.Cells[x][y].ID, false}
  210. end
  211. else
  212. Walls[1] = {self.Cells[x][y].ID, self.Cells[x-1][y].ID}
  213. Walls[2] = {self.Cells[x][y].ID, self.Cells[x+1][y].ID}
  214. Walls[3] = {self.Cells[x][y].ID, self.Cells[x][y-1].ID}
  215. Walls[4] = {self.Cells[x][y].ID, self.Cells[x][y+1].ID}
  216. end
  217. return Walls
  218. end
  219. function Maze:Generate(start, finish, scale, height)
  220. self.Finish = finish
  221. self.Start = start
  222. self.Scale = scale
  223. self.Height = height
  224. self.Model = Instance.new("Model")
  225. self.Model.Name = "Maze"
  226. local Walls = self:NewWalls(start.X, start.Y)
  227. local PermWalls = {}
  228. local PermCells = {[self.Cells[start.X][start.Y].ID] = true}
  229. local Rand = math.random
  230. local function MainLoop()
  231. while wait() do
  232. for i = 1, NodesPerStep do
  233. if not next(Walls, Key) then
  234. return nil
  235. end
  236. local Key = Rand(1, #Walls)
  237. local w = Walls[Key]
  238. table.remove(Walls,Key)
  239. local Other
  240. local Self
  241. if PermCells[w[1]] then
  242. if PermCells[w[2]] then
  243. PermWalls[#PermWalls+1] = w
  244. else
  245. Other = w[2]
  246. Self = w[1]
  247. end
  248. else
  249. Other = w[1]
  250. Self = w[2]
  251. end
  252. if Other then
  253. PermCells[Other] = true
  254. if self.IDs[Other].Edge then
  255. PermWalls[#PermWalls+1] = w
  256. else
  257. for _, Wall in pairs(self:NewWalls(self.IDs[Other].X, self.IDs[Other].Y)) do
  258. if Wall[2] ~= Self then
  259. Walls[#Walls+1] = Wall
  260. end
  261. end
  262. end
  263. end
  264. end
  265. end
  266. end
  267. MainLoop()
  268. for _, Wall in pairs(PermWalls) do
  269. self:CreateWall(Wall[1], Wall[2])
  270. end
  271. local xMax = ((#self.Cells - 1))*scale
  272. local yMax = ((#self.Cells[1] - 1))*scale
  273. local Floor = Instance.new("Part")
  274. Floor.Anchored = true
  275. Floor.BrickColor = BrickColor.new('Bright green')
  276. Floor.Material = "Grass"
  277. Floor.Name = "MainBase"
  278. Floor.Size = Vector3.new(xMax+2, 1.2, yMax+2)
  279. Floor.Position = Vector3.new(xMax/2+scale/2,-0.4,yMax/2+scale/2)
  280. Floor.Parent = self.Model
  281. end
  282. function Maze:CreateWall(id1, id2)
  283. local Wall = Instance.new "Part"
  284. Wall.Anchored = true
  285. Wall.Name = "Walls"
  286. Wall.Size = Vector3.new(self.Scale, self.Height, 2)
  287. local n1 = self.IDs[id1]
  288. local n2 = self.IDs[id2]
  289. Wall.CFrame = CFrame.new(
  290. Vector3.new(n1.X, self.Height/2, n1.Y),
  291. Vector3.new(n2.X, self.Height/2, n2.Y)
  292. )
  293. Wall.Position = Vector3.new((n1.X + n2.X)*self.Scale/2, self.Height/2, (n1.Y + n2.Y)*self.Scale/2)
  294. Wall.Parent = self.Model
  295. end
  296.  
  297. local m = Maze:New(25,25)
  298. m:Generate(Vector2.new(1,25), Vector2.new(50,50), 20, 25)
  299. m.Model.Parent = workspace
  300. m.Model:MoveTo(workspace:FindFirstChild('Base').Position + Vector3.new(0,65,0))
  301.  
  302. for _,c in pairs(m.Model:GetChildren()) do
  303. if c:IsA('Part') then
  304. if c.Name == "Walls" then
  305. c.Anchored = true
  306. c.CanCollide = false
  307. c.Name ="Walls"
  308. c.Transparency = 1
  309. c.TopSurface = 0
  310. c.BottomSurface = 0
  311. c.BrickColor = BrickColor.new('Daisy orange')
  312. c.Material = "Cobblestone"
  313. end
  314. end
  315. end
  316.  
  317. thing = Instance.new('Part', char.Torso)
  318. thing.Anchored = false
  319. thing.CanCollide = false
  320. thing.Transparency = 1
  321. thing.Name = "Trigger"
  322. thing.Size = Vector3.new(225, 0, 225)
  323.  
  324. thing.Touched:connect(function(hit)
  325. if hit.Name == "Walls" then
  326. hit.CanCollide = true
  327. hit.Transparency = 0
  328. local s = Instance.new("SelectionBox", char)
  329. local lasso = Instance.new("SelectionPartLasso",s)
  330. lasso.Humanoid = char.Humanoid
  331. lasso.Part = hit
  332. end
  333. end)
  334.  
  335. thing.TouchEnded:connect(function(unhit)
  336. if unhit.Name == "Walls" then
  337. unhit.CanCollide = false
  338. unhit.Transparency = 1
  339. for _,c in pairs(char:GetChildren()) do
  340. if c:IsA('SelectionBox') then
  341. c:Destroy()
  342. end
  343. end
  344. end
  345. end)
  346.  
  347. char.Torso.CFrame = CFrame.new(0,125,0)
  348. char.Archivable = true
  349.  
  350. game:GetService("RunService").RenderStepped:connect(function()
  351. thing.CFrame = char.Torso.CFrame
  352. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement