WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Search/Requests (https://www.wowinterface.com/forums/forumdisplay.php?f=6)
-   -   Can someone write me a simple add-on? (https://www.wowinterface.com/forums/showthread.php?t=58751)

phage 05-21-21 02:13 PM

Can someone write me a simple add-on?
 
This is something I actually already have in another add-on but I'd like to make it a standalone add-on. I can't figure it out how to steal it from the code so I'm hoping someone here can write it for me. This function needs to target an npc and then interact with them and I'd like to be able to bind the function to any key. Also, whenever the add-on is turned on, I want to be able to override whatever key I designate it to inside the code.

and yes, it is possible, see below.

https://streamable.com/pd8rpp

sezz 05-21-21 02:33 PM

1. use a macro that contains /target npcname
2. bind "interact with target"

?

phage 05-21-21 03:05 PM

Quote:

Originally Posted by sezz (Post 339207)
1. use a macro that contains /target npcname
2. bind "interact with target"

?

I want to have them bound to the same key and you can't do that with basic macros.

Kanegasi 05-21-21 04:42 PM

Quote:

Originally Posted by phage (Post 339206)
This is something I actually already have in another add-on

It would be a hell of a lot easier if you actually shared that addon. It wouldn't make sense for anyone to "make" this addon when the code already exists and someone can just take it out.

phage 05-21-21 05:00 PM

Quote:

Originally Posted by Kanegasi (Post 339211)
It would be a hell of a lot easier if you actually shared that addon. It wouldn't make sense for anyone to "make" this addon when the code already exists and someone can just take it out.

It's tied into too many functions for someone to easily remove. I didn't realize this was such an in-depth coding request.

Kanegasi 05-21-21 05:20 PM

Let others make that determination. Honestly, the fact that you can't write what you believe is "simple" is closely related to the fact that you can't extract this functionality from existing code.

sezz 05-21-21 08:18 PM

Quote:

Originally Posted by phage (Post 339208)
I want to have them bound to the same key and you can't do that with basic macros.

Your current addon works with 1 single button press without using a lua unlocker on official servers?

Just curious, because InteractTarget and RunBinding are protected and I currently can't think of any other method to interact with a NPC, but maybe I'm missing something.

phage 05-22-21 12:59 AM

Quote:

Originally Posted by sezz (Post 339222)
Your current addon works with 1 single button press without using a lua unlocker on official servers?

Just curious, because InteractTarget and RunBinding are protected and I currently can't think of any other method to interact with a NPC, but maybe I'm missing something.

What's a lua unlocker?

Seerah 05-22-21 11:58 AM

Your gif doesn't prove what you think it proves. ;)

And you still haven't linked the addon you are currently using for this purpose.

phage 05-22-21 12:13 PM

Quote:

Originally Posted by Seerah (Post 339224)
Your gif doesn't prove what you think it proves. ;)

And you still haven't linked the addon you are currently using for this purpose.

I'm still not going to link my add-on as it's a private add-on and I don't want others to have access to it.
My gif shows I'm pressing a single keybind to perform each action, what do you mean?

SDPhantom 05-22-21 12:49 PM

1 Attachment(s)
There's an "Interact With Mouseover" keybind under "Targeting".

Edit: It's available to all clients, retail, classic, and BCC.

jeffy162 05-22-21 06:26 PM

Quote:

Originally Posted by phage (Post 339225)
I'm still not going to link my add-on as it's a private add-on and I don't want others to have access to it.
My gif shows I'm pressing a single keybind to perform each action, what do you mean?

If the addon is NOT listed on a public addon site, how can anyone get access to it? If it IS listed on a public addon site, how can it be considered a "private addon"? As far as your GIF goes, it didn't tell me anything. Sorry. :p

phage 05-22-21 07:38 PM

Quote:

Originally Posted by jeffy162 (Post 339227)
If the addon is NOT listed on a public addon site, how can anyone get access to it? If it IS listed on a public addon site, how can it be considered a "private addon"? As far as your GIF goes, it didn't tell me anything. Sorry. :p

If I shared it here, it wouldn't be private.

Anyways, here's the section of the code that handles the one-button target and interact with function. I'm not really sure why you're all saying this is impossible.

I removed a few lines as they're irrelevant to the process.

Code:

local addonName = ...
ezopen_keybind = 'SPACE'
 
function EzOpenMixin:OnEvent(e, ...)
        CreateFrame("Button", "setButton", UIParent, "SecureActionButtonTemplate")
        setButton:SetAttribute("type", "macro")
        setButton:SetAttribute("macrotext", "/run SetOverrideBinding(\""..ezopen_keybind.."\", 'INTERACTTARGET')\n/target NPC NAME HERE")
        setButton:RegisterForClicks("AnyUp", "AnyDown")
        SetOverrideBindingClick(self, false, ezopen_keybind, 'setButton')
    elseif e == "AUCTION_HOUSE_SHOW" then
        SetOverrideBindingClick(self, false, ezopen_keybind, 'setButton')
    elseif e == "AUCTION_HOUSE_CLOSED" then
        -- ClearOverrideBindings(self)
    elseif e == "AUCTION_HOUSE_THROTTLED_MESSAGE_RESPONSE_RECEIVED" then
        C_Timer.After(0.1, function() self.isReady = true end)
    elseif e == "AUCTION_HOUSE_THROTTLED_MESSAGE_SENT" then
        self.isReady = false
    end
end


sezz 05-24-21 03:20 PM

Quote:

Originally Posted by phage (Post 339228)
Anyways, here's the section of the code that handles the one-button target and interact with function. I'm not really sure why you're all saying this is impossible.

Well, because it's 2 button presses - I specifically asked if it's only 1 single key press.
Nevertheless, I'm glad you found it though :) Do you still need help with removing everything that's unrelated to targetting and interacting?

phage 05-24-21 06:27 PM

Quote:

Originally Posted by sezz (Post 339242)
Well, because it's 2 button presses - I specifically asked if it's only 1 single key press.
Nevertheless, I'm glad you found it though :) Do you still need help with removing everything that's unrelated to targetting and interacting?

Yes, I could use the help. I have a hard time understanding lua and explaining what I mean. What I meant was creating an add-on that would be able to do all the functions within one key but have multiple key presses that perform different functions. I wasn't sure how to word that initially.

Seerah 05-25-21 12:05 PM

Ah, yes. That is indeed 2 button presses, not one. So long as they are not protected functions, you can do

Code:

if condition1 then
  do first thing
elseif condition2 then
  do other thing
else
  do third thing
end

(Though the code you linked is for an event handler, not button presses.)
(Oh, and we can't actually see button presses in a gif. ;) )

sezz 05-25-21 03:04 PM

Quote:

Originally Posted by phage (Post 339246)
Yes, I could use the help. I have a hard time understanding lua and explaining what I mean. What I meant was creating an add-on that would be able to do all the functions within one key but have multiple key presses that perform different functions. I wasn't sure how to word that initially.

I'd do it like this:

Lua Code:
  1. local binding = "SPACE";
  2. local target = "Collector Unta";
  3.  
  4. local UnitExists, UnitName, SetOverrideBinding, ClearOverrideBindings, SetOverrideBindingClick, IsMounted, InCombatLockdown = UnitExists, UnitName, SetOverrideBinding, ClearOverrideBindings, SetOverrideBindingClick, IsMounted, InCombatLockdown;
  5.  
  6. local button = CreateFrame("Button", "PhagesCuddleUntaButton", UIParent, "SecureActionButtonTemplate");
  7. button:RegisterForClicks("AnyUp", "AnyDown");
  8. button:SetAttribute("type", "macro")
  9. button:SetAttribute("macrotext", "/cast [nomounted] Mighty Caravan Brutosaur\n/targetexact "..target);
  10. button:SetScript("PostClick", function(self)
  11.     if (not InCombatLockdown() and UnitExists("target") and UnitName("target") == target) then
  12.         SetOverrideBinding(self, true, binding, "INTERACTTARGET");
  13.     end
  14. end);
  15.  
  16. button.Reset = function(self)
  17.     ClearOverrideBindings(self);
  18.     SetOverrideBindingClick(self, false, binding, self:GetName());
  19. end
  20.  
  21. button:RegisterEvent("PLAYER_ENTERING_WORLD");
  22. button:RegisterEvent("PLAYER_TARGET_CHANGED");
  23. button:RegisterEvent("PLAYER_MOUNT_DISPLAY_CHANGED");
  24.  
  25. button:SetScript("OnEvent", function(self, event)
  26.     if (not InCombatLockdown() and (event == "PLAYER_ENTERING_WORLD" or (event == "PLAYER_TARGET_CHANGED" and (not UnitExists("target") or UnitName("target") ~= target)) or event == "PLAYER_MOUNT_DISPLAY_CHANGED" and not IsMounted())) then
  27.         self:Reset();
  28.     end
  29. end);

Simple logic: If Unta is the target it interacts with her, otherwise it mounts up (if not mounted) and also tries to target Unta.

Seems to work fine on the PTR (can't test on live because my subscription just expired and token prices are ridiculous :p), only issue is that it will try to mount up again if you press the key again exactly before the mount cast finished (propably dependant on spell-queuing settings, you'll have to try it yourself if it's annoying).

phage 05-25-21 11:45 PM

Quote:

Originally Posted by sezz (Post 339272)
I'd do it like this:

Lua Code:
  1. local binding = "SPACE";
  2. local target = "Collector Unta";
  3.  
  4. local UnitExists, UnitName, SetOverrideBinding, ClearOverrideBindings, SetOverrideBindingClick, IsMounted, InCombatLockdown = UnitExists, UnitName, SetOverrideBinding, ClearOverrideBindings, SetOverrideBindingClick, IsMounted, InCombatLockdown;
  5.  
  6. local button = CreateFrame("Button", "PhagesCuddleUntaButton", UIParent, "SecureActionButtonTemplate");
  7. button:RegisterForClicks("AnyUp", "AnyDown");
  8. button:SetAttribute("type", "macro")
  9. button:SetAttribute("macrotext", "/cast [nomounted] Mighty Caravan Brutosaur\n/targetexact "..target);
  10. button:SetScript("PostClick", function(self)
  11.     if (not InCombatLockdown() and UnitExists("target") and UnitName("target") == target) then
  12.         SetOverrideBinding(self, true, binding, "INTERACTTARGET");
  13.     end
  14. end);
  15.  
  16. button.Reset = function(self)
  17.     ClearOverrideBindings(self);
  18.     SetOverrideBindingClick(self, false, binding, self:GetName());
  19. end
  20.  
  21. button:RegisterEvent("PLAYER_ENTERING_WORLD");
  22. button:RegisterEvent("PLAYER_TARGET_CHANGED");
  23. button:RegisterEvent("PLAYER_MOUNT_DISPLAY_CHANGED");
  24.  
  25. button:SetScript("OnEvent", function(self, event)
  26.     if (not InCombatLockdown() and (event == "PLAYER_ENTERING_WORLD" or (event == "PLAYER_TARGET_CHANGED" and (not UnitExists("target") or UnitName("target") ~= target)) or event == "PLAYER_MOUNT_DISPLAY_CHANGED" and not IsMounted())) then
  27.         self:Reset();
  28.     end
  29. end);

Simple logic: If Unta is the target it interacts with her, otherwise it mounts up (if not mounted) and also tries to target Unta.

Seems to work fine on the PTR (can't test on live because my subscription just expired and token prices are ridiculous :p), only issue is that it will try to mount up again if you press the key again exactly before the mount cast finished (propably dependant on spell-queuing settings, you'll have to try it yourself if it's annoying).


Very cool! I tried to install it by saving it as a .lua file, creating a toc with the proper callings, but I couldn't turn it on from my add-ons list. Is there something else I need to do for it to appear on that list?

Xrystal 05-26-21 02:23 AM

Did you make sure you log out of the game before adding the files to the respective folder ?
Does the toc file have all the required entries ?

phage 05-26-21 05:57 AM

Quote:

Originally Posted by Xrystal (Post 339275)
Did you make sure you log out of the game before adding the files to the respective folder ?
Does the toc file have all the required entries ?

I did but I'm not sure what all the toc needs. It's also very likely that I didn't save the toc file as a .toc. :)

Yep, that was it, oops.


All times are GMT -6. The time now is 07:07 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI