WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Addon to Leave a Channel if in Garrison (https://www.wowinterface.com/forums/showthread.php?t=50686)

JDoubleU00 12-07-14 06:47 PM

Addon to Leave a Channel if in Garrison
 
OK, I am endeavoring to make my first addon. I have noticed that General chat in the garrison is becoming Barens Trade chat. Here is what is suppose to do in a nutshell.

Player enters world or changes zone (no code for the latter yet), checks to see if player is in their garrison. If yes, then leave General Chat, if not join General chat. If you are in General and not in your garrison, do nothing.

Here is what I have so far:

Code:

local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent", function(self, event, ...)
      local zoneName = GetZoneText();
      message(zoneName);
      if zoneName=="Lunarfall" then
        print("Home");
        LeaveChannelByName("General");
      else
        JoinChannelByName("General");
        print("Adding");
      end
end)

It works to the point of leaving General when entering the world or reloading. I can not get it to join General chat. Any help or pointers are appreciated.

Tonyleila 12-07-14 09:21 PM

I have no idea about the rest but I guess zoneName=="Lunarfall" Will not work since the Garrison zone name changes to <Your character's name>'s Garrison.

Phanx just added Garrison as zone into Broker Instance Difficulty

Code:

local garrisonMaps = {
        [1152] = true, -- FW Horde Garrison Level 1
        [1330] = true, -- FW Horde Garrison Level 2
        [1153] = true, -- FW Horde Garrison Level 3
        [1154] = true, -- FW Horde Garrison Level 4
        [1158] = true, -- SMV Alliance Garrison Level 1
        [1331] = true, -- SMV Alliance Garrison Level 2
        [1159] = true, -- SMV Alliance Garrison Level 3
        [1160] = true, -- SMV Alliance Garrison Level 4
}


saxitoxin 12-08-14 03:24 AM

you will need to register when you change zone in your event, as of now it only check when you enter the world

humfras 12-08-14 03:36 AM

Quote:

Originally Posted by saxitoxin (Post 302017)
you will need to register when you change zone in your event, as of now it only check when you enter the world

Correct.
You need to register "ZONE_CHANGED_NEW_AREA".

JoinChannelByName("General") works for me.

@Tony:
GetZoneText() returns the location without it's owners name.
("Frostwall" für die Horde)

Phanx 12-08-14 03:54 AM

I'd suggest using GetInstanceInfo with the instanceMapIDs Tonyleila posted. That way you're not relying on localized strings.

JDoubleU00 12-08-14 01:26 PM

Here is what I have so far:
Code:

local frame = CreateFrame("Frame")
local ignorezones = {1152, 1330, 1153, 1154, 1158, 1331, 1159, 1160}

frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("ZONE_CHANGED_NEW_AREA")

frame:SetScript("OnEvent", function(self, event, ...)
    local name, _, _, _, _, _, _, instanceMapID, _ = GetInstanceInfo()
            if tContains(ignorezones, instanceMapID) then
                message("Leaving General")
        LeaveChannelByName("General");
      else
                message("jOIN General")
        JoinChannelByName("General");
      end
end)

I cannot get the addon to join the General channel for some reason. Even if I do a reload which should trigger the PLAYER_ENTERING_WORLD event.

What am I missing? A logic error? sigh

myrroddin 12-08-14 02:48 PM

I think you have missed "tcontains", which is a table, but not defined anywhere.

Phanx 12-08-14 03:07 PM

Quote:

Originally Posted by myrroddin (Post 302070)
I think you have missed "tcontains", which is a table, but not defined anywhere.

No, "tContains" is a bad bloated function defined in Blizzard's UI code. While there may be some conceivable scenario where you really need to check if a value exists in an indexed table / array, this is not one of them; use a hash table instead:

Code:

local ignorezones = { [1152]=true, [1330]=true, [1153]=true, [1154]=true, [1158]=true, [1331]=true, [1159]=true, [1160]=true }
and a simple table lookup (instead of a function call + a loop + multiple table lookups + multiple equality checks):

Code:

            if ignorezones[instanceMapID] then

Phanx 12-08-14 03:09 PM

Quote:

Originally Posted by rocnroll (Post 302059)
I cannot get the addon to join the General channel for some reason. Even if I do a reload which should trigger the PLAYER_ENTERING_WORLD event.

Run this:
Code:

/run hooksecurefunc("JoinChannelByName", function(...) print("JoinChannelByName:", ...) end)
Then join the channel manually by some method you know works, and see what's actually passed to the function. If nothing gets printed, you're using the wrong function.


All times are GMT -6. The time now is 02:57 AM.

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