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

Command Arg without quotes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
aequabit
Junior Member
Join Date: Aug 2016
Old 08-11-2016 , 02:19   Command Arg without quotes
Reply With Quote #1

Hello,

I created a command which takes one argument and prints this argument to the chat.

PHP Code:
public Action:chatCommand(clientargs) {
    if(
args 1) {
        
PrintToConsole(client"usage: chatmessage <message>");
        return 
Plugin_Handled;
    }

    new 
String:Arg1[256];

    
GetCmdArg(1Arg1sizeof(Arg1));

    
PrintToChatAll("Admin: %s"Arg1);
    return 
Plugin_Handled;

If I use the command like
PHP Code:
chatmessage "this is my message" 
it prints the whole message.

But if I do
PHP Code:
chatmessage this is my message 
it splits at the first space and only prints "Admin: this".

Is there any way to fix this? Thank you very much for your help!
aequabit is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 08-11-2016 , 03:30   Re: Command Arg without quotes
Reply With Quote #2

If they quote it, it's one argument. If they don't, it's multiple. This is useful in some cases to make parsing much easier if you have multiple parameters but at least one can contain spaces.

If you don't care about the difference, you can just use GetCmdArgString().
Fyren is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 08-11-2016 , 18:20   Re: Command Arg without quotes
Reply With Quote #3

Use GetCmdArgString
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick 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 15:11.


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