View Single Post
03-20-13, 03:28 PM   #26
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by fRodzet View Post
Okay tried WoWPedia.org and i didn't get further than like the first basics before my "AddOn" didn't work properly.
If that's your complete code, then the problem is that you don't have a frame listening for and responding to events, and nothing in your code actually calls your functions.

If that's not your complete code, where is the rest of it?

It's hard to tell what you're trying to do, but it looks like you're trying to print the map position of any group member who whispers you, in which case there are two ways to do that.

#1 - Register for the "CHAT_MSG_WHISPER" event to find out when you get a whisper:

Code:
local f = CreateFrame("Frame", "MyAddon")
f:RegisterEvent("CHAT_MSG_WHISPER")
f:SetScript("OnEvent", function(self, event, message, sender)
    local x, y = GetPlayerMapPosition(sender)
    if x and y then
        DEFAULT_CHAT_FRAME:AddMessage(sender .. " is currently at location " .. x .. ", " .. y)
    end
end)
#2 - Use the chat filtering system to find out when you get a whisper:

Code:
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", function(self, event, message, sender)
    local x, y = GetPlayerMapPosition(sender)
    if x and y then
        DEFAULT_CHAT_FRAME:AddMessage(sender .. " is currently at location " .. x .. ", " .. y)
    end
end)
The second method is simpler, but far more limited, since you can only use it to detect chat messages, not other events like logging in (if you want to save and restore settings between login sessions), changing zones, etc.

Also, I'm not sure GetPlayerMapPosition accepts a name. It might need a real UnitID (like "player" or "raid13") in which case you would need to loop over all the players in your group to find the UnitID for the player who sent you the message. You can test easily whether you need to do this by typing this in-game:
/dump GetPlayerMapPosition("Yourname")
...where "Yourname" is replaced by your character's name. If you get an error message or an empty result, then you'll need to convert the sender's name to a UnitID.
__________________
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