WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Search/Requests (https://www.wowinterface.com/forums/forumdisplay.php?f=6)
-   -   Script that can execute a macro upon changing (PvP) talents (https://www.wowinterface.com/forums/showthread.php?t=58303)

Cretch21 10-16-20 03:03 PM

Script that can execute a macro upon changing (PvP) talents
 
I have a macro that I would like to run every time I change a PvP Talent. Is that possible to do? Thanks guys!

DahkCeles 10-16-20 08:28 PM

I'm sure there's a much more elegant solution, but I came up with this quickly:

Code:

/run local f = CreateFrame("Frame") f:RegisterEvent("PLAYER_PVP_TALENT_UPDATE") f:SetScript("OnEvent", function() print("HelloWorld") end)

Or if you want to put it in an addon...

Lua Code:
  1. local f = CreateFrame("Frame")
  2. f:RegisterEvent("PLAYER_PVP_TALENT_UPDATE")
  3. f:SetScript("OnEvent", function()
  4.     print("HelloWorld")
  5. end)

Cretch21 10-16-20 09:12 PM

That's awesome! Do you think its possible to have that script activate a macro that's on my bars?

If it helps, this is the macro I'm running:

#showtooltip
/run local G=GetSpellInfo SetMacroSpell(GetRunningMacro(), G"Thoughtsteal" or G"Shadowfiend")

I'm using it just for displaying the tooltip (to try and never see that blank "?" on my bars).

DahkCeles 10-17-20 09:48 AM

https://wow.gamepedia.com/API_EditMacro

Before installing this script, create a macro called "myFavouriteMacro" and drag it to an action bar.

You can turn the script into an addon using https://addon.bool.no/


Lua Code:
  1. local macro1 = [=[#showtooltip
  2. /cast Thoughtsteal]=]
  3.  
  4. local macro2 = [=[#showtooltip
  5. /cast Shadowfiend]=]
  6.  
  7. local f = CreateFrame("Frame")
  8. f:RegisterEvent("PLAYER_PVP_TALENT_UPDATE")
  9. f:SetScript("OnEvent", function()
  10.   EditMacro("myFavouriteMacro", nil, nil, GetSpellInfo("Thoughtsteal") and macro1 or macro2)
  11. end)

Cretch21 10-17-20 12:18 PM

You are the motherf**king MVP thank you!!!

Amplus 01-19-21 05:06 AM

Great script!

I also managed to use it for my racial, when I am in Merc mode inside BG.
By chancing the Event from "PLAYER_PVP_TALENT_UPDATE" to "PLAYER_ENTERING_WORLD"

I do wonder if it is possible for the macro to show a greyed out icon if non of the 2 PvP talents are selected? Or perhaps a regular spell, instead of it showing a question mark icon.

DahkCeles 01-23-21 09:59 AM

I have never used merc mode, but I'm going to guess that UNIT_FACTION would fire with arg1="player". You might also be able to try SPELLS_CHANGED?

For your fall-back question.... here is a solution that lets you use as many spells as you want.

Lua Code:
  1. -- list any spell here; doesn't even have to be your class -- doesn't even have to be real!
  2. local spellsInPriorityOrder =
  3. {
  4.     "Ultimate Rogue-Slaying Greater Pyroblast!",
  5.     "Combustion",
  6.     "Arcane Intellect",
  7.     "Thoughtsteal",
  8.     "Shadowfiend",
  9.     "Power Word: Fortitude",
  10.     "Auto Attack"-- fallback for other classes
  11. }
  12.  
  13. -- %s will be replaced by the name of the spell
  14. local macroPattern = [=[#showtooltip
  15. /cast %s]=]
  16.  
  17. local function updateMacro()
  18.     for __, spellName in ipairs(spellsInPriorityOrder) do
  19.         if (GetSpellInfo(spellName)) then
  20.             EditMacro("myFavouriteMacro", nil, nil, macroPattern:format(spellName))
  21.             break
  22.         end
  23.     end    
  24. end
  25.  
  26. local f = CreateFrame("Frame")
  27. f:RegisterEvent("PLAYER_PVP_TALENT_UPDATE")
  28. f:RegisterEvent("PLAYER_LOGIN")
  29. f:RegisterEvent("UNIT_FACTION")
  30. f:SetScript("OnEvent", function(event, arg1)
  31.     if (event ~= UNIT_FACTION or arg1 == "player") then
  32.         updateMacro()
  33.     end
  34. end)

Amplus 01-23-21 03:24 PM

Quote:

Originally Posted by DahkCeles (Post 338356)
I have never used merc mode, but I'm going to guess that UNIT_FACTION would fire with arg1="player". You might also be able to try SPELLS_CHANGED?

For your fall-back question.... here is a solution that lets you use as many spells as you want.

Thanks for looking into it. I just gave it a try and the list works perfectly. That way I can multi multi racial abilities in and use the same macro on Alt characters.

The UNIT_FACTION and SPELLS_CHANGED did some seem the fix it a bit. As soon as I join a BG is updates correctly. But if I launch the game for the first time and login, it shows a red question mark. The macro icon does update if I switch a PvP talent on just reload again. Its like the script is not firing the first time you login into the game.

I did like your first version for spells a bit better. Since I could make 2 separate macros for those 2 spells, instead it only be a /cast "spellname" macro.

Is there a possibility to have a combination of those 2 scripts? And be able to make a list of different macros?

Like:
macro1 = [=[awesomemacro1]=]
macro2 = [=[awesomemacro2]=]
macro3 = [=[awesomemacro3]=]
macro4 = [=[awesomemacro4]=]

I am not sure if that's even possible.

Thanks a lot of the work you already did. I am really happy that there is a nice script for the racial abilities now.

DahkCeles 01-23-21 03:37 PM

I think its just missing PLAYER_LOGIN

Amplus 01-23-21 04:44 PM

Quote:

Originally Posted by DahkCeles (Post 338360)
I think its just missing PLAYER_LOGIN

I did try both PLAYER_LOGIN and PLAYER_ENTERing_WORLD
Even together, not sure why it is not triggering.


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

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