Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --https://github.com/Mokiros/roblox-FE-compatibility
- if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
- local Player,game,owner = owner,game
- local RealPlayer = Player
- do
- print("FE Compatibility code by Mokiros")
- local rp = RealPlayer
- script.Parent = rp.Character
- --RemoteEvent for communicating
- local Event = Instance.new("RemoteEvent")
- Event.Name = "UserInput_Event"
- --Fake event to make stuff like Mouse.KeyDown work
- local function fakeEvent()
- local t = {_fakeEvent=true,Functions={},Connect=function(self,f)table.insert(self.Functions,f) end}
- t.connect = t.Connect
- return t
- end
- --Creating fake input objects with fake variables
- local m = {Target=nil,Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent(),Button2Up=fakeEvent(),Button2Down=fakeEvent()}
- local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
- local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
- CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
- end}
- --Merged 2 functions into one by checking amount of arguments
- CAS.UnbindAction = CAS.BindAction
- --This function will trigger the events that have been :Connect()'ed
- local function te(self,ev,...)
- local t = m[ev]
- if t and t._fakeEvent then
- for _,f in pairs(t.Functions) do
- f(...)
- end
- end
- end
- m.TrigEvent = te
- UIS.TrigEvent = te
- Event.OnServerEvent:Connect(function(plr,io)
- if plr~=rp then return end
- m.Target = io.Target
- m.Hit = io.Hit
- if not io.isMouse then
- local b = io.UserInputState == Enum.UserInputState.Begin
- if io.UserInputType == Enum.UserInputType.MouseButton1 then
- return m:TrigEvent(b and "Button1Down" or "Button1Up")
- end
- if io.UserInputType == Enum.UserInputType.MouseButton2 then
- return m:TrigEvent(b and "Button2Down" or "Button2Up")
- end
- for _,t in pairs(CAS.Actions) do
- for _,k in pairs(t.Keys) do
- if k==io.KeyCode then
- t.Function(t.Name,io.UserInputState,io)
- end
- end
- end
- m:TrigEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
- UIS:TrigEvent(b and "InputBegan" or "InputEnded",io,false)
- end
- end)
- Event.Parent = NLS([==[
- local Player = game:GetService("Players").LocalPlayer
- local Event = script:WaitForChild("UserInput_Event")
- local Mouse = Player:GetMouse()
- local UIS = game:GetService("UserInputService")
- local input = function(io,a)
- if a then return end
- --Since InputObject is a client-side instance, we create and pass table instead
- Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
- end
- UIS.InputBegan:Connect(input)
- UIS.InputEnded:Connect(input)
- local h,t
- --Give the server mouse data 30 times every second, but only if the values changed
- --If player is not moving their mouse, client won't fire events
- while wait(1/30) do
- if h~=Mouse.Hit or t~=Mouse.Target then
- h,t=Mouse.Hit,Mouse.Target
- Event:FireServer({isMouse=true,Target=t,Hit=h})
- end
- end]==],Player.Character)
- ----Sandboxed game object that allows the usage of client-side methods and services
- --Real game object
- local _rg = game
- --Metatable for fake service
- local fsmt = {
- __index = function(self,k)
- local s = rawget(self,"_RealService")
- if s then
- return typeof(s[k])=="function"
- and function(_,...)return s[k](s,...)end or s[k]
- end
- end,
- __newindex = function(self,k,v)
- local s = rawget(self,"_RealService")
- if s then s[k]=v end
- end
- }
- local function FakeService(t,RealService)
- t._RealService = typeof(RealService)=="string" and _rg:GetService(RealService) or RealService
- return setmetatable(t,fsmt)
- end
- --Fake game object
- local g = {
- GetService = function(self,s)
- return rawget(self,s) or _rg:GetService(s)
- end,
- Players = FakeService({
- LocalPlayer = FakeService({GetMouse=function(self)return m end},Player)
- },"Players"),
- UserInputService = FakeService(UIS,"UserInputService"),
- ContextActionService = FakeService(CAS,"ContextActionService"),
- RunService = FakeService({
- _btrs = {},
- RenderStepped = _rg:GetService("RunService").Heartbeat,
- BindToRenderStep = function(self,name,_,fun)
- self._btrs[name] = self.Heartbeat:Connect(fun)
- end,
- UnbindFromRenderStep = function(self,name)
- self._btrs[name]:Disconnect()
- end,
- },"RunService")
- }
- rawset(g.Players,"localPlayer",g.Players.LocalPlayer)
- g.service = g.GetService
- FakeService(g,game)
- --Changing owner to fake player object to support owner:GetMouse()
- game,owner = g,g.Players.LocalPlayer
- NodesPerStep = 30
- plr = owner
- char = plr.Character
- human = char.Humanoid
- torso = char.Torso
- root = char.HumanoidRootPart
- lleg = char["Left Leg"]
- rleg = char["Right Leg"]
- larm = char["Left Arm"]
- rarm = char["Right Arm"]
- head = char.Head
- lshold = torso["Left Shoulder"]
- rshold = torso["Right Shoulder"]
- neck = torso.Neck
- lhip = torso["Left Hip"]
- rhip = torso["Right Hip"]
- lscf = lshold.C0
- rscf = rshold.C0
- ncf = neck.C0
- lhcf = lhip.C0
- rhcf = rhip.C0
- rad = math.rad
- random = math.random
- sin = math.sin
- cos = math.cos
- hurt = false
- local Maze = {}
- function Maze:New(xSize, ySize)
- local Cells = {}
- local IDs = {}
- local ID = 1
- for x = 0, xSize+1 do
- Cells[x] = {}
- for y = 0, ySize+1 do
- Cells[x][y] = {
- ID = ID;
- X = x;
- Y = y;
- Edge = (x == 0 or y == 0 or x==xSize+1 or y == ySize+1)
- }
- IDs[ID] = Cells[x][y]
- ID = ID + 1
- end
- end
- local NewMaze = {
- Cells = Cells;
- IDs = IDs;
- }
- setmetatable(NewMaze, {
- __index = Maze;
- })
- return NewMaze
- end
- function Maze:NewWalls(x, y)
- local Walls = {}
- if (x == self.Finish.X and y == self.Finish.Y) or
- (x == self.Start.X and y == self.Start.Y) then
- if x == #self.Cells then
- Walls[1] = {self.Cells[x][y].ID, self.Cells[x-1][y].ID}
- Walls[2] = {self.Cells[x][y].ID, false}
- else
- Walls[1] = {self.Cells[x][y].ID, self.Cells[x+1][y].ID}
- Walls[2] = {self.Cells[x][y].ID, false}
- end
- if y == #self.Cells[x] then
- Walls[3] = {self.Cells[x][y].ID, self.Cells[x][y-1].ID}
- Walls[4] = {self.Cells[x][y].ID, false}
- else
- Walls[3] = {self.Cells[x][y].ID, self.Cells[x][y+1].ID}
- Walls[4] = {self.Cells[x][y].ID, false}
- end
- else
- Walls[1] = {self.Cells[x][y].ID, self.Cells[x-1][y].ID}
- Walls[2] = {self.Cells[x][y].ID, self.Cells[x+1][y].ID}
- Walls[3] = {self.Cells[x][y].ID, self.Cells[x][y-1].ID}
- Walls[4] = {self.Cells[x][y].ID, self.Cells[x][y+1].ID}
- end
- return Walls
- end
- function Maze:Generate(start, finish, scale, height)
- self.Finish = finish
- self.Start = start
- self.Scale = scale
- self.Height = height
- self.Model = Instance.new("Model")
- self.Model.Name = "Maze"
- local Walls = self:NewWalls(start.X, start.Y)
- local PermWalls = {}
- local PermCells = {[self.Cells[start.X][start.Y].ID] = true}
- local Rand = math.random
- local function MainLoop()
- while wait() do
- for i = 1, NodesPerStep do
- if not next(Walls, Key) then
- return nil
- end
- local Key = Rand(1, #Walls)
- local w = Walls[Key]
- table.remove(Walls,Key)
- local Other
- local Self
- if PermCells[w[1]] then
- if PermCells[w[2]] then
- PermWalls[#PermWalls+1] = w
- else
- Other = w[2]
- Self = w[1]
- end
- else
- Other = w[1]
- Self = w[2]
- end
- if Other then
- PermCells[Other] = true
- if self.IDs[Other].Edge then
- PermWalls[#PermWalls+1] = w
- else
- for _, Wall in pairs(self:NewWalls(self.IDs[Other].X, self.IDs[Other].Y)) do
- if Wall[2] ~= Self then
- Walls[#Walls+1] = Wall
- end
- end
- end
- end
- end
- end
- end
- MainLoop()
- for _, Wall in pairs(PermWalls) do
- self:CreateWall(Wall[1], Wall[2])
- end
- local xMax = ((#self.Cells - 1))*scale
- local yMax = ((#self.Cells[1] - 1))*scale
- local Floor = Instance.new("Part")
- Floor.Anchored = true
- Floor.BrickColor = BrickColor.new('Bright green')
- Floor.Material = "Grass"
- Floor.Name = "MainBase"
- Floor.Size = Vector3.new(xMax+2, 1.2, yMax+2)
- Floor.Position = Vector3.new(xMax/2+scale/2,-0.4,yMax/2+scale/2)
- Floor.Parent = self.Model
- end
- function Maze:CreateWall(id1, id2)
- local Wall = Instance.new "Part"
- Wall.Anchored = true
- Wall.Name = "Walls"
- Wall.Size = Vector3.new(self.Scale, self.Height, 2)
- local n1 = self.IDs[id1]
- local n2 = self.IDs[id2]
- Wall.CFrame = CFrame.new(
- Vector3.new(n1.X, self.Height/2, n1.Y),
- Vector3.new(n2.X, self.Height/2, n2.Y)
- )
- Wall.Position = Vector3.new((n1.X + n2.X)*self.Scale/2, self.Height/2, (n1.Y + n2.Y)*self.Scale/2)
- Wall.Parent = self.Model
- end
- local m = Maze:New(25,25)
- m:Generate(Vector2.new(1,25), Vector2.new(50,50), 20, 25)
- m.Model.Parent = workspace
- m.Model:MoveTo(workspace:FindFirstChild('Base').Position + Vector3.new(0,65,0))
- for _,c in pairs(m.Model:GetChildren()) do
- if c:IsA('Part') then
- if c.Name == "Walls" then
- c.Anchored = true
- c.CanCollide = false
- c.Name ="Walls"
- c.Transparency = 1
- c.TopSurface = 0
- c.BottomSurface = 0
- c.BrickColor = BrickColor.new('Daisy orange')
- c.Material = "Cobblestone"
- end
- end
- end
- thing = Instance.new('Part', char.Torso)
- thing.Anchored = false
- thing.CanCollide = false
- thing.Transparency = 1
- thing.Name = "Trigger"
- thing.Size = Vector3.new(225, 0, 225)
- thing.Touched:connect(function(hit)
- if hit.Name == "Walls" then
- hit.CanCollide = true
- hit.Transparency = 0
- local s = Instance.new("SelectionBox", char)
- local lasso = Instance.new("SelectionPartLasso",s)
- lasso.Humanoid = char.Humanoid
- lasso.Part = hit
- end
- end)
- thing.TouchEnded:connect(function(unhit)
- if unhit.Name == "Walls" then
- unhit.CanCollide = false
- unhit.Transparency = 1
- for _,c in pairs(char:GetChildren()) do
- if c:IsA('SelectionBox') then
- c:Destroy()
- end
- end
- end
- end)
- char.Torso.CFrame = CFrame.new(0,125,0)
- char.Archivable = true
- game:GetService("RunService").RenderStepped:connect(function()
- thing.CFrame = char.Torso.CFrame
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement