Advertisement
Tjkillzyou27

g

Oct 11th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.18 KB | None | 0 0
  1. ToolName="Put tool name here"
  2. ClipSize=500
  3. ReloadTime=5
  4. Firerate=.0000001
  5. MinSpread=2
  6. MaxSpread=3
  7. SpreadRate=0
  8. BaseDamage=30
  9. automatic=true
  10. burst=false
  11. shot=false --Chaingun
  12. BarrlePos=Vector3.new(0,0,0)
  13. Cursors={"http://www.roblox.com/asset/?id=51252603"}
  14. ReloadCursor="http://www.roblox.com/asset/?id=51252608"
  15.  
  16. barrel_1 = script.Parent:findFirstChild("barrelpos1") or script.Parent.Handle
  17. barrel_2 = script.Parent:findFirstChild("barrelpos2") or script.Parent.Handle
  18. double = false --Double Wielded
  19. doublemode = 1 -- 1 is alternating, 2 is both
  20.  
  21. if not game.Lighting:findFirstChild("BulletTexture") then
  22. p = Instance.new("Part")
  23. p.Parent = game.Lighting
  24. p.Name = "BulletTexture"
  25. p.CanCollide = false
  26. p.formFactor = "Custom"
  27. p.Size = Vector3.new(1,0.1,1)
  28. p.Transparency = 1
  29. g = Instance.new("SpecialMesh")
  30. g.Parent = p
  31. end
  32.  
  33. -------------------------------------
  34. Tool = script.Parent
  35.  
  36. p = Instance.new("Part")
  37. p.Parent = game.Lighting
  38. p.Name = "BulletTexture"
  39. p.CanCollide = false
  40. p.formFactor = "Custom"
  41. p.Size = Vector3.new(1,0.1,1)
  42. p.Transparency = 1
  43. g = Instance.new("SpecialMesh")
  44. g.Parent = p
  45.  
  46.  
  47. GuiEffect = "Sine"
  48.  
  49. --[[Sine slows down as it nears,
  50. Bounce overshoots then eases back,
  51. Linear is smooth constant movement,
  52. and others which amplify the magnitude of the effects
  53. (EX: Quad slows down later than Sine,
  54. Elastic overshoots goal a few times.)]]
  55.  
  56.  
  57. -------------------------------------
  58.  
  59. Front = {
  60. r = 255,
  61. g = 255,
  62. b = 255}
  63. Back = {
  64. r = 0,
  65. g = 0,
  66. b = 0,
  67. Size = UDim2.new(.01,0,-.3,0),
  68. Position = UDim2.new(.95,0,.6,0)}
  69.  
  70. local a = Instance.new("ScreenGui")
  71. local b = Instance.new("Frame",a)
  72. local c = Instance.new("Frame",b)
  73. b.Name = "back"
  74. c.Name = "front"
  75. c.BackgroundColor3 = Color3.new(Front.r/255,Front.g/255,Front.b/255)
  76. b.BackgroundColor3 = Color3.new(Back.r/255,Back.g/255,Back.b/255)
  77. b.Size = Back.Size
  78. b.Position = Back.Position
  79. c.Size = UDim2.new(.5,0,-1,0)
  80. c.Position = UDim2.new(.25,0,01,0)
  81. -------------------------------------
  82. equiped=false
  83. dw = false
  84. sp=script.Parent
  85. RayLength=250
  86. Spread=.15
  87. enabled=true
  88. reloading=false
  89. down=false
  90. r=game:service("RunService")
  91. last=0
  92. last2=0
  93. last3=0
  94. last4=0
  95. last5=0
  96. last6=0
  97. UseDouble = false
  98. Bullet=Instance.new("Part")
  99. Bullet.Name="Bullet"
  100. Bullet.BrickColor=BrickColor.new("Mid gray")
  101. Bullet.Anchored=true
  102. Bullet.CanCollide=false
  103. Bullet.Locked=true
  104. Bullet.Size=Vector3.new(1,1,1)
  105. Bullet.Transparency=.45
  106. Bullet.formFactor=0
  107. Bullet.TopSurface=0
  108. Bullet.BottomSurface=0
  109. mesh=Instance.new("SpecialMesh")
  110. mesh.Parent=Bullet
  111. mesh.MeshType="Brick"
  112. mesh.Name="Mesh"
  113. mesh.Scale=Vector3.new(.15,.15,1)
  114.  
  115.  
  116. function check()
  117. sp.Name=ToolName.."-("..tostring(sp.Ammo.Value)..")"
  118. end
  119.  
  120. function computeDirection(vec)
  121. return vec.unit
  122. end
  123.  
  124. -----------------------------------------------------Raycasting functions
  125.  
  126. function raycursive(start,dir,ignore)
  127. newdir = (start+dir)-start
  128. local a,b = workspace:findPartOnRay(Ray.new(start,newdir.unit*999.999),ignore)
  129. if a then
  130. if not a.CanCollide and (a.Name ~= "Left Arm" and a.Name ~= "Left Leg" and a.Name ~= "Right Arm" and a.Name ~= "Right Leg") then
  131. return raycursive(b,dir,a)
  132. else
  133. return a,b
  134. end
  135. else
  136. return a,b
  137. end
  138. end
  139. -------------------------------------
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146. function tagHumanoid(humanoid)
  147. local plr=game.Players:playerFromCharacter(sp.Parent)
  148. if plr~=nil then
  149. local tag=Instance.new("ObjectValue")
  150. tag.Value=plr
  151. tag.Name="creator"
  152. tag.Parent=humanoid
  153. delay(2,function()
  154. if tag~=nil then
  155. tag.Parent=nil
  156. end
  157. end)
  158. end
  159. end
  160.  
  161.  
  162. function reload(mouse)
  163. reloading=true
  164. mouse.Icon=ReloadCursor
  165. local bulletshow = game.Players.LocalPlayer.PlayerGui:findFirstChild("BulletShow")
  166. if bulletshow then
  167. btload = (ClipSize-sp.Ammo.Value)/ClipSize
  168. btloadtime = btload*ReloadTime
  169. bulletshow.back.front:TweenSize(UDim2.new(.5,0,-1,0),out,GuiEffect,btloadtime)
  170. end
  171. while sp.Ammo.Value<ClipSize and reloading and enabled do
  172. wait(ReloadTime/ClipSize)
  173. if reloading then
  174. sp.Ammo.Value=sp.Ammo.Value+1
  175. check()
  176. else
  177. break
  178. end
  179. end
  180. check()
  181. mouse.Icon=Cursors[1]
  182. reloading=false
  183. end
  184.  
  185. function onKeyDown(key,mouse)
  186. key=key:lower()
  187. if key=="r" and not reloading then
  188. Tool.Handle.Reload:Play()
  189. reload(mouse)
  190. --[[elseif key == "f" and not reloading then
  191. if double then
  192. if doublemode == 2 then
  193. Firerate = Firerate * (2 ^ -1)
  194. doublemode = 1
  195. else
  196. Firerate = Firerate * 2
  197. doublemode = 2
  198. end
  199. end]]
  200. end
  201. end
  202.  
  203. function movecframe(p,pos)
  204. p.Parent=game.Lighting
  205. p.Position=pos
  206. p.Parent=game.Workspace
  207. end
  208.  
  209.  
  210. function fire(aim)
  211. sp.Handle.Fire:Play()
  212. local bulletshow = game.Players.LocalPlayer.PlayerGui:findFirstChild("BulletShow")
  213. if bulletshow then
  214. bulletshow.back.front:TweenSize(UDim2.new(.5,0,-tonumber(sp.Ammo.Value)/ClipSize,0),out,GuiEffect,Firerate)
  215. end
  216. t=r.Stepped:wait()
  217. last6=last5
  218. last5=last4
  219. last4=last3
  220. last3=last2
  221. last2=last
  222. last=t
  223.  
  224. local bullet=Bullet:clone()
  225. local bullet2 = Bullet:clone()
  226. local bt2=game.Lighting.BulletTexture:clone()
  227. bt2.BrickColor=BrickColor.new("Bright red")
  228. bt2.Mesh.Scale=Vector3.new(.5,.5,2)
  229. local totalDist=0
  230. Lengthdist=-RayLength/.5
  231. startpoint=barrel_1.CFrame.p
  232. startpoint2 = barrel_2.CFrame.p
  233. if double then
  234. if doublemode == 1 then
  235. if UseDouble then
  236. startpoint=barrel_2.CFrame.p
  237. else
  238. startpoint=barrel_1.CFrame.p
  239. end
  240. end
  241. end
  242. local dir=(aim)-startpoint
  243. local dir2 = (aim)-startpoint2
  244. dir=dir.unit
  245. dir2 = dir2.unit
  246. local cfrm=CFrame.new(startpoint, dir+startpoint)
  247. local cfrm2 = CFrame.new(startpoint2,dir2+startpoint2)
  248. local hit,pos=raycursive(startpoint, cfrm.lookVector * 999)
  249. bullet.Parent=game.Workspace
  250. if double then
  251. bullet2.Parent = workspace
  252. end
  253. bt2.Parent=game.Workspace
  254. if hit~=nil then
  255. local humanoid=hit.Parent:FindFirstChild("Humanoid")
  256. if humanoid~=nil then
  257. local damage=math.random(BaseDamage-(BaseDamage*.25),BaseDamage+(BaseDamage*.25))
  258. if hit.Name=="Head" then
  259. damage=damage*1.25
  260. elseif hit.Name=="Torso" then
  261. else
  262. damage=damage*.75
  263. end
  264. if humanoid.Health>0 then
  265. local eplr=game.Players:playerFromCharacter(humanoid.Parent)
  266. local plr=game.Players:playerFromCharacter(sp.Parent)
  267. if eplr~=nil and plr~=nil then
  268. -- if eplr.TeamColor~=plr.TeamColor or eplr.Neutral or plr.Neutral then
  269. tagHumanoid(humanoid)
  270. humanoid:TakeDamage(damage)
  271. -- end
  272. else
  273. tagHumanoid(humanoid)
  274. humanoid:TakeDamage(damage)
  275. end
  276. end
  277. end
  278. if (hit.Parent:findFirstChild("Hit")) then
  279. hit.Parent.Health.Value = hit.Parent.Health.Value - BaseDamage/3
  280. end
  281. distance=(startpoint-pos).magnitude
  282. distance2 = (startpoint2-pos).magnitude
  283. bullet.CFrame=cfrm*CFrame.new(0,0,-distance/2)
  284. bullet.Mesh.Scale=Vector3.new(.15,.15,distance)
  285. print(bullet.Parent,"shot")
  286. if doublemode == 2 and double then
  287. bullet2.CFrame = cfrm2*CFrame.new(0,0,-distance2/2)
  288. bullet2.Mesh.Scale = Vector3.new(.15,.15,distance2)
  289. print(bullet.CFrame.p,bullet2.CFrame.p)
  290. end
  291. else
  292. bullet.CFrame=cfrm*CFrame.new(0,0,-RayLength/2)
  293. bullet.Mesh.Scale=Vector3.new(.15,.15,RayLength)
  294. if doublemode == 2 and double then
  295. bullet2.CFrame = cfrm2*CFrame.new(0,0,-RayLength/2)
  296. bullet2.Mesh.Scale = Vector3.new(.15,.15,RayLength)
  297. end
  298. end
  299. if pos~=nil then
  300. bt2.CFrame=bullet.CFrame
  301. movecframe(bt2,pos)
  302. end
  303. local deb=game:FindFirstChild("Debris")
  304. if deb==nil then
  305. local debris=Instance.new("Debris")
  306. debris.Parent=game
  307. end
  308. check()
  309. game.Debris:AddItem(bullet,.05)
  310. game.Debris:AddItem(bullet2,.05)
  311. game.Debris:AddItem(bt2,.5)
  312. end
  313.  
  314. function onButton1Up(mouse)
  315. down=false
  316. end
  317.  
  318. function onButton1Down(mouse)
  319. h=sp.Parent:FindFirstChild("Humanoid")
  320. if not enabled or reloading or down or h==nil then
  321. return
  322. end
  323. if sp.Ammo.Value>0 and h.Health>0 then
  324. --[[if sp.Ammo.Value<=0 then
  325. if not reloading then
  326. reload(mouse)
  327. end
  328. return
  329. end]]
  330. down=true
  331. enabled=false
  332. while down do
  333. if sp.Ammo.Value<=0 then
  334. break
  335. end
  336. if burst then
  337. local startpoint=barrel_1.CFrame.p
  338. local mag=(mouse.Hit.p-startpoint).magnitude
  339. local rndm=Vector3.new(math.random(-(Spread/10)*mag,(Spread/10)*mag),math.random(-(Spread/10)*mag,(Spread/10)*mag),math.random(-(Spread/10)*mag,(Spread/10)*mag))
  340. fire(mouse.Hit.p+rndm)
  341. sp.Ammo.Value=sp.Ammo.Value-1
  342. if sp.Ammo.Value<=0 then
  343. break
  344. end
  345. wait(.05)
  346. local startpoint=barrel_1.CFrame.p
  347. local mag2=((mouse.Hit.p+rndm)-startpoint).magnitude
  348. local rndm2=Vector3.new(math.random(-(.1/10)*mag2,(.1/10)*mag2),math.random(-(.1/10)*mag2,(.1/10)*mag2),math.random(-(.1/10)*mag2,(.1/10)*mag2))
  349. fire(mouse.Hit.p+rndm+rndm2)
  350. sp.Ammo.Value=sp.Ammo.Value-1
  351. if sp.Ammo.Value<=0 then
  352. break
  353. end
  354. wait(.05)
  355. fire(mouse.Hit.p+rndm+rndm2+rndm2)
  356. sp.Ammo.Value=sp.Ammo.Value-1
  357. elseif shot then
  358. sp.Ammo.Value=sp.Ammo.Value-1
  359. local startpoint=barrel_1.CFrame.p
  360. local mag=(mouse.Hit.p-startpoint).magnitude
  361. local rndm=Vector3.new(math.random(-(Spread/10)*mag,(Spread/10)*mag),math.random(-(Spread/10)*mag,(Spread/10)*mag),math.random(-(Spread/10)*mag,(Spread/10)*mag))
  362. fire(mouse.Hit.p+rndm)
  363. local mag2=((mouse.Hit.p+rndm)-startpoint).magnitude
  364. local rndm2=Vector3.new(math.random(-(.2/10)*mag2,(.2/10)*mag2),math.random(-(.2/10)*mag2,(.2/10)*mag2),math.random(-(.2/10)*mag2,(.2/10)*mag2))
  365. fire(mouse.Hit.p+rndm+rndm2)
  366. local rndm3=Vector3.new(math.random(-(.2/10)*mag2,(.2/10)*mag2),math.random(-(.2/10)*mag2,(.2/10)*mag2),math.random(-(.2/10)*mag2,(.2/10)*mag2))
  367. fire(mouse.Hit.p+rndm+rndm3)
  368. local rndm4=Vector3.new(math.random(-(.2/10)*mag2,(.2/10)*mag2),math.random(-(.2/10)*mag2,(.2/10)*mag2),math.random(-(.2/10)*mag2,(.2/10)*mag2))
  369. fire(mouse.Hit.p+rndm+rndm4)
  370. else
  371. sp.Ammo.Value=sp.Ammo.Value-1
  372. local startpoint=barrel_1.CFrame.p
  373. local mag=(mouse.Hit.p-startpoint).magnitude
  374. local rndm=Vector3.new(math.random(-(Spread/10)*mag,(Spread/10)*mag),math.random(-(Spread/10)*mag,(Spread/10)*mag),math.random(-(Spread/10)*mag,(Spread/10)*mag))
  375. fire(mouse.Hit.p+rndm)
  376. end
  377. wait(Firerate)
  378. if not automatic then
  379. break
  380. end
  381. end
  382. enabled=true
  383. else
  384. wait()
  385. end
  386. end
  387.  
  388. function onEquippedLocal(mouse)
  389. Bulletzzz = a:clone()
  390. Bulletzzz.Name = "BulletShow"
  391. Bulletzzz.Parent = game.Players.LocalPlayer.PlayerGui
  392. Bulletzzz.back.front.Size = UDim2.new(.5,0,-(script.Parent.Ammo.Value/ClipSize),0)
  393. if mouse==nil then
  394. print("Mouse not found")
  395. return
  396. end
  397. mouse.Icon=Cursors[1]
  398. mouse.KeyDown:connect(function(key) onKeyDown(key,mouse) end)
  399. mouse.Button1Down:connect(function() onButton1Down(mouse) end)
  400. mouse.Button1Up:connect(function() onButton1Up(mouse) end)
  401. check()
  402. equiped=true
  403. if #Cursors>1 then
  404. while equiped do
  405. t=r.Stepped:wait()
  406. local action=sp.Parent:FindFirstChild("Pose")
  407. if action~=nil then
  408. if sp.Parent.Pose.Value=="Standing" then
  409. Spread=MinSpread
  410. else
  411. Spread=MinSpread+((4/10)*(MaxSpread-MinSpread))
  412. end
  413. else
  414. Spread=MinSpread
  415. end
  416. if t-last<SpreadRate then
  417. Spread=Spread+.1*(MaxSpread-MinSpread)
  418. end
  419. if t-last2<SpreadRate then
  420. Spread=Spread+.1*(MaxSpread-MinSpread)
  421. end
  422. if t-last3<SpreadRate then
  423. Spread=Spread+.1*(MaxSpread-MinSpread)
  424. end
  425. if t-last4<SpreadRate then
  426. Spread=Spread+.1*(MaxSpread-MinSpread)
  427. end
  428. if t-last5<SpreadRate then
  429. Spread=Spread+.1*(MaxSpread-MinSpread)
  430. end
  431. if t-last6<SpreadRate then
  432. Spread=Spread+.1*(MaxSpread-MinSpread)
  433. end
  434. if not reloading then
  435. local percent=(Spread-MinSpread)/(MaxSpread-MinSpread)
  436. for i=0,#Cursors-1 do
  437. if percent>(i/(#Cursors-1))-((1/(#Cursors-1))/2) and percent<(i/(#Cursors-1))+((1/(#Cursors-1))/2) then
  438. mouse.Icon=Cursors[i+1]
  439. end
  440. end
  441. end
  442. wait(Firerate*.9)
  443. end
  444. end
  445. end
  446. function onUnequippedLocal(mouse)
  447. equiped=false
  448. reloading=false
  449. if game.Players.LocalPlayer.PlayerGui:findFirstChild("BulletShow") then
  450. game.Players.LocalPlayer.PlayerGui.BulletShow:remove()
  451. end
  452. end
  453. sp.Equipped:connect(onEquippedLocal)
  454. sp.Unequipped:connect(onUnequippedLocal)
  455. check()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement