WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Help with slash command (https://www.wowinterface.com/forums/showthread.php?t=49169)

Anneeta 04-02-14 11:15 PM

Help with slash command
 
Just trying to create a reeaaaally simple addon, but I can't get the slash commands to work. When I try them ingame, I just get the "Type '/help' for a listing of a few commands." message as if they don't exist.

Code:

RegisterAddonMessagePrefix("adry")

SLASH_ADRY1 = '/adry';
local function handler(msg, editbox)
 SendAddonMessage("adry", msg, "PARTY" );
end
SlashCmdList["ADRY"] = handler;

local adryFrame = CreateFrame("FRAME");
adryFrame:RegisterEvent("CHAT_MSG_ADDON");
local function eventHandler(self, event, ...)
 prefix, msg, type, player = ...;
 if prefix == 'adry' then
  if msg == 'dmg' then
  PlaySoundFile("Interface\\AddOns\\Adry\\big_damage.mp3")
  else if msg == 'cc' then
  PlaySoundFile("Interface\\AddOns\\Adry\\CCing.mp3")
  else if msg == 'monk' then
  PlaySoundFile("Interface\\AddOns\\Adry\\monk.mp3")
  else if msg == 'chaim' then
  PlaySoundFile("Interface\\AddOns\\Adry\\chaim.mp3")
  end
 end
end
adryFrame:SetScript("OnEvent", eventHandler);


Tim 04-03-14 12:20 AM

This is all very confusing to what you're trying to do, looks like you just copied various things and tried to make it work for you.

I'm guessing you're wanting a slash command to play a certain sound file depending on what you feed into your slash command. If so...
Code:

SLASH_ADRY1 = '/adry'
local function adry_message(msg, editbox)
  if (msg == "dmg") then
    PlaySoundFile("Interface\\AddOns\\Adry\\big_damage.mp3")
  elseif (msg == "cc") then
    PlaySoundFile("Interface\\AddOns\\Adry\\CCing.mp3")
  elseif (msg == "monk") then
    PlaySoundFile("Interface\\AddOns\\Adry\\monk.mp3")
  elseif (msg == "chaim") then
    PlaySoundFile("Interface\\AddOns\\Adry\\chaim.mp3")
  end
end
SlashCmdList["ADRY"] = adry_message


Here's a reference for creating slash commands: http://www.wowwiki.com/Creating_a_slash_command
When creating nested if statements you need to combine else and if -> elseif : http://www.lua.org/pil/4.3.1.html

More information of what you're trying to do would've been nice and would lead to more thorough help.

Anneeta 04-03-14 01:38 AM

Thanks for the help, sorry I wasn't very descriptive. I'm trying to make it play those sounds not just to me but to other people with the addon in my party (intending to give it to my arena partners).

Phanx 04-03-14 02:48 AM

1. Install BugSack. Based on your description of the problem, you're almost certainly getting an error message that will tell you exactly what and where the problem is in your code, but Blizzard in their infinite wisdom decided not to display error messages by default, and their optional error display is useless for development anyway, since it can't show you errors that occur during loading, which is when this kind of error (most likely a syntax error) is happening.

2. That code is rather messy anyway. Here's a better version (feel free to delete all the comments to shorten it up once you've gone over it and understand what's going on):
Code:

-- Put all the commands and sounds here so it's easier to add more
-- without ending up with a gigantic if-else chain:
local sounds = {
        chaim = "Interface\\AddOns\\Adry\\chaim.mp3",
        cc    = "Interface\\AddOns\\Adry\\CCing.mp3",
        dmg  = "Interface\\AddOns\\Adry\\big_damage.mp3",
        monk  = "Interface\\AddOns\\Adry\\monk.mp3",
}

local f = CreateFrame("Frame")
f:RegisterEvent("CHAT_MSG_ADDON")
f:SetScript("OnEvent", function(self, event, prefix, message, channel, sender)
        if prefix ~= "adry" then return end

        -- You may also want to return out if this is your own message,
        -- and/or if the message wasn't sent by a group member,
        -- eg. if it was whispered to you by a stranger.

        local soundFile = sounds[message]
        if not soundFile then return end

        PlaySoundFile(soundFile, "Master")
end)

SLASH_ADRY1 = "/adry"
SlashCmdList.ADRY = function(message)       
        -- Find the right channel for your current group type:
        local channel
        if IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then
                channel = "INSTANCE_CHAT"
        elseif IsInRaid() then
                channel = "RAID"
        elseif IsInGroup() then
                channel = "PARTY"
        else
                -- Nobody to send to. Quit.
                return
        end

        -- Clean up the message by removing leading/trailing spaces,
        -- and converting to lowercase so it will match the table keys:
        message = strlower(strtrim(message))
       
        -- Send it:
        SendAddonMessage("adry", message, channel)
end

RegisterAddonMessagePrefix("adry")



All times are GMT -6. The time now is 01:48 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI