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

[HELP] Get All Cmd Args


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 09-09-2019 , 10:54   [HELP] Get All Cmd Args
Reply With Quote #1

Hello everyone.

I tried to get all the cmd args that the client will use, has that is unknown the ammount he is going to use I tried this one.

PHP Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR "SpirT"
#define PLUGIN_VERSION "1.0"

char file[512];

#include <sourcemod>
#include <sdktools>

#pragma newdecls required

public Plugin myinfo 
{
    
name "[SpirT] Phrase Setter",
    
author PLUGIN_AUTHOR,
    
description "Sets a player's phrase with a command",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_phrase"Command_Phrase);
    
    
BuildPath(Path_SMfilesizeof(file), "configs/SpirT/phrase.cfg");
    
char dir[512] = "addons/sourcemod/configs/SpirT";
    if(!
DirExists(dir))
    {
        
CreateDirectory(dir511);
    }
}

public 
void OnClientPutInServer(int client)
{
    
KeyValues kv = new KeyValues("SpirTPhrase");
    
kv.ImportFromFile(file);
    
    
char sID[32];
    
GetClientAuthId(clientAuthId_Steam2sIDsizeof(sID));
    
    if(!
KvJumpToKey(kvsIDfalse))
    {
        
PrintToServer("[SpirT - Phrase Set] Player %N don't has his / her phrase set yet!"client);
    }
    
    
char phrase[64];
    
KvGetString(kv"phrase"phrasesizeof(phrase));
    
    
PrintToChatAll("%N Connected: %s"clientphrase);
}

public 
Action Command_Phrase(int clientint args)
{
    if(
args 1)
    {
        
char phrase[128];
        
int phrase_args GetCmdArgs();
        
GetCmdArg(phrase_argsphrasesizeof(phrase));
        
        
KeyValues kvm = new KeyValues("SpirTPhrase");
        
kvm.ImportFromFile(file);
        
        
char steamID[32];
        
GetClientAuthId(clientAuthId_Steam2steamIDsizeof(steamID));
        
        if(
KvJumpToKey(kvmsteamIDtrue))
        {
            
char check[64];
            
KvGetString(kvm"phrase"checksizeof(check), "");
        
            if(!
StrEqual(checkphrase))
            {
                
KvSetString(kvm"phrase"phrase);
            }
            
PrintToChat(client"[SpirT - Phrase Set] Your actual phrase is the same that you're trying to set. Please try another one.");
        }
    }
    
    return 
Plugin_Handled;

And when he connects instead of saying all the phrase, just prints the start!

Let's supose that phrase is "The pro is Me"
It Just's print to chat:
Code:
SpirT Connected: The
So it's just prints the first argument of the cmd. How can I get all and make in only one string to store the value?

Best Regards,

SpirT.
__________________

Last edited by SpirT; 09-09-2019 at 10:54.
SpirT is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-09-2019 , 12:27   Re: [HELP] Get All Cmd Args
Reply With Quote #2

The function GetCmdArgString will do exactly what you want.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 09-09-2019 , 13:41   Re: [HELP] Get All Cmd Args
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
The function GetCmdArgString will do exactly what you want.
Hey. Thanks for your help. So it should look like this?
PHP Code:
char ArgString[64];
int all_args GetCmdArgString(ArgStringsizeof(ArgString)); 
Edit: Tried this:
PHP Code:
char tags[128];
int tag_args GetCmdArgString(tagssizeof(tags)); 
And got an error:
Code:
warning 204 - symbol is assigned a value that is never used: "tag_args"
Second Edit xD:

Tried another way, this time to fix an older plugin
PHP Code:
char szClan[64];
GetCmdArgString(szClansizeof(szClan)); 
It had no errors on copiling, but like when I do the command to set my tag !settag [ TEST ] it just makes the tag with [

Where am I wrong?

Best Regards,

SpirT.
__________________

Last edited by SpirT; 09-09-2019 at 14:04. Reason: Edit for some errors displayed on compile
SpirT is offline
ShD3luxe
Member
Join Date: Aug 2019
Location: Localhost
Old 09-09-2019 , 15:26   Re: [HELP] Get All Cmd Args
Reply With Quote #4

You can try like this :
Code:
int iargs = GetCmdArgs();
char phrase[128],argPhrase[24];
for(int i = 1;i <= iargs;i++)
{
	GetCmdArg(i,argPhrase,sizeof(argPhrase));
	StrCat(phrase,sizeof(phrase),argPhrase);
}
But the GetCmdArgString should worked , try putting some debugging messages , you may store the keyvalue wrong.
ShD3luxe is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 09-09-2019 , 15:51   Re: [HELP] Get All Cmd Args
Reply With Quote #5

Quote:
Originally Posted by ShD3luxe View Post
You can try like this :
Code:
int iargs = GetCmdArgs();
char phrase[128],argPhrase[24];
for(int i = 1;i <= iargs;i++)
{
	GetCmdArg(i,argPhrase,sizeof(argPhrase));
	StrCat(phrase,sizeof(phrase),argPhrase);
}
But the GetCmdArgString should worked , try putting some debugging messages , you may store the keyvalue wrong.
KeyValues is like that
Code:
"SpirTPhrase"
{
	"STEAM_0:1:419435558"
	{
		"tag"	"This is SpirT Message"
	}
}
but with the command it is not storing the value on the kv. I'll put down the Tags version that I'm trying to fix to

EDIT: With the command !phrase This is a test phrase when spirt join And it doesn't changes the value of the Kv, it stays the same! (Value is on the file because I created it!)

PHP Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR "SpirT"
#define PLUGIN_VERSION "1.0"

char file[512];

#include <sourcemod>
#include <sdktools>
#include <cstrike>

ConVar g_enabled;
ConVar g_chat;

#pragma newdecls required

public Plugin myinfo 
{
    
name "[SpirT] ClanTag Setter",
    
author PLUGIN_AUTHOR,
    
description "Sets a player's tag with a command",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_settag"Command_SetTag);
    
RegAdminCmd("sm_sid"Command_sIDADMFLAG_ROOT);
    
    
g_enabled CreateConVar("sm_spirt_tags_enable""1""Enable / Disable all plugin features");
    
g_chat CreateConVar("sm_spirt_tags_chat""[SpirT - Tag Set]""Chat's tag for all the plugin messages");
    
    
AutoExecConfig(true"spirt_tags""SpirT");
    
    
BuildPath(Path_SMfilesizeof(file), "configs/SpirT/tags.cfg");
    
char dir[512] = "addons/sourcemod/configs/SpirT";
    
char dir_config[512] = "cfg/SpirT";
    if(!
DirExists(dir) && !DirExists(dir_config))
    {
        
CreateDirectory(dir511);
        
CreateDirectory(dir_config511);
    }
}

public 
Action Command_sID(int clientint args)
{
    
char sID[64];
    
GetClientAuthId(clientAuthId_Steam2sIDsizeof(sID));
    
PrintToChat(client"Ur SteamID: %s"sID);
    return 
Plugin_Handled;
}

public 
void OnClientPutInServer(int client)
{
    
KeyValues kv = new KeyValues("SpirTTags");
    
kv.ImportFromFile(file);
    
    
char sID[32];
    
GetClientAuthId(clientAuthId_Steam2sIDsizeof(sID));
    
    if(!
KvJumpToKey(kvsIDfalse))
    {
        
PrintToServer("[SpirT - Tag Set] Player %N don't has his / her tag set yet!"client);
    }
    
    
char tag[64];
    
KvGetString(kv"tag"tagsizeof(tag));
    
CS_SetClientClanTag(clienttag);
}

public 
Action Command_SetTag(int clientint args)
{
    
char chat[64];
    
GetConVarString(g_chatchatsizeof(chat));
    
int enabled GetConVarInt(g_enabled);
    if(
enabled 1)
    {
        
PrintToServer("[SpirT] ConVar sm_spirt_tags_enable is set to 0 or the value is not higher than 1. Please change value to activate!");
        return 
Plugin_Handled;
    }
    
    if(
args 1)
    {
        
ReplyToCommand(client"%s Use: sm_settag <tag_you_want>"chat);
        return 
Plugin_Handled;
    }
    
    
char tag[64];
    
GetCmdArg(1tagsizeof(tag));
    
    
KeyValues kv = new KeyValues("SpirTTags");
    
kv.ImportFromFile(file);
    
    
char sID[32];
    
GetClientAuthId(clientAuthId_Steam2sIDsizeof(sID));
    
    if(
KvJumpToKey(kvsIDtrue))
    {
        
char check[64];
        
KvGetString(kv"tag"checksizeof(check), "");
        
        if(!
StrEqual(checktag))
        {
            
KvSetString(kv"tag"tag);
            
CS_SetClientClanTag(clienttag);
        }
        
PrintToChat(client"%s Your actual tag is the same that you're trying to set. Please try another one."chat);
    }
    
    else if(
args 1)
    {
        
char tags[128];
        
GetCmdArgString(tagssizeof(tags));
        
        
KeyValues kvm = new KeyValues("SpirTTags");
        
kvm.ImportFromFile(file);
        
        
char steamID[32];
        
GetClientAuthId(clientAuthId_Steam2steamIDsizeof(steamID));
        
        if(
KvJumpToKey(kvmsteamIDtrue))
        {
            
char check[64];
            
KvGetString(kvm"tag"checksizeof(check), "");
        
            if(!
StrEqual(checktags))
            {
                
KvSetString(kvm"tag"tags);
                
CS_SetClientClanTag(clienttag);
            }
            
PrintToChat(client"%s Your actual tag is the same that you're trying to set. Please try another one."chat);
        }
    }
    
    return 
Plugin_Handled;

__________________

Last edited by SpirT; 09-10-2019 at 08:45. Reason: More details about the issue
SpirT is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 09-11-2019 , 12:34   Re: [HELP] Get All Cmd Args
Reply With Quote #6

u probably need to escape the string, as colons splits them
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: Stefan Milivojevic#5311
I am inevitable is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 09-12-2019 , 13:08   Re: [HELP] Get All Cmd Args
Reply With Quote #7

Quote:
Originally Posted by I am inevitable View Post
u probably need to escape the string, as colons splits them
How do I do that? I'm not so good at SourcePawn, I still have to learn better KeyValues and SQL.

Can you show me how do I do it?

Best Regards,

SpirT.
__________________
SpirT is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 09-12-2019 , 15:32   Re: [HELP] Get All Cmd Args
Reply With Quote #8

In your code, you're not exporting the new data to the file, so any phrase you set isn't being stored. You're also not closing the KV handle afterward, so you have Handle leaks.

Here's how I would store a phrase:

PHP Code:
#include <sourcemod>

public void OnPluginStart()
{
    
RegAdminCmd("sm_phrase"cmdPhraseADMFLAG_ROOT"Set a phrase");
}

public 
Action cmdPhrase(int clientint args)
{
    
char sPhrase[64];
    
GetCmdArgString(sPhrasesizeof(sPhrase));
    
StorePhrase(clientsPhrase);

    return 
Plugin_Handled;
}

stock void StorePhrase(int client, const char[] phrase)
{
    
char sFilePath[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMsFilePathsizeof(sFilePath), "configs/phrases.cfg");

    
KeyValues kvm = new KeyValues("Player Phrases");
    
kvm.ImportFromFile(sFilePath);

    
char sSteamID[32];
    if (
GetClientAuthId(clientAuthId_Steam2sSteamIDsizeof(sSteamID)))
    {
        if (
kvm.JumpToKey(sSteamIDtrue))
        {
            
char sCheck[64];
            
kvm.GetString("phrase"sChecksizeof(sCheck), "");

            if (!
StrEqual(sCheckphrase))
            {
                
kvm.SetString("phrase"phrase);
                
kvm.ExportToFile(sFilePath);

                
ReplyToCommand(client"[SM] You set your new phrase to: \"%s\""phrase);
            }
            else
            {
                
ReplyToCommand(client"[SM] The phrase you entered is the same one that is already saved on the server.");
            }
        }
    }

    
delete kvm;

Example output:

PHP Code:
Crasher_3637 :  !phrase Hello there!
[
SMYou set your new phrase to"Hello there!" 
__________________
Psyk0tik is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 09-13-2019 , 06:55   Re: [HELP] Get All Cmd Args
Reply With Quote #9

Quote:
Originally Posted by Crasher_3637 View Post
In your code, you're not exporting the new data to the file, so any phrase you set isn't being stored. You're also not closing the KV handle afterward, so you have Handle leaks.

Here's how I would store a phrase:

PHP Code:
#include <sourcemod>

public void OnPluginStart()
{
    
RegAdminCmd("sm_phrase"cmdPhraseADMFLAG_ROOT"Set a phrase");
}

public 
Action cmdPhrase(int clientint args)
{
    
char sPhrase[64];
    
GetCmdArgString(sPhrasesizeof(sPhrase));
    
StorePhrase(clientsPhrase);

    return 
Plugin_Handled;
}

stock void StorePhrase(int client, const char[] phrase)
{
    
char sFilePath[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMsFilePathsizeof(sFilePath), "configs/phrases.cfg");

    
KeyValues kvm = new KeyValues("Player Phrases");
    
kvm.ImportFromFile(sFilePath);

    
char sSteamID[32];
    if (
GetClientAuthId(clientAuthId_Steam2sSteamIDsizeof(sSteamID)))
    {
        if (
kvm.JumpToKey(sSteamIDtrue))
        {
            
char sCheck[64];
            
kvm.GetString("phrase"sChecksizeof(sCheck), "");

            if (!
StrEqual(sCheckphrase))
            {
                
kvm.SetString("phrase"phrase);
                
kvm.ExportToFile(sFilePath);

                
ReplyToCommand(client"[SM] You set your new phrase to: \"%s\""phrase);
            }
            else
            {
                
ReplyToCommand(client"[SM] The phrase you entered is the same one that is already saved on the server.");
            }
        }
    }

    
delete kvm;

Example output:

PHP Code:
Crasher_3637 :  !phrase Hello there!
[
SMYou set your new phrase to"Hello there!" 
Ok, gonna try to do it as a "copy" of your example for my TAG one. Thanks!
I'll post then here the source so if you can verify if everything is ok ;)
__________________

Last edited by SpirT; 09-13-2019 at 06:55.
SpirT is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 09-13-2019 , 11:13   Re: [HELP] Get All Cmd Args
Reply With Quote #10

Quote:
Originally Posted by Crasher_3637 View Post
In your code, you're not exporting the new data to the file, so any phrase you set isn't being stored. You're also not closing the KV handle afterward, so you have Handle leaks.

Here's how I would store a phrase:

PHP Code:
#include <sourcemod>

public void OnPluginStart()
{
    
RegAdminCmd("sm_phrase"cmdPhraseADMFLAG_ROOT"Set a phrase");
}

public 
Action cmdPhrase(int clientint args)
{
    
char sPhrase[64];
    
GetCmdArgString(sPhrasesizeof(sPhrase));
    
StorePhrase(clientsPhrase);

    return 
Plugin_Handled;
}

stock void StorePhrase(int client, const char[] phrase)
{
    
char sFilePath[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMsFilePathsizeof(sFilePath), "configs/phrases.cfg");

    
KeyValues kvm = new KeyValues("Player Phrases");
    
kvm.ImportFromFile(sFilePath);

    
char sSteamID[32];
    if (
GetClientAuthId(clientAuthId_Steam2sSteamIDsizeof(sSteamID)))
    {
        if (
kvm.JumpToKey(sSteamIDtrue))
        {
            
char sCheck[64];
            
kvm.GetString("phrase"sChecksizeof(sCheck), "");

            if (!
StrEqual(sCheckphrase))
            {
                
kvm.SetString("phrase"phrase);
                
kvm.ExportToFile(sFilePath);

                
ReplyToCommand(client"[SM] You set your new phrase to: \"%s\""phrase);
            }
            else
            {
                
ReplyToCommand(client"[SM] The phrase you entered is the same one that is already saved on the server.");
            }
        }
    }

    
delete kvm;

Example output:

PHP Code:
Crasher_3637 :  !phrase Hello there!
[
SMYou set your new phrase to"Hello there!" 
For a "clean way" instead of
PHP Code:
if (!StrEqual(sCheckphrase))
            {
                
kvm.SetString("phrase"phrase);
                
kvm.ExportToFile(sFilePath);

                
ReplyToCommand(client"[SM] You set your new phrase to: \"%s\""phrase);
            }
            else
            {
                
ReplyToCommand(client"[SM] The phrase you entered is the same one that is already saved on the server.");
            } 
Can we use
PHP Code:
if (!StrEqual(sCheckphrase))
            {
                
kvm.SetString("phrase"phrase);
                
kvm.ExportToFile(sFilePath);

                
ReplyToCommand(client"[SM] You set your new phrase to: \"%s\""phrase);
            }
            
             
ReplyToCommand(client"[SM] The phrase you entered is the same one that is already saved on the server."); 
And the kvm.ExportToFile(FILEPATH) is it needed? It doesn't export the values to file itself?
__________________
SpirT 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 09:55.


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