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 | wait(1) | |
149 | local debris = game:GetService("Debris") | |
150 | local playerservice = game:GetService("Players") | |
151 | local xplayer = playerservice.LocalPlayer | |
152 | repeat wait(.5) until xplayer ~= nil | |
153 | local xcharacter = xplayer.Character | |
154 | local playermouse = xplayer:GetMouse() | |
155 | local playercam = workspace.CurrentCamera | |
156 | local playercharacter = xplayer.Character | |
157 | ||
158 | repeat wait(.5) until xplayer.Character ~=nil | |
159 | ||
160 | local xhumanoid = xcharacter:WaitForChild('Humanoid') | |
161 | local rltool = Instance.new("Tool") | |
162 | rltool.Name = 'GuidedMissile' | |
163 | rltool.GripForward = Vector3.new(0,0,-1) | |
164 | rltool.GripPos = Vector3.new(0.05,-0.6,-1) | |
165 | rltool.GripRight = Vector3.new(1,0,0) | |
166 | rltool.GripUp = Vector3.new(0,1,0) | |
167 | rltool.ToolTip = 'Launch the rocket and you will begin controlling the rocket' | |
168 | local handle = Instance.new("Part",rltool) | |
169 | handle.Name = "Handle" | |
170 | handle.Material = 'Plastic' | |
171 | handle.CanCollide = true | |
172 | handle.Locked = true | |
173 | handle.Size = Vector3.new(0.84,1.15,3.55) | |
174 | handle.TopSurface = 'Smooth' | |
175 | handle.BottomSurface = 'Smooth' | |
176 | local handlemesh = Instance.new("SpecialMesh",handle) | |
177 | handlemesh.MeshType = Enum.MeshType.FileMesh | |
178 | handlemesh.MeshId = "http://www.roblox.com/asset/?id=94690054" | |
179 | handlemesh.TextureId = "http://www.roblox.com/asset/?id=94689966" | |
180 | handlemesh.Scale = Vector3.new(1.5,1.5,1.5) | |
181 | ||
182 | local MainTool = rltool | |
183 | local AmmoSize = 1 | |
184 | local CurrentAmmo = 1 | |
185 | local AmmoMax = math.huge | |
186 | local ToolEnabled = true | |
187 | local GuidedRocket = false | |
188 | local camerafollow = xhumanoid | |
189 | BaseRocket = nil | |
190 | local cooldown = 4 | |
191 | local RocketSpeed = 75 | |
192 | ||
193 | local newsound = Instance.new("Sound") | |
194 | newsound.Name = 'NewSound' | |
195 | newsound.Volume = 1 | |
196 | newsound.PlaybackSpeed = 1 | |
197 | newsound.EmitterSize = 10 | |
198 | newsound.MaxDistance = 10000 | |
199 | newsound.Looped = false | |
200 | ||
201 | MainTool.Parent = xplayer.Backpack | |
202 | ||
203 | local RocketSize = Vector3.new(1,1,4) | |
204 | ||
205 | function CreateBaseRocket() | |
206 | local rocket = Instance.new("Part") | |
207 | rocket.Name = "Rocket" | |
208 | rocket.Size = RocketSize | |
209 | rocket.CanCollide = false | |
210 | rocket.BottomSurface = 'Smooth' | |
211 | rocket.TopSurface = 'Smooth' | |
212 | rocket.BrickColor = BrickColor.Random() | |
213 | local specialmesh = Instance.new("SpecialMesh",rocket) | |
214 | specialmesh.MeshType = Enum.MeshType.FileMesh | |
215 | specialmesh.Scale = Vector3.new(.5,.5,.2) | |
216 | specialmesh.MeshId = "http://www.roblox.com/asset/?id=2251534" | |
217 | local attachmentr1 = Instance.new("Attachment",rocket) | |
218 | attachmentr1.Name = 'R0' | |
219 | attachmentr1.Position = Vector3.new(-1,0,-1) | |
220 | local attachmentr2 = attachmentr1:Clone() | |
221 | attachmentr2.Name = 'R1' | |
222 | attachmentr2.Position = Vector3.new(1,0,1) | |
223 | attachmentr2.Parent = rocket | |
224 | local trail = Instance.new("Trail",rocket) | |
225 | trail.LightEmission = .75 | |
226 | trail.Color = ColorSequence.new(Color3.new(255/255,0,0),Color3.new(255/255,120/255,0)) | |
227 | trail.Attachment0 = attachmentr1 | |
228 | trail.Attachment1 = attachmentr2 | |
229 | trail.MaxLength = 15 | |
230 | trail.MinLength = .1 | |
231 | trail.Lifetime = 4.5 | |
232 | trail.Transparency = NumberSequence.new({ | |
233 | NumberSequenceKeypoint.new(0,0.0); | |
234 | NumberSequenceKeypoint.new(.858,.081); | |
235 | NumberSequenceKeypoint.new(.958,.181); | |
236 | NumberSequenceKeypoint.new(1,1.0); | |
237 | }) | |
238 | --[[local bodyForce = Instance.new('BodyForce', rocket) | |
239 | bodyForce.Name = 'Antigravity' | |
240 | bodyForce.force = Vector3.new(0, rocket:GetMass() * workspace.Gravity, 0)]] | |
241 | ||
242 | BaseRocket = rocket | |
243 | end | |
244 | ||
245 | function ToolEquipped() | |
246 | CreateBaseRocket() | |
247 | ||
248 | if GuidedRocket == true then | |
249 | MainTool.Enabled = false | |
250 | end | |
251 | if GuidedRocket == false then | |
252 | MainTool.Enabled = true | |
253 | end | |
254 | ||
255 | end | |
256 | ||
257 | --[[function ControlRocket(main,Control_OBJ,Target_Position) | |
258 | ||
259 | Control_OBJ.TargetOffset = Target_Position | |
260 | ||
261 | end]] | |
262 | ||
263 | function ToolActivated() | |
264 | if ToolEnabled== true and xcharacter and xhumanoid.Health > 0 then | |
265 | local targetPosition = xhumanoid.TargetPoint | |
266 | ToolEnabled = false | |
267 | ||
268 | local SwooshSound = newsound:Clone() | |
269 | SwooshSound.PlaybackSpeed = .5 | |
270 | SwooshSound.SoundId = "http://www.roblox.com/Asset?ID=132456187" | |
271 | SwooshSound.Name = 'Swoosh' | |
272 | SwooshSound.Volume = 1 | |
273 | SwooshSound.Looped = true | |
274 | ||
275 | local BoomSound = newsound:Clone() | |
276 | BoomSound.PlaybackSpeed = .7 | |
277 | BoomSound.Volume = 3 | |
278 | BoomSound.PlayOnRemove = true | |
279 | BoomSound.SoundId = "http://www.roblox.com/Asset?ID=138186576" | |
280 | BoomSound.Name = 'Boom' | |
281 | BoomSound.Looped = false | |
282 | ||
283 | ||
284 | local GRocket = BaseRocket:Clone() | |
285 | ||
286 | local RocketControl = Instance.new("RocketPropulsion",GRocket) | |
287 | RocketControl.CartoonFactor = 1 | |
288 | RocketControl.MaxSpeed = RocketSpeed | |
289 | RocketControl.TargetOffset = targetPosition | |
290 | RocketControl.ThrustD = 50000 | |
291 | RocketControl.ThrustP = 500 | |
292 | RocketControl.TargetRadius = 5 | |
293 | RocketControl.MaxThrust = 50000 | |
294 | RocketControl.MaxTorque = Vector3.new(4e6, 4e6, 0) | |
295 | ||
296 | local spawnPosition = (handle.CFrame * CFrame.new(0, 0, -4)).p | |
297 | GRocket.CFrame = CFrame.new(spawnPosition, targetPosition) | |
298 | GRocket.Velocity = GRocket.CFrame.lookVector * RocketSpeed | |
299 | ||
300 | SwooshSound.Parent = GRocket | |
301 | BoomSound.Parent = GRocket | |
302 | debris:AddItem(GRocket,20) | |
303 | GRocket.Parent = workspace | |
304 | playercam.CameraSubject = GRocket | |
305 | RocketControl:Fire() | |
306 | ||
307 | SwooshSound.Playing = false | |
308 | wait(.15) | |
309 | wait(.15) | |
310 | SwooshSound:Play() | |
311 | ||
312 | ||
313 | GRocket.Touched:connect(function(part) | |
314 | if part and GRocket then | |
315 | if part.Parent then | |
316 | if part.Parent and part.Parent.Name ~= xcharacter.Name then | |
317 | local Explosion = Instance.new("Explosion",workspace) | |
318 | Explosion.Position = GRocket.Position | |
319 | Explosion.BlastPressure = 100000 | |
320 | Explosion.BlastRadius = 14 | |
321 | Explosion.ExplosionType = Enum.ExplosionType.CratersAndDebris | |
322 | GuidedRocket = false | |
323 | playercam.CameraSubject = xhumanoid | |
324 | GRocket:Destroy() | |
325 | end | |
326 | end | |
327 | end | |
328 | end) | |
329 | ||
330 | GuidedRocket = true | |
331 | ||
332 | playermouse.Move:Connect(function() | |
333 | if GuidedRocket == true then | |
334 | playermouse.TargetFilter = GRocket | |
335 | RocketControl.TargetOffset = Vector3.new(playermouse.Hit.X,playermouse.Hit.Y,playermouse.Hit.Z) | |
336 | end | |
337 | end) | |
338 | ||
339 | if GRocket.Parent ~= nil and GuidedRocket==true then | |
340 | print('Controlling the rocket') | |
341 | end | |
342 | repeat wait(1) until GRocket.Parent == nil | |
343 | GuidedRocket = false | |
344 | playermouse.TargetFilter = nil | |
345 | playercam.CameraSubject = xhumanoid | |
346 | GuidedRocket = false | |
347 | wait(3) | |
348 | GuidedRocket = false | |
349 | ToolEnabled = true | |
350 | end | |
351 | end | |
352 | ||
353 | function PlayerDied() | |
354 | if GuidedRocket == true and playercam.CameraSubject ~= xhumanoid then | |
355 | GuidedRocket = false | |
356 | playercam.CameraSubject = xhumanoid | |
357 | ToolEnabled = false | |
358 | MainTool.Enabled = false | |
359 | end | |
360 | if playercam.CameraSubject ~= xhumanoid then | |
361 | ToolEnabled = false | |
362 | MainTool.Enabled = false | |
363 | playercam.CameraSubject = xhumanoid | |
364 | GuidedRocket = false | |
365 | end | |
366 | end | |
367 | function ToolUnequipped() | |
368 | MainTool.Enabled = false | |
369 | end | |
370 | ||
371 | MainTool.Equipped:Connect(ToolEquipped) | |
372 | MainTool.Unequipped:Connect(ToolUnequipped) | |
373 | MainTool.Activated:Connect(ToolActivated) | |
374 | xhumanoid.Died:Connect(PlayerDied) |