· 6 years ago · May 25, 2019, 08:36 PM
1if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
2local Player,game,owner = owner,game
3local RealPlayer = Player
4do
5 print("FE Compatibility code by Mokiros")
6 local rp = RealPlayer
7 script.Parent = rp.Character
8
9 --RemoteEvent for communicating
10 local Event = Instance.new("RemoteEvent")
11 Event.Name = "UserInput_Event"
12
13 --Fake event to make stuff like Mouse.KeyDown work
14 local function fakeEvent()
15 local t = {_fakeEvent=true,Functions={},Connect=function(self,f)table.insert(self.Functions,f) end}
16 t.connect = t.Connect
17 return t
18 end
19
20 --Creating fake input objects with fake variables
21 local m = {Target=nil,Hit=CFrame.new(),KeyUp=fakeEvent(),KeyDown=fakeEvent(),Button1Up=fakeEvent(),Button1Down=fakeEvent()}
22 local UIS = {InputBegan=fakeEvent(),InputEnded=fakeEvent()}
23 local CAS = {Actions={},BindAction=function(self,name,fun,touch,...)
24 CAS.Actions[name] = fun and {Name=name,Function=fun,Keys={...}} or nil
25 end}
26 --Merged 2 functions into one by checking amount of arguments
27 CAS.UnbindAction = CAS.BindAction
28
29 --This function will trigger the events that have been :Connect()'ed
30 local function te(self,ev,...)
31 local t = m[ev]
32 if t and t._fakeEvent then
33 for _,f in pairs(t.Functions) do
34 f(...)
35 end
36 end
37 end
38 m.TrigEvent = te
39 UIS.TrigEvent = te
40
41 Event.OnServerEvent:Connect(function(plr,io)
42 if plr~=rp then return end
43 m.Target = io.Target
44 m.Hit = io.Hit
45 if not io.isMouse then
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 Mouse = Player:GetMouse()
66 local UIS = game:GetService("UserInputService")
67 local input = function(io,a)
68 if a then return end
69 --Since InputObject is a client-side instance, we create and pass table instead
70 Event:FireServer({KeyCode=io.KeyCode,UserInputType=io.UserInputType,UserInputState=io.UserInputState,Hit=Mouse.Hit,Target=Mouse.Target})
71 end
72 UIS.InputBegan:Connect(input)
73 UIS.InputEnded:Connect(input)
74
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
85 ----Sandboxed game object that allows the usage of client-side methods and services
86 --Real game object
87 local _rg = game
88
89 --Metatable for fake service
90 local fsmt = {
91 __index = function(self,k)
92 local s = rawget(self,"_RealService")
93 if s then return s[k] end
94 end,
95 __newindex = function(self,k,v)
96 local s = rawget(self,"_RealService")
97 if s then s[k]=v end
98 end,
99 __call = function(self,...)
100 local s = rawget(self,"_RealService")
101 if s then return s(...) end
102 end
103 }
104 local function FakeService(t,RealService)
105 t._RealService = typeof(RealService)=="string" and _rg:GetService(RealService) or RealService
106 return setmetatable(t,fsmt)
107 end
108
109 --Fake game object
110 local g = {
111 GetService = function(self,s)
112 return self[s]
113 end,
114 Players = FakeService({
115 LocalPlayer = FakeService({GetMouse=function(self)return m end},Player)
116 },"Players"),
117 UserInputService = FakeService(UIS,"UserInputService"),
118 ContextActionService = FakeService(CAS,"ContextActionService"),
119 }
120 rawset(g.Players,"localPlayer",g.Players.LocalPlayer)
121 g.service = g.GetService
122
123 g.RunService = FakeService({
124 RenderStepped = _rg:GetService("RunService").Heartbeat,
125 BindToRenderStep = function(self,name,_,fun)
126
127 end,
128 UnbindFromRenderStep = function(self,name)
129 self._btrs[name]:Disconnect()
130 end,
131 },"RunService")
132
133 setmetatable(g,{
134 __index=function(self,s)
135 return _rg:GetService(s) or typeof(_rg[s])=="function"
136 and function(_,...)return _rg[s](_rg,...)end or _rg[s]
137 end,
138 __newindex = fsmt.__newindex,
139 __call = fsmt.__call
140 })
141 --Changing owner to fake player object to support owner:GetMouse()
142 game,owner = g,g.Players.LocalPlayer
143end
144
145--Created with ttyyuu12345's compiler
146--Errors: TouchTransmitter,LocalScript,ModuleScript
147Create = function(itemClass,tabl)
148local item = Instance.new(itemClass)
149for i,v in pairs(tabl) do
150local a,b = ypcall(function() return item[i] end)
151if a then
152item[i] = tabl[i]
153end
154end
155return item
156end
157function runDummyScript(f,scri)
158local oldenv = getfenv(f)
159local newenv = setmetatable({}, {
160__index = function(_, k)
161if k:lower() == 'script' then
162return scri
163else
164return oldenv[k]
165end
166end
167})
168setfenv(f, newenv)
169ypcall(function() f() end)
170end
171cors = {}
172mas = Instance.new("Model",game:GetService("Lighting"))
173mas.Name = "CompiledModel"
174o1 = Create("Tool",{
175["Name"] = "RocketLauncher",
176["Parent"] = mas,
177["TextureId"] = "http://www.roblox.com/asset/?id=90021376",
178["GripForward"] = Vector3.new(1, -0, -0),
179["GripPos"] = Vector3.new(0.699999988, 0, -0.5),
180["GripRight"] = Vector3.new(0, -1, 0),
181["GripUp"] = Vector3.new(0, 0, 1),
182["CanBeDropped"] = false,
183})
184o2 = Create("Part",{
185["Name"] = "Handle",
186["Parent"] = o1,
187["Rotation"] = Vector3.new(-89.9963913, 0, -0),
188["CFrame"] = CFrame.new(0, 0, 0, 1, 0, 0, 0, 6.30170107e-005, 1.00000024, 0, -1.00000024, 6.30170107e-005),
189["CanCollide"] = false,
190["FormFactor"] = Enum.FormFactor.Custom,
191["Size"] = Vector3.new(4.92000628, 0.740000546, 0.839999795),
192["BottomSurface"] = Enum.SurfaceType.Smooth,
193["TopSurface"] = Enum.SurfaceType.Smooth,
194})
195o3 = Create("SpecialMesh",{
196["Parent"] = o2,
197["MeshId"] = "rbxasset://fonts/rocketlauncher.mesh",
198["Scale"] = Vector3.new(0.75, 0.75, 0.75),
199["TextureId"] = "rbxasset://textures/rocketlaunchertex.png",
200["MeshType"] = Enum.MeshType.FileMesh,
201})
202o5 = Create("Script",{
203["Parent"] = o1,
204})
205table.insert(cors,coroutine.create(function()
206wait()
207runDummyScript(function()
208local tool = script.Parent
209local canFire = true
210local gunWeld
211
212-----------------
213--| Constants |--
214-----------------
215
216local GRAVITY_ACCELERATION = 196.2
217
218local RELOAD_TIME = tool.Configurations.ReloadTime.Value -- Seconds until tool can be used again
219local ROCKET_SPEED = tool.Configurations.RocketSpeed.Value -- Speed of the projectile
220
221local MISSILE_MESH_ID = 'http://www.roblox.com/asset/?id=2251534'
222local MISSILE_MESH_SCALE = Vector3.new(0.35, 0.35, 0.25)
223local ROCKET_PART_SIZE = Vector3.new(1.2, 1.2, 3.27)
224
225local RocketScript = script:WaitForChild('Rocket')
226local SwooshSound = script:WaitForChild('Swoosh')
227local BoomSound = script:WaitForChild('Boom')
228
229local attackCooldown = tool.Configurations.AttackCooldown.Value
230local damage = tool.Configurations.Damage.Value
231local reloadTime = tool.Configurations.ReloadTime.Value
232
233local function createEvent(eventName)
234 local event = game.ReplicatedStorage:FindFirstChild(eventName)
235 if not event then
236 event = Instance.new("RemoteEvent", game.ReplicatedStorage)
237 event.Name = eventName
238 end
239 return event
240end
241
242local updateEvent = createEvent("ROBLOX_RocketUpdateEvent")
243local equipEvent = createEvent("ROBLOX_RocketEquipEvent")
244local unequipEvent = createEvent("ROBLOX_RocketUnequipEvent")
245local fireEvent = createEvent("ROBLOX_RocketFireEvent")
246
247updateEvent.OnServerEvent:connect(function(player, neckC0, rshoulderC0)
248 local character = player.Character
249 character.Torso.Neck.C0 = neckC0
250 character.Torso:FindFirstChild("Right Shoulder").C0 = rshoulderC0
251 gunWeld = character:FindFirstChild("Right Arm"):WaitForChild("RightGrip")
252end)
253
254equipEvent.OnServerEvent:connect(function(player)
255 player.Character.Humanoid.AutoRotate = false
256end)
257
258unequipEvent.OnServerEvent:connect(function(player)
259 player.Character.Humanoid.AutoRotate = true
260end)
261
262--NOTE: We create the rocket once and then clone it when the player fires
263local Rocket = Instance.new('Part') do
264 -- Set up the rocket part
265 Rocket.Name = 'Rocket'
266 Rocket.FormFactor = Enum.FormFactor.Custom --NOTE: This must be done before changing Size
267 Rocket.Size = ROCKET_PART_SIZE
268 Rocket.CanCollide = false
269
270 -- Add the mesh
271 local mesh = Instance.new('SpecialMesh', Rocket)
272 mesh.MeshId = MISSILE_MESH_ID
273 mesh.Scale = MISSILE_MESH_SCALE
274
275 -- Add fire
276 local fire = Instance.new('Fire', Rocket)
277 fire.Heat = 5
278 fire.Size = 2
279
280 -- Add a force to counteract gravity
281 local bodyForce = Instance.new('BodyForce', Rocket)
282 bodyForce.Name = 'Antigravity'
283 bodyForce.force = Vector3.new(0, Rocket:GetMass() * GRAVITY_ACCELERATION, 0)
284
285 -- Clone the sounds and set Boom to PlayOnRemove
286 local swooshSoundClone = SwooshSound:Clone()
287 swooshSoundClone.Parent = Rocket
288 local boomSoundClone = BoomSound:Clone()
289 boomSoundClone.PlayOnRemove = true
290 boomSoundClone.Parent = Rocket
291
292 -- Finally, clone the rocket script and enable it
293-- local rocketScriptClone = RocketScript:Clone()
294-- rocketScriptClone.Parent = Rocket
295-- rocketScriptClone.Disabled = false
296end
297
298
299fireEvent.OnServerEvent:connect(function(player, target)
300 if canFire and player.Character == tool.Parent then
301 canFire = false
302
303 -- Create a clone of Rocket and set its color
304 local rocketClone = Rocket:Clone()
305 --game.Debris:AddItem(rocketClone, 30)
306 rocketClone.BrickColor = player.TeamColor
307 rocketClone.Touched:connect(function(hit)
308 if hit and hit.Parent and hit.Parent ~= player.Character and hit.Parent ~= tool then
309 local explosion = Instance.new("Explosion", game.Workspace)
310 explosion.Position = rocketClone.Position
311 rocketClone:Destroy()
312 end
313 end)
314
315 spawn(function()
316 wait(30)
317 if rocketClone then rocketClone:Destroy() end
318 end)
319
320 -- Position the rocket clone and launch!
321 local spawnPosition = (tool.Handle.CFrame * CFrame.new(2, 0, 0)).p
322 rocketClone.CFrame = CFrame.new(spawnPosition, target) --NOTE: This must be done before assigning Parent
323 rocketClone.Velocity = rocketClone.CFrame.lookVector * ROCKET_SPEED --NOTE: This should be done before assigning Parent
324 rocketClone.Parent = game.Workspace
325
326 -- Attach creator tags to the rocket early on
327 local creatorTag = Instance.new('ObjectValue', rocketClone)
328 creatorTag.Value = player
329 creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats
330 local iconTag = Instance.new('StringValue', creatorTag)
331 iconTag.Value = tool.TextureId
332 iconTag.Name = 'icon'
333
334 delay(attackCooldown, function()
335 canFire = true
336 end)
337 end
338end)
339end,o5)
340end))
341o6 = Create("Sound",{
342["Name"] = "Boom",
343["Parent"] = o5,
344["SoundId"] = "rbxasset://sounds/collide.wav",
345["Volume"] = 1,
346})
347o7 = Create("Sound",{
348["Name"] = "Swoosh",
349["Parent"] = o5,
350["SoundId"] = "rbxasset://sounds/Rocket whoosh 01.wav",
351["Volume"] = 0.69999998807907,
352["Looped"] = true,
353})
354o8 = Create("Script",{
355["Name"] = "Rocket",
356["Parent"] = o5,
357})
358table.insert(cors,coroutine.create(function()
359wait()
360runDummyScript(function()
361-----------------
362--| Constants |--
363-----------------
364local BLAST_RADIUS = script.Parent.Parent.Configurations.BlastRadius.Value -- Blast radius of the explosion
365local BLAST_DAMAGE = script.Parent.Parent.Configurations.Damage.Value -- Amount of damage done to players
366local BLAST_FORCE = script.Parent.Parent.Configurations.BlastForce.Value -- Amount of force applied to parts
367
368local IGNORE_LIST = {rocket = 1, handle = 1, effect = 1, water = 1} -- Rocket will fly through things named these
369--NOTE: Keys must be lowercase, values must evaluate to true
370
371-----------------
372--| Variables |--
373-----------------
374
375local DebrisService = game:GetService('Debris')
376local PlayersService = game:GetService('Players')
377
378local Rocket = script.Parent
379
380local CreatorTag = Rocket:WaitForChild('creator')
381local SwooshSound = Rocket:WaitForChild('Swoosh')
382
383-----------------
384--| Functions |--
385-----------------
386
387-- Removes any old creator tags and applies a new one to the target
388local function ApplyTags(target)
389 while target:FindFirstChild('creator') do
390 target.creator:Destroy()
391 end
392
393 local creatorTagClone = CreatorTag:Clone()
394 DebrisService:AddItem(creatorTagClone, 1.5)
395 creatorTagClone.Parent = target
396end
397
398-- Returns the ancestor that contains a Humanoid, if it exists
399local function FindCharacterAncestor(subject)
400 if subject and subject ~= game.Workspace then
401 local humanoid = subject:FindFirstChild('Humanoid')
402 if humanoid then
403 return subject, humanoid
404 else
405 return FindCharacterAncestor(subject.Parent)
406 end
407 end
408 return nil
409end
410
411-- Customized explosive effect that doesn't affect teammates and only breaks joints on dead parts
412local function OnExplosionHit(hitPart, hitDistance, blastCenter)
413 if hitPart and hitDistance then
414 local character, humanoid = FindCharacterAncestor(hitPart.Parent)
415
416 if character then
417 local myPlayer = CreatorTag.Value
418 if myPlayer and not myPlayer.Neutral then -- Ignore friendlies caught in the blast
419 local player = PlayersService:GetPlayerFromCharacter(character)
420 if player and player ~= myPlayer and player.TeamColor == Rocket.BrickColor then
421 return
422 end
423 end
424 end
425
426 if humanoid and humanoid.Health > 0 then -- Humanoids are tagged and damaged
427 if hitPart.Name == 'Torso' then
428 ApplyTags(humanoid)
429 humanoid:TakeDamage(BLAST_DAMAGE)
430 end
431 else -- Loose parts and dead parts are blasted
432 if hitPart.Name ~= 'Handle' then
433 hitPart:BreakJoints()
434 local blastForce = Instance.new('BodyForce', hitPart) --NOTE: We will multiply by mass so bigger parts get blasted more
435 blastForce.force = (hitPart.Position - blastCenter).unit * BLAST_FORCE * hitPart:GetMass()
436 DebrisService:AddItem(blastForce, 0.1)
437 end
438 end
439 end
440end
441
442local function OnTouched(otherPart)
443 if Rocket and otherPart then
444 -- Fly through anything in the ignore list
445 if IGNORE_LIST[string.lower(otherPart.Name)] then
446 return
447 end
448
449 local myPlayer = CreatorTag.Value
450 if myPlayer then
451 -- Fly through the creator
452 if myPlayer.Character and myPlayer.Character:IsAncestorOf(otherPart) then
453 return
454 end
455
456 -- Fly through friendlies
457 if not myPlayer.Neutral then
458 local character = FindCharacterAncestor(otherPart.Parent)
459 local player = PlayersService:GetPlayerFromCharacter(character)
460 if player and player ~= myPlayer and player.TeamColor == Rocket.BrickColor then
461 return
462 end
463 end
464 end
465
466 -- Fly through terrain water
467 if otherPart == game.Workspace.Terrain then
468 --NOTE: If the rocket is large, then the simplifications made here will cause it to fly through terrain in some cases
469 local frontOfRocket = Rocket.Position + (Rocket.CFrame.lookVector * (Rocket.Size.Z / 2))
470 local cellLocation = game.Workspace.Terrain:WorldToCellPreferSolid(frontOfRocket)
471 local cellMaterial = game.Workspace.Terrain:GetCell(cellLocation.X, cellLocation.Y, cellLocation.Z)
472 if cellMaterial == Enum.CellMaterial.Water or cellMaterial == Enum.CellMaterial.Empty then
473 return
474 end
475 end
476
477 -- Create the explosion
478 local explosion = Instance.new('Explosion')
479 explosion.BlastPressure = 0 -- Completely safe explosion
480 explosion.BlastRadius = BLAST_RADIUS
481 explosion.ExplosionType = Enum.ExplosionType.NoCraters
482 explosion.Position = Rocket.Position
483 explosion.Parent = game.Workspace
484
485 -- Connect custom logic for the explosion
486 explosion.Hit:connect(function(hitPart, hitDistance) OnExplosionHit(hitPart, hitDistance, explosion.Position) end)
487
488 -- Move this script and the creator tag (so our custom logic can execute), then destroy the rocket
489 script.Parent = explosion
490 CreatorTag.Parent = script
491 Rocket:Destroy()
492 end
493end
494
495--------------------
496--| Script Logic |--
497--------------------
498
499SwooshSound:Play()
500
501Rocket.Touched:connect(OnTouched)
502
503end,o8)
504end))
505o10 = Create("Configuration",{
506["Name"] = "Configurations",
507["Parent"] = o1,
508})
509o11 = Create("NumberValue",{
510["Name"] = "AttackCooldown",
511["Parent"] = o10,
512["Value"] = 3,
513})
514o12 = Create("IntValue",{
515["Name"] = "Damage",
516["Parent"] = o10,
517["Value"] = 60,
518})
519o13 = Create("NumberValue",{
520["Name"] = "ReloadTime",
521["Parent"] = o10,
522["Value"] = 1,
523})
524o14 = Create("IntValue",{
525["Name"] = "BlastForce",
526["Parent"] = o10,
527["Value"] = 1000,
528})
529o15 = Create("IntValue",{
530["Name"] = "BlastRadius",
531["Parent"] = o10,
532["Value"] = 8,
533})
534o16 = Create("IntValue",{
535["Name"] = "RocketSpeed",
536["Parent"] = o10,
537["Value"] = 60,
538})
539mas.Parent = workspace
540mas:MakeJoints()
541local mas1 = mas:GetChildren()
542for i=1,#mas1 do
543 mas1[i].Parent = script
544 ypcall(function() mas1[i]:MakeJoints() end)
545end
546mas:Destroy()
547for i=1,#cors do
548coroutine.resume(cors[i])
549end