Thread Tools Display Modes
04-02-14, 11:15 PM   #1
Anneeta
A Defias Bandit
Join Date: Apr 2014
Posts: 2
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);
  Reply With Quote
04-03-14, 12:20 AM   #2
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 309
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.
__________________
AddOns: Tim @ WoWInterface
Battle Tag: Mysterio#11164
Current PC Setup: PCPartPicker List
  Reply With Quote
04-03-14, 01:38 AM   #3
Anneeta
A Defias Bandit
Join Date: Apr 2014
Posts: 2
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).
  Reply With Quote
04-03-14, 02:48 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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")
__________________
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

WoWInterface » Developer Discussions » Lua/XML Help » Help with slash command


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