AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   handle_say and read_argv Problem~ (https://forums.alliedmods.net/showthread.php?t=56854)

lucky109 06-22-2007 12:53

handle_say and read_argv Problem~
 
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?

_Master_ 06-22-2007 13:31

Re: handle_say and read_argv Problem~
 
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])



lucky109 06-22-2007 13:39

Re: handle_say and read_argv Problem~
 
Quote:

Originally Posted by _Master_ (Post 493317)
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"

hlstriker 06-22-2007 13:50

Re: handle_say and read_argv Problem~
 
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");
    }



Lee 06-22-2007 18:29

Re: handle_say and read_argv Problem~
 
_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?

stupok 06-22-2007 19:26

Re: handle_say and read_argv Problem~
 
I would go with _Master_ 's solution. :up:

Lee 06-22-2007 21:50

Re: handle_say and read_argv Problem~
 
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)     } }

lucky109 06-23-2007 00:22

Re: handle_say and read_argv Problem~
 
Quote:

Originally Posted by Lee (Post 493494)
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?

_Master_ 06-23-2007 03:32

Re: handle_say and read_argv Problem~
 
[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"


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

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