|
| 01 Jul 2015 03:18 PM |
So, I'm making a module which should turn UserInputService events in to a more "beginner" friendly version (PlayerMouse).
Is there any way I can improve this? ---------------------------------- return function() local Mouse = game.Players.LocalPlayer:GetMouse() local MousePos = Vector2.new(Mouse.X, Mouse.Y)
local Connections = {} local Events = { LeftClick = {connect = function(self, func) Connections.LeftClick = func end}, RightClick = {connect = function(self, func) Connections.RightClick = func end}, LeftDown = {connect = function(self, func) Connections.LeftDown = func end}, RightDown = {connect = function(self, func) Connections.RightDown = func end}, LeftUp = {connect = function(self, func) Connections.LeftUp = func end}, RightUp = {connect = function(self, func) Connections.RightUp = func end}, Moved = {connect = function(self, func) Connections.Moved = func end}, LeftDrag = {connect = function(self, func) Connections.LeftDrag = func end}, RightDrag = {connect = function(self, func) Connections.RightDrag = func end}, KeyPressed = {connect = function(self, func) Connections.KeyPressed = func end}, KeyReleased = {connect = function(self, func) Connections.KeyReleased = func end}, WheelScroll = {connect = function(self, func) Connections.WheelScroll = func end}, }
for i,a in pairs(Events) do Events[i]:connect(function() end) end
local MouseClicks = {MouseButton1=false, MouseButton2=false} local Click = {0, 0}
game["Run Service"].RenderStepped:connect(function() if MouseClicks.MouseButton1 then Click[1]= Click[1] + game.Workspace:GetRealPhysicsFPS()/60 else Click[1] = 100 end if MouseClicks.MouseButton2 then Click[2] = Click[2] + game.Workspace:GetRealPhysicsFPS()/60 else Click[2] = 100 end end)
game:GetService("UserInputService").InputChanged:connect(function(Input, GPE) if not GPE then if Input.UserInputType == Enum.UserInputType.MouseMovement then local FakeMouse = { Delta = Vector2.new(Mouse.X - MousePos.X, Mouse.Y - MousePos.Y) } Connections.Moved(FakeMouse) MousePos = Vector2.new(Mouse.X, Mouse.Y) if MouseClicks.MouseButton1 then Connections.LeftDrag(FakeMouse) end if MouseClicks.MouseButton2 then Connections.RightDrag(FakeMouse) end elseif Input.UserInputType == Enum.UserInputType.MouseWheel then local FakeMouse = { Delta = Vector2.new(0, Input.Position.Z) } Connections.WheelScroll(FakeMouse) end end end)
game:GetService("UserInputService").InputBegan:connect(function(Input, GPE) if not GPE then if Input.UserInputType == Enum.UserInputType.MouseButton1 or Input.UserInputType == Enum.UserInputType.MouseButton2 then Click[tonumber(string.match(Input.UserInputType.Name, "%d"))] = 0 local tab = {"Left", "Right"} Connections[tab[tonumber(string.match(Input.UserInputType.Name, "%d"))].."Down"]() MouseClicks[Input.UserInputType.Name] = true elseif Input.UserInputType == Enum.UserInputType.Keyboard then Connections.KeyPressed(Input.KeyCode.Name) end end end)
game:GetService("UserInputService").InputEnded:connect(function(Input, GPE) if not GPE then if Input.UserInputType == Enum.UserInputType.MouseButton1 or Input.UserInputType == Enum.UserInputType.MouseButton2 then if Click[1] < 10 then Connections.LeftClick() end if Click[2] < 10 then Connections.RightClick() end local tab = {"Left", "Right"} Connections[tab[tonumber(string.match(Input.UserInputType.Name, "%d"))].."Up"]() MouseClicks[Input.UserInputType.Name] = false elseif Input.UserInputType == Enum.UserInputType.Keyboard then Connections.KeyReleased(Input.KeyCode.Name) end end end)
return Events end |
|
|
| Report Abuse |
|
|
| 01 Jul 2015 03:22 PM |
Change:
for i,a in pairs(Events) do Events[i]:connect(function() end) end
TO:
for i, a in next, Events do Events[i]:connect(function() end) end
More efficient. :P |
|
|
| Report Abuse |
|
| |
| |