Quantcast
Condition for when the player has joined a covenant? - WoWInterface
Thread Tools Display Modes
12-11-20, 09:11 AM   #1
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
Condition for when the player has joined a covenant?

I want to do the following if the player hasn't joined a covenant:


local function LoadMinimap()

if not player.has.covenant then
GarrisonLandingPageMinimapButton:ClearAllPoints()
end

end


How do I put that criteria down properly in the if condition?
  Reply With Quote
12-11-20, 12:16 PM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,152
A quick glance through the API reveals the COVENANT_CHOSEN event. Have a look to see if it fits your bill.
  Reply With Quote
12-11-20, 03:39 PM   #3
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
How do I make that reference the player?

Lua Code:
  1. if not playerunit.COVENANT_CHOSEN:0 then

Like this?
  Reply With Quote
12-11-20, 03:53 PM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,152
No, it is an event, which means you need to handle it.
  Reply With Quote
12-11-20, 03:56 PM   #5
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,152
To find out if a player has or has not joined a Covenant, handle the event, and if the argument == 0 then the player has not joined, so do whatever. If the argument is >= 1 =< 4 then the player has joined and the event tells you which Covenant, so do something else.
  Reply With Quote
12-12-20, 05:46 AM   #6
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
Since that is an event, doesn't it only happen when the player chooses a covenant? Or is it an event that happens all the time?
  Reply With Quote
12-12-20, 07:25 AM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,604
Originally Posted by Krainz View Post
Since that is an event, doesn't it only happen when the player chooses a covenant? Or is it an event that happens all the time?
It might be an event that triggers on login as well.
__________________
  Reply With Quote
12-12-20, 08:35 AM   #8
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
I'm trying to debug this so I can learn how to handle an event properly

I put the covenant event handler within a code that disables spell activation overlay just to see how it works

Lua Code:
  1. local addon, ns = ...
  2.  
  3. local f = CreateFrame("Frame")
  4. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  5. f:RegisterEvent("PLAYER_REGEN_ENABLED")
  6. f:RegisterEvent("COVENANT_CHOSEN")
  7. f:SetScript("OnEvent", function(self, event, ...)
  8.     if event == "PLAYER_ENTERING_WORLD" then
  9.         SetCVar("displaySpellActivationOverlays", 0)
  10.         SetCVar("nameplateShowAll", 0)
  11.     elseif event == "PLAYER_REGEN_ENABLED" and not IsAddOnLoaded("ConsolePort") then
  12.         SetCVar("nameplateShowAll", 0)
  13.     elseif event == "COVENANT_CHOSEN" then
  14.         print("Hello World! Hello " .. event);
  15.     end
  16. end)
  17.  
  18. local function eventHandler(self, event, ...)
  19.  print("Hello World! Hello " .. event);
  20. end
  21. f:SetScript("OnEvent", eventHandler);
  22.  
  23. if (MouseIsOver(MacroButton)) then
  24.    -- do something
  25. end
  26.  
  27. if (MouseIsOver(MacroNewButton)) then
  28.    -- do something
  29. end

The only message I get in-game is

Code:
11:33:15 | Hello World! Hello PLAYER_ENTERING_WORLD
Shouldn't I be getting a Hello COVENANT_CHOSEN?
  Reply With Quote
12-12-20, 09:06 AM   #9
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,018
I'd check out C_Covenants.GetActiveCovenantID(). You can also look at the other covenant functions here.

PS: COVENANT_CHOSEN only fires if the choice is made in the current session. Otherwise, use PLAYER_LOGIN as that signals most character data should be available by then.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 12-12-20 at 09:11 AM.
  Reply With Quote
12-12-20, 09:07 AM   #10
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
Originally Posted by SDPhantom View Post
I'd check out C_Covenants.GetActiveCovenantID(). You can also look at the other covenant functions here.
Is it possible to use C_Covenants.GetActiveCovenantID in the local function LoadMinimap() ?

If not then how do I use it?
  Reply With Quote
12-12-20, 11:59 AM   #11
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,604
Originally Posted by Krainz View Post
Is it possible to use C_Covenants.GetActiveCovenantID in the local function LoadMinimap() ?

If not then how do I use it?
As was suggested you can use it amongst your Player Login process to store the active covenant when the game is aware of it. You won't need to check it again. Because you also have the ability to switch covenants tracking the event is still useful.

So create a variable for the addon such as covenantID and then update it with the appropriate value from C_Covenants.GetActiveCovenantID() on PLAYER_LOGIN or when the COVENANT_CHOSEN event fires. You can then use the variable for checks elsewehere in the addon.
__________________
  Reply With Quote
12-12-20, 01:08 PM   #12
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
I think I got something to work!

I was testing in-game and wrote this

/script local covenantID=C_Covenants.GetActiveCovenantID(); print(covenantID);

The game returned me the value 4, which should be accurate since my character has chosen Necrolord

I'll try to work from here and if I end up having any issues I'll post again. Thanks for helping!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Condition for when the player has joined a covenant?

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