Advertisement
IHackShootingGames

Gunnn

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