SHOW:
|
|
- or go back to the newest paste.
| 1 | --just put this on the top of a script and boom 89% works | |
| 2 | --note this does not work on big scripts | |
| 3 | if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
| |
| 4 | local Player,game,owner = owner,game | |
| 5 | local RealPlayer = Player | |
| 6 | do | |
| 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()}
| |
| 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 | for _,t in pairs(CAS.Actions) do | |
| 52 | for _,k in pairs(t.Keys) do | |
| 53 | if k==io.KeyCode then | |
| 54 | t.Function(t.Name,io.UserInputState,io) | |
| 55 | end | |
| 56 | end | |
| 57 | end | |
| 58 | m:TrigEvent(b and "KeyDown" or "KeyUp",io.KeyCode.Name:lower()) | |
| 59 | UIS:TrigEvent(b and "InputBegan" or "InputEnded",io,false) | |
| 60 | end | |
| 61 | end) | |
| 62 | Event.Parent = NLS([==[ | |
| 63 | local Player = game:GetService("Players").LocalPlayer
| |
| 64 | local Event = script:WaitForChild("UserInput_Event")
| |
| 65 | ||
| 66 | local Mouse = Player:GetMouse() | |
| 67 | local UIS = game:GetService("UserInputService")
| |
| 68 | local input = function(io,a) | |
| 69 | if a then return end | |
| 70 | --Since InputObject is a client-side instance, we create and pass table instead | |
| 71 | Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
| |
| 72 | end | |
| 73 | UIS.InputBegan:Connect(input) | |
| 74 | UIS.InputEnded:Connect(input) | |
| 75 | ||
| 76 | local h,t | |
| 77 | --Give the server mouse data 30 times every second, but only if the values changed | |
| 78 | --If player is not moving their mouse, client won't fire events | |
| 79 | while wait(1/30) do | |
| 80 | if h~=Mouse.Hit or t~=Mouse.Target then | |
| 81 | h,t=Mouse.Hit,Mouse.Target | |
| 82 | Event:FireServer({isMouse=true,Target=t,Hit=h})
| |
| 83 | end | |
| 84 | end]==],Player.Character) | |
| 85 | ||
| 86 | ----Sandboxed game object that allows the usage of client-side methods and services | |
| 87 | --Real game object | |
| 88 | local _rg = game | |
| 89 | ||
| 90 | --Metatable for fake service | |
| 91 | local fsmt = {
| |
| 92 | __index = function(self,k) | |
| 93 | local s = rawget(self,"_RealService") | |
| 94 | if s then return s[k] end | |
| 95 | end, | |
| 96 | __newindex = function(self,k,v) | |
| 97 | local s = rawget(self,"_RealService") | |
| 98 | if s then s[k]=v end | |
| 99 | end, | |
| 100 | __call = function(self,...) | |
| 101 | local s = rawget(self,"_RealService") | |
| 102 | if s then return s(...) end | |
| 103 | end | |
| 104 | } | |
| 105 | local function FakeService(t,RealService) | |
| 106 | t._RealService = typeof(RealService)=="string" and _rg:GetService(RealService) or RealService | |
| 107 | return setmetatable(t,fsmt) | |
| 108 | end | |
| 109 | ||
| 110 | --Fake game object | |
| 111 | local g = {
| |
| 112 | GetService = function(self,s) | |
| 113 | return self[s] | |
| 114 | end, | |
| 115 | Players = FakeService({
| |
| 116 | LocalPlayer = FakeService({GetMouse=function(self)return m end},Player)
| |
| 117 | },"Players"), | |
| 118 | UserInputService = FakeService(UIS,"UserInputService"), | |
| 119 | ContextActionService = FakeService(CAS,"ContextActionService"), | |
| 120 | } | |
| 121 | rawset(g.Players,"localPlayer",g.Players.LocalPlayer) | |
| 122 | g.service = g.GetService | |
| 123 | ||
| 124 | g.RunService = FakeService({
| |
| 125 | RenderStepped = _rg:GetService("RunService").Heartbeat,
| |
| 126 | BindToRenderStep = function(self,name,_,fun) | |
| 127 | self._btrs[name] = self.Heartbeat:Connect(fun) | |
| 128 | end, | |
| 129 | UnbindFromRenderStep = function(self,name) | |
| 130 | self._btrs[name]:Disconnect() | |
| 131 | end, | |
| 132 | },"RunService") | |
| 133 | ||
| 134 | setmetatable(g,{
| |
| 135 | __index=function(self,s) | |
| 136 | return _rg:GetService(s) or typeof(_rg[s])=="function" | |
| 137 | and function(_,...)return _rg[s](_rg,...)end or _rg[s] | |
| 138 | end, | |
| 139 | __newindex = fsmt.__newindex, | |
| 140 | __call = fsmt.__call | |
| 141 | }) | |
| 142 | --Changing owner to fake player object to support owner:GetMouse() | |
| 143 | game,owner = g,g.Players.LocalPlayer | |
| 144 | end | |
| 145 | ||
| 146 | ||
| 147 | ||
| 148 | ||
| 149 | lp=game.Players.LocalPlayer | |
| 150 | local Tool = Instance.new('HopperBin',lp.Backpack)
| |
| 151 | Tool.Name='MoveSun' | |
| 152 | ||
| 153 | -- convert number (in hours) to TimeOfDay string | |
| 154 | -- because TimeOfDay doesn't cast numbers as expected (3.7 -> 03:07:00 instead of 3:42:00) | |
| 155 | local function ToTimeOfDay(n) | |
| 156 | n = n % 24 | |
| 157 | local i,f = math.modf(n) | |
| 158 | local m = f*60 | |
| 159 | local mi,mf = math.modf(m) | |
| 160 | m = tostring(math.abs(math.floor(m))) | |
| 161 | local s = tostring(math.abs(math.floor(mf*60))) | |
| 162 | return i..":"..string.rep("0",2-#m)..m..":"..string.rep("0",2-#s)..s
| |
| 163 | end | |
| 164 | ||
| 165 | -- convert TimeOfDay string to number (in hours) | |
| 166 | local function FromTimeOfDay(t) | |
| 167 | local signed,h,m,s = t:match("^(%-?)(%d+):(%d+):(%d+)$")
| |
| 168 | s = tonumber(s)/60 | |
| 169 | m = tonumber(m + s)/60 | |
| 170 | h = tonumber(h) + m | |
| 171 | return h * (#signed > 0 and -1 or 1) | |
| 172 | end | |
| 173 | ||
| 174 | local function rad_sc(n) | |
| 175 | return n/(math.pi*2) | |
| 176 | end | |
| 177 | ||
| 178 | local function sc_rad(n) | |
| 179 | return n*(math.pi*2) | |
| 180 | end | |
| 181 | ||
| 182 | -- convert direction to latitude (as GeographicLatitude) and longitude (as TimeOfDay) | |
| 183 | local function ToLatLon(d) | |
| 184 | d = Vector3.new(-d.x,-d.y,d.z) -- derp derp derp derp derp | |
| 185 | local lat = math.atan2(d.z,math.sqrt(d.x^2 + d.y^2)) | |
| 186 | local lon = math.atan2(d.y,d.x) | |
| 187 | ||
| 188 | lat = rad_sc(lat)*360 + 23.5 | |
| 189 | lon = ToTimeOfDay(rad_sc(lon)*24 - 6) | |
| 190 | ||
| 191 | return lat,lon | |
| 192 | end | |
| 193 | ||
| 194 | --[[ | |
| 195 | -- convert lat and lon to direction (doesn't work) | |
| 196 | local function to_dir(lat,lon) | |
| 197 | lat = sc_rad((lat - 23.5)/360) | |
| 198 | lon = sc_rad((FromTimeOfDay(lon) + 6)/24) | |
| 199 | ||
| 200 | return Vector3.new( | |
| 201 | (math.cos(lat)*math.cos(lon)), | |
| 202 | (math.cos(lat)*math.sin(lon)), | |
| 203 | math.sin(lat) | |
| 204 | ) | |
| 205 | end | |
| 206 | ]] | |
| 207 | ||
| 208 | local Event = {}
| |
| 209 | local function Disconnect(...) | |
| 210 | for _,name in pairs{...} do
| |
| 211 | if Event[name] then | |
| 212 | Event[name]:disconnect() | |
| 213 | Event[name] = nil | |
| 214 | end | |
| 215 | end | |
| 216 | end | |
| 217 | ||
| 218 | local Lighting = Game:GetService("Lighting")
| |
| 219 | local down = false | |
| 220 | ||
| 221 | local P = 0.02 | |
| 222 | local D = 16 | |
| 223 | local position = Lighting:GetSunDirection() | |
| 224 | local velocity = Vector3.new(0,0,0) | |
| 225 | local goal = Lighting:GetSunDirection() | |
| 226 | ||
| 227 | local active = false | |
| 228 | local function Activate(Mouse) | |
| 229 | position = Lighting:GetSunDirection() | |
| 230 | goal = Lighting:GetSunDirection() | |
| 231 | active = true | |
| 232 | Event.Down = Mouse.Button1Down:connect(function() | |
| 233 | down = true | |
| 234 | goal = Mouse.UnitRay.Direction | |
| 235 | end) | |
| 236 | ||
| 237 | Event.Up = Mouse.Button1Up:connect(function() | |
| 238 | down = false | |
| 239 | end) | |
| 240 | ||
| 241 | Event.Move = Mouse.Move:connect(function() | |
| 242 | if down then | |
| 243 | goal = Mouse.UnitRay.Direction | |
| 244 | end | |
| 245 | end) | |
| 246 | ||
| 247 | asd = game:GetService'RunService'.RenderStepped:connect(function() | |
| 248 | velocity = Vector3.new( | |
| 249 | velocity.x + P * ((goal.x - position.x) + D * -velocity.x), | |
| 250 | velocity.y + P * ((goal.y - position.y) + D * -velocity.y), | |
| 251 | velocity.z + P * ((goal.z - position.z) + D * -velocity.z) | |
| 252 | ) | |
| 253 | position = position + velocity | |
| 254 | local lat,lon = ToLatLon(position) | |
| 255 | Lighting.GeographicLatitude = lat | |
| 256 | Lighting.TimeOfDay = lon | |
| 257 | --print(lon) | |
| 258 | --wait() | |
| 259 | end) | |
| 260 | end | |
| 261 | ||
| 262 | local function Deactivate() | |
| 263 | active = false | |
| 264 | down = false | |
| 265 | asd:disconnect() | |
| 266 | Disconnect("Down","Up","Move")
| |
| 267 | end | |
| 268 | ||
| 269 | Tool.Selected:connect(Activate) | |
| 270 | Tool.Deselected:connect(Deactivate) |