Thread Tools Display Modes
07-22-07, 05:06 PM   #1
ialsoagree
A Defias Bandit
Join Date: Jul 2007
Posts: 3
When do Guild API Functions become Available?

I need to know when guild functions become available, and how to delay some initialize functions until they're available (IE. is there an event I can register for?).

Example:
Code:
function mymod_OnLoad()
	if (GetGuildInfo("player")) == "some clan name" then
		DEFAULT_CHAT_FRAME:AddMessage("You're in the some clan name guild");
	else
		DEFAULT_CHAT_FRAME:AddMessage("You're in guild " .. (GetGuildInfo("player")));
	end
	DEFAULT_CHAT_FRAME:AddMessage("Done initializing");
end
When my mod first loads, this function outputs NOTHING. It doesn't return a true or false value, it merely ends the script immediately with no warning or error.

However, after a ReloadUI() this function works as expected, and returns an appropriate message.

When do functions like these become available for use, and how can I run an initialization function when they become available?

Last edited by ialsoagree : 07-22-07 at 05:10 PM.
  Reply With Quote
07-22-07, 05:19 PM   #2
ialsoagree
A Defias Bandit
Join Date: Jul 2007
Posts: 3
Found a solution, registering for the "PLAYER_LOGIN" event.
  Reply With Quote
07-23-07, 03:21 PM   #3
ialsoagree
A Defias Bandit
Join Date: Jul 2007
Posts: 3
Okay, another problem cropped up along the same lines, figured I'd post it incase anyone else had the same issue:

Code:
function MyMod_OnEvent()
	if event:find("PLAYER_ALIVE") then
		GuildRoster();
		local name = UnitName("player");
		DEFAULT_CHAT_FRAME:AddMessage("Test 1");
		if ((GetGuildInfo(name)) == "Some Guild Name") then
			DEFAULT_CHAT_FRAME:AddMessage("Test 2");
		else
			DEFAULT_CHAT_FRAME:AddMessage("Test 3");
		end
	end
end
This code outputs "Test 1" when you log in, nothing else. It's worth noting that the "PLAYER_ALIVE" event is the last event to fire during initial startup. There is no other event to look for after this one.

On ReloadUI it will output "Test 1" and either "Test 2" or "Test 3" as expected.

For whatever reason, GetGuildInfo will not work (at least for your own character, didn't test it on someone else's) until GuildRoster() has finished and fired a GUILD_ROSTER_UPDATE event.

Solution:

Register for the "PLAYER_LOGIN" (or later) event and the "GUILD_ROSTER_UPDATE" event.

Then...

Code:
function MyMod_OnEvent()
	if event:find("PLAYER_ALIVE") then
		if IsInGuild() then
			GuildRoster();
		else
			this:UnregisterEvent("GUILD_ROSTER_UPDATE");
		end
	elseif event:find("GUILD_ROSTER_UPDATE") then
		local name = UnitName("player");
		DEFAULT_CHAT_FRAME:AddMessage("Test 1");
		if ((GetGuildInfo(name)) == "Some Guild Name") then
			DEFAULT_CHAT_FRAME:AddMessage("Test 2");
		else
			DEFAULT_CHAT_FRAME:AddMessage("Test 3");
		end
	end
end
The above code, as expected, will output 2 messages even when first logging in.

(Note, adding IsInGuild() prevents a "You are not in a guild." message from displaying if the person... well... isn't in a guild).

I should also point out, PLAYER_ALIVE only occurs when you actually log into the game. It has nothing to do with being alive, but does provide, according to WoWWiki, access to the talent information. This event should be avoided for initialization functions because a ReloadUI() will NOT fire these scripts. This could be potentially problematic if your mod uses a PLAYER_ALIVE function to initialize part or all of itself.

One last aside, through my testing I've discovered that the GetGuildInfo() function doesn't seem to work on normal unitID's. It appears to require a character name as a string. All attempts to call GetGuildInfo("player") failed for me (I think the exited the script without warning, but I must admit that it's been a while since I tried it), so I assume this is the case.

Last edited by ialsoagree : 07-23-07 at 05:15 PM.
  Reply With Quote
07-23-07, 03:41 PM   #4
Kaomie
A Scalebane Royal Guard
 
Kaomie's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 438
Now that you mention it sounds very like many systems in WoW, like the mail functions you cannot get details (except the general fact you have mail waiting or not, but not the number or kind of mails for example) until you have loaded the mailbox content first. Same here you can know whether or not you are Guilded, but cannot get much more until loading the roster. The difference is you can pull the roster info from anywhere, no near a mailbox
__________________
Kaomie
"WE LOTS OF PEOPLE FROM STRONG SERVER GUILDS" - Trade Channel
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » When do Guild API Functions become Available?


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