Second one part two:
local KickSide = (
(
{
CurrentRecoil * (RAND(1, 5, 1) / 150);
CurrentRecoil * (RAND(1, 5, 1) / -150)
}
)[math.random(1, 2)]
) * StanceSway
local KickBack = CurrentRecoil * StanceSway * 0.3
local KickUp = RAD(90 + (CurrentRecoil * RAND(1.3, 1.4, 0.01) * StanceSway))
TweenJoint(AnimWeld, CF(KickSide, 1, -KickBack), CFANG(KickUp - RAD(90), 0, 0), Linear, 1 / 12)
if FlashFX then FlashFX.Enabled = true end
if FlashGui then
FlashGui.Enabled = true
FlashGui.Label.Rotation = RAND(0, 360)
end
delay(1 / 30, function()
if Idleing and (not Walking) and (not Aimed) then
Gui_Clone.CrossHair.Box:TweenSizeAndPosition(
UDim2.new(0, 70, 0, 70),
UDim2.new(0, -35, 0, -35),
"Out", "Linear", S.AimSpeed, (not Aimed)
)
end
if (not Aiming) and (not RunTween) then
TweenJoint(AnimWeld, CF(0, 1, 0), CF(), Linear, 0.15)
end
if FlashFX then FlashFX.Enabled = false end
if FlashGui then FlashGui.Enabled = false end
end)
end
function MarkHit()
spawn(function()
if Gui_Clone:IsDescendantOf(game) then
Gui_Clone.HitMarker.Visible = true
local StartMark = tick()
LastMark = StartMark
wait(0.5)
if LastMark <= StartMark then
Gui_Clone.HitMarker.Visible = false
end
end
end)
end
--------------------[ ADS FUNCTIONS ]-------------------------------------------------
function AimGun()
if (Camera.CoordinateFrame.p - Camera.Focus.p).magnitude > 1 or Reloading or Knifing or ThrowingGrenade then return end
local Scope = Gui_Clone:WaitForChild("Scope"):WaitForChild("Img")
local Steady = Gui_Clone:WaitForChild("Scope"):WaitForChild("Steady")
Aimed = true
Aiming = true
CurrentRecoil = S.Recoil.Aimed
CurrentSpread = S.Spread.Aimed
Gui_Clone.CrossHair.Box:TweenSizeAndPosition(
UDim2.new(),
UDim2.new(),
Enum.EasingDirection.Out,
Enum.EasingStyle.Sine,
S.AimAnimation and S.AimSpeed or 0,
true
)
if S.AimAnimation then
local CurrentFOV = Camera.FieldOfView
local CurrentCameraOffset = Humanoid.CameraOffset
local CurrentTrans = Scope.BackgroundTransparency
TweenJoint(LWeld, ArmC0[1], S.ArmC1_Aimed.Left, Sine, S.AimSpeed)
TweenJoint(RWeld, ArmC0[2], S.ArmC1_Aimed.Right, Sine, S.AimSpeed)
TweenJoint(AnimWeld, CF(0, 1, 0), CF(), Sine, S.AimSpeed)
TweenJoint(Grip, Grip.C0, Aimed_GripCF, Sine, S.AimSpeed)
TweenJoint(LWeld2, CF(), CF(), Sine, S.AimSpeed)
TweenJoint(RWeld2, CF(), CF(), Sine, S.AimSpeed)
local X = 0
while true do
local NewX = X + 1.5 / S.AimSpeed
X = (NewX > 90 and 90 or NewX)
if (not Aimed) then break end
if (not Selected) then break end
local Alpha = 1 - COS(RAD(X))
Camera.FieldOfView = NumLerp(CurrentFOV, S.MaxZoom, Alpha)
if S.GuiScope then
Scope.BackgroundTransparency = NumLerp(CurrentTrans, 0, Alpha)
end
if X == 90 then break end
RS:wait()
end
else
LWeld.C0, LWeld.C1 = ArmC0[1], S.ArmC1_Aimed.Left
RWeld.C0, RWeld.C1 = ArmC0[2], S.ArmC1_Aimed.Right
AnimWeld.C0 = CF(0, 1, 0)
Grip.C1 = Aimed_GripCF
LWeld2.C1, RWeld2.C1 = CF(), CF()
Camera.FieldOfView = S.MaxZoom
end
Aiming = (not Aimed)
if (not Aiming) and S.GuiScope then
spawn(function()
Steady.Visible = true
Scope.BackgroundTransparency = 1
Scope.ImageTransparency = 0
local Gun_Model = Instance.new("Model")
Gun_Model.Name = "Gun_Model"
for _, Obj in pairs(Gun:GetChildren()) do
if Obj:IsA("BasePart") then
local ObjClone = Obj:Clone()
ObjClone.Parent = Gun_Model
local W = Instance.new("Weld")
W.Part0 = ObjClone
W.Part1 = Obj
W.Parent = ObjClone
local PrevTrans = Instance.new("NumberValue")
PrevTrans.Name = "PrevTrans"
PrevTrans.Value = Obj.Transparency
PrevTrans.Parent = Obj
Obj.Transparency = 1
end
end
Gun_Model.Parent = Character
end)
spawn(function()
while Aimed do
local Ang = (CameraSteady and 0 or (Idleing and AnimAng[2] or AnimAng[4]))
if CameraSway ~= 0 then
local OffsetX, OffsetY = 0, 0
if Idleing then
OffsetX = (RAD(COS(Ang * 5 * (CameraSway ^ 0.4))) / 40) * (CameraSway ^ 1.2) * StanceSway * S.ScopeSway
OffsetY = (RAD(COS(Ang * 2 * (CameraSway ^ 0.4))) / 40) * (CameraSway ^ 1.2) * StanceSway * S.ScopeSway
else
OffsetX = (RAD(COS(Ang * 3/2 * (CameraSway ^ 0.4))) / 25) * (CameraSway ^ 1.2) * StanceSway * S.ScopeSway
OffsetY = (RAD(COS(Ang * 3/5 * (CameraSway ^ 0.4))) / 25) * (CameraSway ^ 1.2) * StanceSway * S.ScopeSway
end
RotCamera(OffsetX, OffsetY)
end
RS:wait()
end
end)
end
end
function UnAimGun(Exception)
local Scope = Gui_Clone:WaitForChild("Scope"):WaitForChild("Img")
local Steady = Gui_Clone:WaitForChild("Scope"):WaitForChild("Steady")
if (not Exception) then
if (not Aimed) then return end
if (Reloading and Exception) or Knifing and (not ThrowingGrenade) then return end
CurrentRecoil = S.Recoil.Hipfire
CurrentSpread = ((Idleing and (not Walking)) and S.Spread.Hipfire or S.Spread.Walking)
if Walking and Aimed then
Gui_Clone.CrossHair.Box:TweenSizeAndPosition(
UDim2.new(0, 150, 0, 150),
UDim2.new(0, -75, 0, -75),
Enum.EasingDirection.Out,
Enum.EasingStyle.Linear,
S.AimAnimation and S.AimSpeed or 0,
true
)
elseif Idleing then
Gui_Clone.CrossHair.Box:TweenSizeAndPosition(
UDim2.new(0, 70, 0, 70),
UDim2.new(0, -35, 0, -35),
Enum.EasingDirection.Out,
Enum.EasingStyle.Linear,
S.AimAnimation and S.AimSpeed or 0,
true
)
end
Aimed = false
Aiming = true
if S.GuiScope then
spawn(function()
local Gun_Model = Character:FindFirstChild("Gun_Model")
if Gun_Model then
Gun_Model:Destroy()
end
for _, Obj in pairs(Gun:GetChildren()) do
if Obj:IsA("BasePart") then
local PrevTrans = Obj:FindFirstChild("PrevTrans")
Obj.Transparency = PrevTrans.Value
PrevTrans:Destroy()
end
end
end)
end
if S.AimAnimation then
local CurrentFOV = Camera.FieldOfView
local CurrentCameraOffset = Humanoid.CameraOffset
local CurrentTrans = (Scope.BackgroundTransparency == 1 and (S.GuiScope and 0 or 1) or Scope.BackgroundTransparency)
Scope.ImageTransparency = 1
Steady.Visible = false
TweenJoint(LWeld, ArmC0[1], S.ArmC1_UnAimed.Left, Sine, S.AimSpeed)
TweenJoint(RWeld, ArmC0[2], S.ArmC1_UnAimed.Right, Sine, S.AimSpeed)
TweenJoint(Grip, Grip.C0, CFANG(0, RAD(20), 0), Sine, S.AimSpeed)
if S.PlayerAnimations then
TweenJoint(LWeld2, CF(), CFANG(0, RAD(ArmTilt), 0), Sine, S.AimSpeed)
TweenJoint(RWeld2, CF(), CFANG(0, RAD(ArmTilt), 0), Sine, S.AimSpeed)
end
local X = 0
while true do
local NewX = X + 1.5 / S.AimSpeed
X = (NewX > 90 and 90 or NewX)
if Aimed then break end
if (not Selected) then break end
local Alpha = 1 - COS(RAD(X))
Camera.FieldOfView = NumLerp(CurrentFOV, 70, Alpha)
Scope.BackgroundTransparency = NumLerp(CurrentTrans, 1, Alpha)
if X == 90 then break end
RS:wait()
end
else
Scope.BackgroundTransparency = 1
Scope.ImageTransparency = 1
Steady.Visible = false
LWeld.C0, LWeld.C1 = ArmC0[1], S.ArmC1_UnAimed.Left
RWeld.C0, RWeld.C1 = ArmC0[2], S.ArmC1_UnAimed.Right
Grip.C1 = CFANG(0, RAD(20), 0)
LWeld2.C1, RWeld2.C1 = CFANG(0, RAD(ArmTilt), 0), CFANG(0, RAD(ArmTilt), 0)
Camera.FieldOfView = 70
end
Aiming = Aimed
else
if S.GuiScope then
spawn(function()
local Gun_Model = Character:FindFirstChild("Gun_Model")
if Gun_Model then
Gun_Model:Destroy()
end
for _, Obj in pairs(Gun:GetChildren()) do
if Obj:IsA("BasePart") then
local PrevTrans = Obj:FindFirstChild("PrevTrans")
Obj.Transparency = PrevTrans.Value
PrevTrans:Destroy()
end
end
end)
end
spawn(function()
Aimed = false
Aiming = false
CurrentRecoil = S.Recoil.Hipfire
CurrentSpread = ((Idleing and (not Walking)) and S.Spread.Hipfire or S.Spread.Walking)
if (not Walking) then
Gui_Clone.CrossHair.Box:TweenSizeAndPosition(
UDim2.new(0, 70, 0, 70),
UDim2.new(0, -35, 0, -35),
Enum.EasingDirection.Out,
Enum.EasingStyle.Linear,
S.AimAnimation and S.AimSpeed or 0,
true
)
else
Gui_Clone.CrossHair.Box:TweenSizeAndPosition(
UDim2.new(0, 150, 0, 150),
UDim2.new(0, -75, 0, -75),
Enum.EasingDirection.Out,
Enum.EasingStyle.Linear,
S.AimAnimation and S.AimSpeed or 0,
true
)
end
local CurrentFOV = Camera.FieldOfView
local CurrentCameraOffset = Humanoid.CameraOffset
local CurrentTrans = (Scope.BackgroundTransparency == 1 and (S.GuiScope and 0 or 1) or Scope.BackgroundTransparency)
Scope.ImageTransparency = 1
Steady.Visible = false
if LWeld:FindFirstChild("TweenCode") then LWeld.TweenCode:Destroy() end
if RWeld:FindFirstChild("TweenCode") then RWeld.TweenCode:Destroy() end
if Grip:FindFirstChild("TweenCode") then Grip.TweenCode:Destroy() end
if LWeld2:FindFirstChild("TweenCode") then LWeld2.TweenCode:Destroy() end
if RWeld2:FindFirstChild("TweenCode") then RWeld2.TweenCode:Destroy() end
if S.AimAnimation then
local X = 0
while true do
local NewX = X + 1.5 / S.AimSpeed
X = (NewX > 90 and 90 or NewX)
if Aimed then break end
if (not Selected) then break end
local Alpha = 1 - COS(RAD(X))
Camera.FieldOfView = NumLerp(CurrentFOV, 70, Alpha)
Scope.BackgroundTransparency = NumLerp(CurrentTrans, 1, Alpha)
if X == 90 then break end
RS:wait()
end
else
Scope.BackgroundTransparency = 1
Scope.ImageTransparency = 1
Steady.Visible = false
Camera.FieldOfView = 70
end
end)
end
end
--------------------[ TEXTURE CREATION FUNCTIONS ]------------------------------------
function CreateBullet(Direction)
local Origin = Gun.Main.CFrame.p
local BulletMass = S.BulletSize.X * S.BulletSize.Y * S.BulletSize.Z
local BulletCF = CF(Origin, Origin + Direction)
local Bullet = Instance.new("Part")
Bullet.BrickColor = S.BulletColor
Bullet.Name = "Bullet"
Bullet.CanCollide = false
Bullet.FormFactor = "Custom"
Bullet.Size = S.BulletSize
Bullet.BottomSurface = "Smooth"
Bullet.TopSurface = "Smooth"
local Mesh = Instance.new("BlockMesh")
Mesh.Scale = S.BulletMeshSize
Mesh.Parent = Bullet
local BF = Instance.new("BodyForce")
BF.force = VEC3(0, BulletMass * (196.2 - S.BulletDropPerSecond), 0)
BF.Parent = Bullet
Bullet.Parent = Gun_Ignore
Bullet.CFrame = BulletCF + Direction * 3
Bullet.Velocity = Direction * S.BulletVelocity
return Bullet
end
function CreateBulletHole(HitPos, HitObj)
local SurfaceCF = GetHitSurfaceCFrame(HitPos, HitObj)
local SurfaceDir = CF(HitObj.CFrame.p, SurfaceCF.p)
local SurfaceDist = SurfaceDir.lookVector * (HitObj.CFrame.p - SurfaceCF.p).magnitude / 2
local SurfaceOffset = HitPos - SurfaceCF.p + SurfaceDist
local SurfaceCFrame = SurfaceDir + SurfaceDist + SurfaceOffset
local HitMark = Instance.new("Part")
HitMark.BrickColor = BrickColor.new("Black")
HitMark.Transparency = 1
HitMark.Anchored = true
HitMark.CanCollide = false
HitMark.FormFactor = "Custom"
HitMark.Size = VEC3(1, 1, 0.2)
HitMark.TopSurface = 0
HitMark.BottomSurface = 0
local Mesh = Instance.new("BlockMesh")
Mesh.Offset = VEC3(0, 0, -0.05)
Mesh.Scale = VEC3(S.BulletHoleSize, S.BulletHoleSize, 0)
Mesh.Parent = HitMark
local Decal = Instance.new("Decal")
Decal.Face = Enum.NormalId.Front
Decal.Texture = S.BulletHoleTexture
Decal.Parent = HitMark
HitMark.Parent = Gun_Ignore
HitMark.CFrame = SurfaceCFrame
if (not HitObj.Anchored) then
local Weld = Instance.new("Weld", HitMark)
Weld.Part0 = HitObj
Weld.Part1 = HitMark
Weld.C0 = HitObj.CFrame:toObjectSpace(SurfaceCFrame)
HitMark.Anchored = false
end
delay(S.BulletHoleVisibleTime, function()
if S.BulletHoleDisappearTime > 0 then
local X = 0
while true do
if X == 90 then break end
if (not Selected) then break end
local NewX = X + (1.5 / S.BulletHoleDisappearTime)
X = (NewX > 90 and 90 or NewX)
local Alpha = X / 90
Decal.Transparency = NumLerp(0, 1, Alpha)
RS:wait()
end
HitMark:Destroy()
else
HitMark:Destroy()
end
end)
end
function CreateShockwave(Center, Radius)
local Shockwave = Instance.new("Part")
Shockwave.BrickColor = S.ShockwaveColor
Shockwave.Material = Enum.Material.SmoothPlastic
Shockwave.Name = "Shockwave"
Shockwave.Anchored = true
Shockwave.CanCollide = false
Shockwave.FormFactor = Enum.FormFactor.Symmetric
Shockwave.Size = VEC3(1, 1, 1)
Shockwave.BottomSurface = Enum.SurfaceType.Smooth
Shockwave.TopSurface = Enum.SurfaceType.Smooth
local Mesh = Instance.new("SpecialMesh")
Mesh.MeshType = Enum.MeshType.Sphere
Mesh.Scale = VEC3()
Mesh.Parent = Shockwave
Shockwave.Parent = Gun_Ignore
Shockwave.CFrame = CF(Center)
spawn(function()
for i = 0, 1, (1 / (60 * S.ShockwaveDuration)) do
local Scale = 2 * Radius * i
Mesh.Scale = VEC3(Scale, Scale, Scale)
Shockwave.Transparency = i
RS:wait()
end
Shockwave:Destroy()
end)
end
--------------------[ HIT HANDLING FUNCTIONS ]----------------------------------------
function Damage(HitObj, HitPos)
local HeadVal = S.Multipliers.Head
local ChestVal = S.Multipliers.Chest
local LimbsVal = S.Multipliers.Limbs
if Humanoid.Health ~= 0 then
if HitObj and HitObj.Parent then
local HumanoidFound = false
local HitHumanoid = nil
if HitObj.Parent.ClassName == "Hat" then
if FindFirstClass(HitObj.Parent.Parent, "Humanoid") then
HitHumanoid = FindFirstClass(HitObj.Parent.Parent, "Humanoid")
HumanoidFound = true
if HitHumanoid.Health > 0 then
if IsEnemy(HitHumanoid) then
local CreatorTag = Instance.new("ObjectValue")
CreatorTag.Value = Player
CreatorTag.Name = "creator"
CreatorTag.Parent = HitHumanoid
HitHumanoid:TakeDamage(S.Damage * RAND(HeadVal, HeadVal + 0.1, 0.01))
MarkHit()
end
end
end
else
if FindFirstClass(HitObj.Parent, "Humanoid") then
HitHumanoid = FindFirstClass(HitObj.Parent, "Humanoid")
HumanoidFound = true
if HitHumanoid.Health > 0 then
if IsEnemy(HitHumanoid) then
local CreatorTag = Instance.new("ObjectValue")
CreatorTag.Value = Player
CreatorTag.Name = "creator"
CreatorTag.Parent = HitHumanoid
local ChosenDamage = 0
if HitObj.Name == "Head" then
ChosenDamage = S.Damage * RAND(HeadVal, HeadVal + 0.1, 0.01)
elseif HitObj.Name == "Torso" then
ChosenDamage = S.Damage * RAND(ChestVal, ChestVal + 0.1, 0.01)
else
ChosenDamage = S.Damage * RAND(LimbsVal, LimbsVal + 0.1, 0.01)
end
HitHumanoid:TakeDamage(ChosenDamage)
MarkHit()
end
end
end
end
if (not HumanoidFound) then
if S.BulletHoles then
CreateBulletHole(HitPos, HitObj)
end
if S.Shockwaves then
CreateShockwave(HitPos, S.ShockwaveRadius)
end
end
return HitHumanoid
end
end
end
function PenetrateWall(HitPos, Direction, HitHumanoid, OriginPos, Bullet)
local HitDist = (HitPos - OriginPos).magnitude
local Thickness, Wall, WallHitPos = 0, nil, nil
for i = 0.1, S.Penetration, 0.1 do
local WallRay = Ray.new(HitPos + (Direction * i), -Direction)
local TempWall, TempWallHitPos = game.Workspace:FindPartOnRayWithIgnoreList(WallRay, Ignore)
if TempWall then
Thickness = i
Wall, WallHitPos = TempWall, TempWallHitPos
break
end
end
if Wall then
CreateBulletHole(WallHitPos, Wall)
if S.InstantHit then
local HitObj2, HitPos2 = nil, nil
if HitHumanoid then
HitObj2, HitPos2 = AdvRayCast(WallHitPos, Direction, S.BulletRange - HitDist, {HitHumanoid.Parent,unpack(Ignore)})
else
HitObj2, HitPos2 = AdvRayCast(WallHitPos, Direction, S.BulletRange - HitDist)
end
Damage(HitObj2, HitPos2)
return HitPos2
else
local LastPos = WallHitPos
local TotalDistTraveled = 0
spawn(function()
while true do
RS:wait()
if TotalDistTraveled >= S.BulletRange - HitDist then
Bullet:Destroy()
break
end
local DistTraveled = (Bullet.Position - LastPos).magnitude
local NewDirection = (Bullet.Position - LastPos).unit
local TempHitObj, TempHitPos = nil, nil
if HitHumanoid then
TempHitObj, TempHitPos = AdvRayCast(LastPos, NewDirection, DistTraveled, {HitHumanoid.Parent,unpack(Ignore)})
else
TempHitObj, TempHitPos = AdvRayCast(LastPos, NewDirection, DistTraveled)
end
if TempHitObj then
Damage(TempHitObj, TempHitPos)
Bullet:Destroy()
return TempHitPos
else
LastPos = Bullet.Position
TotalDistTraveled = TotalDistTraveled + DistTraveled
end
end
end)
end
else
if Bullet then Bullet:Destroy() end
return HitPos
end
end
function IsEnemy(Human)
local Plyr = game.Players:GetPlayerFromCharacter(Human.Parent)
if (not Plyr) then return S.CanDamageNPCs end
return S.AllowFriendlyFire or (Plyr.TeamColor ~= Player.TeamColor or Plyr.Neutral)
end
--------------------[ RELOAD FUNCTIONS ]----------------------------------------------
function ReloadAnim()
TweenJoint(LWeld2, CF(), CF(), Sine, 0.15)
TweenJoint(RWeld2, CF(), CF(), Sine, 0.15)
local Speed = S.ReloadTime / 2
local Mag_Parts = {}
for _, Obj in pairs(Gun:GetChildren()) do
if Obj.Name == "Mag" and Obj:IsA("BasePart") then
INSERT(Mag_Parts, {Original = Obj, Clone1 = Obj:Clone(), Clone2 = Obj:Clone()})
end
end
local W1 = nil
local W2 = nil
local SequenceTable = {
function()
for Index, Mag in pairs(Mag_Parts) do
Mag.Original.Transparency = 1
Mag.Clone1.Parent = Gun_Ignore
Mag.Clone1.CanCollide = true
if Index ~= 1 then
local W = Instance.new("Weld")
W.Part0 = Mag_Parts[1].Clone1
W.Part1 = Mag.Clone1
W.C0 = Mag_Parts[1].Clone1.CFrame:toObjectSpace(Mag.Clone1.CFrame)
W.Parent = Mag_Parts[1].Clone1
end
end
W1 = Instance.new("Weld")
W1.Part0 = Mag_Parts[1].Clone1
W1.Part1 = Handle
W1.C0 = Mag_Parts[1].Original.CFrame:toObjectSpace(Handle.CFrame)
W1.Parent = Mag_Parts[1].Clone1
TweenJoint(LWeld, ArmC0[1], CF(0, 0.61, 0) * CFANG(RAD(70), 0, 0), Linear, 0.5 * Speed)
TweenJoint(RWeld, ArmC0[2], CF(0.4, 0.09, -0.21) * CFANG(RAD(-20), RAD(3), 0), Linear, 0.5 * Speed)
TweenJoint(Grip, Grip.C0, CFANG(0, RAD(10), 0), Linear, 0.5 * Speed)
wait(0.5 * Speed)
end;
function()
TweenJoint(RWeld, ArmC0[2], CF(0.4, -0.01, -0.31) * CFANG(RAD(-22), RAD(3), 0), Sine, 0.3 * Speed)
wait(0.2 * Speed)
end;
function()
W1:Destroy()
Mag_Parts[1].Clone1.Velocity = Handle.Velocity + Handle.CFrame:vectorToWorldSpace(VEC3(0,-1,0)) * 20
spawn(function()
while Mag_Parts[1].Clone1.Velocity.magnitude > 0.1 do wait() end
for _, Mag in pairs(Mag_Parts) do
Mag.Clone1.Anchored = true
Mag.Clone1:BreakJoints()
end
end)
for Index, Mag in pairs(Mag_Parts) do
Mag.Clone2.Parent = Gun_Ignore
if Index ~= 1 then
local W = Instance.new("Weld")
W.Part0 = Mag_Parts[1].Clone2
W.Part1 = Mag.Clone2
W.C0 = Mag_Parts[1].Clone2.CFrame:toObjectSpace(Mag.Clone2.CFrame)
W.Parent = Mag_Parts[1].Clone2
end
end
W2 = Instance.new("Weld")
W2.Part0 = FakeLArm
W2.Part1 = Mag_Parts[1].Clone2
W2.C0 = CF(0, -1, 0) * CFANG(RAD(-90), 0, 0)
W2.Parent = FakeLArm
wait(0.1)
end;
function()
local FakeLArmCF = LWeld.Part0.CFrame * ArmC0[1] * (CF(0.3, 1.85, -0.31) * CFANG(RAD(-20), RAD(30), RAD(-60))):inverse()
local FakeRArmCF = RWeld.Part0.CFrame * ArmC0[2] * (CF(0.4, -0.1, -0.21) * CFANG(RAD(-20), RAD(5), RAD(10))):inverse()
local HandleCF = FakeRArm.CFrame:toObjectSpace(Grip.Part0.CFrame * Grip.C0)
local Mag_Original_CF = Handle.CFrame:toObjectSpace(Mag_Parts[1].Original.CFrame)
local MagC0 = FakeLArmCF:toObjectSpace(FakeRArmCF * HandleCF * Mag_Original_CF)
TweenJoint(LWeld, ArmC0[1], CF(0.3, 1.85, -0.31) * CFANG(RAD(-20), RAD(30), RAD(-60)), Sine, 0.6 * Speed)
TweenJoint(RWeld, ArmC0[2], CF(0.4, -0.1, -0.21) * CFANG(RAD(-20), RAD(5), RAD(10)), Sine, 0.6 * Speed)
TweenJoint(Grip, Grip.C0, CF(), Sine, 0.6 * Speed)
TweenJoint(W2, MagC0, CF(), Sine, 0.6 * Speed)
wait(0.7 * Speed)
end;
function()
for _, Mag in pairs(Mag_Parts) do
Mag.Original.Transparency = 0
Mag.Clone2:Destroy()
end
TweenJoint(LWeld, ArmC0[1], S.ArmC1_UnAimed.Left, Sine, 0.5 * Speed)
TweenJoint(RWeld, ArmC0[2], S.ArmC1_UnAimed.Right, Sine, 0.5 * Speed)
TweenJoint(Grip, Grip.C0, CFANG(0, RAD(20), 0), Sine, 0.5 * Speed)
wait(0.5 * Speed)
end;
}
for _,ReloadFunction in pairs(SequenceTable) do
if BreakReload then
break
end
ReloadFunction()
end
if W1 then W1:Destroy() end
if W2 then W2:Destroy() end
for _, Mag in pairs(Mag_Parts) do
Mag.Clone1:Destroy()
Mag.Clone2:Destroy()
end
end
function Reload()
Running = false
if Ammo.Value < ClipSize.Value and (not Reloading) and StoredAmmo.Value > 0 then
AmmoInClip = (AmmoInClip == 0 and Ammo.Value or AmmoInClip)
Ammo.Value = 0
Reloading = true
if Aimed then UnAimGun(S.ReloadAnimation) end
Gui_Clone.CrossHair.Reload.Visible = true
if Handle:FindFirstChild("ReloadSound") then Handle.ReloadSound:Play() end
if S.ReloadAnimation then
wait()
ReloadAnim()
else
local StartReload = tick()
while true do
if BreakReload then break end
if (tick() - StartReload) >= S.ReloadTime then break end
RS:wait()
end
end
if (not BreakReload) then
if StoredAmmo.Value >= ClipSize.Value then
Ammo.Value = ClipSize.Value
if AmmoInClip > 0 then
StoredAmmo.Value = StoredAmmo.Value - (ClipSize.Value - AmmoInClip)
else
StoredAmmo.Value = StoredAmmo.Value - ClipSize.Value
end
elseif StoredAmmo.Value < ClipSize.Value and StoredAmmo.Value > 0 then
Ammo.Value = StoredAmmo.Value
StoredAmmo.Value = 0
end
end
BreakReload = false
Reloading = false
if Selected then
AmmoInClip = 0
Gui_Clone.CrossHair.Reload.Visible = false
end
end
end
--------------------[ EXTERNAL DATA LOCATING FUNCTIONS ]-----------------------------
function FindFirstClass(Object, Class)
local FoundObject = nil
for _, Obj in pairs(Object:GetChildren()) do
if Obj.ClassName == Class then
FoundObject = Obj
break
end
end
return FoundObject
end
function IsIgnored(Obj)
for _,v in pairs(Ignore) do
if Obj == v or Obj:IsDescendantOf(v) then
return true
end
end
return false
end
function GetHitSurfaceCFrame(HitPos,Obj)
local SurfaceCF = {
{"Back",Obj.CFrame * CF(0,0,Obj.Size.z)};
{"Bottom",Obj.CFrame * CF(0,-Obj.Size.y,0)};
{"Front",Obj.CFrame * CF(0,0,-Obj.Size.z)};
{"Left",Obj.CFrame * CF(-Obj.Size.x,0,0)};
{"Right",Obj.CFrame * CF(Obj.Size.x,0,0)};
{"Top",Obj.CFrame * CF(0,Obj.Size.y,0)}
}
local ClosestDist = HUGE
local ClosestSurface = nil
for _,v in pairs(SurfaceCF) do
local SurfaceDist = (HitPos - v[2].p).magnitude
if SurfaceDist < ClosestDist then
ClosestDist = SurfaceDist
ClosestSurface = v
end
end
return ClosestSurface[2]
end
function AdvRayCast(Origin, Direction, Dist, CustomIgnore)
local NewIgnore = (CustomIgnore and CustomIgnore or Ignore)
local NewRay = Ray.new(Origin, Direction * (Dist > 999 and 999 or Dist))
local HitObj, HitPos = game.Workspace:FindPartOnRayWithIgnoreList(NewRay, NewIgnore)
local LastPos = HitPos
local FinalHitObj, FinalHitPos = nil, nil
local RepTimes = math.floor(Dist / 999)
if (not HitObj) and (Dist > 999) then
for i = 0, RepTimes do
local NewDist = (i == RepTimes and (Dist - (LastPos - Origin).magnitude) or 999)
local Ray2 = Ray.new(LastPos, Direction * NewDist)
local HitObj2, HitPos2 = game.Workspace:FindPartOnRayWithIgnoreList(Ray2, NewIgnore)
if i ~= RepTimes then
if HitObj2 then
FinalHitObj, FinalHitPos = HitObj2, HitPos2
break
end
elseif i == RepTimes then
FinalHitObj, FinalHitPos = HitObj2, HitPos2
end
LastPos = HitPos2
end
return FinalHitObj, FinalHitPos
elseif HitObj or (Dist <= 999) then
return HitObj, HitPos
end
end
--------------------[ KNIFING FUNCTION ]----------------------------------------------
function KnifeAnim()
local Connection = nil
local Blade = Instance.new("Part")
Blade.BrickColor = BrickColor.new("Really black")
Blade.Name = "Blade"
Blade.CanCollide = false
Blade.FormFactor = Enum.FormFactor.Custom
Blade.Size = VEC3(0.5, 2.5, 1)
local Mesh = Instance.new("SpecialMesh")
Mesh.MeshId = S.KnifeMeshId
Mesh.MeshType = Enum.MeshType.FileMesh
Mesh.Scale = VEC3(0.7, 0.7, 0.7)
Mesh.TextureId = S.KnifeTextureId
Mesh.Parent = Blade
Blade.Parent = Gun_Ignore
local BladeWeld = Instance.new("Weld")
BladeWeld.Part0 = Blade
BladeWeld.Part1 = FakeLArm
BladeWeld.C0 = CFANG(RAD(-90), 0, RAD(180))
BladeWeld.C1 = CF(0, -1, 0.75)
BladeWeld.Parent = Blade
Connection = Blade.Touched:connect(function(Obj)
if Obj then
local HitHumanoid = FindFirstClass(Obj.Parent, "Humanoid")
if HitHumanoid and IsEnemy(HitHumanoid) then
local CreatorTag = Instance.new("ObjectValue")
CreatorTag.Name = "creator"
CreatorTag.Value = Player
CreatorTag.Parent = HitHumanoid
HitHumanoid:TakeDamage(HitHumanoid.MaxHealth)
MarkHit()
end
end
end)
TweenJoint(LWeld2, CF(), CFANG(0, RAD(90), 0), Linear, 0.05)
TweenJoint(LWeld, ArmC0[1], CF(-0.1, 0.2, -0.1) * CFANG(0, 0, RAD(-20)), Linear, 0.05)
TweenJoint(RWeld, ArmC0[2], CFANG(RAD(-30), 0, 0), Linear, 0.1)
TweenJoint(Grip, Grip.C0, CF(), Linear, 0.1)
spawn(function()
local Force = HRP.CFrame.lookVector * 8e4
local BF = Instance.new("BodyForce")
BF.force = Force
BF.Parent = HRP
delay(0.03, function()
BF.force = -Force / 2
wait(0.03)
BF:Destroy()
end)
end)
wait(0.05)
RotCamera(RAD(6), 0, true, 0.1)
delay(0.1, function()
RotCamera(RAD(-2), 0, true, 0.05)
end)
TweenJoint(LWeld, ArmC0[1], CF(0.8, 1.7, 0.2) * CFANG(0, 0, RAD(-80)), Linear, 0.06)
wait(0.2)
Connection:disconnect()
wait(0.2)
TweenJoint(LWeld2, CF(), CF(), Linear, 0.15)
TweenJoint(LWeld, ArmC0[1], S.ArmC1_UnAimed.Left, Linear, 0.15)
TweenJoint(RWeld, ArmC0[2], S.ArmC1_UnAimed.Right, Linear, 0.15)
Blade:Destroy()
end
--------------------[ GRENADE FUNCTIONS ]---------------------------------------------
function CreateGrenade()
local Grenade = Instance.new("Model")
local Center = Instance.new("Part")
Center.BrickColor = S.GrenadeColor
Center.Name = "Center"
Center.CanCollide = false
Center.Elasticity = 0
Center.FormFactor = Enum.FormFactor.Custom
Center.Size = S.GrenadeSize
Center.BottomSurface = Enum.SurfaceType.Smooth
Center.TopSurface = Enum.SurfaceType.Smooth
Center.Parent = Grenade
local Mesh1 = Instance.new("SpecialMesh")
Mesh1.MeshType = Enum.MeshType.Sphere
Mesh1.Parent = Center
return Grenade
end
function CreateKnife()
local Knife = Instance.new("Part")
Knife.BrickColor = S.GrenadeColor
Knife.Name = "Knife"
Knife.CanCollide = false
Knife.FormFactor = Enum.FormFactor.Custom
Knife.Size = VEC3(1, 1, 3)
local Mesh = Instance.new("SpecialMesh")
Mesh.MeshId = "http://www.roblox.com/asset/?id=12221720"
Mesh.MeshType = Enum.MeshType.FileMesh
Mesh.Scale = VEC3(0.5, 0.5, 0.5)
Mesh.Parent = Knife
return Knife
end
function CreateTarget()
local Target = Instance.new("Model")
local Center = Instance.new("Part")
Center.BrickColor = BrickColor.new("Bright red")
Center.Material = Enum.Material.SmoothPlastic
Center.Transparency = 0.3
Center.Name = "Center"
Center.Anchored = true
Center.CanCollide = false
Center.FormFactor = Enum.FormFactor.Custom
Center.Size = VEC3(4, 0.2, 4)
Center.Parent = Target
local CylinderMesh = Instance.new("CylinderMesh")
CylinderMesh.Parent = Center
local Line = Instance.new("Part")
Line.BrickColor = BrickColor.new("Bright red")
Line.Transparency = 0.3
Line.Name = "Line"
Line.CFrame = Center.CFrame * CFrame.new(0, 5.1, 0)
Line.Anchored = true
Line.CanCollide = false
Line.FormFactor = Enum.FormFactor.Custom
Line.Size = VEC3(0.4, 10, 0.4)
Line.BottomSurface = Enum.SurfaceType.Smooth
Line.TopSurface = Enum.SurfaceType.Smooth
Line.Parent = Target
return Target
end
function DetonateExplosive(Grenade)
CreateShockwave(Grenade.Position, S.GrenadeBlastRadius)
local GrenadePos = Grenade.Position
local E = Instance.new("Explosion")
E.BlastPressure = S.GrenadeBlastPressure
E.BlastRadius = S.GrenadeBlastRadius
E.DestroyJointRadiusPercent = (S.GrenadeRangeBasedDamage and 0 or 1)
E.ExplosionType = S.GrenadeExplosionType
E.Position = GrenadePos
E.Hit:connect(function(HObj, HDist)
if HObj.Name == "Torso" and (not HObj:IsDescendantOf(Character)) then
if S.GrenadeRangeBasedDamage then
local ClosestPart = nil
local ClosestDist = math.huge
for _, P in pairs(HObj.Parent:GetChildren()) do
if P:IsA("BasePart") then
local Dist = (GrenadePos - P.Position).magnitude
if Dist < ClosestDist then
ClosestPart = P
ClosestDist = Dist
end
end
end
local Dir = (ClosestPart.Position - GrenadePos).unit
local H, P = AdvRayCast(GrenadePos, Dir, 999)
local RayHitHuman = H:IsDescendantOf(HObj.Parent)
if (S.GrenadeRayCastExplosions and RayHitHuman) or (not S.GrenadeRayCastExplosions) then
local HitHumanoid = FindFirstClass(HObj.Parent, "Humanoid")
if HitHumanoid and HitHumanoid.Health > 0 and IsEnemy(HitHumanoid) then
local DistFactor = ClosestDist / S.GrenadeBlastRadius
local DistInvert = math.max(1 - DistFactor,0)
local NewDamage = DistInvert * S.LethalGrenadeDamage
local CreatorTag = Instance.new("ObjectValue")
CreatorTag.Value = Player
CreatorTag.Name = "creator"
CreatorTag.Parent = HitHumanoid
HitHumanoid:TakeDamage(NewDamage)
MarkHit()
end
end
else
local HitHumanoid = FindFirstClass(HObj.Parent, "Humanoid")
if HitHumanoid and HitHumanoid.Health > 0 and IsEnemy(HitHumanoid) then
local CreatorTag = Instance.new("ObjectValue")
CreatorTag.Value = Player
CreatorTag.Name = "creator"
CreatorTag.Parent = HitHumanoid
MarkHit()
end
end
end
end)
E.Parent = game.Workspace
wait()
Grenade.Parent:Destroy()
end
function DetonateSmoke(Grenade)
CreateShockwave(Grenade.Position, S.GrenadeEffectRadius)
local GrenadePos = Grenade.Position
spawn(function()
for i = 1, math.floor(S.GrenadeEffectRadius / 5) + RAND(5, 10) do
local Size = RAND(S.GrenadeEffectRadius * 0.6, S.GrenadeEffectRadius * 0.8)
local Dist = RAND(0, S.GrenadeEffectRadius - Size)
local XRot, YRot = RAD(RAND(0, 180, 10)), RAD(RAND(0, 360, 10))
local RotLV = (CFANG(0, YRot, 0) * CFANG(XRot, 0, 0)).lookVector
local Pos = GrenadePos + (RotLV * VEC3(Dist, Dist / 2, Dist))
local Smoke = Instance.new("Part")
Smoke.Transparency = 1
Smoke.Name = "Smoke"
Smoke.Anchored = true
Smoke.CanCollide = false
Smoke.FormFactor = Enum.FormFactor.Symmetric
Smoke.Size = VEC3(1, 1, 1)
Smoke.TopSurface = Enum.SurfaceType.Smooth
Smoke.BottomSurface = Enum.SurfaceType.Smooth
local Mesh = Instance.new("SpecialMesh")
Mesh.MeshType = Enum.MeshType.Sphere
Mesh.Scale = VEC3(Size, Size, Size)
Mesh.Parent = Smoke
Smoke.Parent = Gun_Ignore
Smoke.CFrame = CF(Pos)
spawn(function()
local Trans = RAND(0.3, 0.5, 0.01)
for X = 0, 90, 2 do
Smoke.CFrame = CF(GrenadePos:lerp(Pos, Sine(X)))
Smoke.Transparency = NumLerp(1, Trans, Sine(X))
RS:wait()
end
wait(S.GrenadeEffectTime)
for X = 0, 90, 0.5 do
Smoke.CFrame = CF(Pos:lerp(Pos + VEC3(0, 20, 0), 1 - COS(RAD(X))))
Smoke.Transparency = NumLerp(Trans, 1, Sine(X))
RS:wait()
end
Smoke:Destroy()
end)
if i % 3 == 0 then
RS:wait()
end
end
end)
wait()
Grenade.Parent:Destroy()
end
function ThrowGrenade(Type)
local Grenade0 = nil
if S.TrajectoryAssist then
spawn(function()
local X = 0
local Vel = (Type == 1 and S.LethalGrenadeThrowVelocity or S.TacticalGrenadeThrowVelocity)
local GetX = function(Ang, T)
local Vx = Vel * math.cos(Ang)
return Vx * T
end
local GetY = function(Ang, T)
local V0y = Vel * math.sin(Ang)
local Vy = V0y + (-196.2 * T)
return (Vy * T) - (-98.1 * T * T)
end
local Target = CreateTarget()
Target.Parent = game.Workspace
Target.PrimaryPart = Target:WaitForChild("Center")
while (Keys[S.LethalGrenadeKey] or Keys[S.TacticalGrenadeKey]) and Selected do
X = X + math.rad(10)
for _,v in pairs(Target:GetChildren()) do
v.Transparency = 0.2 + ((math.sin(X) + 1) / 5)
end
local Lines = {}
local LastX, LastY = nil, nil
for T = 0, 10, 0.1 do
local XPos = GetX(math.rad(7) - HeadRot, T)
local YPos = GetY(math.rad(7) - HeadRot, T)
if LastX and LastY then
local LookV3 = HRP.CFrame.lookVector
local LastPos = (Head.CFrame * CF(1.5, 0, 0)).p + (LookV3 * LastX) + VEC3(0, LastY, 0)
local NewPos = (Head.CFrame * CF(1.5, 0, 0)).p + (LookV3 * XPos) + VEC3(0, YPos, 0)
local LineCF = CF(LastPos, NewPos)
local Dist = (LastPos - NewPos).magnitude
local NewDist = Dist
local H, P = AdvRayCast(LastPos, (NewPos - LastPos), 1, {Camera, unpack(Ignore)})
if H then
NewDist = (P - LastPos).magnitude
local SurfaceCF = GetHitSurfaceCFrame(P, H)
local SurfaceDir = CF(H.CFrame.p, SurfaceCF.p)
local SurfaceDist = SurfaceDir.lookVector * (H.CFrame.p - SurfaceCF.p).magnitude / 2
local SurfaceOffset = P - SurfaceCF.p + SurfaceDist
local SurfaceCFrame = SurfaceDir + SurfaceDist + SurfaceOffset
Target:SetPrimaryPartCFrame(SurfaceCFrame * CFANG(RAD(-90), 0, 0))
Target.Parent = Camera
else
Target.Parent = nil
end
local Line = Instance.new("Part")
Line.BrickColor = BrickColor.Red()
Line.Material = Enum.Material.SmoothPlastic
Line.Transparency = 0.2 + ((math.sin(X) + 1) / 5)
Line.Anchored = true
Line.CanCollide = false
Line.FormFactor = Enum.FormFactor.Custom
Line.Size = Vector3.new(0.4, 0.4, NewDist)
Line.TopSurface = Enum.SurfaceType.Smooth
Line.BottomSurface = Enum.SurfaceType.Smooth
Line.CFrame = LineCF + (LineCF.lookVector * NewDist / 2)
Line.Parent = Camera
table.insert(Lines, Line)
LastX,LastY = XPos,YPos
if H then break end
else
LastX,LastY = XPos,YPos
end
end
wait()
for _,Line in pairs(Lines) do
Line:Destroy()
end
end
Target:Destroy()
end)
end
local AnimTable = {
function()
TweenJoint(LWeld, CF(-1.5, 0, 0), CF(0, 0.6, 0), Linear, 0.2)
TweenJoint(RWeld, CF(1.5, 0, 0) * CFANG(0, 0, RAD(-10)), CF(0, 0.6, 0), Linear, 0.2)
TweenJoint(Grip, Grip.C0, CFANG(0, RAD(10), 0), Linear, 0.2)
wait(0.3)
end;
function()
Grip.Part0 = Torso
Grip.C1 = CF(-1, 0.5, -0.5)
if S.LethalGrenadeType == 3 and Type == 1 then
Grenade0 = CreateKnife()
Grenade0.Parent = Gun_Ignore
local Weld = Instance.new("Weld")
Weld.Part0 = FakeRArm
Weld.Part1 = Grenade0
Weld.C0 = Grip.C0
Weld.C1 = CF(0, 0, -0.5) * CFANG(RAD(90), RAD(90), 0)
Weld.Parent = Grenade0
TweenJoint(LWeld2, CF(), CF(), Sine, 0.3)
TweenJoint(RWeld2, CF(), CF(), Sine, 0.3)
TweenJoint(LWeld, ArmC0[1], CF(0, 0.5, 0.1) * CFANG(RAD(90), 0, 0), Sine, 0.3)
TweenJoint(RWeld, ArmC0[2], CF(0, 0.4, 0.1) * CFANG(RAD(-80), 0, 0), Sine, 0.3)
wait(0.3)
else
Grenade0 = CreateGrenade()
Grenade0.Parent = Gun_Ignore
local Weld = Instance.new("Weld")
Weld.Part0 = FakeRArm
Weld.Part1 = Grenade0:WaitForChild("Center")
Weld.C0 = Grip.C0
Weld.Parent = Grenade0:WaitForChild("Center")
TweenJoint(LWeld2, CF(), CFANG(0, RAD(80), 0), Linear, 0.25)
TweenJoint(RWeld2, CF(), CFANG(0, RAD(-80), 0), Linear, 0.25)
TweenJoint(LWeld, ArmC0[1], CF(-0.2, 0.8, 0.1) * CFANG(RAD(10), 0, RAD(-30)), Linear, 0.25)
TweenJoint(RWeld, ArmC0[2], CF(0.2, 0.8, 0.1) * CFANG(RAD(10), 0, RAD(30)), Linear, 0.25)
wait(0.3)
end
end;