--// Firemode Functions

function CreateBullet(L_197_arg1)
	local L_198_ = L_56_.Position
	local L_199_ = (L_4_.Hit.p - L_198_).unit
	local L_200_ = CFrame.Angles(math.rad(math.random(-L_197_arg1, L_197_arg1)), math.rad(math.random(-L_197_arg1, L_197_arg1)), math.rad(math.random(-L_197_arg1, L_197_arg1)))
	L_199_ = L_200_ * L_199_	
	local L_201_ = CFrame.new(L_198_, L_198_ + L_199_)	
		
	local L_202_ = Instance.new("Part", L_98_)
	game.Debris:AddItem(L_202_, 10)
	L_202_.Shape = Enum.PartType.Ball
	L_202_.Size = Vector3.new(1, 1, 12)
	L_202_.Name = "Bullet"
	L_202_.TopSurface = "Smooth"
	L_202_.BottomSurface = "Smooth"
	L_202_.BrickColor = BrickColor.new("Bright green")
	L_202_.Material = "Neon"
	L_202_.CanCollide = false
		--Bullet.CFrame = FirePart.CFrame + (Grip.CFrame.p - Grip.CFrame.p)
	L_202_.CFrame = L_201_
		
	local L_203_ = Instance.new("Sound")
	L_203_.SoundId = "rbxassetid://341519743"
	L_203_.Looped = true
	L_203_:Play()
	L_203_.Parent = L_202_
	L_203_.Volume = 0.4
	L_203_.MaxDistance = 30
	
	L_202_.Transparency = 1
	local L_204_ = L_202_:GetMass()
	local L_205_ = Instance.new('BodyForce', L_202_)
		
	if not L_80_ then
		L_205_.Force = L_24_.BulletPhysics
		L_202_.Velocity = L_199_ * L_24_.BulletSpeed
	else
		L_205_.Force = L_24_.ExploPhysics
		L_202_.Velocity = L_199_ * L_24_.ExploSpeed
	end
		
	local L_206_ = Instance.new('Attachment', L_202_)
	L_206_.Position = Vector3.new(0.1, 0, 0)
	local L_207_ = Instance.new('Attachment', L_202_)
	L_207_.Position = Vector3.new(-0.1, 0, 0)
			
	local L_208_ = TracerCalculation()
		
	if L_24_.TracerEnabled == true and L_208_ then
		local L_209_ = Instance.new('Trail', L_202_)
		L_209_.Attachment0 = L_206_
		L_209_.Attachment1 = L_207_
		L_209_.Transparency = NumberSequence.new(L_24_.TracerTransparency)
		L_209_.LightEmission = L_24_.TracerLightEmission
		L_209_.TextureLength = L_24_.TracerTextureLength
		L_209_.Lifetime = L_24_.TracerLifetime
		L_209_.FaceCamera = L_24_.TracerFaceCamera
		L_209_.Color = ColorSequence.new(L_24_.TracerColor.Color)
	end
		
	if L_1_:FindFirstChild('Shell') and not L_80_ then	
		CreateShell()	
	end	
		
	delay(0.2, function()
		L_202_.Transparency = 0
	end)
	
	return L_202_
end

function CheckForHumanoid(L_210_arg1)
	local L_211_
	local L_212_
	if (L_210_arg1.Parent:FindFirstChild("Humanoid") or L_210_arg1.Parent.Parent:FindFirstChild("Humanoid")) then
		L_211_ = true
		if L_210_arg1.Parent:FindFirstChild('Humanoid') then
			L_212_ = L_210_arg1.Parent.Humanoid
		elseif L_210_arg1.Parent.Parent:FindFirstChild('Humanoid') then
			L_212_ = L_210_arg1.Parent.Parent.Humanoid
		end
	else
		L_211_ = false
	end	
	return L_211_, L_212_
end

function CastRay(L_213_arg1)
	local L_214_, L_215_, L_216_
	local L_217_ = L_53_.Position;
	local L_218_ = L_213_arg1.Position;
	local L_219_ = 0

	local L_220_ = L_80_	
	
	while true do
		L_103_:wait()
		L_218_ = L_213_arg1.Position;
		L_219_ = L_219_ + (L_218_ - L_217_).magnitude
		L_214_, L_215_, L_216_ = workspace:FindPartOnRayWithIgnoreList(Ray.new(L_217_, (L_218_ - L_217_)), IgnoreList);
		local L_221_ = Vector3.new(0, 1, 0):Cross(L_216_)
		local L_222_ = math.asin(L_221_.magnitude) -- division by 1 is redundant
		if L_219_ > L_24_.BulletDecay then
			L_213_arg1:Destroy()
			break
		end
		if L_214_ and (L_214_ and L_214_.Transparency >= 1 or L_214_.CanCollide == false) and L_214_.Name ~= 'Right Arm' and L_214_.Name ~= 'Left Arm' and L_214_.Name ~= 'Right Leg' and L_214_.Name ~= 'Left Leg' and L_214_.Name ~= 'Armor' then
			table.insert(IgnoreList, L_214_)
		end
	
		if L_214_ then
			L_221_ = Vector3.new(0, 1, 0):Cross(L_216_)
			L_222_ = math.asin(L_221_.magnitude) -- division by 1 is redundant
		
			L_115_:FireServer(L_215_)
		
			local L_223_ = CheckForHumanoid(L_214_)
			if L_223_ == false then
				L_213_arg1:Destroy()
				local L_224_ = L_110_:InvokeServer(L_215_, L_221_, L_222_, L_216_, "Part", L_214_)
			elseif L_223_ == true then
				L_213_arg1:Destroy()
				local L_225_ = L_110_:InvokeServer(L_215_, L_221_, L_222_, L_216_, "Human", L_214_)
			end
		end
	
		if L_214_ and L_220_ then
			L_113_:FireServer(L_215_)
		end
	
		if L_214_ and (L_214_.Parent:FindFirstChild("Humanoid") or L_214_.Parent.Parent:FindFirstChild("Humanoid")) then
			local L_226_, L_227_ = CheckForHumanoid(L_214_)
			if L_226_ then
				L_108_:FireServer(L_227_)
				if L_24_.AntiTK then
					if game.Players:FindFirstChild(L_227_.Parent.Name) and game.Players:FindFirstChild(L_227_.Parent.Name).TeamColor ~= L_2_.TeamColor then
						if L_214_.Name == 'Head' then
							L_107_:FireServer(L_227_, L_24_.HeadDamage)
							local L_228_ = L_19_:WaitForChild('BodyHit'):clone()
							L_228_.Parent = L_2_.PlayerGui
							L_228_:Play()
							game:GetService("Debris"):addItem(L_228_, L_228_.TimeLength)
						end
						if L_214_.Name ~= 'Head' and not (L_214_.Parent:IsA('Accessory') or L_214_.Parent:IsA('Hat')) then
							if L_214_.Name ~= 'Torso' and L_214_.Name ~= 'HumanoidRootPart' and L_214_.Name ~= 'Armor' then
								L_107_:FireServer(L_227_, L_24_.LimbDamage)
							elseif L_214_.Name == 'Torso' or L_214_.Name == 'HumanoidRootPart' and L_214_.Name ~= 'Armor'  then
								L_107_:FireServer(L_227_, L_24_.BaseDamage)
							elseif L_214_.Name == 'Armor' then
								L_107_:FireServer(L_227_, L_24_.ArmorDamage)
							end
							local L_229_ = L_19_:WaitForChild('BodyHit'):clone()
							L_229_.Parent = L_2_.PlayerGui
							L_229_:Play()
							game:GetService("Debris"):addItem(L_229_, L_229_.TimeLength)
						end
						if (L_214_.Parent:IsA('Accessory') or L_214_.Parent:IsA('Hat')) then
							L_107_:FireServer(L_227_, L_24_.HeadDamage)
							local L_230_ = L_19_:WaitForChild('BodyHit'):clone()
							L_230_.Parent = L_2_.PlayerGui
							L_230_:Play()
							game:GetService("Debris"):addItem(L_230_, L_230_.TimeLength)
						end
					end
				else
					if L_214_.Name == 'Head' then
						L_107_:FireServer(L_227_, L_24_.HeadDamage)
						local L_231_ = L_19_:WaitForChild('BodyHit'):clone()
						L_231_.Parent = L_2_.PlayerGui
						L_231_:Play()
						game:GetService("Debris"):addItem(L_231_, L_231_.TimeLength)
					end
					if L_214_.Name ~= 'Head' and not (L_214_.Parent:IsA('Accessory') or L_214_.Parent:IsA('Hat')) then
						if L_214_.Name ~= 'Torso' and L_214_.Name ~= 'HumanoidRootPart' and L_214_.Name ~= 'Armor' then
							L_107_:FireServer(L_227_, L_24_.LimbDamage)
						elseif L_214_.Name == 'Torso' or L_214_.Name == 'HumanoidRootPart' and L_214_.Name ~= 'Armor' then
							L_107_:FireServer(L_227_, L_24_.BaseDamage)
						elseif L_214_.Name == 'Armor' then
							L_107_:FireServer(L_227_, L_24_.ArmorDamage)
						end
						local L_232_ = L_19_:WaitForChild('BodyHit'):clone()
						L_232_.Parent = L_2_.PlayerGui
						L_232_:Play()
						game:GetService("Debris"):addItem(L_232_, L_232_.TimeLength)
					end
					if (L_214_.Parent:IsA('Accessory') or L_214_.Parent:IsA('Hat')) then
						L_107_:FireServer(L_227_, L_24_.HeadDamage)
						local L_233_ = L_19_:WaitForChild('BodyHit'):clone()
						L_233_.Parent = L_2_.PlayerGui
						L_233_:Play()
						game:GetService("Debris"):addItem(L_233_, L_233_.TimeLength)
					end
				end	
			end
		end
	
		if L_214_ and L_214_.Parent:FindFirstChild("Humanoid") then
			return L_214_, L_215_;
		end
		L_217_ = L_218_;
	end
end

function fireSemi()
	if L_15_ then
		L_66_ = false
		Recoiling = true
		Shooting = true
		
		--CheckReverb()
		
		L_56_:WaitForChild('Fire'):Play()	
		L_106_:FireServer()
		L_99_ = CreateBullet(L_24_.BulletSpread)
		L_100_ = L_100_ - 1
		UpdateAmmo()
		RecoilFront = true
		local L_234_, L_235_ = spawn(function()
			CastRay(L_99_)
		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 then
					if L_100_ > 0 then
						BoltingForwardAnim()
					end
				end
			end)
		end
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)		
		
		wait(L_24_.Firerate)
		
		local L_236_ = JamCalculation()
		if L_236_ then
			L_66_ = false
		else
			L_66_ = true
		end
		Shooting = false
	end
end

function fireExplo()
	if L_15_ then
		L_66_ = false
		Recoiling = true
		Shooting = true
		L_57_:WaitForChild('Fire'):Play()
		L_106_:FireServer()
		L_99_ = CreateBullet(L_24_.BulletSpread)
		L_102_ = L_102_ - 1
		UpdateAmmo()
		RecoilFront = true
		local L_237_, L_238_ = spawn(function()
			CastRay(L_99_)
		end)
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)		
			
		L_66_ = false
		Shooting = false
	end
end

function fireShot()
	if L_15_ then
		L_66_ = false
		Recoiling = true
		Shooting = true
		RecoilFront = true
		--CheckReverb()
		L_56_:WaitForChild('Fire'):Play()
		L_106_:FireServer()
		for L_240_forvar1 = 1, L_24_.ShotNum do
			L_99_ = CreateBullet(L_24_.BulletSpread)
			local L_241_, L_242_ = spawn(function()
				CastRay(L_99_)
			end)
		end
						
		for L_243_forvar1, L_244_forvar2 in pairs(L_56_:GetChildren()) do
			if L_244_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_244_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_245_forvar1, L_246_forvar2 in pairs(L_56_:GetChildren()) do
				if L_246_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_246_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 then
					if L_100_ > 0 then
						BoltingForwardAnim()
					end
				end
			end)
		end
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		L_100_ = L_100_ - 1
		UpdateAmmo()
		wait(L_24_.Firerate)
		
		L_73_ = true
		BoltBackAnim()
		BoltForwardAnim()
		IdleAnim()
		L_73_ = false
		
		local L_239_ = JamCalculation()
		if L_239_ then
			L_66_ = false
		else
			L_66_ = true
		end
		
		Shooting = false
	end
end

function fireBoltAction()
	if L_15_ then
		L_66_ = false
		Recoiling = true
		Shooting = true
		--CheckReverb()
		L_56_:WaitForChild('Fire'):Play()
		L_106_:FireServer()
		L_99_ = CreateBullet(L_24_.BulletSpread)
		L_100_ = L_100_ - 1
		UpdateAmmo()
		RecoilFront = true
		local L_247_, L_248_ = spawn(function()
			CastRay(L_99_)
		end)
						
		for L_250_forvar1, L_251_forvar2 in pairs(L_56_:GetChildren()) do
			if L_251_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_251_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_252_forvar1, L_253_forvar2 in pairs(L_56_:GetChildren()) do
				if L_253_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_253_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 then
					if L_100_ > 0 then
						BoltingForwardAnim()
					end
				end
			end)
		end
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		wait(L_24_.Firerate)
		
		L_73_ = true
		BoltBackAnim()
		BoltForwardAnim()
		IdleAnim()
		L_73_ = false
		
		local L_249_ = JamCalculation()
		if L_249_ then
			L_66_ = false
		else
			L_66_ = true
		end		
		
		Shooting = false
	end
end

function fireAuto()
	while not Shooting and L_100_ > 0 and L_65_ and L_66_ and L_15_ do
		L_66_ = false
		Recoiling = true
		--CheckReverb()
		L_56_:WaitForChild('Fire'):Play()
		L_106_:FireServer()
		L_100_ = L_100_ - 1
		UpdateAmmo()
		Shooting = true
		RecoilFront = true
		L_99_ = CreateBullet(L_24_.BulletSpread)
		local L_254_, L_255_ = spawn(function()
			CastRay(L_99_)
		end)
					
		for L_257_forvar1, L_258_forvar2 in pairs(L_56_:GetChildren()) do
			if L_258_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_258_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_259_forvar1, L_260_forvar2 in pairs(L_56_:GetChildren()) do
				if L_260_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_260_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 then
					if L_100_ > 0 then
						BoltingForwardAnim()
					end
				end
			end)
		end
		
		
		delay(L_24_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		wait(L_24_.Firerate)
		
		local L_256_ = JamCalculation()
		if L_256_ then
			L_66_ = false
		else
			L_66_ = true
		end
		
		Shooting = false
	end
end

function fireBurst()
	if not Shooting and L_100_ > 0 and L_65_ and L_15_ then
		for L_261_forvar1 = 1, L_24_.BurstNum do
			if L_100_ > 0 and L_65_ then
				L_66_ = false
				Recoiling = true
			--CheckReverb()
				L_56_:WaitForChild('Fire'):Play()
				L_106_:FireServer()
				L_99_ = CreateBullet(L_24_.BulletSpread)
				local L_262_, L_263_ = spawn(function()
					CastRay(L_99_)
				end)
					
				for L_265_forvar1, L_266_forvar2 in pairs(L_56_:GetChildren()) do
					if L_266_forvar2.Name:sub(1, 7) == "FlashFX" then
						L_266_forvar2.Enabled = true
					end
				end
		
				delay(1 / 30, function()
					for L_267_forvar1, L_268_forvar2 in pairs(L_56_:GetChildren()) do
						if L_268_forvar2.Name:sub(1, 7) == "FlashFX" then
							L_268_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 then
							if L_100_ > 0 then
								BoltingForwardAnim()
							end
						end
					end)
				end
			
				L_100_ = L_100_ - 1
				UpdateAmmo()
				RecoilFront = true
				delay(L_24_.Firerate / 2, function()
					Recoiling = false
					RecoilFront = false
				end)
				wait(L_24_.Firerate)
			
				local L_264_ = JamCalculation()
				if L_264_ then
					L_66_ = false
				else
					L_66_ = true
				end
		
			end
			Shooting = true
		end
		Shooting = false
	end
end

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