AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Get two arguments (https://forums.alliedmods.net/showthread.php?t=318806)

einsfuhrer 09-21-2019 17:45

Get two arguments
 
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!

xerox8521 09-21-2019 18:39

Re: Get two arguments
 
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.

einsfuhrer 09-29-2019 10:33

Re: Get two arguments
 
Quote:

Originally Posted by xerox8521 (Post 2667812)
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?

Ilusion9 09-29-2019 12:24

Re: Get two arguments
 
Quote:

Originally Posted by einsfuhrer (Post 2668348)
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).

einsfuhrer 09-29-2019 16:35

Re: Get two arguments
 
Ahh, cool of you to share. Really helped me understand!


All times are GMT -4. The time now is 05:49.

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