WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Parse a command out (https://www.wowinterface.com/forums/showthread.php?t=12608)

iowa 09-30-07 07:40 AM

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 :

Quote:

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.

mulesh 09-30-07 08:08 AM

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


iowa 09-30-07 08:44 AM

No, I want the reponse of a command

mulesh 09-30-07 09:08 AM

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?).

iowa 09-30-07 01:07 PM

Thank's, I will try

iowa 10-01-07 09:22 AM

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 :

Quote:

.test
This exemple return :

Quote:

There is 18 objet
Thank's.

iowa 10-03-07 10:54 PM

up please :'(

flaska 10-03-07 11:20 PM

what's wrong with slash commands (/command) ?
Why do you want to imitate private server gm commands (.command) ?

iowa 10-05-07 09:36 AM

Thank's for your reponse.
For more information : I want create an addon for gm private server.

Seerah 10-05-07 09:46 AM

well, private servers are not supported, condoned, or endorsed here.

Cairenn 10-06-07 01:26 PM

Quote:

Originally Posted by Seerah
well, private servers are not supported, condoned, or endorsed here.

Quoted for emphasis.


All times are GMT -6. The time now is 07:22 AM.

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