local T={}local q=(game:GetService("\080\108\097\121\101\114\115")).LocalPlayer:GetMouse()local H=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local r=workspace.CurrentCamera local n=workspace local s=Ray.new function T.GetPosition(T)return H:GetMouseLocation()end function T.GetDelta(T)return H:GetMouseDelta()end function T.Lock(T)H.MouseBehavior=Enum.MouseBehavior.LockCurrentPosition end function T.LockCenter(T)H.MouseBehavior=Enum.MouseBehavior.LockCenter end function T.Unlock(T)H.MouseBehavior=Enum.MouseBehavior.Default end function T.SetMouseIcon(H,T)q.Icon=T and"\114\098\120\097\115\115\101\116\105\100\058\047\047"..T or""end function T.SetMouseIconEnabled(q,T)H.MouseIconEnabled=T end function T.IsMouseIconEnabled(T)return H.MouseIconEnabled end function T.GetRay(T)local q=H:GetMouseLocation()local n=r:ViewportPointToRay(q.X,q.Y)return s(n.Origin,n.Direction*999)end function T.Cast(r,T,q,H)return n:FindPartOnRay(r:GetRay(),T,q,H)end function T.CastWithIgnoreList(r,T,q,H)return n:FindPartOnRayWithIgnoreList(r:GetRay(),T,q,H)end function T.CastWithWhitelist(H,T,q)return n:FindPartOnRayWithWhitelist(H:GetRay(),T,q)end function T.Start(T) end function T.Init(T)T.LeftDown=T.Shared.Event.new()T.LeftUp=T.Shared.Event.new()T.RightDown=T.Shared.Event.new()T.RightUp=T.Shared.Event.new()T.MiddleDown=T.Shared.Event.new()T.MiddleUp=T.Shared.Event.new()T.Moved=T.Shared.Event.new()T.Scrolled=T.Shared.Event.new()H.InputBegan:Connect(function(q,H)if H then return end if q.UserInputType==Enum.UserInputType.MouseButton1 then T.LeftDown:Fire()elseif q.UserInputType==Enum.UserInputType.MouseButton2 then T.RightDown:Fire()elseif q.UserInputType==Enum.UserInputType.MouseButton3 then T.MiddleDown:Fire()end end)H.InputEnded:Connect(function(q,H)if q.UserInputType==Enum.UserInputType.MouseButton1 then T.LeftUp:Fire()elseif q.UserInputType==Enum.UserInputType.MouseButton2 then T.RightUp:Fire()elseif q.UserInputType==Enum.UserInputType.MouseButton3 then T.MiddleUp:Fire()end end)H.InputChanged:Connect(function(q,H)if q.UserInputType==Enum.UserInputType.MouseMovement then T.Moved:Fire()elseif q.UserInputType==Enum.UserInputType.MouseWheel then if not H then T.Scrolled:Fire(q.Position.Z)end end end)end return T
-- Mouse
-- Crazyman32
-- December 28, 2017

--[[
	
	Vector2   Mouse:GetPosition()
	Vector2   Mouse:GetDelta()
	Void      Mouse:Lock()
	Void      Mouse:LockCenter()
	Void      Mouse:Unlock()
	Void      Mouse:SetMouseIcon(iconId)
	Void      Mouse:SetMouseIconEnabled(isEnabled)
	Boolean   Mouse:IsMouseIconEnabled()
	Many      Mouse:Cast(ignoreDescendantsInstance, terrainCellsAreCubes, ignoreWater)
	Many      Mouse:CastWithIgnoreList(ignoreDescendantsTable, terrainCellsAreCubes, ignoreWater)
	Many      Mouse:CastWithWhitelist(whitelistDescendantsTable, ignoreWater)
	
	Mouse.LeftDown()
	Mouse.LeftUp()
	Mouse.RightDown()
	Mouse.RightUp()
	Mouse.MiddleDown()
	Mouse.MiddleUp()
	Mouse.Moved()
	Mouse.Scrolled(amount)
	
--]]



local Mouse = {}

local playerMouse = game:GetService("Players").LocalPlayer:GetMouse()
local userInput = game:GetService("UserInputService")
local cam = workspace.CurrentCamera

local workspace = workspace
local RAY = Ray.new


function Mouse:GetPosition()
	return userInput:GetMouseLocation()
end


function Mouse:GetDelta()
	return userInput:GetMouseDelta()
end


function Mouse:Lock()
	userInput.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
end


function Mouse:LockCenter()
	userInput.MouseBehavior = Enum.MouseBehavior.LockCenter
end


function Mouse:Unlock()
	userInput.MouseBehavior = Enum.MouseBehavior.Default
end


function Mouse:SetMouseIcon(iconId)
	playerMouse.Icon = (iconId and ("rbxassetid://" .. iconId) or "")
end


function Mouse:SetMouseIconEnabled(enabled)
	userInput.MouseIconEnabled = enabled
end


function Mouse:IsMouseIconEnabled()
	return userInput.MouseIconEnabled
end


function Mouse:GetRay()
	local mousePos = userInput:GetMouseLocation()
	local viewportMouseRay = cam:ViewportPointToRay(mousePos.X, mousePos.Y)
	return RAY(viewportMouseRay.Origin, viewportMouseRay.Direction * 999)
end


function Mouse:Cast(ignoreDescendantsInstance, terrainCellsAreCubes, ignoreWater)
	return workspace:FindPartOnRay(self:GetRay(), ignoreDescendantsInstance, terrainCellsAreCubes, ignoreWater)
end


function Mouse:CastWithIgnoreList(ignoreDescendantsTable, terrainCellsAreCubes, ignoreWater)
	return workspace:FindPartOnRayWithIgnoreList(self:GetRay(), ignoreDescendantsTable, terrainCellsAreCubes, ignoreWater)
end


function Mouse:CastWithWhitelist(whitelistDescendantsTable, ignoreWater)
	return workspace:FindPartOnRayWithWhitelist(self:GetRay(), whitelistDescendantsTable, ignoreWater)
end


function Mouse:Start()
	
end


function Mouse:Init()
	
	self.LeftDown   = self.Shared.Event.new()
	self.LeftUp     = self.Shared.Event.new()
	self.RightDown  = self.Shared.Event.new()
	self.RightUp    = self.Shared.Event.new()
	self.MiddleDown = self.Shared.Event.new()
	self.MiddleUp   = self.Shared.Event.new()
	self.Moved      = self.Shared.Event.new()
	self.Scrolled   = self.Shared.Event.new()
	
	userInput.InputBegan:Connect(function(input, processed)
		if (processed) then return end
		if (input.UserInputType == Enum.UserInputType.MouseButton1) then
			self.LeftDown:Fire()
		elseif (input.UserInputType == Enum.UserInputType.MouseButton2) then
			self.RightDown:Fire()
		elseif (input.UserInputType == Enum.UserInputType.MouseButton3) then
			self.MiddleDown:Fire()
		end
	end)
	
	userInput.InputEnded:Connect(function(input, processed)
		if (input.UserInputType == Enum.UserInputType.MouseButton1) then
			self.LeftUp:Fire()
		elseif (input.UserInputType == Enum.UserInputType.MouseButton2) then
			self.RightUp:Fire()
		elseif (input.UserInputType == Enum.UserInputType.MouseButton3) then
			self.MiddleUp:Fire()
		end
	end)
	
	userInput.InputChanged:Connect(function(input, processed)
		if (input.UserInputType == Enum.UserInputType.MouseMovement) then
			self.Moved:Fire()
		elseif (input.UserInputType == Enum.UserInputType.MouseWheel) then
			if (not processed) then
				self.Scrolled:Fire(input.Position.Z)
			end
		end
	end)
	
end


return Mouse
