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

Get two arguments


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
einsfuhrer
Member
Join Date: Jun 2019
Old 09-21-2019 , 17:45   Get two arguments
Reply With Quote #1

So I'm having this issue. I want to gag the player I type in as the first argument and the second argument should be stored in the "reason" variable so I can use that as reason on the gag.

But when I type "!tgag trum test" then the reason is "trum test". How can I seperate the first argument from the second?

PHP Code:
#include <sourcemod>
#include <sourcecomms>

#pragma semicolon 1
#pragma newdecls required

public Plugin myinfo = {
    
name        "Trusted",
    
author      "",
    
description "",
    
version     "",
    
url         ""
};

public 
void OnPluginStart()
{
    
RegAdminCmd("sm_tgag"Command_tGagADMFLAG_CUSTOM6"Trusted gag command");
}

public 
Action Command_tGag(int clientint args)
{

    
char name[64];
    
GetCmdArgString(namesizeof(name));

    
char reason[64];
    
GetCmdArgString(reasonsizeof(reason));


    if (
args 2)
    {
        
ReplyToCommand(client" \x0C[TURF]⠀\x08Usage: sm_tgag <name> <reason>");
        return 
Plugin_Handled;
    }

    
SourceComms_SetClientGag(clienttrue30truereason);

    return 
Plugin_Handled;


Thanks in advanced!
einsfuhrer is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 09-21-2019 , 18:39   Re: Get two arguments
Reply With Quote #2

Use GetCmdArg. They start at index 1 as 0 is the command like it says on the page.

Also you are currently muting the player that sends the command. You can use FindTarget to find a player. Make sure you properly check the return value.

Last edited by xerox8521; 09-21-2019 at 18:43. Reason: Added info about Finding a target
xerox8521 is offline
einsfuhrer
Member
Join Date: Jun 2019
Old 09-29-2019 , 10:33   Re: Get two arguments
Reply With Quote #3

Quote:
Originally Posted by xerox8521 View Post
Use GetCmdArg. They start at index 1 as 0 is the command like it says on the page.

Also you are currently muting the player that sends the command. You can use FindTarget to find a player. Make sure you properly check the return value.
I don't really understand, could you send how I should include the GetCmdArg?
einsfuhrer is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 09-29-2019 , 12:24   Re: Get two arguments
Reply With Quote #4

Quote:
Originally Posted by einsfuhrer View Post
I don't really understand, could you send how I should include the GetCmdArg?
PHP Code:

char arg1
[64];
GetCmdArg(1arg1sizeof(arg1)); // get first argument, arg1 holds the argument

char arg2[64];
GetCmdArg(2arg2sizeof(arg2)); // get second argument, arg2 holds the argument 
The argument with index 0 (GetCmdArg(0, arg, sizeof(arg))) holds the command name (ex: sm_ban, sm_kick).
__________________
Ilusion9 is offline
einsfuhrer
Member
Join Date: Jun 2019
Old 09-29-2019 , 16:35   Re: Get two arguments
Reply With Quote #5

Ahh, cool of you to share. Really helped me understand!
einsfuhrer 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 06:27.


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