Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  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 owner = game.Players.LocalPlayer
  3. --https://github.com/Mokiros/roblox-FE-compatibility
  4. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  5. local Player,game,owner = owner,game
  6. local RealPlayer = Player
  7. do
  8. print("FE Compatibility code V2 by Mokiros")
  9. local RealPlayer = RealPlayer
  10. script.Parent = RealPlayer.Character
  11.  
  12. --Fake event to make stuff like Mouse.KeyDown work
  13. local Disconnect_Function = function(this)
  14. this[1].Functions[this[2]] = nil
  15. end
  16. local Disconnect_Metatable = {__index={disconnect=Disconnect_Function,Disconnect=Disconnect_Function}}
  17. local FakeEvent_Metatable = {__index={
  18. Connect = function(this,f)
  19. local i = tostring(math.random(0,10000))
  20. while this.Functions[i] do
  21. i = tostring(math.random(0,10000))
  22. end
  23. this.Functions[i] = f
  24. return setmetatable({this,i},Disconnect_Metatable)
  25. end
  26. }}
  27. FakeEvent_Metatable.__index.connect = FakeEvent_Metatable.__index.Connect
  28. local function fakeEvent()
  29. return setmetatable({Functions={}},FakeEvent_Metatable)
  30. end
  31.  
  32. --Creating fake input objects with fake variables
  33. local FakeMouse = {Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent(),Button2Up=fakeEvent(),Button2Down=fakeEvent()}
  34. FakeMouse.keyUp = FakeMouse.KeyUp
  35. FakeMouse.keyDown = FakeMouse.KeyDown
  36. local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
  37. local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
  38. CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
  39. end}
  40. --Merged 2 functions into one by checking amount of arguments
  41. CAS.UnbindAction = CAS.BindAction
  42.  
  43. --This function will trigger the events that have been :Connect()'ed
  44. local function TriggerEvent(self,ev,...)
  45. for _,f in pairs(self[ev].Functions) do
  46. f(...)
  47. end
  48. end
  49. FakeMouse.TriggerEvent = TriggerEvent
  50. UIS.TriggerEvent = TriggerEvent
  51.  
  52. --Client communication
  53. local Event = Instance.new("RemoteEvent")
  54. Event.Name = "UserInput_Event"
  55. Event.OnServerEvent:Connect(function(plr,io)
  56. if plr~=RealPlayer then return end
  57. FakeMouse.Target = io.Target
  58. FakeMouse.Hit = io.Hit
  59. if not io.isMouse then
  60. local b = io.UserInputState == Enum.UserInputState.Begin
  61. if io.UserInputType == Enum.UserInputType.MouseButton1 then
  62. return FakeMouse:TriggerEvent(b and "Button1Down" or "Button1Up")
  63. end
  64. if io.UserInputType == Enum.UserInputType.MouseButton2 then
  65. return FakeMouse:TriggerEvent(b and "Button2Down" or "Button2Up")
  66. end
  67. for _,t in pairs(CAS.Actions) do
  68. for _,k in pairs(t.Keys) do
  69. if k==io.KeyCode then
  70. t.Function(t.Name,io.UserInputState,io)
  71. end
  72. end
  73. end
  74. FakeMouse:TriggerEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
  75. UIS:TriggerEvent(b and "InputBegan" or "InputEnded",io,false)
  76. end
  77. end)
  78.  
  79. ----Sandboxed game object that allows the usage of client-side methods and services
  80. --Real game object
  81. local RealGame = game
  82.  
  83. --Metatable for fake service
  84. local FakeService_Metatable = {
  85. __index = function(self,k)
  86. local s = rawget(self,"_RealService")
  87. if s then
  88. return typeof(s[k])=="function"
  89. and function(_,...)return s[k](s,...)end or s[k]
  90. end
  91. end,
  92. __newindex = function(self,k,v)
  93. local s = rawget(self,"_RealService")
  94. if s then s[k]=v end
  95. end
  96. }
  97. local function FakeService(t,RealService)
  98. t._RealService = typeof(RealService)=="string" and RealGame:GetService(RealService) or RealService
  99. return setmetatable(t,FakeService_Metatable)
  100. end
  101.  
  102. --Fake game object
  103. local FakeGame = {
  104. GetService = function(self,s)
  105. return rawget(self,s) or RealGame:GetService(s)
  106. end,
  107. Players = FakeService({
  108. LocalPlayer = FakeService({GetMouse=function(self)return FakeMouse end},Player)
  109. },"Players"),
  110. UserInputService = FakeService(UIS,"UserInputService"),
  111. ContextActionService = FakeService(CAS,"ContextActionService"),
  112. RunService = FakeService({
  113. _btrs = {},
  114. RenderStepped = RealGame:GetService("RunService").Heartbeat,
  115. BindToRenderStep = function(self,name,_,fun)
  116. self._btrs[name] = self.Heartbeat:Connect(fun)
  117. end,
  118. UnbindFromRenderStep = function(self,name)
  119. self._btrs[name]:Disconnect()
  120. end,
  121. },"RunService")
  122. }
  123. rawset(FakeGame.Players,"localPlayer",FakeGame.Players.LocalPlayer)
  124. FakeGame.service = FakeGame.GetService
  125. FakeService(FakeGame,game)
  126. --Changing owner to fake player object to support owner:GetMouse()
  127. game,owner = FakeGame,FakeGame.Players.LocalPlayer
  128. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement