AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Parse (https://forums.alliedmods.net/showthread.php?t=170680)

Diegorkable 10-27-2011 19:39

Parse
 
Hey.

I used the parse() function in the 'say' hook function and it doesnt work properly I don't know why. I did the following:

PHP Code:

public plugin_init()
{
            
// bla bla...
            
register_clcmd("say""say_hook")
}

public 
say_hook(id)
{
    new 
message[100]
    
read_args(message99)
    
    new 
part1[50], part2[50]
    
parse(messagepart1, (sizeof(part1) - 1), part2, (sizeof(part2) - 1))
    
client_print(idprint_chat"Arg1 = %s, Arg2 = %s"part1part2)


When I try for example type /points p1Mp, it prints then this:
Code:

Arg1 = /points, Arg2 =
And that's wierd, I don't get why is arg2 is nothing, the parse should copy the 2nd arg into part2 variable.

What am I doing wrong?

Thanks in advance.

Erox902 10-27-2011 19:46

Re: Parse
 
Cuz' of this I believe it assumes that the first part is 49 characters:
PHP Code:

new part1[50], part2[50

I think you'll have to check were the first space in the msg is.

Seems kinda wierd however that you got that ", Arg2 =" printed. :?

Diegorkable 10-27-2011 19:57

Re: Parse
 
The message is simple: "/level p1Mp"

the space is after '/level' and then p1Mp. and I dont think the 50 is the cause, cuz what it does is take arg1 and just copy it on 50 cells array (then it'll have like 8 cells with values then the rest are NULL TERMINATORS), but it doesnt (shouldnt) affect the parse....

Diegorkable 10-27-2011 20:14

Re: Parse
 
Just found something wierd, it parses the message by " but not SPACE
I typed /level" p1Mp
and it said:

arg1 = /level, arg2 = p1Mp

Why the heck is it breaking at "??? how can I change it to SPACE

Erox902 10-27-2011 20:19

Re: Parse
 
Quote:

Originally Posted by Diegorkable (Post 1584573)
the space is after '/level' and then p1Mp. and I dont think the 50 is the cause, cuz what it does is take arg1 and just copy it on 50 cells array (then it'll have like 8 cells with values then the rest are NULL TERMINATORS), but it doesnt (shouldnt) affect the parse....

Not sure but maybe you'll have to check out strbreak() or split():shock:

Emp` 10-27-2011 20:31

Re: Parse
 
read_args places all the arguments within quotes. You need to use remove_quotes on message first.

parse separates based on quotations before spaces.

Diegorkable 10-27-2011 20:46

Re: Parse
 
ty :)


All times are GMT -4. The time now is 14:15.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.