Raised This Month: $ Target: $400
 0% 

handle_say and read_argv Problem~


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 06-22-2007 , 21:50   Re: handle_say and read_argv Problem~
Reply With Quote #1

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 #2

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 #3

[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



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