PDA

View Full Version : When is an item added to the local cache?


JonRico
30-06-2006, 02:41 AM
I write a mod that adds item its sees in channels to its own database.

Annoyingly it also adds items it sees in languages that are not the clients current default language. So I thought it would be cool to filter those out.

To do this, when I see an item not in my database, I get its item id from the link in the text and then call GetItemInfo. I use the returned values to check that the name of the item i see in the text is the same as the name returned by GetItemInfo. If it is, I add it to my database. If its not, I assume its an item in another language and ignore it.

The problem is, it seems to add items randomly. Sometimes GetItemInfo returns null, sometimes it does not. I know its supposed to return null if the item is not in your local cache, but I assumed seeing it in a channel message would add it to the local cache.

If the item in question is whispered to me, it always seems to work. If the item is in another channel it normally seems to fail, but does work sometimes. :)

function TypeLinks_OnEvent()
if (event == "CHAT_MSG_CHANNEL") then
TypeLinks_ScanTextForLinks(arg1);
end
end

I simply call my scanner method on all channel messages. What I guess I want to know is when the item is added to the cache and if I can ensure its added to the cache before my method fires?

Can anyone help?

JonRico
19-07-2006, 02:44 AM
Well here is what I had to do. :P

In order to test if a given item link in chat is in your local language, you need to get the item id in the link and then check the name given to you by GetItemInfo(item id) is the same as the name given in the link.

GetItemInfo returns null if the item given by its id is not in your local cache.

Since the item has been linked to you by another player, it is in the server cache. So you can safely force addition of it to your local cache. To do that, display its tooltip.

GameTooltip_SetDefaultAnchor(GameTooltip, someParent);
GameTooltip:SetHyperlink(hyperLinkToItem);
GameTooltip:Hide();

In practice though GetItemInfo sometimes still returns null. This is a timing issue (I think :P), so I need store the items that are returned null and then process them again on some later event (in my case when chat messages are displayed or when the player logs out). The items then are ALWAYS in the local cache and can be safely compared.

Just in case anyone wondered. ;)

Wintrow
25-07-2006, 03:25 PM
nice :)8910

JonRico
27-07-2006, 03:51 AM
I have used this to write another little mod that automatically changes the language of item links in chats to the clients default.

So basically if a player using the (for example) german client links something to your english client, then you just see the normal english name.

Its pretty pointless since you can just click on the link and the tooltip is english and most of the time the translation is obvious anyway, but it works. :)