Thread Tools Display Modes
09-30-07, 07:40 AM   #1
iowa
A Murloc Raider
Join Date: Sep 2007
Posts: 6
Parse a command out

Hello all,

Sorry for my poor english but I'm french.
I want parse a command out, My command is like :

aaaaaa 18 eeeee
And I want find "18".
Maybe a hook is a good solution, i writed this :

[code]
----------------------------------------------------------------
-- Variables
----------------------------------------------------------------
local filtre = "false";

----------------------------------------------------------------
-- Evenement chargement
----------------------------------------------------------------
function GmTool_OnLoad()
-- Crée la slash command
SlashCmdList["GMTOOL"] = GmTool_perso_Slash;
SLASH_GMTOOL1 = "/gt";
end

----------------------------------------------------------------
-- Evenement d'appel de /gt
----------------------------------------------------------------
function GmTool_perso_Slash(cmd)
DEFAULT_CHAT_FRAME:AddMessage("Command: " .. cmd);

if cmd == "dtoff" then
-- Met en place le Hook
GmTool_HookAllChatFrames();

-- Met en place l'indicateur de filtre
filtre = "true";
end

end

----------------------------------------------------------------
-- Hook
----------------------------------------------------------------
function GmTool_HookAllChatFrames()
for i=1,NUM_CHAT_WINDOWS do
local cf = getglobal("ChatFrame"..i);
cf.GmTool_Orig_AddMessage = cf.AddMessage;
cf.AddMessage = GmTool_ChatFrame_AddMessage;
end
end

function GmTool_ChatFrame_AddMessage(self, msg)
if msg == "Command: test" then
DEFAULT_CHAT_FRAME:AddMessage(msg);
DEFAULT_CHAT_FRAME:AddMessage(self);
end
end

[/quote]

But it's not good
Thank's for your help.
 
09-30-07, 08:08 AM   #2
mulesh
A Chromatic Dragonspawn
 
mulesh's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 193
This will handle two variables entered for a command.

Code:
function GmTool_OnLoad()
SlashCmdList["GMTOOL"] = GmTool_perso_Slash;
SLASH_GMTOOL1 = "/gt";
end

function GmTool_perso_Slash(msg)
    local Cmd, Sub = GmTool_GetCmd(msg);
    if (Cmd and Sub) then
        DEFAULT_CHAT_FRAME:AddMessage(Cmd);
        DEFAULT_CHAT_FRAME:AddMessage(Sub);
    end
end

function GmTool_GetCmd(msg)
    if (msg) then
        local a,b,c=strfind(msg, "(%S+)");
        if a then
            return c, strsub(msg, b+2);
        else
            return "";
        end
    end
end
__________________
"Don"t tase me bro!" ~ Andrew Meyer
 
09-30-07, 08:44 AM   #3
iowa
A Murloc Raider
Join Date: Sep 2007
Posts: 6
No, I want the reponse of a command
 
09-30-07, 09:08 AM   #4
mulesh
A Chromatic Dragonspawn
 
mulesh's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 193
You want a slash command to do something, is that it? In your code you use "/gt dtoff" to do GmTool_HookAllChatFrames();

Your slash code is just a bit off then. You need parenthesis in your IF statement. Like this:
----------------------------------------------------------------
-- Evenement d'appel de /gt
----------------------------------------------------------------
function GmTool_perso_Slash(cmd)
DEFAULT_CHAT_FRAME:AddMessage("Command: " .. cmd);

if (cmd == "dtoff") then
-- Met en place le Hook
GmTool_HookAllChatFrames();

-- Met en place l'indicateur de filtre
filtre = "true";
end

end

I thought you were trying to parse a command with options like in your first example:

aaaaa 18 eeeee

With aaaaa being the slash command and 18 eeeee being the options for that command.

I also noticed a problem with your GmTool_HookAllChatFrames() function.
This line - cf.AddMessage = GmTool_ChatFrame_AddMessage
Try changing it to this
GmTool_ChatFrame_AddMessage(cf.AddMessage);
This will call your AddMessage function with your message as a variable.
You will need to remove the Self from function GmTool_ChatFrame_AddMessage(self, msg) because there is nothing defining it in your code (whats Self supposed to be anyway?).
__________________
"Don"t tase me bro!" ~ Andrew Meyer

Last edited by mulesh : 09-30-07 at 09:20 AM.
 
09-30-07, 01:07 PM   #5
iowa
A Murloc Raider
Join Date: Sep 2007
Posts: 6
Thank's, I will try
 
10-01-07, 09:22 AM   #6
iowa
A Murloc Raider
Join Date: Sep 2007
Posts: 6
In game, I have a command, this command return a string and i want find this string to parse and extract an int value.
What is the best solution please ?
Hook ?


For example when I write in chat room :

.test
This exemple return :

There is 18 objet
Thank's.
 
10-03-07, 10:54 PM   #7
iowa
A Murloc Raider
Join Date: Sep 2007
Posts: 6
up please :'(
 
10-03-07, 11:20 PM   #8
flaska
A Theradrim Guardian
AddOn Compiler - Click to view compilations
Join Date: Dec 2006
Posts: 65
what's wrong with slash commands (/command) ?
Why do you want to imitate private server gm commands (.command) ?
 
10-05-07, 09:36 AM   #9
iowa
A Murloc Raider
Join Date: Sep 2007
Posts: 6
Thank's for your reponse.
For more information : I want create an addon for gm private server.
 
10-05-07, 09:46 AM   #10
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
well, private servers are not supported, condoned, or endorsed here.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

 
10-06-07, 01:26 PM   #11
Cairenn
Credendo Vides
 
Cairenn's Avatar
Premium Member
WoWInterface Admin
Join Date: Mar 2004
Posts: 7,134
Originally Posted by Seerah
well, private servers are not supported, condoned, or endorsed here.
Quoted for emphasis.
__________________
“Do what you feel in your heart to be right — for you’ll be criticized anyway.” ~ Eleanor Roosevelt
~~~~~~~~~~~~~~~~~~~
Co-Founder & Admin: MMOUI
FaceBook Profile, Page, Group
Avatar Image by RaffaeleMarinetti
 

WoWInterface » Developer Discussions » Lua/XML Help » Parse a command out

Thread Tools
Display Modes

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