1. #1
    Keyboard Turner
    10+ Year Old Account
    Join Date
    Apr 2013
    Location
    Minnesota
    Posts
    5

    Adding a function to my addon

    I've been working on an addon for a couple months now and have gotten it setup for the most part to do what I want. However I was wondering if there would be a way to make it detect if a person isn't in a guild to put the message into say or general chat.

    Code:
    local ml;
    
    function LevelUp_OnLoad()
    	LevelUp:RegisterEvent("PLAYER_LEVEL_UP");
    
    	local ourRace = UnitRace("player");
    
    	if (ourRace == "Human" or ourRace == "Dwarf" or ourRace == "Gnome" or ourRace == "Night Elf" or ourRace == "Draenei" or ourRace == "Worgen") then
    		ml = "Common";
    	else
    		ml = "Orcish";
    	end
    
    	SLASH_LEVELUP1 = "/levelup";
    	SlashCmdList["LEVELUP"] = function(msg)
    		LevelUp_SlashCommandHandler(msg);
    	end
    
    end
    
    -- This is the chat message sent when you enter the test slash command /levelup
    function LevelUp_SlashCommandHandler(msg)
    --	arg1 = UnitLevel("player");
    	SendChatMessage("Ding Dong! The Witch is dead. Which old Witch? The Wicked Witch! Ding Dong! The Wicked Witch is dead.", "GUILD", ml, "");
    	PlaySoundFile("Interface\\AddOns\\LevelUp\\LevelUp.mp3")
    end
    
    -- This is the Chat output send upon the event your character levels
    function LevelUp_OnEvent(event)
            if ( (event == "PLAYER_LEVEL_UP") ) then
    	SendChatMessage("Ding Dong! The Witch is dead. Which old Witch? The Wicked Witch! Ding Dong! The Wicked Witch is dead.", "GUILD", ml, "");
    	PlaySoundFile("Interface\\AddOns\\LevelUp\\LevelUp.mp3")
    end
    I was thinking there should be a simple way to make it happen using the IsInGuild() piece and having an else in there.

  2. #2
    Deleted
    Code:
    local ml;
    
    function LevelUp_OnLoad()
    	LevelUp:RegisterEvent("PLAYER_LEVEL_UP");
    
    	local _, ourRace = UnitRace("player");
    
    	if (ourRace == "Human" or ourRace == "Dwarf" or ourRace == "Gnome" or ourRace == "NightElf" or ourRace == "Draenei" or ourRace == "Worgen") then
    		ml = "Common";
    	else
    		ml = "Orcish";
    	end
    
    	SLASH_LEVELUP1 = "/levelup";
    	SlashCmdList["LEVELUP"] = function(msg)
    		LevelUp_SlashCommandHandler(msg);
    	end
    
    end
    
    -- This is the chat message sent when you enter the test slash command /levelup
    function LevelUp_SlashCommandHandler(msg)
    -- arg1 = UnitLevel("player");
    	SendChatMessage("Ding Dong! The Witch is dead. Which old Witch? The Wicked Witch! Ding Dong! The Wicked Witch is dead.", (IsInGuild() and "GUILD" or "SAY"), ml, "");
    	PlaySoundFile("Interface\\AddOns\\LevelUp\\LevelUp.mp3")
    end
    
    -- This is the Chat output send upon the event your character levels
    function LevelUp_OnEvent(event)
      if ( (event == "PLAYER_LEVEL_UP") ) then
    		SendChatMessage("Ding Dong! The Witch is dead. Which old Witch? The Wicked Witch! Ding Dong! The Wicked Witch is dead.", (IsInGuild() and "GUILD" or "SAY"), ml, "");
    		PlaySoundFile("Interface\\AddOns\\LevelUp\\LevelUp.mp3")
    	end
    end
    You're better off using the 2nd return from UnitRace() as that returns a locale independent string (I corrected your Night Elf check accordingly).
    Your OnEvent function would error because your 'if then' clause was missing an 'end'.
    Also added the guild check in there so it will send to "GUILD" if you're guilded or "SAY" if you're not.
    (Drycoded and untested, I'm assuming the LevelUp frame is created in another file/xml.)

  3. #3
    Keyboard Turner
    10+ Year Old Account
    Join Date
    Apr 2013
    Location
    Minnesota
    Posts
    5
    Nice that worked as I had hoped for. Never would have thought that when I was looking at different codes and such.

    ---------- Post added 2013-06-09 at 07:00 PM ----------

    One other thing I was wondering if it would be possible somehow to have it use general as an alternative to say.

  4. #4
    Deleted
    Passing nil as arg3 to SendChatMessage uses your faction's default language.

    As for General, arg2 would be "CHANNEL", arg4 would be the channel ID.

  5. #5
    Keyboard Turner
    10+ Year Old Account
    Join Date
    Apr 2013
    Location
    Minnesota
    Posts
    5
    I sort of get it, though I'm going to admit that I'm a little stuck on actually making it work. If I put it in it would replace the "SAY" right?

    So instead it would go: "CHANNEL" nil, "1" or would it be "CHANNEL" nil, "GENERAL"?

    I'm assuming too that I need to add a couple other lines in to take into account for the arg2, arg3 and arg4 as well. That would be where I think I've been messing up.

  6. #6
    Deleted
    Code:
    SendChatMessage("text","CHANNEL",nil,(GetChannelName("General")))
    PS: GetChannelName has a deceptive name. Its first return value is the channel ID.

  7. #7
    Keyboard Turner
    10+ Year Old Account
    Join Date
    Apr 2013
    Location
    Minnesota
    Posts
    5
    So I put that in, didn't get any errors but it didn't seem to quite work.

    (IsInGuild() and "GUILD" or "SAY")

    That is what I currently have and attempting to add in the channel thing. Not quite sure if I am putting it in the right spot or not.

  8. #8
    Deleted
    Code:
    if IsInGuild() then
        SendChatMessage("text","GUILD")
    else
        SendChatMessage("text","CHANNEL",nil,(GetChannelName("General")))
    end

  9. #9
    Keyboard Turner
    10+ Year Old Account
    Join Date
    Apr 2013
    Location
    Minnesota
    Posts
    5
    Odd that I didn't think of that one, will put that to the test again and see if it works properly.

    Would that fit doing:

    Code:
    if ( (event == "PLAYER_LEVEL_UP") ) then
    if IsInGuild() then
        SendChatMessage("Ding Dong! The Witch is dead. Which old Witch? The Wicked Witch! Ding Dong! The Wicked Witch is dead.", "GUILD" , ml, "");
    		PlaySoundFile("Interface\\AddOns\\LevelUp\\LevelUp.mp3")
    else
    		SendChatMessage("Ding Dong! The Witch is dead. Which old Witch? The Wicked Witch! Ding Dong! The Wicked Witch is dead.", "CHANNEL", nil, (GetChannelName("General")), ml, "");
    		PlaySoundFile("Interface\\AddOns\\LevelUp\\LevelUp.mp3")
    Or would I be doing something wrong still in that?
    Last edited by Homura; 2013-06-11 at 02:26 PM.

  10. #10
    Deleted
    Code:
    if event == "PLAYER_LEVEL_UP" then
        if IsInGuild() then
            SendChatMessage("Ding Dong! The Witch is dead. Which old Witch? The Wicked Witch! Ding Dong! The Wicked Witch is dead.", "GUILD");
            PlaySoundFile("Interface\\AddOns\\LevelUp\\LevelUp.mp3")
        else
            SendChatMessage("Ding Dong! The Witch is dead. Which old Witch? The Wicked Witch! Ding Dong! The Wicked Witch is dead.", "CHANNEL", nil, (GetChannelName("General")));
            PlaySoundFile("Interface\\AddOns\\LevelUp\\LevelUp.mp3")
        end
    end

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •