Advertisement
rewfsdg3

Untitled

Nov 7th, 2018
117
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. end
  139.  
  140.  
  141. lp= owner
  142. local Tool = Instance.new('HopperBin',lp.Backpack)
  143. Tool.Name='MoveSun'
  144.  
  145. -- convert number (in hours) to TimeOfDay string
  146. -- because TimeOfDay doesn't cast numbers as expected (3.7 -> 03:07:00 instead of 3:42:00)
  147. local function ToTimeOfDay(n)
  148. n = n % 24
  149. local i,f = math.modf(n)
  150. local m = f*60
  151. local mi,mf = math.modf(m)
  152. m = tostring(math.abs(math.floor(m)))
  153. local s = tostring(math.abs(math.floor(mf*60)))
  154. return i..":"..string.rep("0",2-#m)..m..":"..string.rep("0",2-#s)..s
  155. end
  156.  
  157. -- convert TimeOfDay string to number (in hours)
  158. local function FromTimeOfDay(t)
  159. local signed,h,m,s = t:match("^(%-?)(%d+):(%d+):(%d+)$")
  160. s = tonumber(s)/60
  161. m = tonumber(m + s)/60
  162. h = tonumber(h) + m
  163. return h * (#signed > 0 and -1 or 1)
  164. end
  165.  
  166. local function rad_sc(n)
  167. return n/(math.pi*2)
  168. end
  169.  
  170. local function sc_rad(n)
  171. return n*(math.pi*2)
  172. end
  173.  
  174. -- convert direction to latitude (as GeographicLatitude) and longitude (as TimeOfDay)
  175. local function ToLatLon(d)
  176. d = Vector3.new(-d.x,-d.y,d.z) -- derp derp derp derp derp
  177. local lat = math.atan2(d.z,math.sqrt(d.x^2 + d.y^2))
  178. local lon = math.atan2(d.y,d.x)
  179.  
  180. lat = rad_sc(lat)*360 + 23.5
  181. lon = ToTimeOfDay(rad_sc(lon)*24 - 6)
  182.  
  183. return lat,lon
  184. end
  185.  
  186. --[[
  187. -- convert lat and lon to direction (doesn't work)
  188. local function to_dir(lat,lon)
  189. lat = sc_rad((lat - 23.5)/360)
  190. lon = sc_rad((FromTimeOfDay(lon) + 6)/24)
  191.  
  192. return Vector3.new(
  193. (math.cos(lat)*math.cos(lon)),
  194. (math.cos(lat)*math.sin(lon)),
  195. math.sin(lat)
  196. )
  197. end
  198. ]]
  199.  
  200. local Event = {}
  201. local function Disconnect(...)
  202. for _,name in pairs{...} do
  203. if Event[name] then
  204. Event[name]:disconnect()
  205. Event[name] = nil
  206. end
  207. end
  208. end
  209.  
  210. local Lighting = Game:GetService("Lighting")
  211. local down = false
  212.  
  213. local P = 0.02
  214. local D = 16
  215. local position = Lighting:GetSunDirection()
  216. local velocity = Vector3.new(0,0,0)
  217. local goal = Lighting:GetSunDirection()
  218.  
  219. local active = false
  220. local function Activate(Mouse)
  221. position = Lighting:GetSunDirection()
  222. goal = Lighting:GetSunDirection()
  223. active = true
  224. Event.Down = Mouse.Button1Down:connect(function()
  225. down = true
  226. goal = Mouse.UnitRay.Direction
  227. end)
  228.  
  229. Event.Up = Mouse.Button1Up:connect(function()
  230. down = false
  231. end)
  232.  
  233. Event.Move = Mouse.Move:connect(function()
  234. if down then
  235. goal = Mouse.UnitRay.Direction
  236. end
  237. end)
  238.  
  239. asd = game:GetService'RunService'.RenderStepped:connect(function()
  240. velocity = Vector3.new(
  241. velocity.x + P * ((goal.x - position.x) + D * -velocity.x),
  242. velocity.y + P * ((goal.y - position.y) + D * -velocity.y),
  243. velocity.z + P * ((goal.z - position.z) + D * -velocity.z)
  244. )
  245. position = position + velocity
  246. local lat,lon = ToLatLon(position)
  247. Lighting.GeographicLatitude = lat
  248. Lighting.TimeOfDay = lon
  249. --print(lon)
  250. --wait()
  251. end)
  252. end
  253.  
  254. local function Deactivate()
  255. active = false
  256. down = false
  257. asd:disconnect()
  258. Disconnect("Down","Up","Move")
  259. end
  260.  
  261. Tool.Selected:connect(Activate)
  262. Tool.Deselected:connect(Deactivate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement