Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------Gun info
- ToolName="Assault Rifle"
- ClipSize=30
- ReloadTime=3
- Firerate=.16
- MinSpread=0.3
- MaxSpread=0.4
- SpreadRate=0
- BaseDamage=35
- automatic=true
- burst=false
- shot=false --Shotgun
- BarrlePos=Vector3.new(0,0,0)
- Cursors={"rbxasset://textures\\GunCursor.png"}
- ReloadCursor="rbxasset://textures\\GunWaitCursor.png"
- barrel_1 = script.Parent:findFirstChild("IHackShootingGames") or script.Parent.Handle
- barrel_2 = script.Parent:findFirstChild("IHackShootingGames") or script.Parent.Handle
- double = false --Double Wielded
- doublemode = 1 -- 1 is alternating, 2 is both
- if not game.Lighting:findFirstChild("BulletTexture") then
- p = Instance.new("Part")
- p.Parent = game.Lighting
- p.Name = "BulletTexture"
- p.CanCollide = false
- p.formFactor = "Custom"
- p.Size = Vector3.new(1,0.1,1)
- p.Transparency = 1
- g = Instance.new("SpecialMesh")
- g.Parent = p
- end
- -------------------------------------
- Tool = script.Parent
- p = Instance.new("Part")
- p.Parent = game.Lighting
- p.Name = "BulletTexture"
- p.CanCollide = false
- p.formFactor = "Custom"
- p.Size = Vector3.new(1,0.1,1)
- p.Transparency = 1
- g = Instance.new("SpecialMesh")
- g.Parent = p
- GuiEffect = "Linear"
- --[[Sine slows down as it nears,
- Bounce overshoots then eases back,
- Linear is smooth constant movement,
- and others which amplify the magnitude of the effects
- (EX: Quad slows down later than Sine,
- Elastic overshoots goal a few times.)]]
- -------------------------------------
- Front = {
- r = 255,
- g = 255,
- b = 255}
- Back = {
- r = 0,
- g = 0,
- b = 0,
- Size = UDim2.new(.01,0,-.3,0),
- Position = UDim2.new(.95,0,.6,0)}
- local a = Instance.new("ScreenGui")
- local b = Instance.new("Frame",a)
- local c = Instance.new("Frame",b)
- b.Name = "back"
- c.Name = "front"
- c.BackgroundColor3 = Color3.new(Front.r/255,Front.g/255,Front.b/255)
- b.BackgroundColor3 = Color3.new(Back.r/255,Back.g/255,Back.b/255)
- b.Size = Back.Size
- b.Position = Back.Position
- c.Size = UDim2.new(.5,0,-1,0)
- c.Position = UDim2.new(.25,0,01,0)
- -------------------------------------
- equiped=false
- dw = false
- sp=script.Parent
- RayLength=1000
- Spread=.15
- enabled=true
- reloading=false
- down=false
- r=game:service("RunService")
- last=0
- last2=0
- last3=0
- last4=0
- last5=0
- last6=0
- UseDouble = false
- Bullet=Instance.new("Part")
- Bullet.Name="Bullet"
- Bullet.BrickColor=BrickColor.new("Bright red")
- Bullet.Anchored=true
- Bullet.CanCollide=false
- Bullet.Locked=true
- Bullet.Size=Vector3.new(1,1,1)
- Bullet.Transparency=.45
- Bullet.formFactor=0
- Bullet.TopSurface=0
- Bullet.BottomSurface=0
- mesh=Instance.new("SpecialMesh")
- mesh.Parent=Bullet
- mesh.MeshType="Brick"
- mesh.Name="Mesh"
- mesh.Scale=Vector3.new(.15,.15,1)
- function check()
- sp.Name=ToolName.."-("..tostring(sp.Ammo.Value)..")"
- end
- function computeDirection(vec)
- return vec.unit
- end
- -----------------------------------------------------Raycasting functions
- function raycursive(start,dir,ignore)
- newdir = (start+dir)-start
- local a,b = workspace:findPartOnRay(Ray.new(start,newdir.unit*999.999),ignore)
- if a then
- 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
- return raycursive(b,dir,a)
- else
- return a,b
- end
- else
- return a,b
- end
- end
- -------------------------------------
- function tagHumanoid(humanoid)
- local plr=game.Players:playerFromCharacter(sp.Parent)
- if plr~=nil then
- local tag=Instance.new("ObjectValue")
- tag.Value=plr
- tag.Name="creator"
- tag.Parent=humanoid
- delay(2,function()
- if tag~=nil then
- tag.Parent=nil
- end
- end)
- end
- end
- function reload(mouse)
- reloading=true
- mouse.Icon=ReloadCursor
- local bulletshow = game.Players.LocalPlayer.PlayerGui:findFirstChild("BulletShow")
- if bulletshow then
- btload = (ClipSize-sp.Ammo.Value)/ClipSize
- btloadtime = btload*ReloadTime
- bulletshow.back.front:TweenSize(UDim2.new(.5,0,-1,0),out,GuiEffect,btloadtime)
- end
- while sp.Ammo.Value<ClipSize and reloading and enabled do
- wait(ReloadTime/ClipSize)
- if reloading then
- sp.Ammo.Value=sp.Ammo.Value+1
- check()
- else
- break
- end
- end
- check()
- mouse.Icon=Cursors[1]
- reloading=false
- end
- function onKeyDown(key,mouse)
- key=key:lower()
- if key=="r" and not reloading then
- Tool.Handle.Reload:Play()
- reload(mouse)
- --[[elseif key == "f" and not reloading then
- if double then
- if doublemode == 2 then
- Firerate = Firerate * (2 ^ -1)
- doublemode = 1
- else
- Firerate = Firerate * 2
- doublemode = 2
- end
- end]]
- end
- end
- function movecframe(p,pos)
- p.Parent=game.Lighting
- p.Position=pos
- p.Parent=game.Workspace
- end
- function fire(aim)
- sp.Handle.Fire:Play()
- local bulletshow = game.Players.LocalPlayer.PlayerGui:findFirstChild("BulletShow")
- if bulletshow then
- bulletshow.back.front:TweenSize(UDim2.new(.5,0,-tonumber(sp.Ammo.Value)/ClipSize,0),out,GuiEffect,Firerate)
- end
- t=r.Stepped:wait()
- last6=last5
- last5=last4
- last4=last3
- last3=last2
- last2=last
- last=t
- local bullet=Bullet:clone()
- local bullet2 = Bullet:clone()
- local bt2=game.Lighting.BulletTexture:clone()
- bt2.BrickColor=BrickColor.new("Bright red")
- bt2.Mesh.Scale=Vector3.new(.5,.5,2)
- local totalDist=0
- Lengthdist=-RayLength/.5
- startpoint=barrel_1.CFrame.p
- startpoint2 = barrel_2.CFrame.p
- if double then
- if doublemode == 1 then
- if UseDouble then
- startpoint=barrel_2.CFrame.p
- else
- startpoint=barrel_1.CFrame.p
- end
- end
- end
- local dir=(aim)-startpoint
- local dir2 = (aim)-startpoint2
- dir=dir.unit
- dir2 = dir2.unit
- local cfrm=CFrame.new(startpoint, dir+startpoint)
- local cfrm2 = CFrame.new(startpoint2,dir2+startpoint2)
- local hit,pos=raycursive(startpoint, cfrm.lookVector * 999)
- bullet.Parent=game.Workspace
- if double then
- bullet2.Parent = workspace
- end
- bt2.Parent=game.Workspace
- if hit~=nil then
- local humanoid=hit.Parent:FindFirstChild("Humanoid")
- if humanoid~=nil then
- local damage=math.random(BaseDamage-(BaseDamage*.25),BaseDamage+(BaseDamage*.25))
- if hit.Name=="Head" then
- damage=damage*1.25
- elseif hit.Name=="Torso" then
- else
- damage=damage*.75
- end
- if humanoid.Health>0 then
- local eplr=game.Players:playerFromCharacter(humanoid.Parent)
- local plr=game.Players:playerFromCharacter(sp.Parent)
- if eplr~=nil and plr~=nil then
- -- if eplr.TeamColor~=plr.TeamColor or eplr.Neutral or plr.Neutral then
- tagHumanoid(humanoid)
- humanoid:TakeDamage(damage)
- -- end
- else
- tagHumanoid(humanoid)
- humanoid:TakeDamage(damage)
- end
- end
- end
- if (hit.Parent:findFirstChild("Hit")) then
- hit.Parent.Health.Value = hit.Parent.Health.Value - BaseDamage/3
- end
- distance=(startpoint-pos).magnitude
- distance2 = (startpoint2-pos).magnitude
- bullet.CFrame=cfrm*CFrame.new(0,0,-distance/2)
- bullet.Mesh.Scale=Vector3.new(.15,.15,distance)
- print(bullet.Parent,"shot")
- if doublemode == 2 and double then
- bullet2.CFrame = cfrm2*CFrame.new(0,0,-distance2/2)
- bullet2.Mesh.Scale = Vector3.new(.15,.15,distance2)
- print(bullet.CFrame.p,bullet2.CFrame.p)
- end
- else
- bullet.CFrame=cfrm*CFrame.new(0,0,-RayLength/2)
- bullet.Mesh.Scale=Vector3.new(.15,.15,RayLength)
- if doublemode == 2 and double then
- bullet2.CFrame = cfrm2*CFrame.new(0,0,-RayLength/2)
- bullet2.Mesh.Scale = Vector3.new(.15,.15,RayLength)
- end
- end
- if pos~=nil then
- bt2.CFrame=bullet.CFrame
- movecframe(bt2,pos)
- end
- local deb=game:FindFirstChild("Debris")
- if deb==nil then
- local debris=Instance.new("Debris")
- debris.Parent=game
- end
- check()
- game.Debris:AddItem(bullet,.05)
- game.Debris:AddItem(bullet2,.05)
- game.Debris:AddItem(bt2,.5)
- end
- function onButton1Up(mouse)
- down=false
- end
- function onButton1Down(mouse)
- h=sp.Parent:FindFirstChild("Humanoid")
- if not enabled or reloading or down or h==nil then
- return
- end
- if sp.Ammo.Value>0 and h.Health>0 then
- --[[if sp.Ammo.Value<=0 then
- if not reloading then
- reload(mouse)
- end
- return
- end]]
- down=true
- enabled=false
- while down do
- if sp.Ammo.Value<=0 then
- break
- end
- if burst then
- local startpoint=barrel_1.CFrame.p
- local mag=(mouse.Hit.p-startpoint).magnitude
- 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))
- fire(mouse.Hit.p+rndm)
- sp.Ammo.Value=sp.Ammo.Value-1
- if sp.Ammo.Value<=0 then
- break
- end
- wait(.05)
- local startpoint=barrel_1.CFrame.p
- local mag2=((mouse.Hit.p+rndm)-startpoint).magnitude
- 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))
- fire(mouse.Hit.p+rndm+rndm2)
- sp.Ammo.Value=sp.Ammo.Value-1
- if sp.Ammo.Value<=0 then
- break
- end
- wait(.05)
- fire(mouse.Hit.p+rndm+rndm2+rndm2)
- sp.Ammo.Value=sp.Ammo.Value-1
- elseif shot then
- sp.Ammo.Value=sp.Ammo.Value-1
- local startpoint=barrel_1.CFrame.p
- local mag=(mouse.Hit.p-startpoint).magnitude
- 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))
- fire(mouse.Hit.p+rndm)
- local mag2=((mouse.Hit.p+rndm)-startpoint).magnitude
- 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))
- fire(mouse.Hit.p+rndm+rndm2)
- 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))
- fire(mouse.Hit.p+rndm+rndm3)
- 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))
- fire(mouse.Hit.p+rndm+rndm4)
- else
- sp.Ammo.Value=sp.Ammo.Value-1
- local startpoint=barrel_1.CFrame.p
- local mag=(mouse.Hit.p-startpoint).magnitude
- 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))
- fire(mouse.Hit.p+rndm)
- end
- wait(Firerate)
- if not automatic then
- break
- end
- end
- enabled=true
- else
- wait()
- end
- end
- function onEquippedLocal(mouse)
- Bulletzzz = a:clone()
- Bulletzzz.Name = "BulletShow"
- Bulletzzz.Parent = game.Players.LocalPlayer.PlayerGui
- Bulletzzz.back.front.Size = UDim2.new(.5,0,-(script.Parent.Ammo.Value/ClipSize),0)
- if mouse==nil then
- print("Mouse not found")
- return
- end
- mouse.Icon=Cursors[1]
- mouse.KeyDown:connect(function(key) onKeyDown(key,mouse) end)
- mouse.Button1Down:connect(function() onButton1Down(mouse) end)
- mouse.Button1Up:connect(function() onButton1Up(mouse) end)
- check()
- equiped=true
- if #Cursors>1 then
- while equiped do
- t=r.Stepped:wait()
- local action=sp.Parent:FindFirstChild("Pose")
- if action~=nil then
- if sp.Parent.Pose.Value=="Standing" then
- Spread=MinSpread
- else
- Spread=MinSpread+((4/10)*(MaxSpread-MinSpread))
- end
- else
- Spread=MinSpread
- end
- if t-last<SpreadRate then
- Spread=Spread+.1*(MaxSpread-MinSpread)
- end
- if t-last2<SpreadRate then
- Spread=Spread+.1*(MaxSpread-MinSpread)
- end
- if t-last3<SpreadRate then
- Spread=Spread+.1*(MaxSpread-MinSpread)
- end
- if t-last4<SpreadRate then
- Spread=Spread+.1*(MaxSpread-MinSpread)
- end
- if t-last5<SpreadRate then
- Spread=Spread+.1*(MaxSpread-MinSpread)
- end
- if t-last6<SpreadRate then
- Spread=Spread+.1*(MaxSpread-MinSpread)
- end
- if not reloading then
- local percent=(Spread-MinSpread)/(MaxSpread-MinSpread)
- for i=0,#Cursors-1 do
- if percent>(i/(#Cursors-1))-((1/(#Cursors-1))/2) and percent<(i/(#Cursors-1))+((1/(#Cursors-1))/2) then
- mouse.Icon=Cursors[i+1]
- end
- end
- end
- wait(Firerate*.9)
- end
- end
- end
- function onUnequippedLocal(mouse)
- equiped=false
- reloading=false
- if game.Players.LocalPlayer.PlayerGui:findFirstChild("BulletShow") then
- game.Players.LocalPlayer.PlayerGui.BulletShow:remove()
- end
- end
- sp.Equipped:connect(onEquippedLocal)
- sp.Unequipped:connect(onUnequippedLocal)
- check()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement