Raised This Month: $ Target: $400
 0% 

handle_say and read_argv Problem~


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lucky109
Senior Member
Join Date: Jan 2005
Old 06-22-2007 , 12:53   handle_say and read_argv Problem~
Reply With Quote #1

Code:
public plugin_init() {
	register_clcmd("say", "handle_say");
}

public handle_say(id)
{
    new arg[32]
    read_argv(2,arg,31)
    new tag[64]
    read_args(tag,63)
    if(  containi(tag, "!test") != -1 )
    {
    client_print(id, print_chat, "[AMXX] %s", arg);
    }
}
i want to get the words when people type !test helo
it's show "[AMXX] helo" right

i'm tried it's work if type "say !test helo" in console
can't work if press Y to type "!test helo"

how can fix it?

Last edited by lucky109; 06-22-2007 at 12:56.
lucky109 is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 06-22-2007 , 13:31   Re: handle_say and read_argv Problem~
Reply With Quote #2

I have no idea what you're trying to do with those argument # readings

PHP Code:
public handle_say(id)
{
     new 
arg[64]
     
read_args(arg63)
     if(
equal(arg"!test "6))
        
client_print(idprint_chat"[AMXX] %s"arg[6])

_Master_ is offline
lucky109
Senior Member
Join Date: Jan 2005
Old 06-22-2007 , 13:39   Re: handle_say and read_argv Problem~
Reply With Quote #3

Quote:
Originally Posted by _Master_ View Post
I have no idea what you're trying to do with those argument # readings

PHP Code:
public handle_say(id)
{
     new 
arg[64]
     
read_args(arg63)
     if(
equal(arg"!test "6))
        
client_print(idprint_chat"[AMXX] %s"arg[6])

just want to know how to output "!test helo"
lucky109 is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 06-22-2007 , 13:50   Re: handle_say and read_argv Problem~
Reply With Quote #4

I really don't understand what you mean either...

PHP Code:
public handle_say(id)
{
    new 
arg[32];
    
    
read_args(arg31);
    
remove_quotes(arg);
    
    if(
containi(arg"!test helo") != -1)
    {
        
client_print(idprint_chat"[AMXX] helo");
    }

hlstriker is offline
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 06-22-2007 , 18:29   Re: handle_say and read_argv Problem~
Reply With Quote #5

_Master_'s code attempts to do what was asked. Yours does not.

Code:
client_print(id, print_chat, "[AMXX] %s", arg[6])
Wouldn't printing arg[6] only include the first character of the argument?

Last edited by Lee; 06-22-2007 at 18:34.
Lee is offline
Old 06-22-2007, 18:36
Deviance
This message has been deleted by Deviance. Reason: Whatever...
stupok
Veteran Member
Join Date: Feb 2006
Old 06-22-2007 , 19:26   Re: handle_say and read_argv Problem~
Reply With Quote #7

I would go with _Master_ 's solution.
stupok is offline
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 06-22-2007 , 21:50   Re: handle_say and read_argv Problem~
Reply With Quote #8

Why did you delete your code? There wasn't much wrong with your approach and as I said before, I don't think _Master_'s will actually work.

Anyway..

Code:
public handle_say(id) {     new arg[64]     read_args(arg, 63)     if(equali(arg, "!test ", 6))     {         replace(arg, 63, "!test ", "")         client_print(id, print_chat, "[AMXX] %s", arg)     } }

Last edited by Lee; 06-22-2007 at 21:56.
Lee is offline
lucky109
Senior Member
Join Date: Jan 2005
Old 06-23-2007 , 00:22   Re: handle_say and read_argv Problem~
Reply With Quote #9

Quote:
Originally Posted by Lee View Post
Why did you delete your code? There wasn't much wrong with your approach and as I said before, I don't think _Master_'s will actually work.

Anyway..

Code:
public handle_say(id) {     new arg[64]     read_args(arg, 63)     if(equali(arg, "!test ", 6))     {         replace(arg, 63, "!test ", "")         client_print(id, print_chat, "[AMXX] %s", arg)     } }

i want to do this :

command: !test [username] [message]

if(equali(arg, "!test ", 6)) i can get username now..
how can i get the [message] only?

Last edited by lucky109; 06-23-2007 at 03:52.
lucky109 is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 06-23-2007 , 03:32   Re: handle_say and read_argv Problem~
Reply With Quote #10

[OFF-TOPIC]
@ LEE: "%s" implies that the argumet be treated as array and will copy the content of that array beginning with the first element supplied and ending it when it reads '/0'. So instead of using "arg" as a way to get all the text you could use arg[0] as well because strings are always passed by reference. Having said that, arg[6] is a sub-text of arg[0] which starts at position 6 in the array. If we use anything else than "%s" then it's treated as a SINGLE element and then your statement is correct.
[/OFF-TOPIC]

@ lucky109: If we get inside this if(equali(arg, "!test ", 6)) then arg[6] will hold the text said. A more elaborate way for this:
PHP Code:
public handle_say(id){
    new 
arg[64]
    
    
read_args(argsizeof arg)
    
remove_quotes(arg)
    
trim(arg)
    
    if(
equali(arg"!test"5)){
        
trim(arg[5])
        
        
// At this point arg[5] holds the text said after "!test"
        // arg[5] starts with the first non-space char
        
client_print(idprint_chat"[AMXX] %s"arg[5])
    }

Ex:
say "this won't show anything because it's missing !test"
say "!test this would show" <- will print "[AMXX] this would show"
say "!testthis would show also" <- will print "[AMXX] this would show also"
say "!test_______________________________________ _______will show too" <- will print "[AMXX] will show too"

Last edited by _Master_; 06-23-2007 at 03:48.
_Master_ is offline
Reply


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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:31.


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