Raised This Month: $51 Target: $400
 12% 

Read_argv, how to?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kiki33hun
Veteran Member
Join Date: Jul 2011
Location: Magyarország
Old 03-21-2012 , 13:31   Read_argv, how to?
Reply With Quote #1

Iam create simple command!

PHP Code:
register_concmd("say /numbers""testhan"
Like: say /numbers 255 160 98

PHP Code:
public testhan(id)
{
   
client_print(idprint_chat"your numbers: %d %d %d", ..etc

How to? Thanx!
__________________
kiki33hun is offline
kramesa
Veteran Member
Join Date: Feb 2011
Location: Brazil
Old 03-21-2012 , 13:37   Re: Read_argv, how to?
Reply With Quote #2

Next time search.

Code:
#include <amxmodx> public plugin_init()     register_concmd("say /numbers", "CmdNum"); public CmdNum(id) {     new Arg[3], Arg2[3], Arg3[3];     read_argv(1, Arg, 2);     read_argv(2, Arg2, 2);     read_argv(3. Arg3, 2);         client_print(id, print_chat, "Numbers: %d %d %d", Arg, Arg2, Arg3); }
__________________
kramesa is offline
kiki33hun
Veteran Member
Join Date: Jul 2011
Location: Magyarország
Old 03-21-2012 , 13:40   Re: Read_argv, how to?
Reply With Quote #3

Quote:
Originally Posted by kramesa View Post
Next time search.

Code:
#include <amxmodx> public plugin_init()     register_concmd("say /numbers", "CmdNum"); public CmdNum(id) {     new Arg[3], Arg2[3], Arg3[3];     read_argv(1, Arg, 2);     read_argv(2, Arg2, 2);     read_argv(3. Arg3, 2);         client_print(id, print_chat, "Numbers: %d %d %d", Arg, Arg2, Arg3); }

HTML Code:
Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team

C:\Users\Kiki\Desktop\asdasdadsads.sma(11) : error 001: expected token: ",", but found "."
C:\Users\Kiki\Desktop\asdasdadsads.sma(11) : error 029: invalid expression, assumed zero
C:\Users\Kiki\Desktop\asdasdadsads.sma(11) : warning 215: expression has no effect
C:\Users\Kiki\Desktop\asdasdadsads.sma(11) : warning 215: expression has no effect
C:\Users\Kiki\Desktop\asdasdadsads.sma(11) : error 001: expected token: ";", but found ")"
C:\Users\Kiki\Desktop\asdasdadsads.sma(11) : fatal error 107: too many error messages on one line

Compilation aborted.
4 Errors.
Could not locate output file C:\Users\Kiki\Desktop\asdasdadsads.amx (compile failed).

Compilation Time: 0,99 sec
3. --> 3, , THANX
__________________

Last edited by kiki33hun; 03-21-2012 at 13:41.
kiki33hun is offline
killergirl
Senior Member
Join Date: Jul 2010
Old 03-21-2012 , 13:43   Re: Read_argv, how to?
Reply With Quote #4

PHP Code:
public yourFunction(id){
    
    static 
arg[256], buff[10], val[2], val2[2], val3[2]
    
    
read_args(arg255)
    
    if(
containi(arg"/testhan") != -1){
        
copy(buff9arg[9])
        
        
parse(buffval1val21val31)
        
        
client_print(idprint_chat"Your nums are: %d %d %d"str_to_num(val1), str_to_num(val2), str_to_num(val3) )
        
        
//or
        
        
client_print(idprint_chat"Your nums are: %s"buff)
        
        return 
PLUGIN_HANDLED
    
}
    
    return 
PLUGIN_CONTINUE

killergirl is offline
kiki33hun
Veteran Member
Join Date: Jul 2011
Location: Magyarország
Old 03-21-2012 , 13:46   Re: Read_argv, how to?
Reply With Quote #5

Quote:
Originally Posted by kramesa View Post
Next time search.

Code:
#include <amxmodx> public plugin_init()     register_concmd("say /numbers", "CmdNum"); public CmdNum(id) {     new Arg[3], Arg2[3], Arg3[3];     read_argv(1, Arg, 2);     read_argv(2, Arg2, 2);     read_argv(3. Arg3, 2);         client_print(id, print_chat, "Numbers: %d %d %d", Arg, Arg2, Arg3); }
Not working!


killergirl thanx
__________________
kiki33hun is offline
kiki33hun
Veteran Member
Join Date: Jul 2011
Location: Magyarország
Old 03-21-2012 , 13:50   Re: Read_argv, how to?
Reply With Quote #6

Quote:
Originally Posted by killergirl View Post
PHP Code:
public yourFunction(id){
    
    static 
arg[256], buff[10], val[2], val2[2], val3[2]
    
    
read_args(arg255)
    
    if(
containi(arg"/testhan") != -1){
        
copy(buff9arg[9])
        
        
parse(buffval1val21val31)
        
        
client_print(idprint_chat"Your nums are: %d %d %d"str_to_num(val1), str_to_num(val2), str_to_num(val3) )
        
        
//or
        
        
client_print(idprint_chat"Your nums are: %s"buff)
        
        return 
PLUGIN_HANDLED
    
}
    
    return 
PLUGIN_CONTINUE

Not working
__________________
kiki33hun is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 03-21-2012 , 13:58   Re: Read_argv, how to?
Reply With Quote #7

There's a small typo here:
Quote:
Originally Posted by kramesa View Post
read_argv(3. Arg3, 2);
Replace that dot with a comma.
__________________

Last edited by Hunter-Digital; 03-21-2012 at 13:58.
Hunter-Digital is offline
killergirl
Senior Member
Join Date: Jul 2010
Old 03-21-2012 , 14:01   Re: Read_argv, how to?
Reply With Quote #8

PHP Code:
register_clcmd("say /testhan""yourFunction"
->

PHP Code:
register_clcmd("say""yourFunction"
killergirl is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-21-2012 , 14:02   Re: Read_argv, how to?
Reply With Quote #9

When using chat commands, "say" is the real command to hook and then the rest is 1 whole argument string for the command.
To get the arguments inside of that, you have to parse it.
In the case of say commands, we kind of have a command inside of a command:
say "/command arg1 arg2 ..."

So, basically it would look like this:
Code:
public plugin_init() {     register_clcmd("say", "CmdSay"); } public CmdSay(id) {     new args[194];     read_args(args, charsmax(args));     remove_quotes(args);         new command[32];     strbreak(args, command, charsmax(command), args, charsmax(args));         if(equali(command, "/numbers")) {         new Array:numberList = ArrayCreate(), numbers;                 if(args[0]) {             new number[12];                         while(contain(args, " ") >= 0) {                 strbreak(args, number, charsmax(number), args, charsmax(args));                                 if(is_str_num(number)) {                     ArrayPushCell(numberList, str_to_num(number));                     numbers++;                 }             }                         if(is_str_num(args)) {                 ArrayPushCell(numberList, str_to_num(args));                 numbers++;             }         }                 // numberList holds all the numbers from the command                 ArrayDestroy(numberList);     } }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
kiki33hun
Veteran Member
Join Date: Jul 2011
Location: Magyarország
Old 03-21-2012 , 14:19   Re: Read_argv, how to?
Reply With Quote #10

Quote:
Originally Posted by Exolent[jNr] View Post
When using chat commands, "say" is the real command to hook and then the rest is 1 whole argument string for the command.
To get the arguments inside of that, you have to parse it.
In the case of say commands, we kind of have a command inside of a command:
say "/command arg1 arg2 ..."

So, basically it would look like this:
Code:
public plugin_init() {     register_clcmd("say", "CmdSay"); } public CmdSay(id) {     new args[194];     read_args(args, charsmax(args));     remove_quotes(args);         new command[32];     strbreak(args, command, charsmax(command), args, charsmax(args));         if(equali(command, "/numbers")) {         new Array:numberList = ArrayCreate(), numbers;                 if(args[0]) {             new number[12];                         while(contain(args, " ") >= 0) {                 strbreak(args, number, charsmax(number), args, charsmax(args));                                 if(is_str_num(number)) {                     ArrayPushCell(numberList, str_to_num(number));                     numbers++;                 }             }                         if(is_str_num(args)) {                 ArrayPushCell(numberList, str_to_num(args));                 numbers++;             }         }                 // numberList holds all the numbers from the command                 ArrayDestroy(numberList);     } }
Not working
Typed: say /numbers 1
Chat: 49
Typed: say /numbers 2
Chat: 50
Typed: say /numbers 3
Chat: 51
__________________
kiki33hun 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 12:12.


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