--// Firemode Functions

function CreateBullet(L_185_arg1)
	local L_186_ = L_55_.Position
	local L_187_ = (L_4_.Hit.p - L_186_).unit
	local L_188_ = CFrame.Angles(math.rad(math.random(-L_185_arg1, L_185_arg1)), math.rad(math.random(-L_185_arg1, L_185_arg1)), math.rad(math.random(-L_185_arg1, L_185_arg1)))
	L_187_ = L_188_ * L_187_	
	local L_189_ = CFrame.new(L_186_, L_186_ + L_187_)	
		
	local L_190_ = Instance.new("Part", L_93_)
	game.Debris:AddItem(L_190_, 10)
	L_190_.Shape = Enum.PartType.Ball
	L_190_.Size = Vector3.new(1, 1, 12)
	L_190_.Name = "Bullet"
	L_190_.TopSurface = "Smooth"
	L_190_.BottomSurface = "Smooth"
	L_190_.BrickColor = BrickColor.new("Bright green")
	L_190_.Material = "Neon"
	L_190_.CanCollide = false
		--Bullet.CFrame = FirePart.CFrame + (Grip.CFrame.p - Grip.CFrame.p)
	L_190_.CFrame = L_189_
		
	local L_191_ = Instance.new("Sound")
	L_191_.SoundId = "rbxassetid://341519743"
	L_191_.Looped = true
	L_191_:Play()
	L_191_.Parent = L_190_
	L_191_.Volume = 0.4
	L_191_.MaxDistance = 30
	
	L_190_.Transparency = 1
	local L_192_ = L_190_:GetMass()
	local L_193_ = Instance.new('BodyForce', L_190_)
		
	if not L_77_ then
		L_193_.Force = L_24_.BulletPhysics
		L_190_.Velocity = L_187_ * L_24_.BulletSpeed
	else
		L_193_.Force = L_24_.ExploPhysics
		L_190_.Velocity = L_187_ * L_24_.ExploSpeed
	end
		
	local L_194_ = Instance.new('Attachment', L_190_)
	L_194_.Position = Vector3.new(0.1, 0, 0)
	local L_195_ = Instance.new('Attachment', L_190_)
	L_195_.Position = Vector3.new(-0.1, 0, 0)
			
	local L_196_ = TracerCalculation()
		
	if L_24_.TracerEnabled == true and L_196_ then
		local L_197_ = Instance.new('Trail', L_190_)
		L_197_.Attachment0 = L_194_
		L_197_.Attachment1 = L_195_
		L_197_.Transparency = NumberSequence.new(L_24_.TracerTransparency)
		L_197_.LightEmission = L_24_.TracerLightEmission
		L_197_.TextureLength = L_24_.TracerTextureLength
		L_197_.Lifetime = L_24_.TracerLifetime
		L_197_.FaceCamera = L_24_.TracerFaceCamera
		L_197_.Color = ColorSequence.new(L_24_.TracerColor.Color)
	end
		
	if L_1_:FindFirstChild('Shell') and not L_77_ then	
		CreateShell()	
	end	
		
	delay(0.2, function()
		L_190_.Transparency = 0
	end)
	
	return L_190_
end

function CheckForHumanoid(L_198_arg1)
	local L_199_
	local L_200_
	if (L_198_arg1.Parent:FindFirstChild("Humanoid") or L_198_arg1.Parent.Parent:FindFirstChild("Humanoid")) then
		L_199_ = true
		if L_198_arg1.Parent:FindFirstChild('Humanoid') then
			L_200_ = L_198_arg1.Parent.Humanoid
		elseif L_198_arg1.Parent.Parent:FindFirstChild('Humanoid') then
			L_200_ = L_198_arg1.Parent.Parent.Humanoid
		end
	else
		L_199_ = false
	end	
	return L_199_, L_200_
end

function CastRay(L_201_arg1)
	local L_202_, L_203_, L_204_
	local L_205_ = L_52_.Position;
	local L_206_ = L_201_arg1.Position;
	local L_207_ = 0

	local L_208_ = L_77_	
	
	while true do
		L_98_:wait()
		L_206_ = L_201_arg1.Position;
		L_207_ = L_207_ + (L_206_ - L_205_).magnitude
		L_202_, L_203_, L_204_ = workspace:FindPartOnRayWithIgnoreList(Ray.new(L_205_, (L_206_ - L_205_)), IgnoreList);
		local L_209_ = Vector3.new(0, 1, 0):Cross(L_204_)
		local L_210_ = math.asin(L_209_.magnitude) -- division by 1 is redundant
		if L_207_ > 10000 then
			break
		end
		if L_202_ and (L_202_ and L_202_.Transparency >= 1 or L_202_.CanCollide == false) then
			table.insert(IgnoreList, L_202_)
		end
	
		if L_202_ then
			L_209_ = Vector3.new(0, 1, 0):Cross(L_204_)
			L_210_ = math.asin(L_209_.magnitude) -- division by 1 is redundant
		
			local L_211_ = CheckForHumanoid(L_202_)
			if L_211_ == false then
				L_201_arg1:Destroy()
				local L_212_ = L_105_:InvokeServer(L_203_, L_209_, L_210_, L_204_, "Part")
				table.insert(IgnoreList, L_212_)
			elseif L_211_ == true then
				L_201_arg1:Destroy()
				local L_213_ = L_105_:InvokeServer(L_203_, L_209_, L_210_, L_204_, "Human")
				table.insert(IgnoreList, L_213_)
			end
		end
	
		if L_202_ and L_208_ then
			L_108_:FireServer(L_203_)
		end
	
		if L_202_ and (L_202_.Parent:FindFirstChild("Humanoid") or L_202_.Parent.Parent:FindFirstChild("Humanoid")) then
			local L_214_, L_215_ = CheckForHumanoid(L_202_)
			if L_214_ then
				L_103_:FireServer(L_215_)
				if L_24_.AntiTK then
					if game.Players:FindFirstChild(L_215_.Parent.Name) and game.Players:FindFirstChild(L_215_.Parent.Name).TeamColor ~= L_2_.TeamColor then
						if L_202_.Name == 'Head' then
							L_102_:FireServer(L_215_, L_24_.HeadDamage)
							local L_216_ = L_19_:WaitForChild('BodyHit'):clone()
							L_216_.Parent = L_2_.PlayerGui
							L_216_:Play()
							game:GetService("Debris"):addItem(L_216_, L_216_.TimeLength)
						elseif L_202_.Name ~= 'Head' and not (L_202_.Parent:IsA('Accessory') or L_202_.Parent:IsA('Hat')) then
							L_102_:FireServer(L_215_, L_24_.Damage)
							local L_217_ = L_19_:WaitForChild('BodyHit'):clone()
							L_217_.Parent = L_2_.PlayerGui
							L_217_:Play()
							game:GetService("Debris"):addItem(L_217_, L_217_.TimeLength)
						elseif (L_202_.Parent:IsA('Accessory') or L_202_.Parent:IsA('Hat')) then
							L_102_:FireServer(L_215_, L_24_.HeadDamage)
							local L_218_ = L_19_:WaitForChild('BodyHit'):clone()
							L_218_.Parent = L_2_.PlayerGui
							L_218_:Play()
							game:GetService("Debris"):addItem(L_218_, L_218_.TimeLength)
						end
					end
				else
					if L_202_.Name == 'Head' then
						L_102_:FireServer(L_215_, L_24_.HeadDamage)
						local L_219_ = L_19_:WaitForChild('BodyHit'):clone()
						L_219_.Parent = L_2_.PlayerGui
						L_219_:Play()
						game:GetService("Debris"):addItem(L_219_, L_219_.TimeLength)
					elseif L_202_.Name ~= 'Head' and not (L_202_.Parent:IsA('Accessory') or L_202_.Parent:IsA('Hat')) then
						L_102_:FireServer(L_215_, L_24_.Damage)
						local L_220_ = L_19_:WaitForChild('BodyHit'):clone()
						L_220_.Parent = L_2_.PlayerGui
						L_220_:Play()
						game:GetService("Debris"):addItem(L_220_, L_220_.TimeLength)
					elseif (L_202_.Parent:IsA('Accessory') or L_202_.Parent:IsA('Hat')) then
						L_102_:FireServer(L_215_, L_24_.HeadDamage)
						local L_221_ = L_19_:WaitForChild('BodyHit'):clone()
						L_221_.Parent = L_2_.PlayerGui
						L_221_:Play()
						game:GetService("Debris"):addItem(L_221_, L_221_.TimeLength)
					end
				end	
			end
		end
	
		if L_202_ and L_202_.Parent:FindFirstChild("Humanoid") then
			return L_202_, L_203_;
		end
		L_205_ = L_206_;
	end
end

function fireSemi()
	if L_15_ then
		L_65_ = false
		Recoiling = true
		Shooting = true
		
		CheckReverb()
		
		L_55_:WaitForChild('Fire'):Play()	
		L_101_:FireServer()
		L_94_ = CreateBullet(0)
		L_95_ = L_95_ - 1
		UpdateAmmo()
		RecoilFront = true
		local L_222_, L_223_ = spawn(function()
			CastRay(L_94_)
		end)
		
		if L_24_.CanBolt == true then
			BoltingBackAnim()
			delay(L_24_.Firerate / 2, function()
				if L_24_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_24_.CanSlideLock == true and L_95_ <= 0 then
					BoltingBackAnim()
				end
			end)
		end
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)		
		
		wait(L_24_.Firerate)
		
		local L_224_ = JamCalculation()
		if L_224_ then
			L_65_ = false
		else
			L_65_ = true
		end
		Shooting = false
	end
end

function fireExplo()
	if L_15_ then
		L_65_ = false
		Recoiling = true
		Shooting = true
		L_56_:WaitForChild('Fire'):Play()
		L_101_:FireServer()
		L_94_ = CreateBullet(0)
		L_97_ = L_97_ - 1
		UpdateAmmo()
		RecoilFront = true
		local L_225_, L_226_ = spawn(function()
			CastRay(L_94_)
		end)
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)		
			
		L_65_ = false
		Shooting = false
	end
end

function fireShot()
	if L_15_ then
		L_65_ = false
		Recoiling = true
		Shooting = true
		RecoilFront = true
		CheckReverb()
		L_55_:WaitForChild('Fire'):Play()
		L_101_:FireServer()
		for L_228_forvar1 = 1, L_24_.ShotNum do
			L_94_ = CreateBullet(2)
			local L_229_, L_230_ = spawn(function()
				CastRay(L_94_)
			end)
		end
						
		for L_231_forvar1, L_232_forvar2 in pairs(L_55_:GetChildren()) do
			if L_232_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_232_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_233_forvar1, L_234_forvar2 in pairs(L_55_:GetChildren()) do
				if L_234_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_234_forvar2.Enabled = false
				end
			end
		end)
		
		if L_24_.CanBolt == true then
			BoltingBackAnim()
			delay(L_24_.Firerate / 2, function()
				if L_24_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_24_.CanSlideLock == true and L_95_ > 0 then
					BoltingBackAnim()
				end
			end)
		end
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		L_95_ = L_95_ - 1
		UpdateAmmo()
		wait(L_24_.Firerate)
		
		L_72_ = true
		BoltBackAnim()
		BoltForwardAnim()
		IdleAnim()
		L_72_ = false
		
		local L_227_ = JamCalculation()
		if L_227_ then
			L_65_ = false
		else
			L_65_ = true
		end
		
		Shooting = false
	end
end

function fireBoltAction()
	if L_15_ then
		L_65_ = false
		Recoiling = true
		Shooting = true
		CheckReverb()
		L_55_:WaitForChild('Fire'):Play()
		L_101_:FireServer()
		L_94_ = CreateBullet(0)
		L_95_ = L_95_ - 1
		UpdateAmmo()
		RecoilFront = true
		local L_235_, L_236_ = spawn(function()
			CastRay(L_94_)
		end)
						
		for L_238_forvar1, L_239_forvar2 in pairs(L_55_:GetChildren()) do
			if L_239_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_239_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_240_forvar1, L_241_forvar2 in pairs(L_55_:GetChildren()) do
				if L_241_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_241_forvar2.Enabled = false
				end
			end
		end)
		
		if L_24_.CanBolt == true then
			BoltingBackAnim()
			delay(L_24_.Firerate / 2, function()
				if L_24_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_24_.CanSlideLock == true and L_95_ > 0 then
					BoltingBackAnim()
				end
			end)
		end
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		wait(L_24_.Firerate)
		
		L_72_ = true
		BoltBackAnim()
		BoltForwardAnim()
		IdleAnim()
		L_72_ = false
		
		local L_237_ = JamCalculation()
		if L_237_ then
			L_65_ = false
		else
			L_65_ = true
		end		
		
		Shooting = false
	end
end

function fireAuto()
	while not Shooting and L_95_ > 0 and L_64_ and L_65_ and L_15_ do
		L_65_ = false
		Recoiling = true
		CheckReverb()
		L_55_:WaitForChild('Fire'):Play()
		L_101_:FireServer()
		L_95_ = L_95_ - 1
		UpdateAmmo()
		Shooting = true
		RecoilFront = true
		L_94_ = CreateBullet(0)
		local L_242_, L_243_ = spawn(function()
			CastRay(L_94_)
		end)
					
		for L_245_forvar1, L_246_forvar2 in pairs(L_55_:GetChildren()) do
			if L_246_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_246_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_247_forvar1, L_248_forvar2 in pairs(L_55_:GetChildren()) do
				if L_248_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_248_forvar2.Enabled = false
				end
			end
		end)
		
		if L_24_.CanBolt == true then
			BoltingBackAnim()
			delay(L_24_.Firerate / 2, function()
				if L_24_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_24_.CanSlideLock == true and L_95_ > 0 then
					BoltingForwardAnim()
				end
			end)
		end
		
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		wait(L_24_.Firerate)
		
		local L_244_ = JamCalculation()
		if L_244_ then
			L_65_ = false
		else
			L_65_ = true
		end
		
		Shooting = false
	end
end

function fireBurst()
	if not Shooting and L_95_ > 0 and L_64_ and L_15_ then
		for L_249_forvar1 = 1, L_24_.BurstNum do
			if L_95_ > 0 and L_64_ then
				L_65_ = false
				Recoiling = true
				CheckReverb()
				L_55_:WaitForChild('Fire'):Play()
				L_101_:FireServer()
				L_94_ = CreateBullet(0)
				local L_250_, L_251_ = spawn(function()
					CastRay(L_94_)
				end)
					
				for L_253_forvar1, L_254_forvar2 in pairs(L_55_:GetChildren()) do
					if L_254_forvar2.Name:sub(1, 7) == "FlashFX" then
						L_254_forvar2.Enabled = true
					end
				end
		
				delay(1 / 30, function()
					for L_255_forvar1, L_256_forvar2 in pairs(L_55_:GetChildren()) do
						if L_256_forvar2.Name:sub(1, 7) == "FlashFX" then
							L_256_forvar2.Enabled = false
						end
					end
				end)
			
				if L_24_.CanBolt == true then
					BoltingBackAnim()
					delay(L_24_.Firerate / 2, function()
						if L_24_.CanSlideLock == false then
							BoltingForwardAnim()
						elseif L_24_.CanSlideLock == true and L_95_ > 0 then
							BoltingForwardAnim()
						end
					end)
				end
			
				L_95_ = L_95_ - 1
				UpdateAmmo()
				RecoilFront = true
				delay(L_24_.Firerate / 2, function()
					Recoiling = false
					RecoilFront = false
				end)
				wait(L_24_.Firerate)
			
				local L_252_ = JamCalculation()
				if L_252_ then
					L_65_ = false
				else
					L_65_ = true
				end
		
			end
			Shooting = true
		end
		Shooting = false
	end
end

function Shoot()
	if L_15_ and L_65_ then
		if L_86_ == 1 then
			fireSemi()
		elseif L_86_ == 2 then
			fireAuto()
		elseif L_86_ == 3 then
			fireBurst()	
		elseif L_86_ == 4 then
			fireBoltAction()
		elseif L_86_ == 5 then
			fireShot()
		elseif L_86_ == 6 then
			fireExplo()
		end
	end
end
