This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

New to SourcePawn trying to link a command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Vict77
Junior Member
Join Date: Dec 2022
Old 12-17-2022 , 09:40   New to SourcePawn trying to link a command
Reply With Quote #1

Hi all. I'm trying to link a client command to the correct result.
This has sm_test 1, sm_test 2, and sm_test 3 in three separate cfg files which shows correctly in the server console once a selection is made.

How do I make it so that typing !test or /test shows the correct result to the client? I'm pretty sure this is simple, but I'm new so any help would greatly be appreciated.

Me: !test
Me: This test is Normal. <----- would pick up correct result sm_test 2

Code:
public void OnPluginStart() 
{	        
        RegConsoleCmd("sm_test", Command_ShowTest, "testing");                                  	
}

public Action:Command_ShowTest(i, args)
{
        decl String:arg[20];
	GetCmdArgString(arg, sizeof(arg));
	new V1 = StringToInt(arg,3);
	
        if (V1 == 1) {ReplyToCommand(i, "This test is Easy.");}
	else if (V1 == 2) {ReplyToCommand(i, "This test is Normal.");}
	else if (V1 == 3) {ReplyToCommand(i, "This test is Hard.");}
        return Plugin_Handled;       
}
Vict77 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 12-17-2022 , 10:16   Re: New to SourcePawn trying to link a command
Reply With Quote #2

PHP Code:
public void OnPluginStart()
{
    
RegConsoleCmd("sm_test"Command_ShowTest"testing");
}

Action Command_ShowTest(int clientint args)
{
    
int difficulty GetCmdArgInt(1);
    switch (
difficulty)
    {
        case 
1ReplyToCommand(client"This test is Easy.");
        case 
2ReplyToCommand(client"This test is Normal.");
        case 
3ReplyToCommand(client"This test is Hard.");
        default: 
ReplyToCommand(client"This test is *Unknown* (%d)."difficulty);
    }
    return 
Plugin_Handled;

Attached Files
File Type: sp Get Plugin or Get Source (Vict77_test.sp - 29 views - 532 Bytes)
__________________

Last edited by Marttt; 12-17-2022 at 14:47.
Marttt is offline
Vict77
Junior Member
Join Date: Dec 2022
Old 12-17-2022 , 14:02   Re: New to SourcePawn trying to link a command
Reply With Quote #3

Quote:
Originally Posted by Marttt View Post
PHP Code:
public void OnPluginStart()
{
    
RegConsoleCmd("sm_test"Command_ShowTest"testing");
}

Action Command_ShowTest(int clientint args)
{
    
int difficulty GetCmdArgInt(1);
    switch (
difficulty)
    {
        case 
1ReplyToCommand(client"This test is Easy.");
        case 
2ReplyToCommand(client"This test is Normal.");
        case 
3ReplyToCommand(client"This test is Hard.");
        default: 
ReplyToCommand(client"This test is *Unknown* (%d)."difficulty);
    }
    return 
Plugin_Handled;


Thanks Marttt for the fast response and the help, but it does not compile.
Vict77 is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 12-17-2022 , 14:21   Re: New to SourcePawn trying to link a command
Reply With Quote #4

PHP Code:
public void OnPluginStart()
{
    
RegConsoleCmd("sm_test"Command_ShowTest"testing");
}

public 
Action Command_ShowTest(int clientint args)
{
    if(!
args)
    {
        
ReplyToCommand(client"You must send any number as an argument: sm_test <number>");
        return 
Plugin_Handled;
    }

    
char arg[12];
    
GetCmdArg(1argsizeof(arg));

    switch(
StringToInt(arg)%4)    // -3 to 3 with any number ^_^
    
{
        case 
1:  ReplyToCommand(client"This test is Easy.");
        case 
2:  ReplyToCommand(client"This test is Normal.");
        case 
3:  ReplyToCommand(client"This test is Hard.");
        default: 
ReplyToCommand(client"This test is wrong (arg: %s)."arg);
    }
    return 
Plugin_Handled;

__________________
Grey83 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 12-17-2022 , 14:49   Re: New to SourcePawn trying to link a command
Reply With Quote #5

Quote:
Originally Posted by Vict77 View Post
Thanks Marttt for the fast response and the help, but it does not compile.
Should compile file in SM1.11, you can paste the code here and add a plugin name, then download.

Anyway Grey version should work for older versions.
__________________
Marttt is offline
Vict77
Junior Member
Join Date: Dec 2022
Old 12-17-2022 , 15:21   Re: New to SourcePawn trying to link a command
Reply With Quote #6

Quote:
Originally Posted by Marttt View Post
Should compile file in SM1.11, you can paste the code here and add a plugin name, then download.

Anyway Grey version should work for older versions.
Thanks Marttt! I've had compiles both with that link and in SM with no issues in the past, but yours compiled with no errors. What's the best way to create .sp files? I've been using Notepad in Windows 10. However, if I type !test or /test it returns 0 instead of the current result of either This test is Easy, Normal, or Hard. So the main part I'm trying to get working isn't working.

Last edited by Vict77; 12-17-2022 at 15:34.
Vict77 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 12-17-2022 , 17:01   Re: New to SourcePawn trying to link a command
Reply With Quote #7

according to your example you have to type "!test <number>" in chat otherwise won't work.
If you wan't store that value somewhere then you have to create a variable outside the scope and set it.

PHP Code:
int lastDifficulty;

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_test"Command_ShowTest"testing");
}

Action Command_ShowTest(int clientint args)
{
    if (
args 0)
        
lastDifficulty GetCmdArgInt(1);

    switch (
lastDifficulty)
    {
        case 
1ReplyToCommand(client"This test is Easy.");
        case 
2ReplyToCommand(client"This test is Normal.");
        case 
3ReplyToCommand(client"This test is Hard.");
        default: 
ReplyToCommand(client"This test is *Unknown* (%d)."lastDifficulty);
    }
    return 
Plugin_Handled;

__________________
Marttt is offline
Vict77
Junior Member
Join Date: Dec 2022
Old 12-17-2022 , 18:08   Re: New to SourcePawn trying to link a command
Reply With Quote #8

Quote:
Originally Posted by Marttt View Post
according to your example you have to type "!test <number>" in chat otherwise won't work.
If you wan't store that value somewhere then you have to create a variable outside the scope and set it.

PHP Code:
int lastDifficulty;

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_test"Command_ShowTest"testing");
}

Action Command_ShowTest(int clientint args)
{
    if (
args 0)
        
lastDifficulty GetCmdArgInt(1);

    switch (
lastDifficulty)
    {
        case 
1ReplyToCommand(client"This test is Easy.");
        case 
2ReplyToCommand(client"This test is Normal.");
        case 
3ReplyToCommand(client"This test is Hard.");
        default: 
ReplyToCommand(client"This test is *Unknown* (%d)."lastDifficulty);
    }
    return 
Plugin_Handled;

That did it! Thanks again Marttt! It works perfectly. Only problem I'm still having is copy/pasting the code from here and creating a .sp file. It appears to be a Firefox issue, because using Edge it worked fine.
Vict77 is offline
Vict77
Junior Member
Join Date: Dec 2022
Old 12-17-2022 , 18:26   Re: New to SourcePawn trying to link a command
Reply With Quote #9

Last question if you don't mind. Is there a way to block !test 1, 2 or 3 from the client only? While !test does show the current value, if you type !test 1, 2, or 3 it will change it even though it's not actually the correct value.

Last edited by Vict77; 12-17-2022 at 18:27.
Vict77 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 12-17-2022 , 18:44   Re: New to SourcePawn trying to link a command
Reply With Quote #10

don't know what you mean, you will need be more clear and specific on what you need
looks like what you wan't is read the value from a cvar, instead a command.
__________________
Marttt is offline
Reply



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 21:24.


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