Quantcast
Any easy way to detect that pvp talents are active? - WoWInterface
Thread Tools Display Modes
03-17-21, 05:08 AM   #1
millanzarreta
A Deviate Faerie Dragon
 
millanzarreta's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2010
Posts: 11
Question Any easy way to detect that pvp talents are active?

Hi!

I thought it would be easy, but I can't find any way to detect if PvP talents are active or not, is there any way or function to detect this?

From what I have tested, the logic that PvP talents follow is:
- Always active in instantiated PvP zones (arena, BGs, brawls)
- Never active in instantiated PvE zones (dungeons, raids, scenarios, ...)
- Always active in Free for All PvP areas of the world (regardless of the selected war mode)
- Always active in the open world when you have War Mode On
- In the open world with War Mode Off, PvP talents are deactivated, but if you enter PvP combat they are activated, and they are deactivated again after a while

Based on the above, a certain logic can be built to detect if PvP talents are available or not. But the last point is the most problematic since even without War Mode you can activate PvP to enter combat with other players (it can be activated manually, or it also remains activated for 5 minutes when you deactivate WarMode in a city ).

I have tested the IsSpellKnown function to detect if an ability is known, but the result is always "false" even if you have selected it and with war mode on, and even if this is an active spell and not a passive spell. I have also tested the IsSpellUsable function, but the result is always "true".

The GetPvpTalentInfoByID(talentId) function gives information about whether you have the selected talent or not, but not whether it is active or not at a certain time. And something similar for the GetPvpTalentSlotInfo(slot) function.

The UnitIsPVP("player") function is the closest thing I know of, but it doesn't work either, since it only tells you if the player is marked for PvP, but this does not necessarily mean that they have active PvP talents. For example, you are flagged for PvP in hostile zones even if you have war mode off.

What do you think is the best way to detect that you have active PvP talents? Is there an easy way to detect it or do you have to check in which area you are and in some cases also check if you have the PvP Mode On or Off?

Last edited by millanzarreta : 03-17-21 at 05:10 AM.
  Reply With Quote
03-17-21, 09:11 AM   #2
Ketho
A Molten Giant
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 994
There does not appear to be a convenient API for that, but I'd like to be proven wrong.

Originally Posted by millanzarreta View Post
I have tested the IsSpellKnown function to detect if an ability is known, but the result is always "false" even if you have selected it and with war mode on, and even if this is an active spell and not a passive spell.

IsSpellKnown() works for me with the spell ID returned by the aforementioned GetPvpTalentInfoByID()
For example the Holy Priest [Greater Heal] pvp talent:
Lua Code:
  1. "|cff71d5ff|Hpvptal:112|h[Greater Heal]|h|r"
  2. "|cff71d5ff|Hspell:289666:0|h[Greater Heal]|h|r"
  3. /dump GetPvpTalentInfoByID(112) -- 6th return is the spell id
  4. /dump IsSpellKnown(289666) -- returns true when usable and false when not

IsPlayerSpell() seems to work for both passive/non-passive pvp talents, while IsSpellKnown() only works for non-passive pvp talents.

Lua Code:
  1. local function ArePvpTalentsActive()
  2.     local talents = C_SpecializationInfo.GetAllSelectedPvpTalentIDs()
  3.     for _, pvptalent in pairs(talents) do
  4.         local spellID = select(6, GetPvpTalentInfoByID(pvptalent))
  5.         if IsPlayerSpell(spellID) then
  6.             return true
  7.         end
  8.     end
  9. end
  10.  
  11.  
  12. local function OnEvent(self, event, ...)
  13.     local status = ArePvpTalentsActive() and "active" or "not active"
  14.     print("PvP Talents are "..status)
  15. end
  16.  
  17. local f = CreateFrame("Frame")
  18. f:RegisterEvent("SPELLS_CHANGED")
  19. f:SetScript("OnEvent", OnEvent)

Originally Posted by millanzarreta View Post
since even without War Mode you can activate PvP to enter combat with other players (it can be activated manually, or it also remains activated for 5 minutes when you deactivate WarMode in a city ).

Activating it manually with warmode off and using /pvp did not seem to activate the pvp talents for me. But I assume it does indeed get activated when you enter combat with other players.

Last edited by Ketho : 03-17-21 at 09:39 AM.
  Reply With Quote
03-18-21, 07:53 PM   #3
Ketho
A Molten Giant
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 994
Weird how people make a lengthy post on their problem and then just, don't respond

  Reply With Quote
03-18-21, 09:57 PM   #4
millanzarreta
A Deviate Faerie Dragon
 
millanzarreta's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2010
Posts: 11
Ohh please don't be mad, it's only been two days, lately I've had hard work and I couldn't do much about this. Although I have been able to see the reply, I wanted to answer you after having tried your solution and verify if it worked for me or if there was a problem to give you my opinion. Tomorrow is Friday and I will be able to dedicate more time to this. Seriously, thanks a lot for the help
  Reply With Quote
03-20-21, 12:49 AM   #5
millanzarreta
A Deviate Faerie Dragon
 
millanzarreta's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2010
Posts: 11
Originally Posted by Ketho View Post
IsSpellKnown() works for me with the spell ID returned by the aforementioned GetPvpTalentInfoByID()
I tested IsSpellKnown() again and it works for new active spells from PvP talents, but don't work for pasive talents and for new spells that replace others (for example Ice Form that replaces Icy Veins); the latter is what I had tested and that is why I assumed it never worked.

Originally Posted by Ketho View Post
IsPlayerSpell() seems to work for both passive/non-passive pvp talents
Ohh yes, IsPlayerSpell() is the key, works like a charm, it has worked for me for all the PvP talents I have tested

Good point about the SPELLS_CHANGED event, seems to fire always when PvP talents go ON or OFF (although obviously it can also be triggered on many other occasions, it's ok for what I needed)

Originally Posted by Ketho View Post
Activating it manually with warmode off and using /pvp did not seem to activate the pvp talents for me. But I assume it does indeed get activated when you enter combat with other players
Yes, warmode off disable the PvP talents and they cannot be activated with /pvp, but they are automatic activated when you enter in PvP combat, and automatic disabled some seconds after you leave the PvP combat.

I used your function with minor modifications:

Lua Code:
  1. local function ArePvpTalentsActive()
  2.     local inInstance, instanceType = IsInInstance()
  3.     if inInstance and (instanceType == "pvp" or instanceType == "arena") then
  4.         return true
  5.     elseif inInstance and (instanceType == "party" or instanceType == "raid" or instanceType == "scenario") then
  6.         return false
  7.     else
  8.         local talents = C_SpecializationInfo.GetAllSelectedPvpTalentIDs()
  9.         for _, pvptalent in pairs(talents) do
  10.             local spellID = select(6, GetPvpTalentInfoByID(pvptalent))
  11.             if IsPlayerSpell(spellID) then
  12.                 return true
  13.             end
  14.         end
  15.     end
  16. end
  17.  
  18. local function OnEvent(self, event, ...)
  19.     local status = ArePvpTalentsActive() and "active" or "not active"
  20.     print("PvP Talents are "..status)
  21. end
  22.      
  23. local f = CreateFrame("Frame")
  24. f:RegisterEvent("SPELLS_CHANGED")
  25. f:SetScript("OnEvent", OnEvent)

I add a previous check of IsInInstance() to fast-check if the player is in PvP instance or PvE instance, where as far as I know the PvP talents are always enabled and disabled respectively. Surely this is not necessary, but it seems better to me this way.

Thank you a lot, greetings
  Reply With Quote
03-20-21, 02:03 AM   #6
Ketho
A Molten Giant
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 994
Glad I could help
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Any easy way to detect that pvp talents are active?

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