-------------//Events\\-------------


Evt.HitEffect.OnClientEvent:Connect(function(Player,Position, HitPart, Normal, Material,Settings)
	if Player ~= plr then 
		HitMod.HitEffect(Ignore_Model,Position, HitPart, Normal, Material,Settings)
	end
end)

Evt.Atirar.OnClientEvent:Connect(function(Player,Arma,Suppressor,FlashHider)
	if Player ~= plr and Arma then 
		if Player.Character:FindFirstChild("S"..Arma.Name) and Player.Character:FindFirstChild('S'..Arma.Name).Handle:FindFirstChild("Muzzle") then
			local Muzzle = Player.Character:FindFirstChild("S"..Arma.Name).Handle.Muzzle

			if Suppressor then
				Muzzle.Supressor:Play()
			else
				Muzzle.Fire:Play()
			end

			if FlashHider then
				Muzzle["Smoke"]:Emit(10)
			else
				Muzzle["FlashFX[Flash]"]:Emit(10)
				Muzzle["Smoke"]:Emit(10)
			end
		end


		if Player.Character:FindFirstChild("AnimBase") ~= nil and Player.Character.AnimBase:FindFirstChild("AnimBaseW") then
			local AnimBase = Player.Character:WaitForChild("AnimBase"):WaitForChild("AnimBaseW")
			TS:Create(AnimBase, TweenInfo.new(0.05,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0), {C1 =  CFrame.new(0,0,0.15):Inverse()} ):Play()
			delay(.1,function()
				TS:Create(AnimBase, TweenInfo.new(.05,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0), {C1 =  CFrame.new():Inverse()} ):Play()
			end)
		end
	end
end)

Evt.SVLaser.OnClientEvent:Connect(function(Player,Position,Modo,Cor,IR,Arma)

	if Player ~= plr and Player.Character and Arma then

		if ACS_Workspace.Server:FindFirstChild(Player.Name.."_Laser") == nil then
			local Dot = Instance.new('Part',ACS_Workspace.Server)
			local Att0 = Instance.new('Attachment',Dot)
			Att0.Name = "Att0"
			Dot.Name = Player.Name.."_Laser"
			Dot.Transparency = 1

			if Player.Character:FindFirstChild("S"..Arma.Name) and Player.Character:FindFirstChild('S'..Arma.Name).Handle:FindFirstChild("Muzzle") then
				local Muzzle = Player.Character:FindFirstChild("S"..Arma.Name).Handle.Muzzle

				local Laser = Instance.new('Beam',Dot)
				Laser.Transparency = NumberSequence.new(0)
				Laser.LightEmission = 1
				Laser.LightInfluence = 0
				Laser.Attachment0 = Att0
				Laser.Attachment1 = Muzzle
				Laser.Color = ColorSequence.new(Cor)
				Laser.FaceCamera = true
				Laser.Width0 = 0.01
				Laser.Width1 = 0.01
				if not NVG then
					Laser.Enabled = false
				end
			end
		end

		if Modo == 1 then
			if ACS_Workspace.Server:FindFirstChild(Player.Name.."_Laser") then
				local LA = ACS_Workspace.Server:FindFirstChild(Player.Name.."_Laser")
				LA.Shape = 'Ball'
				LA.Size = Vector3.new(0.2, 0.2, 0.2)
				LA.CanCollide = false
				LA.Anchored = true
				LA.Color = Cor
				LA.Material = Enum.Material.Neon
				LA.Position = Position	
				if NVG then
					LA.Transparency = 0

					if LA:FindFirstChild("Beam") then
						LA.Beam.Enabled = true
					end
				else
					if IR then
						LA.Transparency = 1
					else
						LA.Transparency = 0
					end

					if LA:FindFirstChild("Beam") then
						LA.Beam.Enabled = false
					end
				end
			end

		elseif Modo == 2 then
			if ACS_Workspace.Server:FindFirstChild(Player.Name.."_Laser") then
				ACS_Workspace.Server:FindFirstChild(Player.Name.."_Laser"):Destroy()
			end
		end
	end
end)

Evt.SVFlash.OnClientEvent:Connect(function(Player,Arma,Mode)

	if Player ~= plr and Player.Character and Arma then
		local Weapon = Player.Character:FindFirstChild("S"..Arma.Name)
		if Weapon then
			if Mode then
				for index, Key in pairs(Weapon:GetDescendants()) do
					if Key:IsA("BasePart") and Key.Name == "FlashPoint" then
						Key.Light.Enabled = true
					end
				end
			else
				for index, Key in pairs(Weapon:GetDescendants()) do
					if Key:IsA("BasePart") and Key.Name == "FlashPoint" then
						Key.Light.Enabled = false
					end
				end
			end
		end
	end
end)

Evt.Whizz.OnClientEvent:connect(function()

	local Som = Instance.new('Sound')
	Som.Parent = plr.PlayerGui
	Som.SoundId = "rbxassetid://"..WhizzSound[math.random(1,#WhizzSound)]
	Som.Volume = 2
	Som.PlayOnRemove = true
	Som:Destroy()

end)

Evt.MedSys.MedHandler.OnClientEvent:connect(function(Mode)

	if Mode == 4 then
		local FX = Instance.new('ColorCorrectionEffect')
		FX.Parent = cam

		TS:Create(FX,TweenInfo.new(.15,Enum.EasingStyle.Linear),{Contrast = -.25}):Play()
		delay(.15,function()
			TS:Create(FX,TweenInfo.new(1.5,Enum.EasingStyle.Sine,Enum.EasingDirection.In,0,false,0.15),{Contrast = 0}):Play()
			Debris:AddItem(FX,1.5)
		end)

	elseif Mode == 5 then
		local FX = Instance.new('ColorCorrectionEffect')
		FX.Parent = cam

		TS:Create(FX,TweenInfo.new(.15,Enum.EasingStyle.Linear),{Contrast = .5}):Play()
		delay(.15,function()
			TS:Create(FX,TweenInfo.new(1.5,Enum.EasingStyle.Sine,Enum.EasingDirection.In,0,false,0.15),{Contrast = 0}):Play()
			Debris:AddItem(FX,1.5)
		end)

	elseif Mode == 6 then
		local FX = Instance.new('ColorCorrectionEffect')
		FX.Parent = cam

		TS:Create(FX,TweenInfo.new(.15,Enum.EasingStyle.Linear),{Contrast = -.25}):Play()
		delay(.15,function()
			TS:Create(FX,TweenInfo.new(60,Enum.EasingStyle.Sine,Enum.EasingDirection.In,0,false,0.15),{Contrast = 0}):Play()
			Debris:AddItem(FX,60)
		end)

	elseif Mode == 7 then
		local FX = Instance.new('ColorCorrectionEffect')
		FX.Parent = cam

		TS:Create(FX,TweenInfo.new(.15,Enum.EasingStyle.Linear),{Contrast = .5}):Play()
		delay(.15,function()
			TS:Create(FX,TweenInfo.new(30,Enum.EasingStyle.Sine,Enum.EasingDirection.In,0,false,0.15),{Contrast = 0}):Play()
			Debris:AddItem(FX,30)
		end)
	end

end)

Evt.Suppression.OnClientEvent:Connect(function(Mode,Intensity,Tempo)
	local SE_GUI = plr.PlayerGui:FindFirstChild("StatusUI")
	if plr.Character and plr.Character.Humanoid.Health > 0 and SE_GUI then
		if Mode == 1 then

			TS:Create(SE_GUI.Efeitos.Suppress,TweenInfo.new(.1),{ImageTransparency = 0, Size = UDim2.fromScale(1,1.15)}):Play()
			delay(.1,function()
				TS:Create(SE_GUI.Efeitos.Suppress,TweenInfo.new(1,Enum.EasingStyle.Exponential,Enum.EasingDirection.InOut,0,false,0.15),{ImageTransparency = 1,Size = UDim2.fromScale(2,2)}):Play()
			end)
		elseif Mode == 2 then

			local ring = PastaFx.EarRing:Clone()
			ring.Parent = plr.PlayerGui
			ring.Volume = 0
			ring:Play()
			Debris:AddItem(ring,Tempo)

			TS:Create(ring,TweenInfo.new(.1),{Volume = 2}):Play()
			delay(.1,function()
				TS:Create(ring,TweenInfo.new(Tempo,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0.15),{Volume = 0}):Play()
			end)

			TS:Create(SE_GUI.Efeitos.Dirty,TweenInfo.new(.1),{ImageTransparency = 0, Size = UDim2.fromScale(1,1.15)}):Play()
			delay(.1,function()
				TS:Create(SE_GUI.Efeitos.Dirty,TweenInfo.new(Tempo,Enum.EasingStyle.Exponential,Enum.EasingDirection.InOut,0,false,0.15),{ImageTransparency = 1,Size = UDim2.fromScale(2,2)}):Play()
			end)

		else

			local ring = PastaFx.EarRing:Clone()
			ring.Parent = plr.PlayerGui
			ring.Volume = 0
			ring:Play()
			Debris:AddItem(ring,Tempo)

			TS:Create(ring,TweenInfo.new(.1),{Volume = 2}):Play()
			delay(.1,function()
				TS:Create(ring,TweenInfo.new(Tempo,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0.15),{Volume = 0}):Play()
			end)
		end
	end
end)

Evt.GunStance.OnClientEvent:Connect(function(Player,stance,Data)
	if not Player or not Player.Character then return; end;
	if not Player.Character:FindFirstChild("Humanoid") or Player.Character.Humanoid.Health <= 0 then return; end;
	if not Player.Character:FindFirstChild("AnimBase") or not Player.Character.AnimBase:FindFirstChild("RAW") or not Player.Character.AnimBase:FindFirstChild("LAW") then return; end;

	local Right_Weld = Player.Character.AnimBase:FindFirstChild("RAW")
	local Left_Weld = Player.Character.AnimBase:FindFirstChild("LAW")

	if not Right_Weld or not Left_Weld then return; end;
	--// Some Yanderedev work over here, huh?
	if stance == 0 then
		TS:Create(Right_Weld, TweenInfo.new(.25,Enum.EasingStyle.Sine), {C0 = Data.SV_RightArmPos} ):Play()
		TS:Create(Left_Weld, TweenInfo.new(.25,Enum.EasingStyle.Sine), {C0 = Data.SV_LeftArmPos} ):Play()
		return;
	elseif stance == 2 then
		TS:Create(Right_Weld, TweenInfo.new(.25,Enum.EasingStyle.Sine), {C0 = Data.RightAim} ):Play()
		TS:Create(Left_Weld, TweenInfo.new(.25,Enum.EasingStyle.Sine), {C0 = Data.LeftAim} ):Play()
		return;
	elseif stance == 1 then
		TS:Create(Right_Weld, TweenInfo.new(.25,Enum.EasingStyle.Sine), {C0 = Data.RightHighReady} ):Play()
		TS:Create(Left_Weld, TweenInfo.new(.25,Enum.EasingStyle.Sine), {C0 = Data.LeftHighReady} ):Play()
		return;
	elseif stance == -1 then
		TS:Create(Right_Weld, TweenInfo.new(.25,Enum.EasingStyle.Sine), {C0 = Data.RightLowReady} ):Play()
		TS:Create(Left_Weld, TweenInfo.new(.25,Enum.EasingStyle.Sine), {C0 = Data.LeftLowReady} ):Play()
		return;
	elseif stance == -2 then
		TS:Create(Right_Weld, TweenInfo.new(.25,Enum.EasingStyle.Sine), {C0 = Data.RightPatrol} ):Play()
		TS:Create(Left_Weld, TweenInfo.new(.25,Enum.EasingStyle.Sine), {C0 = Data.LeftPatrol} ):Play()
		return;
	elseif stance == 3 then
		TS:Create(Right_Weld, TweenInfo.new(.25,Enum.EasingStyle.Sine), {C0 = Data.RightSprint} ):Play()
		TS:Create(Left_Weld, TweenInfo.new(.25,Enum.EasingStyle.Sine), {C0 = Data.LeftSprint} ):Play()
		return;
	end
	return;
end)

Evt.HeadRot.OnClientEvent:Connect(function(Player, CF)
	if not Player or Player == plr or not Player.Character or not Player.Character:FindFirstChild("Torso") or not Player.Character:FindFirstChild("Head") then return; end;
	local Neck = Player.Character.Torso:FindFirstChild("Neck");
	if not Neck then return; end;
	TS:Create(Neck, TweenInfo.new(.2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {C1 = CF}):Play()
end)

function CastRay(Bullet)
	if not Bullet then return; end;

	local Bpos = Bullet.Position
	local Bpos2 = Bpos
	local recast = false
	local raycastResult

	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = Ignore_Model
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	raycastParams.IgnoreWater = true

	while Bullet do
		Run.Heartbeat:Wait()
		if not Bullet.Parent then break; end;
		Bpos = Bullet.Position

		-- Set an origin and directional vector
		raycastResult = workspace:Raycast(Bpos2, (Bpos - Bpos2) * 1, raycastParams)
		recast = false

		if raycastResult then
			local Hit2 = raycastResult.Instance

			if Hit2 and (Hit2.Parent:IsA('Accessory') or Hit2.Parent:IsA('Hat') or Hit2.Transparency >= 1 or Hit2.CanCollide == false or Hit2.Name == "Ignorable" or Hit2.Name == "Glass" or Hit2.Name == "Ignore" or Hit2.Parent.Name == "Top" or Hit2.Parent.Name == "Helmet" or Hit2.Parent.Name == "Up" or Hit2.Parent.Name == "Down" or Hit2.Parent.Name == "Face" or Hit2.Parent.Name == "Olho" or Hit2.Parent.Name == "Headset" or Hit2.Parent.Name == "Numero" or Hit2.Parent.Name == "Vest" or Hit2.Parent.Name == "Chest" or Hit2.Parent.Name == "Waist" or Hit2.Parent.Name == "Back" or Hit2.Parent.Name == "Belt" or Hit2.Parent.Name == "Leg1" or Hit2.Parent.Name == "Leg2" or Hit2.Parent.Name == "Arm1"  or Hit2.Parent.Name == "Arm2") and Hit2.Name ~= 'Right Arm' and Hit2.Name ~= 'Left Arm' and Hit2.Name ~= 'Right Leg' and Hit2.Name ~= 'Left Leg' and Hit2.Name ~= "UpperTorso" and Hit2.Name ~= "LowerTorso" and Hit2.Name ~= "RightUpperArm" and Hit2.Name ~= "RightLowerArm" and Hit2.Name ~= "RightHand" and Hit2.Name ~= "LeftUpperArm" and Hit2.Name ~= "LeftLowerArm" and Hit2.Name ~= "LeftHand" and Hit2.Name ~= "RightUpperLeg" and Hit2.Name ~= "RightLowerLeg" and Hit2.Name ~= "RightFoot" and Hit2.Name ~= "LeftUpperLeg" and Hit2.Name ~= "LeftLowerLeg" and Hit2.Name ~= "LeftFoot" and Hit2.Name ~= 'Armor' and Hit2.Name ~= 'EShield' then
				table.insert(Ignore_Model, Hit2)
				recast = true
				CastRay(Bullet)
				break
			end
		end

		if raycastResult and not recast then
			Bullet:Destroy()
			break
		end

		Bpos2 = Bpos

	end
end


Evt.ServerBullet.OnClientEvent:Connect(function(Player, Origin, Direction, WeaponData, ModTable)
	if Player ~= plr and Player.Character then 
		local Bullet = Instance.new("Part",ACS_Workspace.Server)
		Bullet.Name = Player.Name.."_Bullet"
		Bullet.CanCollide = false
		Bullet.Shape = Enum.PartType.Ball
		Bullet.Transparency = 1
		Bullet.Size = Vector3.new(1,1,1)

		local BulletCF 		= CFrame.new(Origin, Direction) 
		local WalkMul 		= WeaponData.WalkMult * ModTable.WalkMult
		local BColor 		= Color3.fromRGB(255,255,255)

		if WeaponData.RainbowMode then
			BColor = Color3.fromRGB(math.random(0,255),math.random(0,255),math.random(0,255))
		else
			BColor = WeaponData.TracerColor
		end

		if WeaponData.Tracer == true then

			local At1 = Instance.new("Attachment")
			At1.Name = "At1"
			At1.Position = Vector3.new(-(.05),0,0)
			At1.Parent = Bullet

			local At2  = Instance.new("Attachment")
			At2.Name = "At2"
			At2.Position = Vector3.new((.05),0,0)
			At2.Parent = Bullet

			local Particles = Instance.new("Trail")
			Particles.Transparency = NumberSequence.new({
				NumberSequenceKeypoint.new(0, 0, 0);
				NumberSequenceKeypoint.new(1, 1);
			}
			)
			Particles.WidthScale = NumberSequence.new({
				NumberSequenceKeypoint.new(0, 2, 0);
				NumberSequenceKeypoint.new(1, 1);
			}
			)


			Particles.Color = ColorSequence.new(BColor)
			Particles.Texture = "rbxassetid://232918622"
			Particles.TextureMode = Enum.TextureMode.Stretch

			Particles.FaceCamera = true
			Particles.LightEmission = 1
			Particles.LightInfluence = 0
			Particles.Lifetime = .25
			Particles.Attachment0 = At1
			Particles.Attachment1 = At2
			Particles.Parent = Bullet
		end

		if WeaponData.BulletFlare == true then
			local bg = Instance.new("BillboardGui", Bullet)
			bg.Adornee = Bullet
			local flashsize = math.random(275, 375)/10
			bg.Size = UDim2.new(flashsize, 0, flashsize, 0)
			bg.LightInfluence = 0
			local flash = Instance.new("ImageLabel", bg)
			flash.BackgroundTransparency = 1
			flash.Size = UDim2.new(1, 0, 1, 0)
			flash.Position = UDim2.new(0, 0, 0, 0)
			flash.Image = "http://www.roblox.com/asset/?id=1047066405"
			flash.ImageTransparency = math.random(2, 5)/15
			flash.ImageColor3 = BColor
		end

		local BulletMass = Bullet:GetMass()
		local Force = Vector3.new(0,BulletMass * (196.2) - (WeaponData.BulletDrop) * (196.2), 0)
		local BF = Instance.new("BodyForce",Bullet)

		Bullet.CFrame = BulletCF
		Bullet:ApplyImpulse(Direction * WeaponData.MuzzleVelocity * ModTable.MuzzleVelocity)
		BF.Force = Force

		game.Debris:AddItem(Bullet, 5)
		CastRay(Bullet)
	end
end)