PDA

View Full Version : sending (raw) slash commands via addon


DamageCase
27-02-2007, 10:48 PM
Hi all,

I'm trying to make a little enhancment for a already existing mod.
It's pretty small, but hey you gotta start somewhere.

The problem I have now is that I can't get the addon to send a slash command to the ui.
The idea is that I fill in 2 input fields and that input is compressed into a slash command for another addon.

Everything works fine, but what channel do I need to use for that?

If I use this example here:

SendChatMessage("/mycommand", "WHISPER", "Common", Unitname("player"));

It won't work, it will simply send the /mycommand as a whisper to myself. And like this I've tried other variations too.

SendChatMessage is prolly not the way to go ;p But it was the best I could come up with :((((

Anyone have clou how I could format a string and send that as a slash command to the ui via LUA?

Any help will be appreciated :)

Jumpy
28-02-2007, 02:03 AM
I don't know if this is what you are looking for but take a look here http://www.wowwiki.com/API_SendChatMessage

aspinkorgall
28-02-2007, 02:53 AM
I mashed out the following by ripping out some code from the ChatFrame.lua file that the default UI uses to look up commands, so I cant really accept responsibility for that part of the code. It will however do as you ask - execute a slash command (with a little processing) from an addon:


function MyAddon_Find(command)
for index, value in pairs(SlashCmdList) do
local i = 1;
local cmdString = TEXT(getglobal("SLASH_"..index..i));
while ( cmdString ) do
cmdString = strupper(cmdString);
if ( cmdString == command ) then
DEFAULT_CHAT_FRAME:AddMessage(index)
return index;
end
i = i + 1;
cmdString = TEXT(getglobal("SLASH_"..index..i));
end
end
end

function MyAddon_Execute(command, param)
SlashCmdList[MyAddon_Find(command)](param)
end
Use it as follows:

/script MyAddon_Execute("/CT",nil)

The "/CT" must be converted to capitals, although you could add that to the function, and it doesn't currently work with blizzard chat/emote commands as these are processed very differently.

You should take a closer look at the ChatFrame.lua file yourself. You can get the LUA files for the default UI from:
http://ftp.blizzard.com/pub/WoW/other/InterfaceAddOnKit_Win.zip (PC)
or
http://ftp.blizzard.com/pub/WoW/other/InterfaceAddOnKit_OSX.zip (OSX)

I do hope that's of some help, but to be honest, it does seem like a rather difficult way to do things. What exactly are you trying to do?

Wintrow
28-02-2007, 11:44 AM
You do know you can call the (non-local) functions of another addon from your own addon right?

So if you own both addons just make:

function Addon1_DoStuff(params)
Addon1_MyPrint(params);
end

and

local function Addon2_SendStuffToOtherAddon(stuff)
if IsAddOnLoaded('Addon1') and Addon1_DoStuff then
Addon1_DoStuff(stuff);
end
end

Sherkhan
28-02-2007, 07:26 PM
line = "/command , etc...";
ChatFrameEditBox:SetText("");
ChatFrameEditBox:Insert(line);
ChatEdit_SendText(ChatFrameEditBox);

This will send a slash command to the chat frame, on the current channel.

Rowaa
28-02-2007, 09:50 PM
:Show and then :SetText(line) would be enough, but that will wipe anything you might have typing at that moment. As suggested by Wintrow, you'd better call required functions directly.