XxMirayxX21

OrnamentalMouse

May 22nd, 2021
869
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- // Constants \\ --
  2. -- [ Services ] --
  3. local Services = setmetatable({}, {__index = function(Self, Index)
  4.     local NewService = game.GetService(game, Index)
  5.     if NewService then
  6.         Self[Index] = NewService
  7.     end
  8.     return NewService
  9. end})
  10.  
  11. -- [ LocalPlayer ] --
  12. local LocalPlayer = Services.Players.LocalPlayer
  13.  
  14. -- // Variables \\ --
  15. local IconChanged = Instance.new("BindableEvent")
  16.  
  17. -- // Functions \\ --
  18. local Utility = {}
  19. function Utility.new(Class, Properties, Children)
  20.     local NewInstance = Instance.new(Class)
  21.     for i,v in pairs(Properties or {}) do
  22.         if i ~= "Parent" then
  23.             NewInstance[i] = v
  24.         end
  25.     end
  26.     for i,v in ipairs(Children or {}) do
  27.         if typeof(v) == "Instance" then
  28.             v.Parent = NewInstance
  29.         end
  30.     end
  31.  
  32.     NewInstance.Parent = Properties.Parent
  33.     return NewInstance
  34. end
  35.  
  36. local function Quadratic(Origin, CurveOffset, Goal, Alpha)
  37.     local L1 = Origin:Lerp(CurveOffset, Alpha)
  38.     local L2 = CurveOffset:Lerp(Goal, Alpha)
  39.     return L1:Lerp(L2, Alpha)
  40. end
  41.  
  42. local function GetMousePosition()
  43.     return Services.UserInputService:GetMouseLocation() - Vector2.new(0, 36)
  44. end
  45.  
  46. -- // Main Module \\ --
  47. local OrnamentalMouse = {}
  48. OrnamentalMouse.ClassName = "OrnamentalMouse"
  49. OrnamentalMouse.__index = OrnamentalMouse
  50.  
  51. function OrnamentalMouse.new()
  52.     local self = setmetatable({
  53.         Enabled = true;
  54.         AutoUpdate = true;
  55.         Sensitivity = 0.5;
  56.     }, OrnamentalMouse)
  57.     self._ForceUpdate = false;
  58.  
  59.     -- Interface --
  60.     self._ScreenGui = Instance.new("ScreenGui")
  61.     self._Icon = Instance.new("ImageLabel")
  62.  
  63.     -- Event Listeners --
  64.     IconChanged.Event:Connect(function(Icon)
  65.         if Icon == "" then
  66.             Icon = "rbxasset://textures/ArrowFarCursor.png"
  67.         end
  68.         Services.RunService.RenderStepped:Wait()
  69.         self._Icon.Image = Icon
  70.     end)
  71.  
  72.     -- Actions --
  73.     self._ScreenGui.DisplayOrder = 5e10
  74.  
  75.     self._Icon.Name = "Icon"
  76.     self._Icon.AnchorPoint = Vector2.new(0.5, 0.5)
  77.     self._Icon.BackgroundTransparency = 1
  78.     self._Icon.Size = UDim2.new(0, 64, 0, 64)
  79.     self._Icon.Image = "rbxasset://textures/ArrowFarCursor.png"
  80.     self._Icon.ScaleType = Enum.ScaleType.Fit
  81.  
  82.     self._Icon.Parent = self._ScreenGui
  83.     self._ScreenGui.Parent = Services.RunService:IsStudio() and (LocalPlayer:FindFirstChildWhichIsA("PlayerGui") or LocalPlayer:WaitForChild("PlayerGui")) or Services.CoreGui
  84.  
  85.     Services.RunService:BindToRenderStep("UpdateOrnamentalMouse", Enum.RenderPriority.Input.Value, function()
  86.         Services.UserInputService.MouseIconEnabled = not self.Enabled
  87.         self._Icon.Visible = self.Enabled
  88.         self._Icon.Size = Services.UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter and UDim2.new(0, 32, 0, 32) or UDim2.new(0, 64, 0, 64)
  89.         if self.AutoUpdate or self._ForceUpdate then
  90.             local MousePosition = GetMousePosition()
  91.             self:TweenPosition(MousePosition, 0.05)
  92.         end
  93.         if Services.UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) or Services.UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then
  94.             self._ForceUpdate = true
  95.         end
  96.     end)
  97.  
  98.     return self
  99. end
  100.  
  101. function OrnamentalMouse:OverridePosition(Position)
  102.     self._Icon.Position = UDim2.fromOffset(Position.X, Position.Y)
  103. end
  104.  
  105. function OrnamentalMouse:TweenPosition(Position, Duration)
  106.     local Distance = (GetMousePosition() - self._Icon.AbsolutePosition).Magnitude
  107.     local Speed = (Distance * 0.01) / (self.Sensitivity * 10)
  108.     Services.TweenService:Create(self._Icon, TweenInfo.new(Duration or Speed), {Position = UDim2.fromOffset(Position.X, Position.Y)}):Play()
  109. end
  110.  
  111. function OrnamentalMouse:MoveBezier(Position)
  112.     local Distance = (GetMousePosition() - Position).Magnitude
  113.     local LoopCount = math.clamp(Distance * 0.05, 1, 50)  / (self.Sensitivity * 10)
  114.     local RandomOffset = math.random(-25, 25)
  115.     for i = 1, LoopCount do
  116.         local MousePosition = GetMousePosition()
  117.         local Result = Quadratic(MousePosition, Vector2.new(Position.X + RandomOffset, MousePosition.Y), Position, i/LoopCount)
  118.         self:TweenPosition(Result)
  119.         Services.RunService.RenderStepped:Wait()
  120.     end
  121. end
  122.  
  123. -- // Metatable \\ --
  124. -- [ Metatable ] --
  125. local RawMetatable = getrawmetatable(game)
  126. local __newindex = RawMetatable.__newindex
  127. local __namecall = RawMetatable.__namecall
  128.  
  129. setreadonly(RawMetatable, false)
  130.  
  131. RawMetatable.__newindex = newcclosure(function(Self, Index, Value)
  132.     if (typeof(Self) == "Instance" and (Self:IsA("PlayerMouse") or Self:IsA("Mouse"))) and Index == "Icon" then
  133.         IconChanged:Fire(Value)
  134.     end
  135.     return __newindex(Self, Index, Value)
  136. end)
  137.  
  138. setreadonly(RawMetatable, true)
  139.  
  140. -- // Actions \\ --
  141. local MouseBoi = OrnamentalMouse.new()
  142. wait(20.5)
  143. --[[
  144. while true do
  145.     wait(2.5)
  146.     MouseBoi.AutoUpdate = false
  147.     MouseBoi:MoveBezier(Vector2.new(100, 100))
  148.     wait(5)
  149.     MouseBoi.AutoUpdate = true
  150. end
  151. ]]
  152. --LocalPlayer:GetMouse().Icon = "http://www.roblox.com/asset/?id=6022668898"
  153.  
  154. return OrnamentalMouse
RAW Paste Data