LelXD

Rocket Launcher

Feb 15th, 2016
6,709
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.33 KB | None | 1 0
  1. --Created with ttyyuu12345's compiler
  2. --Errors: TouchTransmitter,LocalScript,ModuleScript
  3. Create = function(itemClass,tabl)
  4. local item = Instance.new(itemClass)
  5. for i,v in pairs(tabl) do
  6. local a,b = ypcall(function() return item[i] end)
  7. if a then
  8. item[i] = tabl[i]
  9. end
  10. end
  11. return item
  12. end
  13. function runDummyScript(f,scri)
  14. local oldenv = getfenv(f)
  15. local newenv = setmetatable({}, {
  16. __index = function(_, k)
  17. if k:lower() == 'script' then
  18. return scri
  19. else
  20. return oldenv[k]
  21. end
  22. end
  23. })
  24. setfenv(f, newenv)
  25. ypcall(function() f() end)
  26. end
  27. cors = {}
  28. mas = Instance.new("Model",game:GetService("Lighting"))
  29. mas.Name = "CompiledModel"
  30. o1 = Create("Tool",{
  31. ["Name"] = "RocketLauncher",
  32. ["Parent"] = mas,
  33. ["TextureId"] = "http://www.roblox.com/asset/?id=90021376",
  34. ["GripForward"] = Vector3.new(1, -0, -0),
  35. ["GripPos"] = Vector3.new(0.699999988, 0, -0.5),
  36. ["GripRight"] = Vector3.new(0, -1, 0),
  37. ["GripUp"] = Vector3.new(0, 0, 1),
  38. ["CanBeDropped"] = false,
  39. })
  40. o2 = Create("Part",{
  41. ["Name"] = "Handle",
  42. ["Parent"] = o1,
  43. ["Rotation"] = Vector3.new(-89.9963913, 0, -0),
  44. ["CFrame"] = CFrame.new(0, 0, 0, 1, 0, 0, 0, 6.30170107e-005, 1.00000024, 0, -1.00000024, 6.30170107e-005),
  45. ["CanCollide"] = false,
  46. ["FormFactor"] = Enum.FormFactor.Custom,
  47. ["Size"] = Vector3.new(4.92000628, 0.740000546, 0.839999795),
  48. ["BottomSurface"] = Enum.SurfaceType.Smooth,
  49. ["TopSurface"] = Enum.SurfaceType.Smooth,
  50. })
  51. o3 = Create("SpecialMesh",{
  52. ["Parent"] = o2,
  53. ["MeshId"] = "rbxasset://fonts/rocketlauncher.mesh",
  54. ["Scale"] = Vector3.new(0.75, 0.75, 0.75),
  55. ["TextureId"] = "rbxasset://textures/rocketlaunchertex.png",
  56. ["MeshType"] = Enum.MeshType.FileMesh,
  57. })
  58. o5 = Create("Script",{
  59. ["Parent"] = o1,
  60. })
  61. table.insert(cors,coroutine.create(function()
  62. wait()
  63. runDummyScript(function()
  64. local tool = script.Parent
  65. local canFire = true
  66. local gunWeld
  67.  
  68. -----------------
  69. --| Constants |--
  70. -----------------
  71.  
  72. local GRAVITY_ACCELERATION = 196.2
  73.  
  74. local RELOAD_TIME = tool.Configurations.ReloadTime.Value -- Seconds until tool can be used again
  75. local ROCKET_SPEED = tool.Configurations.RocketSpeed.Value -- Speed of the projectile
  76.  
  77. local MISSILE_MESH_ID = 'http://www.roblox.com/asset/?id=2251534'
  78. local MISSILE_MESH_SCALE = Vector3.new(0.35, 0.35, 0.25)
  79. local ROCKET_PART_SIZE = Vector3.new(1.2, 1.2, 3.27)
  80.  
  81. local RocketScript = script:WaitForChild('Rocket')
  82. local SwooshSound = script:WaitForChild('Swoosh')
  83. local BoomSound = script:WaitForChild('Boom')
  84.  
  85. local attackCooldown = tool.Configurations.AttackCooldown.Value
  86. local damage = tool.Configurations.Damage.Value
  87. local reloadTime = tool.Configurations.ReloadTime.Value
  88.  
  89. local function createEvent(eventName)
  90. local event = game.ReplicatedStorage:FindFirstChild(eventName)
  91. if not event then
  92. event = Instance.new("RemoteEvent", game.ReplicatedStorage)
  93. event.Name = eventName
  94. end
  95. return event
  96. end
  97.  
  98. local updateEvent = createEvent("ROBLOX_RocketUpdateEvent")
  99. local equipEvent = createEvent("ROBLOX_RocketEquipEvent")
  100. local unequipEvent = createEvent("ROBLOX_RocketUnequipEvent")
  101. local fireEvent = createEvent("ROBLOX_RocketFireEvent")
  102.  
  103. updateEvent.OnServerEvent:connect(function(player, neckC0, rshoulderC0)
  104. local character = player.Character
  105. character.Torso.Neck.C0 = neckC0
  106. character.Torso:FindFirstChild("Right Shoulder").C0 = rshoulderC0
  107. gunWeld = character:FindFirstChild("Right Arm"):WaitForChild("RightGrip")
  108. end)
  109.  
  110. equipEvent.OnServerEvent:connect(function(player)
  111. player.Character.Humanoid.AutoRotate = false
  112. end)
  113.  
  114. unequipEvent.OnServerEvent:connect(function(player)
  115. player.Character.Humanoid.AutoRotate = true
  116. end)
  117.  
  118. --NOTE: We create the rocket once and then clone it when the player fires
  119. local Rocket = Instance.new('Part') do
  120. -- Set up the rocket part
  121. Rocket.Name = 'Rocket'
  122. Rocket.FormFactor = Enum.FormFactor.Custom --NOTE: This must be done before changing Size
  123. Rocket.Size = ROCKET_PART_SIZE
  124. Rocket.CanCollide = false
  125.  
  126. -- Add the mesh
  127. local mesh = Instance.new('SpecialMesh', Rocket)
  128. mesh.MeshId = MISSILE_MESH_ID
  129. mesh.Scale = MISSILE_MESH_SCALE
  130.  
  131. -- Add fire
  132. local fire = Instance.new('Fire', Rocket)
  133. fire.Heat = 5
  134. fire.Size = 2
  135.  
  136. -- Add a force to counteract gravity
  137. local bodyForce = Instance.new('BodyForce', Rocket)
  138. bodyForce.Name = 'Antigravity'
  139. bodyForce.force = Vector3.new(0, Rocket:GetMass() * GRAVITY_ACCELERATION, 0)
  140.  
  141. -- Clone the sounds and set Boom to PlayOnRemove
  142. local swooshSoundClone = SwooshSound:Clone()
  143. swooshSoundClone.Parent = Rocket
  144. local boomSoundClone = BoomSound:Clone()
  145. boomSoundClone.PlayOnRemove = true
  146. boomSoundClone.Parent = Rocket
  147.  
  148. -- Finally, clone the rocket script and enable it
  149. -- local rocketScriptClone = RocketScript:Clone()
  150. -- rocketScriptClone.Parent = Rocket
  151. -- rocketScriptClone.Disabled = false
  152. end
  153.  
  154.  
  155. fireEvent.OnServerEvent:connect(function(player, target)
  156. if canFire and player.Character == tool.Parent then
  157. canFire = false
  158.  
  159. -- Create a clone of Rocket and set its color
  160. local rocketClone = Rocket:Clone()
  161. --game.Debris:AddItem(rocketClone, 30)
  162. rocketClone.BrickColor = player.TeamColor
  163. rocketClone.Touched:connect(function(hit)
  164. if hit and hit.Parent and hit.Parent ~= player.Character and hit.Parent ~= tool then
  165. local explosion = Instance.new("Explosion", game.Workspace)
  166. explosion.Position = rocketClone.Position
  167. rocketClone:Destroy()
  168. end
  169. end)
  170.  
  171. spawn(function()
  172. wait(30)
  173. if rocketClone then rocketClone:Destroy() end
  174. end)
  175.  
  176. -- Position the rocket clone and launch!
  177. local spawnPosition = (tool.Handle.CFrame * CFrame.new(2, 0, 0)).p
  178. rocketClone.CFrame = CFrame.new(spawnPosition, target) --NOTE: This must be done before assigning Parent
  179. rocketClone.Velocity = rocketClone.CFrame.lookVector * ROCKET_SPEED --NOTE: This should be done before assigning Parent
  180. rocketClone.Parent = game.Workspace
  181.  
  182. -- Attach creator tags to the rocket early on
  183. local creatorTag = Instance.new('ObjectValue', rocketClone)
  184. creatorTag.Value = player
  185. creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats
  186. local iconTag = Instance.new('StringValue', creatorTag)
  187. iconTag.Value = tool.TextureId
  188. iconTag.Name = 'icon'
  189.  
  190. delay(attackCooldown, function()
  191. canFire = true
  192. end)
  193. end
  194. end)
  195. end,o5)
  196. end))
  197. o6 = Create("Sound",{
  198. ["Name"] = "Boom",
  199. ["Parent"] = o5,
  200. ["SoundId"] = "rbxasset://sounds/collide.wav",
  201. ["Volume"] = 1,
  202. })
  203. o7 = Create("Sound",{
  204. ["Name"] = "Swoosh",
  205. ["Parent"] = o5,
  206. ["SoundId"] = "rbxasset://sounds/Rocket whoosh 01.wav",
  207. ["Volume"] = 0.69999998807907,
  208. ["Looped"] = true,
  209. })
  210. o8 = Create("Script",{
  211. ["Name"] = "Rocket",
  212. ["Parent"] = o5,
  213. })
  214. table.insert(cors,coroutine.create(function()
  215. wait()
  216. runDummyScript(function()
  217. -----------------
  218. --| Constants |--
  219. -----------------
  220. local BLAST_RADIUS = script.Parent.Parent.Configurations.BlastRadius.Value -- Blast radius of the explosion
  221. local BLAST_DAMAGE = script.Parent.Parent.Configurations.Damage.Value -- Amount of damage done to players
  222. local BLAST_FORCE = script.Parent.Parent.Configurations.BlastForce.Value -- Amount of force applied to parts
  223.  
  224. local IGNORE_LIST = {rocket = 1, handle = 1, effect = 1, water = 1} -- Rocket will fly through things named these
  225. --NOTE: Keys must be lowercase, values must evaluate to true
  226.  
  227. -----------------
  228. --| Variables |--
  229. -----------------
  230.  
  231. local DebrisService = game:GetService('Debris')
  232. local PlayersService = game:GetService('Players')
  233.  
  234. local Rocket = script.Parent
  235.  
  236. local CreatorTag = Rocket:WaitForChild('creator')
  237. local SwooshSound = Rocket:WaitForChild('Swoosh')
  238.  
  239. -----------------
  240. --| Functions |--
  241. -----------------
  242.  
  243. -- Removes any old creator tags and applies a new one to the target
  244. local function ApplyTags(target)
  245. while target:FindFirstChild('creator') do
  246. target.creator:Destroy()
  247. end
  248.  
  249. local creatorTagClone = CreatorTag:Clone()
  250. DebrisService:AddItem(creatorTagClone, 1.5)
  251. creatorTagClone.Parent = target
  252. end
  253.  
  254. -- Returns the ancestor that contains a Humanoid, if it exists
  255. local function FindCharacterAncestor(subject)
  256. if subject and subject ~= game.Workspace then
  257. local humanoid = subject:FindFirstChild('Humanoid')
  258. if humanoid then
  259. return subject, humanoid
  260. else
  261. return FindCharacterAncestor(subject.Parent)
  262. end
  263. end
  264. return nil
  265. end
  266.  
  267. -- Customized explosive effect that doesn't affect teammates and only breaks joints on dead parts
  268. local function OnExplosionHit(hitPart, hitDistance, blastCenter)
  269. if hitPart and hitDistance then
  270. local character, humanoid = FindCharacterAncestor(hitPart.Parent)
  271.  
  272. if character then
  273. local myPlayer = CreatorTag.Value
  274. if myPlayer and not myPlayer.Neutral then -- Ignore friendlies caught in the blast
  275. local player = PlayersService:GetPlayerFromCharacter(character)
  276. if player and player ~= myPlayer and player.TeamColor == Rocket.BrickColor then
  277. return
  278. end
  279. end
  280. end
  281.  
  282. if humanoid and humanoid.Health > 0 then -- Humanoids are tagged and damaged
  283. if hitPart.Name == 'Torso' then
  284. ApplyTags(humanoid)
  285. humanoid:TakeDamage(BLAST_DAMAGE)
  286. end
  287. else -- Loose parts and dead parts are blasted
  288. if hitPart.Name ~= 'Handle' then
  289. hitPart:BreakJoints()
  290. local blastForce = Instance.new('BodyForce', hitPart) --NOTE: We will multiply by mass so bigger parts get blasted more
  291. blastForce.force = (hitPart.Position - blastCenter).unit * BLAST_FORCE * hitPart:GetMass()
  292. DebrisService:AddItem(blastForce, 0.1)
  293. end
  294. end
  295. end
  296. end
  297.  
  298. local function OnTouched(otherPart)
  299. if Rocket and otherPart then
  300. -- Fly through anything in the ignore list
  301. if IGNORE_LIST[string.lower(otherPart.Name)] then
  302. return
  303. end
  304.  
  305. local myPlayer = CreatorTag.Value
  306. if myPlayer then
  307. -- Fly through the creator
  308. if myPlayer.Character and myPlayer.Character:IsAncestorOf(otherPart) then
  309. return
  310. end
  311.  
  312. -- Fly through friendlies
  313. if not myPlayer.Neutral then
  314. local character = FindCharacterAncestor(otherPart.Parent)
  315. local player = PlayersService:GetPlayerFromCharacter(character)
  316. if player and player ~= myPlayer and player.TeamColor == Rocket.BrickColor then
  317. return
  318. end
  319. end
  320. end
  321.  
  322. -- Fly through terrain water
  323. if otherPart == game.Workspace.Terrain then
  324. --NOTE: If the rocket is large, then the simplifications made here will cause it to fly through terrain in some cases
  325. local frontOfRocket = Rocket.Position + (Rocket.CFrame.lookVector * (Rocket.Size.Z / 2))
  326. local cellLocation = game.Workspace.Terrain:WorldToCellPreferSolid(frontOfRocket)
  327. local cellMaterial = game.Workspace.Terrain:GetCell(cellLocation.X, cellLocation.Y, cellLocation.Z)
  328. if cellMaterial == Enum.CellMaterial.Water or cellMaterial == Enum.CellMaterial.Empty then
  329. return
  330. end
  331. end
  332.  
  333. -- Create the explosion
  334. local explosion = Instance.new('Explosion')
  335. explosion.BlastPressure = 0 -- Completely safe explosion
  336. explosion.BlastRadius = BLAST_RADIUS
  337. explosion.ExplosionType = Enum.ExplosionType.NoCraters
  338. explosion.Position = Rocket.Position
  339. explosion.Parent = game.Workspace
  340.  
  341. -- Connect custom logic for the explosion
  342. explosion.Hit:connect(function(hitPart, hitDistance) OnExplosionHit(hitPart, hitDistance, explosion.Position) end)
  343.  
  344. -- Move this script and the creator tag (so our custom logic can execute), then destroy the rocket
  345. script.Parent = explosion
  346. CreatorTag.Parent = script
  347. Rocket:Destroy()
  348. end
  349. end
  350.  
  351. --------------------
  352. --| Script Logic |--
  353. --------------------
  354.  
  355. SwooshSound:Play()
  356.  
  357. Rocket.Touched:connect(OnTouched)
  358.  
  359. end,o8)
  360. end))
  361. o10 = Create("Configuration",{
  362. ["Name"] = "Configurations",
  363. ["Parent"] = o1,
  364. })
  365. o11 = Create("NumberValue",{
  366. ["Name"] = "AttackCooldown",
  367. ["Parent"] = o10,
  368. ["Value"] = 3,
  369. })
  370. o12 = Create("IntValue",{
  371. ["Name"] = "Damage",
  372. ["Parent"] = o10,
  373. ["Value"] = 60,
  374. })
  375. o13 = Create("NumberValue",{
  376. ["Name"] = "ReloadTime",
  377. ["Parent"] = o10,
  378. ["Value"] = 1,
  379. })
  380. o14 = Create("IntValue",{
  381. ["Name"] = "BlastForce",
  382. ["Parent"] = o10,
  383. ["Value"] = 1000,
  384. })
  385. o15 = Create("IntValue",{
  386. ["Name"] = "BlastRadius",
  387. ["Parent"] = o10,
  388. ["Value"] = 8,
  389. })
  390. o16 = Create("IntValue",{
  391. ["Name"] = "RocketSpeed",
  392. ["Parent"] = o10,
  393. ["Value"] = 60,
  394. })
  395. mas.Parent = workspace
  396. mas:MakeJoints()
  397. local mas1 = mas:GetChildren()
  398. for i=1,#mas1 do
  399. mas1[i].Parent = script
  400. ypcall(function() mas1[i]:MakeJoints() end)
  401. end
  402. mas:Destroy()
  403. for i=1,#cors do
  404. coroutine.resume(cors[i])
  405. end
Advertisement
Add Comment
Please, Sign In to add comment