WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Condition for when the player has joined a covenant? (https://www.wowinterface.com/forums/showthread.php?t=58453)

Krainz 12-11-20 09:11 AM

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?

myrroddin 12-11-20 12:16 PM

A quick glance through the API reveals the COVENANT_CHOSEN event. Have a look to see if it fits your bill.

Krainz 12-11-20 03:39 PM

How do I make that reference the player?

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

Like this?

myrroddin 12-11-20 03:53 PM

No, it is an event, which means you need to handle it.

myrroddin 12-11-20 03:56 PM

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.

Krainz 12-12-20 05:46 AM

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?

Xrystal 12-12-20 07:25 AM

Quote:

Originally Posted by Krainz (Post 337888)
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.

Krainz 12-12-20 08:35 AM

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?

SDPhantom 12-12-20 09:06 AM

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.

Krainz 12-12-20 09:07 AM

Quote:

Originally Posted by SDPhantom (Post 337893)
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?

Xrystal 12-12-20 11:59 AM

Quote:

Originally Posted by Krainz (Post 337894)
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.

Krainz 12-12-20 01:08 PM

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!


All times are GMT -6. The time now is 01:31 AM.

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