--// Firemode Functions

function CreateBullet(L_165_arg1)
	local L_166_ = L_41_.Position
	local L_167_ = (L_4_.Hit.p - L_166_).unit
	local L_168_ = CFrame.Angles(math.rad(math.random(-L_165_arg1, L_165_arg1)), math.rad(math.random(-L_165_arg1, L_165_arg1)), math.rad(math.random(-L_165_arg1, L_165_arg1)))
	L_167_ = L_168_ * L_167_	
	local L_169_ = CFrame.new(L_166_, L_166_ + L_167_)	
		
	local L_170_ = Instance.new("Part", L_76_)
	game.Debris:AddItem(L_170_, 10)
	L_170_.Shape = Enum.PartType.Ball
	L_170_.Size = Vector3.new(1, 1, 12)
	L_170_.Name = "Bullet"
	L_170_.TopSurface = "Smooth"
	L_170_.BottomSurface = "Smooth"
	L_170_.BrickColor = BrickColor.new("Bright green")
	L_170_.Material = "Neon"
	L_170_.CanCollide = false
		--Bullet.CFrame = FirePart.CFrame + (Grip.CFrame.p - Grip.CFrame.p)
	L_170_.CFrame = L_169_
		
	local L_171_ = Instance.new("Sound")
	L_171_.SoundId = "rbxassetid://341519743"
	L_171_.Looped = true
	L_171_:Play()
	L_171_.Parent = L_170_
	L_171_.Volume = 0.4
	L_171_.MaxDistance = 30
	
	L_170_.Transparency = 1
	local L_172_ = L_170_:GetMass()
	local L_173_ = Instance.new('BodyForce', L_170_)
		
	if not L_60_ then
		L_173_.Force = L_23_.BulletPhysics
		L_170_.Velocity = L_167_ * L_23_.BulletSpeed
	else
		L_173_.Force = L_23_.ExploPhysics
		L_170_.Velocity = L_167_ * L_23_.ExploSpeed
	end
		
	local L_174_ = Instance.new('Attachment', L_170_)
	L_174_.Position = Vector3.new(0.1, 0, 0)
	local L_175_ = Instance.new('Attachment', L_170_)
	L_175_.Position = Vector3.new(-0.1, 0, 0)
			
	local L_176_ = TracerCalculation()
		
	if L_23_.TracerEnabled == true and L_176_ then
		local L_177_ = Instance.new('Trail', L_170_)
		L_177_.Attachment0 = L_174_
		L_177_.Attachment1 = L_175_
		L_177_.Transparency = NumberSequence.new(L_23_.TracerTransparency)
		L_177_.LightEmission = L_23_.TracerLightEmission
		L_177_.TextureLength = L_23_.TracerTextureLength
		L_177_.Lifetime = L_23_.TracerLifetime
		L_177_.FaceCamera = L_23_.TracerFaceCamera
		L_177_.Color = ColorSequence.new(L_23_.TracerColor.Color)
	end
		
	if L_1_:FindFirstChild('Shell') and not L_60_ then	
		CreateShell()	
	end	
		
	delay(0.2, function()
		L_170_.Transparency = 0
	end)
	
	return L_170_
end

function CheckForHumanoid(L_178_arg1)
	local L_179_
	local L_180_
	if (L_178_arg1.Parent:FindFirstChild("Humanoid") or L_178_arg1.Parent.Parent:FindFirstChild("Humanoid")) then
		L_179_ = true
		if L_178_arg1.Parent:FindFirstChild('Humanoid') then
			L_180_ = L_178_arg1.Parent.Humanoid
		elseif L_178_arg1.Parent.Parent:FindFirstChild('Humanoid') then
			L_180_ = L_178_arg1.Parent.Parent.Humanoid
		end
	else
		L_179_ = false
	end	
	return L_179_, L_180_
end

function CastRay(L_181_arg1)
	local L_182_, L_183_, L_184_
	local L_185_ = L_38_.Position;
	local L_186_ = L_181_arg1.Position;
	local L_187_ = 0

	local L_188_ = L_60_	
	
	while true do
		L_81_:wait()
		L_186_ = L_181_arg1.Position;
		L_187_ = L_187_ + (L_186_ - L_185_).magnitude
		L_182_, L_183_, L_184_ = workspace:FindPartOnRayWithIgnoreList(Ray.new(L_185_, (L_186_ - L_185_)), IgnoreList);
		local L_189_ = Vector3.new(0, 1, 0):Cross(L_184_)
		local L_190_ = math.asin(L_189_.magnitude) -- division by 1 is redundant
		if L_187_ > 10000 then
			break
		end
		if L_182_ and (L_182_ and L_182_.Transparency >= 1 or L_182_.CanCollide == false) then
			table.insert(IgnoreList, L_182_)
		end
	
		if L_182_ then
			L_189_ = Vector3.new(0, 1, 0):Cross(L_184_)
			L_190_ = math.asin(L_189_.magnitude) -- division by 1 is redundant
		
			local L_191_ = CheckForHumanoid(L_182_)
			if L_191_ == false then
				L_181_arg1:Destroy()
				local L_192_ = L_88_:InvokeServer(L_183_, L_189_, L_190_, L_184_, "Part")
				table.insert(IgnoreList, L_192_)
			elseif L_191_ == true then
				L_181_arg1:Destroy()
				local L_193_ = L_88_:InvokeServer(L_183_, L_189_, L_190_, L_184_, "Human")
				table.insert(IgnoreList, L_193_)
			end
		end
	
		if L_182_ and L_188_ then
			L_91_:FireServer(L_183_)
		end
	
		if L_182_ and (L_182_.Parent:FindFirstChild("Humanoid") or L_182_.Parent.Parent:FindFirstChild("Humanoid")) then
			local L_194_, L_195_ = CheckForHumanoid(L_182_)
			if L_194_ then
				L_86_:FireServer(L_195_)
				if L_23_.AntiTK then
					if game.Players:FindFirstChild(L_195_.Parent.Name) and game.Players:FindFirstChild(L_195_.Parent.Name).TeamColor ~= L_2_.TeamColor then
						if L_182_.Name == 'Head' then
							L_85_:FireServer(L_195_, L_23_.HeadDamage)
							local L_196_ = L_18_:WaitForChild('BodyHit'):clone()
							L_196_.Parent = L_2_.PlayerGui
							L_196_:Play()
							game:GetService("Debris"):addItem(L_196_, L_196_.TimeLength)
						elseif L_182_.Name ~= 'Head' and not (L_182_.Parent:IsA('Accessory') or L_182_.Parent:IsA('Hat')) then
							L_85_:FireServer(L_195_, L_23_.Damage)
							local L_197_ = L_18_:WaitForChild('BodyHit'):clone()
							L_197_.Parent = L_2_.PlayerGui
							L_197_:Play()
							game:GetService("Debris"):addItem(L_197_, L_197_.TimeLength)
						elseif (L_182_.Parent:IsA('Accessory') or L_182_.Parent:IsA('Hat')) then
							L_85_:FireServer(L_195_, L_23_.HeadDamage)
							local L_198_ = L_18_:WaitForChild('BodyHit'):clone()
							L_198_.Parent = L_2_.PlayerGui
							L_198_:Play()
							game:GetService("Debris"):addItem(L_198_, L_198_.TimeLength)
						end
					end
				else
					if L_182_.Name == 'Head' then
						L_85_:FireServer(L_195_, L_23_.HeadDamage)
						local L_199_ = L_18_:WaitForChild('BodyHit'):clone()
						L_199_.Parent = L_2_.PlayerGui
						L_199_:Play()
						game:GetService("Debris"):addItem(L_199_, L_199_.TimeLength)
					elseif L_182_.Name ~= 'Head' and not (L_182_.Parent:IsA('Accessory') or L_182_.Parent:IsA('Hat')) then
						L_85_:FireServer(L_195_, L_23_.Damage)
						local L_200_ = L_18_:WaitForChild('BodyHit'):clone()
						L_200_.Parent = L_2_.PlayerGui
						L_200_:Play()
						game:GetService("Debris"):addItem(L_200_, L_200_.TimeLength)
					elseif (L_182_.Parent:IsA('Accessory') or L_182_.Parent:IsA('Hat')) then
						L_85_:FireServer(L_195_, L_23_.HeadDamage)
						local L_201_ = L_18_:WaitForChild('BodyHit'):clone()
						L_201_.Parent = L_2_.PlayerGui
						L_201_:Play()
						game:GetService("Debris"):addItem(L_201_, L_201_.TimeLength)
					end
				end	
			end
		end
	
		if L_182_ and L_182_.Parent:FindFirstChild("Humanoid") then
			return L_182_, L_183_;
		end
		L_185_ = L_186_;
	end
end

function fireSemi()
	if L_15_ then
		L_51_ = false
		Recoiling = true
		Shooting = true
		L_41_:WaitForChild('Fire'):Play()
		L_84_:FireServer()
		L_77_ = CreateBullet(0)
		L_78_ = L_78_ - 1
		RecoilFront = true
		local L_202_, L_203_ = spawn(function()
			CastRay(L_77_)
		end)
		
		if L_23_.CanBolt == true then
			BoltingBackAnim()
			delay(L_23_.Firerate / 2, function()
				if L_23_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_23_.CanSlideLock == true and L_78_ <= 0 then
					BoltingBackAnim()
				end
			end)
		end
		
		delay(L_23_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)		
		
		wait(L_23_.Firerate)
		
		local L_204_ = JamCalculation()
		if L_204_ then
			L_51_ = false
		else
			L_51_ = true
		end
		Shooting = false
	end
end

function fireExplo()
	if L_15_ then
		L_51_ = false
		Recoiling = true
		Shooting = true
		L_42_:WaitForChild('Fire'):Play()
		L_84_:FireServer()
		L_77_ = CreateBullet(0)
		L_80_ = L_80_ - 1
		RecoilFront = true
		local L_205_, L_206_ = spawn(function()
			CastRay(L_77_)
		end)
		
		delay(L_23_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)		
			
		L_51_ = false
		Shooting = false
	end
end

function fireShot()
	if L_15_ then
		L_51_ = false
		Recoiling = true
		Shooting = true
		RecoilFront = true
		L_41_:WaitForChild('Fire'):Play()
		L_84_:FireServer()
		for L_208_forvar1 = 1, L_23_.ShotNum do
			L_77_ = CreateBullet(2)
			local L_209_, L_210_ = spawn(function()
				CastRay(L_77_)
			end)
		end
						
		for L_211_forvar1, L_212_forvar2 in pairs(L_41_:GetChildren()) do
			if L_212_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_212_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_213_forvar1, L_214_forvar2 in pairs(L_41_:GetChildren()) do
				if L_214_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_214_forvar2.Enabled = false
				end
			end
		end)
		
		if L_23_.CanBolt == true then
			BoltingBackAnim()
			delay(L_23_.Firerate / 2, function()
				if L_23_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_23_.CanSlideLock == true and L_78_ > 0 then
					BoltingBackAnim()
				end
			end)
		end
		
		delay(L_23_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		L_78_ = L_78_ - 1
		wait(L_23_.Firerate)
		
		L_58_ = true
		BoltBackAnim()
		BoltForwardAnim()
		IdleAnim()
		L_58_ = false
		
		local L_207_ = JamCalculation()
		if L_207_ then
			L_51_ = false
		else
			L_51_ = true
		end
		
		Shooting = false
	end
end

function fireBoltAction()
	if L_15_ then
		L_51_ = false
		Recoiling = true
		Shooting = true
		L_41_:WaitForChild('Fire'):Play()
		L_84_:FireServer()
		L_77_ = CreateBullet(0)
		L_78_ = L_78_ - 1
		RecoilFront = true
		local L_215_, L_216_ = spawn(function()
			CastRay(L_77_)
		end)
						
		for L_218_forvar1, L_219_forvar2 in pairs(L_41_:GetChildren()) do
			if L_219_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_219_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_220_forvar1, L_221_forvar2 in pairs(L_41_:GetChildren()) do
				if L_221_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_221_forvar2.Enabled = false
				end
			end
		end)
		
		if L_23_.CanBolt == true then
			BoltingBackAnim()
			delay(L_23_.Firerate / 2, function()
				if L_23_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_23_.CanSlideLock == true and L_78_ > 0 then
					BoltingBackAnim()
				end
			end)
		end
		
		delay(L_23_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		wait(L_23_.Firerate)
		
		L_58_ = true
		BoltBackAnim()
		BoltForwardAnim()
		IdleAnim()
		L_58_ = false
		
		local L_217_ = JamCalculation()
		if L_217_ then
			L_51_ = false
		else
			L_51_ = true
		end		
		
		Shooting = false
	end
end

function fireAuto()
	while not Shooting and L_78_ > 0 and L_50_ and L_51_ and L_15_ do
		L_51_ = false
		Recoiling = true
		L_41_:WaitForChild('Fire'):Play()
		L_84_:FireServer()
		L_78_ = L_78_ - 1
		Shooting = true
		RecoilFront = true
		L_77_ = CreateBullet(0)
		local L_222_, L_223_ = spawn(function()
			CastRay(L_77_)
		end)
					
		for L_225_forvar1, L_226_forvar2 in pairs(L_41_:GetChildren()) do
			if L_226_forvar2.Name:sub(1, 7) == "FlashFX" then
				L_226_forvar2.Enabled = true
			end
		end
	
		delay(1 / 30, function()
			for L_227_forvar1, L_228_forvar2 in pairs(L_41_:GetChildren()) do
				if L_228_forvar2.Name:sub(1, 7) == "FlashFX" then
					L_228_forvar2.Enabled = false
				end
			end
		end)
		
		if L_23_.CanBolt == true then
			BoltingBackAnim()
			delay(L_23_.Firerate / 2, function()
				if L_23_.CanSlideLock == false then
					BoltingForwardAnim()
				elseif L_23_.CanSlideLock == true and L_78_ > 0 then
					BoltingForwardAnim()
				end
			end)
		end
		
		
		delay(L_23_.Firerate / 2, function()
			Recoiling = false
			RecoilFront = false
		end)
		wait(L_23_.Firerate)
		
		local L_224_ = JamCalculation()
		if L_224_ then
			L_51_ = false
		else
			L_51_ = true
		end
		
		Shooting = false
	end
end

function fireBurst()
	if not Shooting and L_78_ > 0 and L_50_ and L_15_ then
		for L_229_forvar1 = 1, L_23_.BurstNum do
			if L_78_ > 0 and L_50_ then
				L_51_ = false
				Recoiling = true
				L_41_:WaitForChild('Fire'):Play()
				L_84_:FireServer()
				L_77_ = CreateBullet(0)
				local L_230_, L_231_ = spawn(function()
					CastRay(L_77_)
				end)
					
				for L_233_forvar1, L_234_forvar2 in pairs(L_41_:GetChildren()) do
					if L_234_forvar2.Name:sub(1, 7) == "FlashFX" then
						L_234_forvar2.Enabled = true
					end
				end
		
				delay(1 / 30, function()
					for L_235_forvar1, L_236_forvar2 in pairs(L_41_:GetChildren()) do
						if L_236_forvar2.Name:sub(1, 7) == "FlashFX" then
							L_236_forvar2.Enabled = false
						end
					end
				end)
			
				if L_23_.CanBolt == true then
					BoltingBackAnim()
					delay(L_23_.Firerate / 2, function()
						if L_23_.CanSlideLock == false then
							BoltingForwardAnim()
						elseif L_23_.CanSlideLock == true and L_78_ > 0 then
							BoltingForwardAnim()
						end
					end)
				end
			
				L_78_ = L_78_ - 1
				RecoilFront = true
				delay(L_23_.Firerate / 2, function()
					Recoiling = false
					RecoilFront = false
				end)
				wait(L_23_.Firerate)
			
				local L_232_ = JamCalculation()
				if L_232_ then
					L_51_ = false
				else
					L_51_ = true
				end
		
			end
			Shooting = true
		end
		Shooting = false
	end
end

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