ManOhMan

Untitled

Jun 26th, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- This script has been converted to FE by iPxter
  2.  
  3.  
  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,Mouse,mouse,UserInputService,ContextActionService = owner
  6. do
  7. print("FE Compatibility code by Mokiros | Translated to FE by iPxter")
  8. script.Parent = Player.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,Connect=function(self,f)self.Function=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()}
  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 and t.Function then
  34. t.Function(...)
  35. end
  36. end
  37. m.TrigEvent = te
  38. UIS.TrigEvent = te
  39.  
  40. Event.OnServerEvent:Connect(function(plr,io)
  41. if plr~=Player then return end
  42. if io.isMouse then
  43. m.Target = io.Target
  44. m.Hit = io.Hit
  45. else
  46. local b = io.UserInputState == Enum.UserInputState.Begin
  47. if io.UserInputType == Enum.UserInputType.MouseButton1 then
  48. return m:TrigEvent(b and "Button1Down" or "Button1Up")
  49. end
  50. for _,t in pairs(CAS.Actions) do
  51. for _,k in pairs(t.Keys) do
  52. if k==io.KeyCode then
  53. t.Function(t.Name,io.UserInputState,io)
  54. end
  55. end
  56. end
  57. m:TrigEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower())
  58. UIS:TrigEvent(b and "InputBegan" or "InputEnded",io,false)
  59. end
  60. end)
  61. Event.Parent = NLS([==[
  62. local Player = game:GetService("Players").LocalPlayer
  63. local Event = script:WaitForChild("UserInput_Event")
  64.  
  65. local UIS = game:GetService("UserInputService")
  66. local input = function(io,a)
  67. if a then return end
  68. --Since InputObject is a client-side instance, we create and pass table instead
  69. Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState})
  70. end
  71. UIS.InputBegan:Connect(input)
  72. UIS.InputEnded:Connect(input)
  73.  
  74. local Mouse = Player:GetMouse()
  75. local h,t
  76. --Give the server mouse data 30 times every second, but only if the values changed
  77. --If player is not moving their mouse, client won't fire events
  78. while wait(1/30) do
  79. if h~=Mouse.Hit or t~=Mouse.Target then
  80. h,t=Mouse.Hit,Mouse.Target
  81. Event:FireServer({isMouse=true,Target=t,Hit=h})
  82. end
  83. end]==],Player.Character)
  84. Mouse,mouse,UserInputService,ContextActionService = m,m,UIS,CAS
  85. end
  86. lp=owner
  87. local Tool = Instance.new('HopperBin',lp.Backpack)
  88. Tool.Name='MoveSun'
  89.  
  90. -- convert number (in hours) to TimeOfDay string
  91. -- because TimeOfDay doesn't cast numbers as expected (3.7 -> 03:07:00 instead of 3:42:00)
  92. local function ToTimeOfDay(n)
  93. n = n % 24
  94. local i,f = math.modf(n)
  95. local m = f*60
  96. local mi,mf = math.modf(m)
  97. m = tostring(math.abs(math.floor(m)))
  98. local s = tostring(math.abs(math.floor(mf*60)))
  99. return i..":"..string.rep("0",2-#m)..m..":"..string.rep("0",2-#s)..s
  100. end
  101.  
  102. -- convert TimeOfDay string to number (in hours)
  103. local function FromTimeOfDay(t)
  104. local signed,h,m,s = t:match("^(%-?)(%d+):(%d+):(%d+)$")
  105. s = tonumber(s)/60
  106. m = tonumber(m + s)/60
  107. h = tonumber(h) + m
  108. return h * (#signed > 0 and -1 or 1)
  109. end
  110.  
  111. local function rad_sc(n)
  112. return n/(math.pi*2)
  113. end
  114.  
  115. local function sc_rad(n)
  116. return n*(math.pi*2)
  117. end
  118.  
  119. -- convert direction to latitude (as GeographicLatitude) and longitude (as TimeOfDay)
  120. local function ToLatLon(d)
  121. d = Vector3.new(-d.x,-d.y,d.z) -- derp derp derp derp derp
  122. local lat = math.atan2(d.z,math.sqrt(d.x^2 + d.y^2))
  123. local lon = math.atan2(d.y,d.x)
  124.  
  125. lat = rad_sc(lat)*360 + 23.5
  126. lon = ToTimeOfDay(rad_sc(lon)*24 - 6)
  127.  
  128. return lat,lon
  129. end
  130.  
  131. --[[
  132. -- convert lat and lon to direction (doesn't work)
  133. local function to_dir(lat,lon)
  134. lat = sc_rad((lat - 23.5)/360)
  135. lon = sc_rad((FromTimeOfDay(lon) + 6)/24)
  136.  
  137. return Vector3.new(
  138. (math.cos(lat)*math.cos(lon)),
  139. (math.cos(lat)*math.sin(lon)),
  140. math.sin(lat)
  141. )
  142. end
  143. ]]
  144.  
  145. local Event = {}
  146. local function Disconnect(...)
  147. for _,name in pairs{...} do
  148. if Event[name] then
  149. Event[name]:disconnect()
  150. Event[name] = nil
  151. end
  152. end
  153. end
  154.  
  155. local Lighting = Game:GetService("Lighting")
  156. local down = false
  157.  
  158. local P = 0.02
  159. local D = 16
  160. local position = Lighting:GetSunDirection()
  161. local velocity = Vector3.new(0,0,0)
  162. local goal = Lighting:GetSunDirection()
  163.  
  164. local active = false
  165. local function Activate(Mouse)
  166. position = Lighting:GetSunDirection()
  167. goal = Lighting:GetSunDirection()
  168. active = true
  169. Event.Down = Mouse.Button1Down:connect(function()
  170. down = true
  171. goal = Mouse.UnitRay.Direction
  172. end)
  173.  
  174. Event.Up = Mouse.Button1Up:connect(function()
  175. down = false
  176. end)
  177.  
  178. Event.Move = Mouse.Move:connect(function()
  179. if down then
  180. goal = Mouse.UnitRay.Direction
  181. end
  182. end)
  183.  
  184. asd = game:GetService'RunService'.RenderStepped:connect(function()
  185. velocity = Vector3.new(
  186. velocity.x + P * ((goal.x - position.x) + D * -velocity.x),
  187. velocity.y + P * ((goal.y - position.y) + D * -velocity.y),
  188. velocity.z + P * ((goal.z - position.z) + D * -velocity.z)
  189. )
  190. position = position + velocity
  191. local lat,lon = ToLatLon(position)
  192. Lighting.GeographicLatitude = lat
  193. Lighting.TimeOfDay = lon
  194. --print(lon)
  195. --wait()
  196. end)
  197. end
  198.  
  199. local function Deactivate()
  200. active = false
  201. down = false
  202. asd:disconnect()
  203. Disconnect("Down","Up","Move")
  204. end
  205.  
  206. Tool.Selected:connect(Activate)
  207. Tool.Deselected:connect(Deactivate)
Add Comment
Please, Sign In to add comment