Advertisement
UhhLegoboy

Metroid Arm Cannon

Apr 13th, 2017
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.85 KB | None | 0 0
  1. local runDummyScript = function(f,scri)
  2. local oldenv = getfenv(f)
  3. local newenv = setmetatable({}, {
  4. __index = function(_, k)
  5. if k:lower() == 'script' then
  6. return scri
  7. else
  8. return oldenv[k]
  9. end
  10. end
  11. })
  12. setfenv(f, newenv)
  13. ypcall(function() f() end)
  14. end
  15. cors = {}
  16. mas = Instance.new("Model",game:GetService("Lighting"))
  17. mas.Name = "CompiledModel"
  18. o1 = Instance.new("Tool")
  19. o2 = Instance.new("Part")
  20. o4 = Instance.new("Decal")
  21. o5 = Instance.new("Decal")
  22. o6 = Instance.new("Sound")
  23. o7 = Instance.new("Sound")
  24. o8 = Instance.new("PointLight")
  25. o9 = Instance.new("LocalScript")
  26. o10 = Instance.new("LocalScript")
  27. o11 = Instance.new("Sound")
  28. o1.Name = "Arm Cannon"
  29. o1.Parent = mas
  30. o1.GripForward = Vector3.new(1, -0, -0)
  31. o1.GripRight = Vector3.new(0, 0, 1)
  32. o1.ToolTip = "Based off of Metroid"
  33. o2.Name = "Handle"
  34. o2.Parent = o1
  35. o2.Material = Enum.Material.SmoothPlastic
  36. o2.BrickColor = BrickColor.new("Shamrock")
  37. o2.Position = Vector3.new(1.5150001, 5.50499964, -0.914999843)
  38. o2.Rotation = Vector3.new(-0, -90, 0)
  39. o2.Size = Vector3.new(1.82999992, 1.13000011, 1.08999991)
  40. o2.CFrame = CFrame.new(1.5150001, 5.50499964, -0.914999843, 0, 0, -1.00000024, 0, 1, 0, 1.00000024, 0, 0)
  41. o2.BackSurface = Enum.SurfaceType.Weld
  42. o2.BottomSurface = Enum.SurfaceType.Weld
  43. o2.FrontSurface = Enum.SurfaceType.Weld
  44. o2.LeftSurface = Enum.SurfaceType.Weld
  45. o2.RightSurface = Enum.SurfaceType.Weld
  46. o2.TopSurface = Enum.SurfaceType.Weld
  47. o2.Color = Color3.new(0.356863, 0.603922, 0.298039)
  48. o2.Position = Vector3.new(1.5150001, 5.50499964, -0.914999843)
  49. o4.Parent = o2
  50. o4.Texture = "http://www.roblox.com/asset/?id=22285987"
  51. o4.Face = Enum.NormalId.Left
  52. o5.Parent = o2
  53. o5.Texture = "http://www.roblox.com/asset/?id=22285987"
  54. o5.Face = Enum.NormalId.Right
  55. o6.Name = "Fire"
  56. o6.Parent = o2
  57. o6.SoundId = "http://www.roblox.com/asset?id=130113322"
  58. o7.Name = "Reload"
  59. o7.Parent = o2
  60. o7.SoundId = "http://www.roblox.com/asset?id=130113370"
  61. o8.Parent = o2
  62. o8.Color = Color3.new(1, 1, 0)
  63. o8.Range = 6
  64. o9.Name = "MouseIcon"
  65. o9.Parent = o1
  66. table.insert(cors,coroutine.create(function()
  67. wait()
  68. runDummyScript(function()
  69. local MOUSE_ICON = 'rbxasset://textures/GunCursor.png'
  70. local RELOADING_ICON = 'rbxasset://textures/GunWaitCursor.png'
  71.  
  72. local Tool = script.Parent
  73.  
  74. local Mouse = nil
  75.  
  76. local function UpdateIcon()
  77.     if Mouse then
  78.         Mouse.Icon = Tool.Enabled and MOUSE_ICON or RELOADING_ICON
  79.     end
  80. end
  81.  
  82. local function OnEquipped(mouse)
  83.     Mouse = mouse
  84.     UpdateIcon()
  85. end
  86.  
  87. local function OnChanged(property)
  88.     if property == 'Enabled' then
  89.         UpdateIcon()
  90.     end
  91. end
  92.  
  93. Tool.Equipped:connect(OnEquipped)
  94. Tool.Changed:connect(OnChanged)
  95.  
  96. end,o9)
  97. end))
  98. o10.Name = "ToolScript"
  99. o10.Parent = o1
  100. table.insert(cors,coroutine.create(function()
  101. wait()
  102. runDummyScript(function()
  103. -----------------
  104. --| Constants |--
  105. -----------------
  106.  
  107. local SHOT_SPEED = 100
  108. local SHOT_TIME = 1
  109.  
  110. local NOZZLE_OFFSET = Vector3.new(0, 0.4, -1.1)
  111.  
  112. -----------------
  113. --| Variables |--
  114. -----------------
  115.  
  116. local PlayersService = Game:GetService('Players')
  117. local DebrisService = Game:GetService('Debris')
  118.  
  119. local Tool = script.Parent
  120. local Handle = Tool:WaitForChild('Handle')
  121.  
  122. local FireSound = Handle:WaitForChild('Fire')
  123. local ReloadSound = Handle:WaitForChild('Reload')
  124. local HitFadeSound = script:WaitForChild('HitFade')
  125.  
  126. local PointLight = Handle:WaitForChild('PointLight')
  127.  
  128. local Character = nil
  129. local Humanoid = nil
  130. local Player = nil
  131.  
  132. local BaseShot = nil
  133.  
  134. -----------------
  135. --| Functions |--
  136. -----------------
  137.  
  138. -- Returns a character ancestor and its Humanoid, or nil
  139. local function FindCharacterAncestor(subject)
  140.     if subject and subject ~= Workspace then
  141.         local humanoid = subject:FindFirstChild('Humanoid')
  142.         if humanoid then
  143.             return subject, humanoid
  144.         else
  145.             return FindCharacterAncestor(subject.Parent)
  146.         end
  147.     end
  148.     return nil
  149. end
  150.  
  151. -- Removes any old creator tags and applies new ones to the specified target
  152. local function ApplyTags(target)
  153.     while target:FindFirstChild('creator') do
  154.         target.creator:Destroy()
  155.     end
  156.  
  157.     local creatorTag = Instance.new('ObjectValue')
  158.     creatorTag.Value = Player
  159.     creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats
  160.  
  161.     local iconTag = Instance.new('StringValue')
  162.     iconTag.Value = Tool.TextureId
  163.     iconTag.Name = 'icon'
  164.  
  165.     iconTag.Parent = creatorTag
  166.     creatorTag.Parent = target
  167.     DebrisService:AddItem(creatorTag, 4)
  168. end
  169.  
  170. -- Returns all objects under instance with Transparency
  171. local function GetTransparentsRecursive(instance, partsTable)
  172.     local partsTable = partsTable or {}
  173.     for _, child in pairs(instance:GetChildren()) do
  174.         if child:IsA('BasePart') or child:IsA('Decal') then
  175.             table.insert(partsTable, child)
  176.         end
  177.         GetTransparentsRecursive(child, partsTable)
  178.     end
  179.     return partsTable
  180. end
  181.  
  182. local function SelectionBoxify(instance)
  183.     local selectionBox = Instance.new('SelectionBox')
  184.     selectionBox.Adornee = instance
  185.     selectionBox.Color = BrickColor.new('New Yeller')
  186.     selectionBox.Parent = instance
  187.     return selectionBox
  188. end
  189.  
  190. local function Light(instance)
  191.     local light = PointLight:Clone()
  192.     light.Range = light.Range + 2
  193.     light.Parent = instance
  194. end
  195.  
  196. local function FadeOutObjects(objectsWithTransparency, fadeIncrement)
  197.     repeat
  198.         local lastObject = nil
  199.         for _, object in pairs(objectsWithTransparency) do
  200.             object.Transparency = object.Transparency + fadeIncrement
  201.             lastObject = object
  202.         end
  203.         wait()
  204.     until lastObject.Transparency >= 1 or not lastObject
  205. end
  206.  
  207. local function Dematerialize(character, humanoid, firstPart)
  208.     humanoid.WalkSpeed = 0
  209.  
  210.     local parts = {}
  211.     for _, child in pairs(character:GetChildren()) do
  212.         if child:IsA('BasePart') then
  213.             child.Anchored = true
  214.             table.insert(parts, child)
  215.         elseif child:IsA('LocalScript') or child:IsA('Script') then
  216.             child:Destroy()
  217.         end
  218.     end
  219.  
  220.     local selectionBoxes = {}
  221.  
  222.     local firstSelectionBox = SelectionBoxify(firstPart)
  223.     Light(firstPart)
  224.     wait(0.05)
  225.  
  226.     for _, part in pairs(parts) do
  227.         if part ~= firstPart then
  228.             table.insert(selectionBoxes, SelectionBoxify(part))
  229.             Light(part)
  230.         end
  231.     end
  232.  
  233.     local objectsWithTransparency = GetTransparentsRecursive(character)
  234.     FadeOutObjects(objectsWithTransparency, 0.1)
  235.  
  236.     wait(0.5)
  237.  
  238.     humanoid.Health = 0
  239.     DebrisService:AddItem(character, 2)
  240.  
  241.     local fadeIncrement = 0.05
  242.     Delay(0.2, function()
  243.         FadeOutObjects({firstSelectionBox}, fadeIncrement)
  244.         if character then
  245.             character:Destroy()
  246.         end
  247.     end)
  248.     FadeOutObjects(selectionBoxes, fadeIncrement)
  249. end
  250.  
  251. local function OnTouched(shot, otherPart)
  252.     local character, humanoid = FindCharacterAncestor(otherPart)
  253.     if character and humanoid and character ~= Character then
  254.         ApplyTags(humanoid)
  255.         if shot then
  256.             local hitFadeSound = shot:FindFirstChild(HitFadeSound.Name)
  257.             if hitFadeSound then
  258.                 hitFadeSound.Parent = humanoid.Torso
  259.                 hitFadeSound:Play()
  260.             end
  261.             shot:Destroy()
  262.         end
  263.         Dematerialize(character, humanoid, otherPart)
  264.     end
  265. end
  266.  
  267. local function OnEquipped()
  268.     Character = Tool.Parent
  269.     Humanoid = Character:WaitForChild('Humanoid')
  270.     Player = PlayersService:GetPlayerFromCharacter(Character)
  271. end
  272.  
  273. local function OnActivated()
  274.     if Tool.Enabled and Humanoid.Health > 0 then
  275.         Tool.Enabled = false
  276.  
  277.         FireSound:Play()
  278.  
  279.         local handleCFrame = Handle.CFrame
  280.         local firingPoint = handleCFrame.p + handleCFrame:vectorToWorldSpace(NOZZLE_OFFSET)
  281.         local shotCFrame = CFrame.new(firingPoint, Humanoid.TargetPoint)
  282.  
  283.         local laserShotClone = BaseShot:Clone()
  284.         laserShotClone.CFrame = shotCFrame + (shotCFrame.lookVector * (BaseShot.Size.Z / 2))
  285.         local bodyVelocity = Instance.new('BodyVelocity')
  286.         bodyVelocity.velocity = shotCFrame.lookVector * SHOT_SPEED
  287.         bodyVelocity.Parent = laserShotClone
  288.         laserShotClone.Touched:connect(function(otherPart)
  289.             OnTouched(laserShotClone, otherPart)
  290.         end)
  291.         DebrisService:AddItem(laserShotClone, SHOT_TIME)
  292.         laserShotClone.Parent = Tool
  293.  
  294.         wait(0.6) -- FireSound length
  295.  
  296.         ReloadSound:Play()
  297.         wait(0.75) -- ReloadSound length
  298.  
  299.         Tool.Enabled = true
  300.     end
  301. end
  302.  
  303. local function OnUnequipped()
  304.    
  305. end
  306.  
  307. --------------------
  308. --| Script Logic |--
  309. --------------------
  310.  
  311. BaseShot = Instance.new('Part')
  312. BaseShot.Name = 'Effect'
  313. BaseShot.FormFactor = Enum.FormFactor.Custom
  314. BaseShot.Size = Vector3.new(0.2, 0.2, 3)
  315. BaseShot.CanCollide = false
  316. BaseShot.BrickColor = BrickColor.new('Toothpaste')
  317. SelectionBoxify(BaseShot)
  318. Light(BaseShot)
  319. HitFadeSound:Clone().Parent = BaseShot
  320.  
  321. Tool.Equipped:connect(OnEquipped)
  322. Tool.Unequipped:connect(OnUnequipped)
  323. Tool.Activated:connect(OnActivated)
  324.  
  325. end,o10)
  326. end))
  327. o11.Name = "HitFade"
  328. o11.Parent = o10
  329. o11.SoundId = "http://www.roblox.com/asset?id=130113415"
  330. mas.Parent = workspace
  331. mas:MakeJoints()
  332. local mas1 = mas:GetChildren()
  333. for i=1,#mas1 do
  334.     mas1[i].Parent = game:GetService("Players").LocalPlayer.Backpack
  335.     ypcall(function() mas1[i]:MakeJoints() end)
  336. end
  337. mas:Destroy()
  338. for i=1,#cors do
  339. coroutine.resume(cors[i])
  340. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement