Posted by liquid51 on Thu, 02 Aug 2012 19:09:24
Specifically, Autorun. I'm trying to write a simple addon that tracks whether autorun is active or not. Being a beginner with both addons and programming in general, it's become quite the project.
I first thought of this addon while farming. I have all of the necessary commands bound to the mouse, so I can farm with one hand and eat/drink/be lazy/etc. with the other. The only thing that annoys me is when I gather a node, mount, jump, hold L+R to begin movement and then enable autorun, but never release L+R. When I get to the next node, I release the mouse buttons, thinking to stop, but Autorun is still enabled (because L+R was clicked first), and I fly right by.
Surely this isn't such a severe issue that it REQUIRES an addon just to keep my sanity in check. I simply had the thought and started researching to see if I could make it happen. When Power Auras failed me, I decided to try my hand at making the addon myself.
My main issue comes from the fact that the AutoRun command is a toggle and has no "On/Off" state (as I understand it, it merely triggers player forward movement, exactly as if I were holding the L+R mouse buttons). With some help from others, I've created some really simple hooksecurefunc's that print when I click Autorun and again on "MoveForwardStop/MoveBackwardStop", but they only respond to input from "W" and "S", not the mouse buttons. Furthermore, depending on the order I click them, the "on/off" messages get out of order (ugh, what a sloppy method, eh?). I thought I had it figured out with "MoveAndSteerStart", but the keybind-able move and steer command is separate from the movement command triggered by L+R click (even though it accomplished the exact same result).
There must be some kind of protected move and steer command that is called when using the mouse buttons, right? If so, shouldn't I be able to hook it?
I'm fairly certain that this is already the sloppiest, most poorly coded addon out there, but it's a start, right? Thanks in advance for any insight you can share!
Posted by semlar on Fri, 03 Aug 2012 02:47:23
I don't know if holding both mouse buttons calls something specific, but I do know holding the left button calls "CameraOrSelectOrMoveStart" and holding the right button calls "TurnOrActionStart", which means you should be able to determine if they're both being held down simultaneously by hooking them and their respective "Stop" functions and storing a couple variables to compare.
Here's a little example..
local LeftButtonDown, RightButtonDown = false, false hooksecurefunc("CameraOrSelectOrMoveStart", function() LeftButtonDown = true if RightButtonDown then print("I'm moving!") end end) hooksecurefunc("CameraOrSelectOrMoveStop", function() LeftButtonDown = false if RightButtonDown then print("I'm stopping!") end end) hooksecurefunc("TurnOrActionStart", function() RightButtonDown = true if LeftButtonDown then print("I'm moving!") end end) hooksecurefunc("TurnOrActionStop", function() RightButtonDown = false if LeftButtonDown then print("I'm stopping!") end end)
Posted by liquid51 on Sat, 04 Aug 2012 16:47:23
This is exactly what I was looking for! I didn't think to look for their individual functions and the results of calling both commands simultaneously.
My end goal here is to learn what I'm doing as I go, not just have an addon created for me. Thanks for helping me get past that roadblock Semlar!
Posted by semlar on Sat, 04 Aug 2012 19:22:29
Glad I could help, if you have any other questions don't hesitate to ask!