Thread Tools Display Modes
10-16-20, 03:03 PM   #1
Cretch21
A Murloc Raider
Join Date: Oct 2020
Posts: 6
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!
  Reply With Quote
10-16-20, 08:28 PM   #2
DahkCeles
A Cliff Giant
 
DahkCeles's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2020
Posts: 73
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)
  Reply With Quote
10-16-20, 09:12 PM   #3
Cretch21
A Murloc Raider
Join Date: Oct 2020
Posts: 6
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).
  Reply With Quote
10-17-20, 09:48 AM   #4
DahkCeles
A Cliff Giant
 
DahkCeles's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2020
Posts: 73
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)
  Reply With Quote
10-17-20, 12:18 PM   #5
Cretch21
A Murloc Raider
Join Date: Oct 2020
Posts: 6
You are the motherf**king MVP thank you!!!
  Reply With Quote
01-19-21, 05:06 AM   #6
Amplus
A Defias Bandit
Join Date: Apr 2020
Posts: 3
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.
  Reply With Quote
01-23-21, 09:59 AM   #7
DahkCeles
A Cliff Giant
 
DahkCeles's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2020
Posts: 73
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)

Last edited by DahkCeles : 01-23-21 at 10:04 AM. Reason: Tabs/whitespace
  Reply With Quote
01-23-21, 03:24 PM   #8
Amplus
A Defias Bandit
Join Date: Apr 2020
Posts: 3
Originally Posted by DahkCeles View Post
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.
  Reply With Quote
01-23-21, 03:37 PM   #9
DahkCeles
A Cliff Giant
 
DahkCeles's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2020
Posts: 73
I think its just missing PLAYER_LOGIN
  Reply With Quote
01-23-21, 04:44 PM   #10
Amplus
A Defias Bandit
Join Date: Apr 2020
Posts: 3
Originally Posted by DahkCeles View Post
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.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » Script that can execute a macro upon changing (PvP) talents

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off