AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Problem with agrument reading (https://forums.alliedmods.net/showthread.php?t=56038)

vbSteve 06-05-2007 06:09

Problem with agrument reading
 
Hi,

I'm making a plugin that will work as a clan chat (a private chat system for clan members only)

I'm having problems with reading the first argument of the command amx_clansay <Message>, which I bound to "messagemode amx_clansay". Everytime I use it, it keeps resulting in the same error:
Usage: amx_clansay <Message>

I'm desperate (Ive been looking for hours and hours), and I can't find where I'm wrong; maybe you guys can find it. I'm guessing it's something to do with "read_argv(1, argSay, 255);"

Here's a the part of the code that needs attention:

Code:

#include <amxmodx>

#define ADM_LEVEL ADMIN_LEVEL_H
#define msgPrefix "[Clan]"
#define Color "^x04"                // Green

public plugin_init(){
        register_plugin("Clan Chat", "1.0.7", "mCoDev Systems");
       
        register_concmd("amx_clansay", "do_clansay", ADM_LEVEL, " <Message>");

        return PLUGIN_HANDLED;
}

public do_clansay(id, level, cid){
        new argSay[256];  // Hold command argument
        new tMsg[256];  // Hold Message
        new pName[33];    // Hold playername
        new p = get_maxplayers(); // Max players.
        new pid;  // Hold player id

        read_argv(1, argSay, 255);
       
        if (!cmd_access(id, level, cid, 3)) return PLUGIN_HANDLED;
       
        get_user_name(id, pName, 32);
        format(tMsg, 255, "%s %s %s: %s", Color, msgPrefix, pName, argSay);
       
        for(pid=1; pid <= p; ++pid){
                if(get_user_flags(pid) & ADM_LEVEL){
                        if(is_user_connected(pid)){
                                print_message(pid, tMsg); // Subroutine print_message.
                        }
                }
        }
       
        return PLUGIN_HANDLED;
}



Many thanks in advance.
Steve

regalis 06-05-2007 06:25

Re: Problem with agrument reading
 
I think you have to write the message in "" with this way...
You could try to do a for-loop and get all the arguments(the single words of the message)
This let you get the number of arguments (words)
Code:

get_msg_args()
greetz regalis

_Master_ 06-05-2007 06:50

Re: Problem with agrument reading
 
1) use get_players(). NEVER use get_maxplayers() like that again.
2) use read_args(). read_argv(1, ...) gets the first argument.

regalis 06-05-2007 06:54

Re: Problem with agrument reading
 
Quote:

Originally Posted by _Master_ (Post 485877)
1) use get_players(). NEVER use get_maxplayers() like that again.
2) use read_args(). read_argv(1, ...) gets the first argument.

You are the master!
You won the thread :mrgreen:

vbSteve 06-05-2007 07:39

Re: Problem with agrument reading
 
Hi,

Still didn't work.
It works when I use it with more than 1 parameters, but it has to work with only 1 too. I copied a part from my console (client side):
Code:

Type 'amx_help' in the console to see available commands
Time Left: 29:10 min. Next Map: cs_militia_cz
Usage:  amx_clansay  <Message>      -----> Used this with "messagemode amx_clansay"
] amx_clansay yo
Usage:  amx_clansay  <Message>
] amx_clansay "yo"
Usage:  amx_clansay  <Message>
] amx_clansay yo yo
[Clan] ``TeamDW| Lumos: yo yo
] amx_clansay "yo" 0
[Clan] ``TeamDW| Lumos: "yo" 0
] amx_clansay "yo yo"
Usage:  amx_clansay  <Message>

Tried with get_msg_args, but then resulted in compile err "undefined symbol"
Now changed code code to:

Code:

#include <amxmodx>
#include <amxmisc>

#define ADM_LEVEL ADMIN_LEVEL_H
#define msgPrefix "[Clan]"
#define Color "^x04"                // Green

new gSayText;

public plugin_init(){
        register_plugin("Clan Chat", "1.0.23", "mCoDev Systems");
       
        register_concmd("amx_clansay", "do_clansay", ADM_LEVEL, " <Message>");
        //register_concmd("amx_clantsay", "do_clantsay", ADM_LEVEL, " <Message>");
        //register_concmd("amx_clansayall", "do_clansayall", ADM_LEVEL, " <Message>");

        gSayText = get_user_msgid("SayText");
       
        return PLUGIN_HANDLED;
}

public do_clansay(id, level, cid){
        new argSay[255];                // Hold argument
        new tMsg[256];                        // Hold new message
        new pName[33];                        // Hold playername
        new pid;                        // Hold player ID, Hold counter
        new p = get_maxplayers();
       
        if (!cmd_access(id, level, cid, 3)) return PLUGIN_HANDLED;
               
        read_args(argSay, 254);
       
        get_user_name(id, pName, 32);
        format(tMsg, 255, "%s %s %s: %s", Color, msgPrefix, pName, argSay);
       
        for(pid=1; pid <= p; ++pid){
                if(get_user_flags(pid) & ADM_LEVEL){
                        if(is_user_connected(pid)){
                                server_print("(%i) %s %s: %s", pid, msgPrefix, pName, argSay);
                                client_print(pid, print_console, "%s %s: %s", msgPrefix, pName, argSay);
                               
                                message_begin(MSG_ONE, gSayText, {0,0,0}, pid);
                                write_byte(pid);
                                write_string(tMsg);
                                message_end();
                        }
                }
        }
       
        return PLUGIN_HANDLED;
}

Thanks.

_Master_ 06-05-2007 07:51

Re: Problem with agrument reading
 
Actually it ONLY works when you use it with more than (or equal to) 2 arguments.
PHP Code:

if (!cmd_access(idlevelcid3)) return PLUGIN_HANDLED

http://forums.alliedmods.net/showthread.php?t=55149

vbSteve 06-05-2007 08:01

Re: Problem with agrument reading
 
lol. Yeah that makes sens, in fact it works now perfect =) Thanks loads :)


All times are GMT -4. The time now is 10:33.

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