VanishingDragon

Untitled

Mar 11th, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.86 KB | None | 0 0
  1. --Credits to Paul Migo & OpTic Wisdom
  2. game:GetObjects("rbxassetid://503182370")[1].Parent=game.Players.LocalPlayer.Backpack
  3. game.Players.LocalPlayer.Backpack.AssaultRifle.Main.Transparency = 0
  4. game.Players.LocalPlayer.Backpack.AssaultRifle.Part1.Transparency = 0
  5. game.Players.LocalPlayer.Backpack.AssaultRifle.Part2.Transparency = 0
  6. game.Players.LocalPlayer.Backpack.AssaultRifle.Part3.Transparency = 0
  7. game.Players.LocalPlayer.Backpack.AssaultRifle.Part4.Transparency = 0
  8. game.Players.LocalPlayer.Backpack.AssaultRifle.Partkaas.Transparency = 0
  9. game.Players.LocalPlayer.Backpack.AssaultRifle.Part5.Transparency = 0
  10. game.Players.LocalPlayer.Backpack.AssaultRifle.Part6.Transparency = 0
  11. game.Players.LocalPlayer.Backpack.AssaultRifle.Part7.Transparency = 0
  12. game.Players.LocalPlayer.Backpack.AssaultRifle.Part8.Transparency = 0
  13. game.Players.LocalPlayer.Backpack.AssaultRifle.Part9.Transparency = 0
  14. game.Players.LocalPlayer.Backpack.AssaultRifle.Part10.Transparency = 0
  15. game.Players.LocalPlayer.Backpack.AssaultRifle.Part11.Transparency = 0
  16. game.Players.LocalPlayer.Backpack.AssaultRifle.Part12.Transparency = 0
  17. game.Players.LocalPlayer.Backpack.AssaultRifle.Part13.Transparency = 0
  18. --------------------- TEMPLATE ASSAULT RIFLE WEAPON ---------------------------
  19. -- Waits for the child of the specified parent
  20. local function WaitForChild(parent, childName)
  21. while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
  22. return parent[childName]
  23. end
  24. ----- MAGIC NUMBERS ABOUT THE TOOL -----
  25. -- How much damage a bullet does
  26. local Damage = 100
  27. -- How many times per second the gun can fire
  28. local FireRate = 20 / 30
  29. -- The maximum distance the can can shoot, this value should never go above 1000
  30. local Range = 400
  31. -- In radians the minimum accuracy penalty
  32. local MinSpread = 0.01
  33. -- In radian the maximum accuracy penalty
  34. local MaxSpread = 0.1
  35. -- Number of bullets in a clip
  36. local ClipSize = 300
  37. -- DefaultValue for spare ammo
  38. local SpareAmmo = 600
  39. -- The amount the aim will increase or decrease by
  40. -- decreases this number reduces the speed that recoil takes effect
  41. local AimInaccuracyStepAmount = 0.0125
  42. -- Time it takes to reload weapon
  43. local ReloadTime = 1
  44. ----------------------------------------
  45. -- Colors
  46. local FriendlyReticleColor = Color3.new(0, 1, 0)
  47. local EnemyReticleColor = Color3.new(1, 0, 0)
  48. local NeutralReticleColor = Color3.new(1, 1, 1)
  49. local Spread = MinSpread
  50. local AmmoInClip = ClipSize
  51. local Tool = game.Players.LocalPlayer.Backpack.AssaultRifle
  52. local Handle = WaitForChild(Tool, 'Handle')
  53. local WeaponGui = nil
  54. local LeftButtonDown
  55. local Reloading = false
  56. local IsShooting = false
  57. -- Player specific convenience variables
  58. local MyPlayer = nil
  59. local MyCharacter = nil
  60. local MyHumanoid = nil
  61. local MyTorso = nil
  62. local MyMouse = nil
  63. local RecoilAnim
  64. local RecoilTrack = nil
  65. local IconURL = Tool.TextureId -- URL to the weapon icon asset
  66. local DebrisService = game:GetService('Debris')
  67. local PlayersService = game:GetService('Players')
  68. local OnFireConnection = nil
  69. local OnReloadConnection = nil
  70. local DecreasedAimLastShot = false
  71. local LastSpreadUpdate = time()
  72. -- this is a dummy object that holds the flash made when the gun is fired
  73. local FlashHolder = nil
  74. local WorldToCellFunction = Workspace.Terrain.WorldToCellPreferSolid
  75. local GetCellFunction = Workspace.Terrain.GetCell
  76. function RayIgnoreCheck(hit, pos)
  77. if hit then
  78. if hit.Transparency >= 1 or string.lower(hit.Name) == "water" or
  79. hit.Name == "Effect" or hit.Name == "Rocket" or hit.Name == "Bullet" or
  80. hit.Name == "Handle" or hit:IsDescendantOf(MyCharacter) then
  81. return true
  82. elseif hit:IsA('Terrain') and pos then
  83. local cellPos = WorldToCellFunction(Workspace.Terrain, pos)
  84. if cellPos then
  85. local cellMat = GetCellFunction(Workspace.Terrain, cellPos.x, cellPos.y, cellPos.z)
  86. if cellMat and cellMat == Enum.CellMaterial.Water then
  87. return true
  88. end
  89. end
  90. end
  91. end
  92. return false
  93. end
  94. -- @preconditions: vec should be a unit vector, and 0 < rayLength <= 1000
  95. function RayCast(startPos, vec, rayLength)
  96. local hitObject, hitPos = game.Workspace:FindPartOnRay(Ray.new(startPos + (vec * .01), vec * rayLength), Handle)
  97. if hitObject and hitPos then
  98. local distance = rayLength - (hitPos - startPos).magnitude
  99. if RayIgnoreCheck(hitObject, hitPos) and distance > 0 then
  100. -- there is a chance here for potential infinite recursion
  101. return RayCast(hitPos, vec, distance)
  102. end
  103. end
  104. return hitObject, hitPos
  105. end
  106. function TagHumanoid(humanoid, player)
  107. -- Add more tags here to customize what tags are available.
  108. while humanoid:FindFirstChild('creator') do
  109. humanoid:FindFirstChild('creator'):Destroy()
  110. end
  111. local creatorTag = Instance.new("ObjectValue")
  112. creatorTag.Value = player
  113. creatorTag.Name = "creator"
  114. creatorTag.Parent = humanoid
  115. DebrisService:AddItem(creatorTag, 1.5)
  116. local weaponIconTag = Instance.new("StringValue")
  117. weaponIconTag.Value = IconURL
  118. weaponIconTag.Name = "icon"
  119. weaponIconTag.Parent = creatorTag
  120. end
  121. local function CreateFlash()
  122. if FlashHolder then
  123. local flash = Instance.new('Fire', FlashHolder)
  124. flash.Color = Color3.new(1, 140 / 255, 0)
  125. flash.SecondaryColor = Color3.new(1, 0, 0)
  126. flash.Size = 0.3
  127. DebrisService:AddItem(flash, FireRate / 1.5)
  128. else
  129. FlashHolder = Instance.new("Part", Tool)
  130. FlashHolder.Transparency = 1
  131. FlashHolder.CanCollide= false
  132. FlashHolder.Size = Vector3.new(1, 1, 1)
  133. FlashHolder.Position = Tool.Handle.Position
  134. local Weld = Instance.new("ManualWeld")
  135. Weld.C0 = CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)
  136. Weld.C1 = CFrame.new(0, 2.2, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0)
  137. Weld.Part0 = FlashHolder
  138. Weld.Part1 = Tool.Handle
  139. Weld.Parent = FlashHolder
  140. end
  141. end
  142. local function CreateBullet(bulletPos)
  143. local bullet = Instance.new('Part', Workspace)
  144. bullettext = Instance.new("Decal" ,bullet)
  145. bullettext1 = Instance.new("Decal" ,bullet)
  146. bullettext1.Texture = "http://www.roblox.com/asset/?id=164688340"
  147. bullettext2 = Instance.new("Decal" ,bullet)
  148. bullettext2.Texture = "http://www.roblox.com/asset/?id=164688340"
  149. bullettext1.Face = "Front"
  150. bullettext.Texture = "http://www.roblox.com/asset/?id=164688340"
  151. bullettext.Face = "Back"
  152. bullettext2.Face = "Top"
  153. bullet.FormFactor = Enum.FormFactor.Custom
  154. bullet.Size = Vector3.new(4, 4, 0.1)
  155. bullet.BrickColor = MyPlayer.TeamColor
  156. bullet.Shape = Enum.PartType.Block
  157. bullet.CanCollide = false
  158. bullet.CFrame = CFrame.new(bulletPos)
  159. bullet.Anchored = true
  160. bullet.TopSurface = Enum.SurfaceType.Smooth
  161. bullet.BottomSurface = Enum.SurfaceType.Smooth
  162. bullet.Name = 'Bullet'
  163. bullet.Transparency = 1
  164. DebrisService:AddItem(bullet, 2.5)
  165. local fire = Instance.new("Fire", bullet)
  166. fire.Color = Color3.new(MyPlayer.TeamColor.r, MyPlayer.TeamColor.g, MyPlayer.TeamColor.b)
  167. fire.SecondaryColor = Color3.new(MyPlayer.TeamColor.r, MyPlayer.TeamColor.g, MyPlayer.TeamColor.b)
  168. fire.Size = 5
  169. fire.Heat = 0
  170. DebrisService:AddItem(fire, 0.2)
  171. return bullet
  172. end
  173. local function Reload()
  174. if not Reloading then
  175. Reloading = true
  176. -- Don't reload if you are already full or have no extra ammo
  177. if AmmoInClip ~= ClipSize and SpareAmmo > 0 then
  178. if RecoilTrack then
  179. RecoilTrack:Stop()
  180. end
  181. if WeaponGui and WeaponGui:FindFirstChild('Crosshair') then
  182. if WeaponGui.Crosshair:FindFirstChild('ReloadingLabel') then
  183. WeaponGui.Crosshair.ReloadingLabel.Visible = true
  184. end
  185. end
  186. wait(ReloadTime)
  187. -- Only use as much ammo as you have
  188. local ammoToUse = math.min(ClipSize - AmmoInClip, SpareAmmo)
  189. AmmoInClip = AmmoInClip + ammoToUse
  190. SpareAmmo = SpareAmmo - ammoToUse
  191. UpdateAmmo(AmmoInClip)
  192. end
  193. Reloading = false
  194. end
  195. end
  196. function OnFire()
  197. if IsShooting then return end
  198. if MyHumanoid and MyHumanoid.Health > 0 then
  199. if RecoilTrack and AmmoInClip > 0 then
  200. RecoilTrack:Play()
  201. end
  202. IsShooting = true
  203. while LeftButtonDown and AmmoInClip > 0 and not Reloading do
  204. if Spread and not DecreasedAimLastShot then
  205. Spread = math.min(MaxSpread, Spread + AimInaccuracyStepAmount)
  206. UpdateCrosshair(Spread)
  207. end
  208. CreateFlash()
  209. if MyMouse then
  210. local targetPoint = MyMouse.Hit.p
  211. local shootDirection = (targetPoint - Handle.Position).unit
  212. -- Adjust the shoot direction randomly off by a little bit to account for recoil
  213. shootDirection = CFrame.Angles((0.5 - math.random()) * 2 * Spread,
  214. (0.5 - math.random()) * 2 * Spread,
  215. (0.5 - math.random()) * 2 * Spread) * shootDirection
  216. local hitObject, bulletPos = RayCast(Handle.Position, shootDirection, Range)
  217. local bullet
  218. -- Create a bullet here
  219. if hitObject then
  220. bullet = CreateBullet(bulletPos)
  221. end
  222. if hitObject and hitObject.Parent then
  223. local hitHumanoid = hitObject.Parent:FindFirstChild("Humanoid")
  224. if hitHumanoid then
  225. local hitPlayer = game.Players:GetPlayerFromCharacter(hitHumanoid.Parent)
  226. if MyPlayer.Neutral or (hitPlayer and hitPlayer.TeamColor ~= MyPlayer.TeamColor) then
  227. TagHumanoid(hitHumanoid, MyPlayer)
  228. hitHumanoid:TakeDamage(Damage)
  229. if bullet then
  230. bullet:Destroy()
  231. bullet = nil
  232. --bullet.Transparency = 1
  233. end
  234. Spawn(UpdateTargetHit)
  235. end
  236. end
  237. end
  238. Kek = Instance.new ("Sound" ,game.Players.LocalPlayer.Character.AssaultRifle.Handle)
  239. Kek.Name = "FireSound"
  240. Kek.SoundId = "rbxassetid://384987591"
  241. Kek.Volume = 100
  242. Kek:Play()
  243. AmmoInClip = AmmoInClip - 1
  244. UpdateAmmo(AmmoInClip)
  245. end
  246. wait(FireRate)
  247. end
  248. IsShooting = false
  249. wait(5)
  250. local children = game.Workspace:GetChildren()
  251. for _, child in pairs(children) do
  252. for _, child in pairs(child:GetChildren()) do
  253. table.insert(children, child)
  254. end
  255. if child:IsA("Sound") and child.Name == "FireSound" then
  256. child:Destroy()
  257. if AmmoInClip == 0 then
  258. Reload()
  259. end
  260. end
  261. end
  262. if RecoilTrack then
  263. RecoilTrack:Stop()
  264. end
  265. end
  266. end
  267. local TargetHits = 0
  268. function UpdateTargetHit()
  269. TargetHits = TargetHits + 1
  270. if WeaponGui and WeaponGui:FindFirstChild('Crosshair') and WeaponGui.Crosshair:FindFirstChild('TargetHitImage') then
  271. WeaponGui.Crosshair.TargetHitImage.Visible = true
  272. end
  273. wait(0.5)
  274. TargetHits = TargetHits - 1
  275. if TargetHits == 0 and WeaponGui and WeaponGui:FindFirstChild('Crosshair') and WeaponGui.Crosshair:FindFirstChild('TargetHitImage') then
  276. WeaponGui.Crosshair.TargetHitImage.Visible = false
  277. end
  278. end
  279. function UpdateCrosshair(value, mouse)
  280. if WeaponGui then
  281. local absoluteY = 650
  282. WeaponGui.Crosshair:TweenSize(
  283. UDim2.new(0, value * absoluteY * 2 + 23, 0, value * absoluteY * 2 + 23),
  284. Enum.EasingDirection.Out,
  285. Enum.EasingStyle.Linear,
  286. 0.33)
  287. end
  288. end
  289. function UpdateAmmo(value)
  290. if WeaponGui and WeaponGui:FindFirstChild('AmmoHud') and WeaponGui.AmmoHud:FindFirstChild('ClipAmmo') then
  291. WeaponGui.AmmoHud.ClipAmmo.Text = AmmoInClip
  292. if value > 0 and WeaponGui:FindFirstChild('Crosshair') and WeaponGui.Crosshair:FindFirstChild('ReloadingLabel') then
  293. WeaponGui.Crosshair.ReloadingLabel.Visible = false
  294. end
  295. end
  296. if WeaponGui and WeaponGui:FindFirstChild('AmmoHud') and WeaponGui.AmmoHud:FindFirstChild('TotalAmmo') then
  297. WeaponGui.AmmoHud.TotalAmmo.Text = SpareAmmo
  298. end
  299. end
  300. function OnMouseDown()
  301. LeftButtonDown = true
  302. OnFire()
  303. end
  304. function OnMouseUp()
  305. LeftButtonDown = false
  306. end
  307. function OnKeyDown(key)
  308. if string.lower(key) == 'r' then
  309. Reload()
  310. end
  311. end
  312. function OnEquipped(mouse)
  313. RecoilAnim = WaitForChild(Tool, 'Recoil')
  314. MyCharacter = Tool.Parent
  315. MyPlayer = game:GetService('Players'):GetPlayerFromCharacter(MyCharacter)
  316. MyHumanoid = MyCharacter:FindFirstChild('Humanoid')
  317. MyTorso = MyCharacter:FindFirstChild('Torso')
  318. MyMouse = mouse
  319. WeaponGui = WaitForChild(Tool, 'WeaponHud'):Clone()
  320. if WeaponGui and MyPlayer then
  321. WeaponGui.Parent = MyPlayer.PlayerGui
  322. UpdateAmmo(AmmoInClip)
  323. end
  324. if RecoilAnim then
  325. RecoilTrack = MyHumanoid:LoadAnimation(RecoilAnim)
  326. end
  327. if MyMouse then
  328. -- Disable mouse icon
  329. MyMouse.Icon = "http://www.roblox.com/asset/?id=18662154"
  330. MyMouse.Button1Down:connect(OnMouseDown)
  331. MyMouse.Button1Up:connect(OnMouseUp)
  332. MyMouse.KeyDown:connect(OnKeyDown)
  333. end
  334. end
  335. -- Unequip logic here
  336. function OnUnequipped()
  337. LeftButtonDown = false
  338. Reloading = false
  339. MyCharacter = nil
  340. MyHumanoid = nil
  341. MyTorso = nil
  342. MyPlayer = nil
  343. MyMouse = nil
  344. if OnFireConnection then
  345. OnFireConnection:disconnect()
  346. end
  347. if OnReloadConnection then
  348. OnReloadConnection:disconnect()
  349. end
  350. if FlashHolder then
  351. FlashHolder = nil
  352. end
  353. if WeaponGui then
  354. WeaponGui.Parent = nil
  355. WeaponGui = nil
  356. end
  357. if RecoilTrack then
  358. RecoilTrack:Stop()
  359. end
  360. end
  361. local function SetReticleColor(color)
  362. if WeaponGui and WeaponGui:FindFirstChild('Crosshair') then
  363. for _, line in pairs(WeaponGui.Crosshair:GetChildren()) do
  364. if line:IsA('Frame') then
  365. line.BorderColor3 = color
  366. end
  367. end
  368. end
  369. end
  370. Tool.Equipped:connect(OnEquipped)
  371. Tool.Unequipped:connect(OnUnequipped)
  372. while true do
  373. wait(0.033)
  374. if WeaponGui and WeaponGui:FindFirstChild('Crosshair') and MyMouse then
  375. WeaponGui.Crosshair.Position = UDim2.new(0, MyMouse.X, 0, MyMouse.Y)
  376. SetReticleColor(NeutralReticleColor)
  377. local target = MyMouse.Target
  378. if target and target.Parent then
  379. local player = PlayersService:GetPlayerFromCharacter(target.Parent)
  380. if player then
  381. if MyPlayer.Neutral or player.TeamColor ~= MyPlayer.TeamColor then
  382. SetReticleColor(EnemyReticleColor)
  383. else
  384. SetReticleColor(FriendlyReticleColor)
  385. end
  386. end
  387. end
  388. end
  389. if Spread and not IsShooting then
  390. local currTime = time()
  391. if currTime - LastSpreadUpdate > FireRate * 2 then
  392. LastSpreadUpdate = currTime
  393. Spread = math.max(MinSpread, Spread - AimInaccuracyStepAmount)
  394. UpdateCrosshair(Spread, MyMouse)
  395. end
  396. end
  397. end
  398.  
  399. Script chunked by https://mdbooktech.com/codechunk
Add Comment
Please, Sign In to add comment