Advertisement
Godofadmin1337

gun

Jul 17th, 2018
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.26 KB | None | 0 0
  1.  
  2. --Converted with ttyyuu12345's model to script plugin v4
  3. function sandbox(var,func)
  4. local env = getfenv(func)
  5. local newenv = setmetatable({},{
  6. __index = function(self,k)
  7. if k=="script" then
  8. return var
  9. else
  10. return env[k]
  11. end
  12. end,
  13. })
  14. setfenv(func,newenv)
  15. return func
  16. end
  17. cors = {}
  18. mas = Instance.new("Model",game:GetService("Lighting"))
  19. Tool0 = Instance.new("Tool")
  20. Part1 = Instance.new("Part")
  21. LocalScript2 = Instance.new("LocalScript")
  22. SpecialMesh3 = Instance.new("SpecialMesh")
  23. PointLight4 = Instance.new("PointLight")
  24. PointLight5 = Instance.new("PointLight")
  25. SpotLight6 = Instance.new("SpotLight")
  26. Sound7 = Instance.new("Sound")
  27. Part8 = Instance.new("Part")
  28. SpecialMesh9 = Instance.new("SpecialMesh")
  29. Weld10 = Instance.new("Weld")
  30. Script11 = Instance.new("Script")
  31. Tool0.Name = "TommyGun"
  32. Tool0.Parent = mas
  33. Tool0.TextureId = "http://www.roblox.com/asset/?id=116747513"
  34. Tool0.GripForward = Vector3.new(-0.342020124, -0.734681308, -0.585888743)
  35. Tool0.GripPos = Vector3.new(0, -0.600000024, 0.5)
  36. Tool0.GripRight = Vector3.new(0.938404799, -0.234404698, -0.253871709)
  37. Tool0.GripUp = Vector3.new(-0.0491797142, 0.636630058, -0.769599557)
  38. Tool0.ToolTip = "nigger nigger nigger"
  39. Part1.Name = "Handle"
  40. Part1.Parent = Tool0
  41. Part1.Rotation = Vector3.new(90, -65.9399948, 90)
  42. Part1.FormFactor = Enum.FormFactor.Custom
  43. Part1.Size = Vector3.new(0.540003419, 1.26000023, 4.10998917)
  44. Part1.CFrame = CFrame.new(0.612733841, 32.6300011, -45.7190094, 2.7213483e-08, -0.407661706, -0.913133502, 1.21492656e-08, 0.913132966, -0.407661796, 1.0000006, 0, 2.98023224e-08)
  45. Part1.Position = Vector3.new(0.612733841, 32.6300011, -45.7190094)
  46. Part1.Orientation = Vector3.new(24.0599995, -90, 0)
  47. LocalScript2.Parent = Part1
  48. table.insert(cors,sandbox(LocalScript2,function()
  49. ------------------------
  50. --[[UTIL Functions]]--
  51. ------------------------
  52. --Global functions used by all classes are wrapped in UTIL
  53. --deal with it.
  54. local UTIL = {}
  55.  
  56. function UTIL.Class(tableIn,template)
  57. tableIn = tableIn or {}
  58. local mt = {
  59. __metatable = UTIL.DeepCopy(template);
  60. __index = UTIL.DeepCopy(template);
  61. }
  62. return setmetatable(tableIn, mt)
  63. end
  64. function UTIL.MakeClass(...)
  65. local arg = {...}
  66. assert(#arg>0, 'ERROR: class needs 1 argument or more')
  67. local members = arg[1]
  68. for i=2,#arg,1 do
  69. if type(arg[i])=='table' then
  70. for key,val in pairs(arg[i]) do
  71. if not members[key] then
  72. members[key] = val
  73. end
  74. end
  75. end
  76. end
  77. local function New(init)
  78. return UTIL.Class(init or {},members)
  79. end
  80. local function Copy(obj, ...)
  81. local newobj = obj:New(unpack(arg))
  82. for n,v in pairs(obj) do newobj[n] = v end
  83. return newobj
  84. end
  85. members.New = New
  86. members.Copy = Copy
  87. return mt
  88. end
  89.  
  90. function UTIL.DeepCopy(orig)
  91. local orig_type = type(orig)
  92. local copy
  93. if orig_type == 'table' then
  94. copy = {}
  95. for orig_key, orig_value in next, orig, nil do
  96. copy[UTIL.DeepCopy(orig_key)] = UTIL.DeepCopy(orig_value)
  97. end
  98. setmetatable(copy, UTIL.DeepCopy(getmetatable(orig)))
  99. else -- number, string, boolean, etc
  100. copy = orig
  101. end
  102. return copy
  103. end
  104.  
  105. function UTIL.Instantiate(guiType)
  106. return function(data)
  107. local obj = Instance.new(guiType)
  108. for k, v in pairs(data) do
  109. if type(k) == 'number' then
  110. v.Parent = obj
  111. else
  112. obj[k] = v
  113. end
  114. end
  115. return obj
  116. end
  117. end
  118.  
  119. function UTIL.RetroRegister(func,...)
  120. func()
  121. for _,i in ipairs({...}) do
  122. i:connect(func)
  123. end
  124. end
  125.  
  126. -- Waits for a new character to be added if the current one is invalid
  127. -- (Ensures that you don't have the old dead character after a respawn)
  128. function UTIL.WaitForValidCharacter(player)
  129. local character = player.Character
  130. if not character or not character.Parent or not character:FindFirstChild('Humanoid') or character.Humanoid.Health <= 0 then
  131. player.CharacterAdded:wait()
  132. wait(0) --NOTE: Necessary for server scripts executing on the same event
  133. character = player.Character
  134. end
  135. return character
  136. end
  137.  
  138.  
  139. -- Returns a character ancestor and its Humanoid, or nil
  140. function UTIL.FindCharacterAncestor(subject)
  141. if subject and subject ~= Workspace then
  142. local humanoid = subject:FindFirstChild('Humanoid')
  143. if humanoid then
  144. return subject, humanoid
  145. else
  146. return UTIL.FindCharacterAncestor(subject.Parent)
  147. end
  148. end
  149. return nil
  150. end
  151.  
  152. UTIL.AssetURL = 'http://www.roblox.com/asset/?id='
  153.  
  154.  
  155. UTIL.TouchEnabled = game:GetService("UserInputService").TouchEnabled
  156. do
  157. local suceeded,_ =pcall(function() game.Workspace.CurrentCamera:GetPanSpeed() end)
  158. UTIL.CanCheckPanSpeed = suceeded
  159. end
  160.  
  161.  
  162. local DebrisService = Game:GetService('Debris')
  163. local DebugPrintOffset = 0
  164. function UTIL.Dprint(...)
  165. local line = ''
  166. for _, segment in pairs({...}) do
  167. line = line .. (line and ' ' or '') .. tostring(segment)
  168. end
  169. local gui = Instance.new('ScreenGui')
  170. local label = Instance.new('TextLabel')
  171. label.Text = line
  172. label.Size = UDim2.new(0.25, 0, 0.05, 0)
  173. label.BackgroundTransparency = 0.5
  174. label.Position = UDim2.new(0, 0, 0, DebugPrintOffset)
  175. label.TextWrapped = true
  176. label.Parent = gui
  177. DebrisService:AddItem(gui, 30)
  178. gui.Parent = script.Parent
  179. DebugPrintOffset = (DebugPrintOffset <= 600) and DebugPrintOffset + 30 or 0
  180. end
  181. --
  182. --All Welding Related Utility functions should be put here
  183. --
  184. WeldUtil = {}
  185.  
  186.  
  187. do
  188.  
  189.  
  190. function WeldUtil:WeldBetween(a, b)
  191. local weld = Instance.new("Weld")
  192. weld.Part0 = a
  193. weld.Part1 = b
  194. weld.C0 = CFrame.new()
  195. weld.C1 = b.CFrame:inverse() * a.CFrame
  196. weld.Parent = a
  197. return weld
  198. end
  199.  
  200. function WeldUtil:PermaWeld(weld)
  201. local OriginalParent = weld.Parent
  202. weld.Changed:connect(function()
  203. Delay(0,function() weld.Parent = OriginalParent end)
  204. end)
  205. end
  206.  
  207. end
  208.  
  209. local InternalEvent =
  210. {
  211. Listeners = nil,
  212. }
  213. do
  214. UTIL.MakeClass(InternalEvent)
  215. function InternalEvent:Connect(func)
  216. if not self.Listeners then self.Listeners = {} end
  217. table.insert(self.Listeners,func)
  218. end
  219. function InternalEvent:Fire(...)
  220. if not self.Listeners then return end
  221. local args = {...}
  222. for _,i in ipairs(self.Listeners) do
  223. Spawn(function() i(unpack(args)) end)
  224. end
  225. end
  226. end
  227.  
  228. local PartProjectile =
  229. {
  230. Damage = 5, -- Base output damage per shot.
  231. Range = 250, -- Max distance that the weapon can fire.
  232. Speed = 1,--how many studs per second to move
  233. DirectionRay=nil,
  234. Part = nil,
  235. IsAlive = true,
  236. IgnoreList = {},
  237. }
  238. do
  239. UTIL.MakeClass(PartProjectile)
  240. function PartProjectile.New(base,ray)
  241. local init = nil
  242. --if base is a copy of this class, then copy over fields
  243. if type(base) == 'table' and base.Update then
  244. init = UTIL.DeepCopy(base)
  245. init.Part= base.Part:Clone()
  246. else
  247. init = UTIL.DeepCopy(PartProjectile)
  248. init.Part = base:Clone()
  249. end
  250. init.Part.CFrame = CFrame.new(ray.Origin,ray.Origin+ray.Direction)
  251. init.Part.Parent = game.Workspace
  252. init.DirectionRay = ray
  253. table.insert(init.IgnoreList,init.Part)
  254. return init
  255. end
  256.  
  257. function PartProjectile:Hit(part)
  258. local char,hum = UTIL.FindCharacterAncestor(part)
  259.  
  260. if hum then
  261. hum:TakeDamage(self.Damage)
  262. end
  263. self.IsAlive = false
  264. end
  265.  
  266. function PartProjectile:Update(dt)
  267. if not self.IsAlive then return end
  268. local oldPos = self.Part.CFrame
  269. self.Part.CFrame = oldPos+(self.DirectionRay.Direction*self.Speed*dt)
  270. if (self.Part.CFrame.p-self.DirectionRay.Origin).magnitude>self.Range then
  271. self.IsAlive = false
  272. end
  273. local obj = game.Workspace:FindPartOnRayWithIgnoreList( Ray.new(oldPos.p,self.DirectionRay.Direction*self.Speed*dt), self.IgnoreList,false )
  274. if obj then
  275. self:Hit(obj)
  276. end
  277.  
  278. end
  279.  
  280. function PartProjectile:Destroy()
  281. self.Part.Parent = nil
  282. end
  283.  
  284. end
  285.  
  286. --[[shooting Tool Class]]--
  287.  
  288. local ShootingTool =
  289. {
  290. FireRate = .5, -- How often the weapon can fire.
  291. Automatic = false, -- hold down to continue firing
  292. Spread = 0, -- The bigger the spread, the more inaccurate the shots will be.
  293. ClipSize = 50, -- Shots in a clip
  294. ReloadTime = 3, -- Time it takes to reload the tool.
  295. StartingClips = -1,
  296. BarrelPos = CFrame.new(0, 0, - 1.2), -- L, F, U
  297.  
  298. SourcePart = nil,
  299. TemplateProjectile = nil,
  300. Projectiles = {},
  301. IsFireing = false,
  302.  
  303. OnFire = nil,
  304. OnReload = nil,
  305.  
  306. BulletsLeft = 50,
  307.  
  308. LastReload = 0,
  309.  
  310. FireSound = nil,
  311.  
  312. }
  313. do
  314. UTIL.MakeClass(ShootingTool)
  315. function ShootingTool.New(nSource,nProjectile)
  316. local init= UTIL.DeepCopy(ShootingTool)
  317. init.SourcePart= nSource
  318. init.TemplateProjectile = nProjectile
  319. init.OnFire = InternalEvent.New()
  320. init.OnReload = InternalEvent.New()
  321. return init
  322. end
  323.  
  324. function ShootingTool:UpdateBullets(dt)
  325. for index,i in ipairs(self.Projectiles) do
  326. if i.IsAlive then
  327. i:Update(dt)
  328. else
  329. i:Destroy()
  330. table.remove(self.Projectiles, index)
  331. end
  332. end
  333. end
  334.  
  335. function ShootingTool:StartFireing(mouse)
  336. if tick()-self.LastReload<self.ReloadTime then return end
  337. while self.IsFireing do wait() end
  338. self.IsFireing = true
  339. repeat
  340. if tick()-self.LastReload>self.ReloadTime then
  341. local startPos = self.SourcePart.CFrame:toWorldSpace(self.BarrelPos)
  342. local dir = (CFrame.Angles((math.random()-.5)*2*self.Spread,(math.random()-.5)*2*self.Spread,(math.random()-.5)*2*self.Spread)*CFrame.new((mouse.Hit.p-startPos.p).unit)).p
  343. local nprojectile = PartProjectile.New(self.TemplateProjectile, Ray.new(startPos.p,dir))
  344.  
  345. table.insert(self.Projectiles,nprojectile)
  346. self.OnFire:Fire()
  347. if self.FireSound then
  348. self.FireSound:Play()
  349. end
  350. self.BulletsLeft = self.BulletsLeft -1
  351. end
  352. if self.BulletsLeft==0 then
  353. self.OnReload:Fire()
  354. self.BulletsLeft = self.ClipSize
  355. self.LastReload = tick()
  356. end
  357. wait(self.FireRate)
  358. until not self.IsFireing or not self.Automatic
  359. end
  360.  
  361. function ShootingTool:EndFireing()
  362. self.IsFireing=false
  363. end
  364.  
  365. end
  366. do
  367. local Handle = script.Parent
  368. local Tool = Handle.Parent
  369.  
  370. local BarrelClip = UTIL.Instantiate"Part"
  371. {
  372. Size = Vector3.new(0.2, 0.2, 0.32),
  373. UTIL.Instantiate'SpecialMesh'
  374. {
  375. TextureId = "http://www.roblox.com/asset/?id=116679995",
  376. MeshId = "http://www.roblox.com/asset/?id=116740155",
  377. Scale = Vector3.new(0.9, 0.9, 0.9),
  378. },
  379. CanCollide = false,
  380. Parent = Tool
  381. }
  382.  
  383. local BarrelWeld = UTIL.Instantiate"Weld"
  384. {
  385. C1 = CFrame.new(0.0183372498, 0.378660202, 0.237049103, 0.00777955074, 0.0069010579, 0.999946177, -0.0223222617, 0.999727845, -0.00672559161, -0.999720693, -0.0222686939, 0.00793197285),
  386. C0 = CFrame.new(0, 0, 0, 0.00777955074, 0.0069010579, 0.999946177, -0.0223222617, 0.999727845, -0.00672559161, -0.999720693, -0.0222686939, 0.00793197285),
  387. Part0 = Handle,
  388. Part1 = BarrelClip,
  389. Parent = Handle,
  390. }
  391. WeldUtil:PermaWeld(BarrelWeld)
  392.  
  393. local OrangeLight = Handle:WaitForChild('OrangeLight')
  394. local RedLight = Handle:WaitForChild('RedLight')
  395. local SpotLight = Handle:WaitForChild('SpotLight')
  396.  
  397.  
  398. local Player = game.Players.LocalPlayer
  399. local Character = UTIL.WaitForValidCharacter(Player)
  400. local HoldAni = UTIL.Instantiate"Animation"
  401. {AnimationId = "http://www.roblox.com/Asset?ID=116690317"}
  402. local ReloadAni = UTIL.Instantiate"Animation"
  403. {AnimationId = "http://www.roblox.com/Asset?ID=116695140"}
  404.  
  405. local HoldAniTrack
  406. local ReloadAniTrack
  407. local ShellMesh = UTIL.Instantiate"SpecialMesh"
  408. {
  409. MeshId = UTIL.AssetURL..94295100,--116680945,
  410. TextureId = UTIL.AssetURL..94287792,--116681256,
  411. Scale = Vector3.new(2.8,2.8,5),
  412. }
  413. local Projectile
  414. do
  415. local tpart = UTIL.Instantiate"Part"
  416. {
  417. Anchored = true,
  418. CanCollide = false,
  419. Size = Vector3.new(.2,.2,.6),
  420. ShellMesh:Clone(),
  421. }
  422. Projectile = PartProjectile.New(tpart,Ray.new())
  423. end
  424. table.insert(Projectile.IgnoreList,Handle)
  425.  
  426. Projectile.Speed = 200
  427. local Gun = ShootingTool.New(Handle,Projectile)
  428. Gun.Automatic = true
  429. Gun.BarrelPos = CFrame.new(0, 0, - 3.1)
  430. Gun.FireRate = .05
  431. Gun.Spread = .1
  432. Gun.FireSound = Handle:WaitForChild('FireSound')
  433.  
  434. Gun.OnFire:Connect(function()
  435. SpotLight.Enabled = true
  436. if(math.random()>.5) then
  437. OrangeLight.Enabled =true
  438. else
  439. RedLight.Enabled =true
  440. end
  441. wait(.05)
  442. SpotLight.Enabled = false
  443. OrangeLight.Enabled =false
  444. RedLight.Enabled =false
  445. end)
  446.  
  447. Gun.OnReload:Connect(function()
  448. local leftArm = Character:FindFirstChild('Left Arm')
  449. if not leftArm then return end
  450. local reloadBarrel = BarrelClip:Clone()
  451. reloadBarrel.Parent = Tool
  452. local tweld=WeldUtil:WeldBetween(reloadBarrel,leftArm)
  453. BarrelClip.Transparency = 1
  454. if ReloadAniTrack then
  455. ReloadAniTrack:Play()
  456. end
  457. wait(3)
  458. reloadBarrel:Destroy()
  459. tweld:Destroy()
  460. BarrelClip.Transparency = 0
  461. end)
  462.  
  463. Tool.Equipped:connect(function(mouse)
  464.  
  465. Character = UTIL.WaitForValidCharacter(Player)
  466. local Humanoid = Character:FindFirstChild('Humanoid')
  467. table.insert(Projectile.IgnoreList,Character)
  468. HoldAniTrack = Humanoid:LoadAnimation(HoldAni)
  469. ReloadAniTrack = Humanoid:LoadAnimation(ReloadAni)
  470. HoldAniTrack:Play()
  471. mouse.Button1Down:connect(function()
  472. Gun:StartFireing(mouse)
  473. end)
  474. mouse.Button1Up:connect(function()
  475. Gun:EndFireing()
  476. end)
  477. end)
  478. Tool.Unequipped:connect(function()
  479. HoldAniTrack:Stop()
  480. end)
  481. while true do
  482. Gun:UpdateBullets(1/30)
  483. wait()
  484. end
  485.  
  486. end
  487.  
  488. end))
  489. SpecialMesh3.Parent = Part1
  490. SpecialMesh3.MeshId = "http://www.roblox.com/asset/?id=116679805"
  491. SpecialMesh3.Scale = Vector3.new(0.899999976, 0.899999976, 0.899999976)
  492. SpecialMesh3.TextureId = "http://www.roblox.com/asset/?id=116679995"
  493. SpecialMesh3.MeshType = Enum.MeshType.FileMesh
  494. SpecialMesh3.Scale = Vector3.new(0.899999976, 0.899999976, 0.899999976)
  495. PointLight4.Name = "OrangeLight"
  496. PointLight4.Parent = Part1
  497. PointLight4.Color = Color3.new(0.886275, 0.505882, 0.121569)
  498. PointLight4.Enabled = false
  499. PointLight4.Brightness = 4
  500. PointLight4.Range = 4
  501. PointLight4.Color = Color3.new(0.886275, 0.505882, 0.121569)
  502. PointLight5.Name = "RedLight"
  503. PointLight5.Parent = Part1
  504. PointLight5.Color = Color3.new(1, 0, 0)
  505. PointLight5.Enabled = false
  506. PointLight5.Brightness = 4
  507. PointLight5.Range = 4
  508. PointLight5.Color = Color3.new(1, 0, 0)
  509. SpotLight6.Parent = Part1
  510. SpotLight6.Color = Color3.new(1, 0, 0)
  511. SpotLight6.Enabled = false
  512. SpotLight6.Brightness = 8
  513. SpotLight6.Angle = 45
  514. SpotLight6.Color = Color3.new(1, 0, 0)
  515. Sound7.Name = "FireSound"
  516. Sound7.Parent = Part1
  517. Sound7.SoundId = "http://www.roblox.com/asset/?id=116745227"
  518. Part8.Name = "BarrelClip"
  519. Part8.Parent = Tool0
  520. Part8.Rotation = Vector3.new(88.9399948, -64.659996, 89.4300003)
  521. Part8.CanCollide = false
  522. Part8.FormFactor = Enum.FormFactor.Custom
  523. Part8.Size = Vector3.new(0.200000003, 0.200000003, 0.319990754)
  524. Part8.CFrame = CFrame.new(0.976270974, 32.3943062, -45.7094498, 0.00428991765, -0.427933723, -0.903802216, 0.0094730733, 0.903783858, -0.427882999, 0.999949038, -0.00672531035, 0.00793248415)
  525. Part8.Position = Vector3.new(0.976270974, 32.3943062, -45.7094498)
  526. Part8.Orientation = Vector3.new(25.3299999, -89.5, 0.599999964)
  527. SpecialMesh9.Parent = Part8
  528. SpecialMesh9.MeshId = "http://www.roblox.com/asset/?id=116740155"
  529. SpecialMesh9.Scale = Vector3.new(0.899999976, 0.899999976, 0.899999976)
  530. SpecialMesh9.TextureId = "http://www.roblox.com/asset/?id=116679995"
  531. SpecialMesh9.MeshType = Enum.MeshType.FileMesh
  532. SpecialMesh9.Scale = Vector3.new(0.899999976, 0.899999976, 0.899999976)
  533. Weld10.Parent = Part8
  534. Weld10.C0 = CFrame.new(0, 0, 0, 0.00777906645, 0.00690134289, 0.999947846, -0.0223223157, 0.99972713, -0.00672530197, -0.999722123, -0.0222686492, 0.00793247484)
  535. Weld10.C1 = CFrame.new(0.00955963135, -0.363422394, -0.235873222, 2.98023224e-08, 0, 1.0000006, 0, 1, 0, -1.0000006, 0, 2.98023224e-08)
  536. Weld10.Part0 = Part8
  537. Weld10.Part1 = Part1
  538. Script11.Parent = Part8
  539. table.insert(cors,sandbox(Script11,function()
  540. wait(.1)
  541. script.Parent:Destroy()
  542. wait(1)
  543. end))
  544. for i,v in pairs(mas:GetChildren()) do
  545. v.Parent = game:GetService("Players").LocalPlayer.Backpack
  546. pcall(function() v:MakeJoints() end)
  547. end
  548. mas:Destroy()
  549. for i,v in pairs(cors) do
  550. spawn(function()
  551. pcall(v)
  552. end)
  553. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement