Thread Tools Display Modes
12-07-14, 06:47 PM   #1
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Question 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.
  Reply With Quote
12-07-14, 09:21 PM   #2
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
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
}
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________
  Reply With Quote
12-08-14, 03:24 AM   #3
saxitoxin
A Theradrim Guardian
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 60
you will need to register when you change zone in your event, as of now it only check when you enter the world
  Reply With Quote
12-08-14, 03:36 AM   #4
humfras
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 131
Originally Posted by saxitoxin View Post
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)
__________________
Author of VuhDo CursorCastBar OptiTaunt Poisoner RaidMobMarker

Last edited by humfras : 12-08-14 at 03:43 AM.
  Reply With Quote
12-08-14, 03:54 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I'd suggest using GetInstanceInfo with the instanceMapIDs Tonyleila posted. That way you're not relying on localized strings.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-08-14, 01:26 PM   #6
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
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
  Reply With Quote
12-08-14, 02:48 PM   #7
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I think you have missed "tcontains", which is a table, but not defined anywhere.
  Reply With Quote
12-08-14, 03:07 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by myrroddin View Post
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
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-08-14, 03:09 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by rocnroll View Post
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.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Addon to Leave a Channel if in Garrison

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