About the wrong command
#1

Hello guys,

For example, I used the command '/ test'. However, the server has '/ testing' command. How can I list similar commands instead of "SERVER: Unknown Command"?

The message that should come out is: "Incorrect command entered. Similar to: / testing"

I don't know how to do it. I'm waiting for your help.

Regards.
Reply
#2

You'd literally have to make a /test command that would refer back to /testing (which is useless) that's why some cmd includes give you the option of creating an alias, other names for the same command.
Reply
#3

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
You'd literally have to make a /test command that would refer back to /testing (which is useless) that's why some cmd includes give you the option of creating an alias, other names for the same command.
Since the first three letters are similar, can't I propose this instead of the error command?
Reply
#4

Define the alias for your command
Reply
#5

Quote:
Originally Posted by Grumbles
Посмотреть сообщение
Since the first three letters are similar, can't I propose this instead of the error command?
No. This is something you'll have to implement.

Which command processor are you using? Most of the more modern ones such as SmartCMD, Pawn.CMD, or YCMD all include ways to define alias commands to do exactly what you are asking for (as RogueDrifter mentioned already).

If you are using an older one such as ZCMD, you'll need to call the other command within a completely separate command.



@"iorp"; GET THE FUCK OUT OF HERE YOU IMBECILE. THIS IS A PLACE WHERE WE TEACH PEOPLE. IT'S CALLED "SCRIPTING HELP", NOT "BULLSHIT". If you don't know how to help just don't. If you do know how to help then do that instead of commenting something dumb that's not going to help or teach anyone.
Reply
#6

Quote:
Originally Posted by Crayder
Посмотреть сообщение
No. This is something you'll have to implement.

Which command processor are you using? Most of the more modern ones such as SmartCMD, Pawn.CMD, or YCMD all include ways to define alias commands to do exactly what you are asking for (as RogueDrifter mentioned already).

If you are using an older one such as ZCMD, you'll need to call the other command within a completely separate command.



@"iorp"; GET THE FUCK OUT OF HERE YOU IMBECILE. THIS IS A PLACE WHERE WE TEACH PEOPLE. IT'S CALLED "SCRIPTING HELP", NOT "BULLSHIT". If you don't know how to help just don't. If you do know how to help then do that instead of commenting something dumb that's not going to help or teach anyone.
Nope, If he asked me "how to make a alias" or "I do not know what the alias is", Then I will send him a complete description of the alias for the command and He can search for it on the forum. ****** once told me, We provide the information that was needed, Instead of teaching every single line of code, so fuck of
Reply
#7

You misunderstood me. I'm not talking about alias. I don't know the name of a command. I'm just writing '/ hel'.
I want to say that the command '/ help' is on the server instead of the unknown command error.

I guess you didn't understand me for using ****** translate. XD
Reply
#8

Quote:
Originally Posted by Grumbles
Посмотреть сообщение
You misunderstood me. I'm not talking about alias. I don't know the name of a command. I'm just writing '/ hel'.
I want to say that the command '/ help' is on the server instead of the unknown command error.

I guess you didn't understand me for using ****** translate. XD
Again, different command processors go about this different ways.

From my understanding you wish to display a message like "Sorry the command '/hel' doesn't exist! Did you mean '/help'?"

To do this you will need a list of all of your commands and a way to compare each command to the given input. You may even want a Levenshtein distance calculation. This will determine which command is closest to the input.

Once you have that part figured out the rest depends on what command processor you use. So, again, what command processor do you use?
Reply
#9

Quote:
Originally Posted by Crayder
Посмотреть сообщение
No. This is something you'll have to implement.
@"iorp"; GET THE FUCK OUT OF HERE YOU IMBECILE. THIS IS A PLACE WHERE WE TEACH PEOPLE. IT'S CALLED "SCRIPTING HELP", NOT "BULLSHIT". If you don't know how to help just don't. If you do know how to help then do that instead of commenting something dumb that's not going to help or teach anyone.
get a chill pill
Reply
#10

Quote:
Originally Posted by Crayder
Посмотреть сообщение
Again, different command processors go about this different ways.

From my understanding you wish to display a message like "Sorry the command '/hel' doesn't exist! Did you mean '/help'?"

To do this you will need a list of all of your commands and a way to compare each command to the given input. You may even want a Levenshtein distance calculation. This will determine which command is closest to the input.

Once you have that part figured out the rest depends on what command processor you use. So, again, what command processor do you use?
Yeah, that's exactly what I mean. I'm using OnPlayerCommandText as the command client.
Reply
#11

Quote:
Originally Posted by iorp
Посмотреть сообщение
Nope, If he asked me "how to make a alias" or "I do not know what the alias is", Then I will send him a complete description of the alias for the command and He can search for it on the forum. ****** once told me, We provide the information that was needed, Instead of teaching every single line of code, so fuck of
Funny actually. And I'm sure you misunderstood his words.
Reply
#12

Quote:
Originally Posted by Grumbles
Посмотреть сообщение
Yeah, that's exactly what I mean. I'm using OnPlayerCommandText as the command client.
Okay. Then first I'd highly recommend using a command processor such as SmartCMD or Pawn.CMD, they are advanced but still great for beginners (YCMD, which is my choice, is GREAT as well, but may be a small bit more confusing).

Then, since you want to do a comparison with all of your commands... you'll want to do something similar to below;

pawn Код:
mathMin(inp1,inp2)
    return (inp1 > inp2 ? inp2 : inp1);

LevenshteinDistance(strs[], strt[])
{
    new n = strlen(strs), m = strlen(strt);
   
    new d[128][128];

    if (n == 0)
        return m;

    if (m == 0)
        return n;

    for (new i; i <= n; i++)
        d[i][0] = i;
   
    for (new j; j <= m; j++)
        d[0][j] = j;

    for (new j = 1; j <= m; j++)
    {
        for (new i = 1; i <= n; i++)
        {
            if (strs[i - 1] == strt[j - 1])
                d[i][j] = d[i - 1][j - 1];
            else
                d[i][j] = mathMin(mathMin(d[i - 1][j] + 1, d[i][j - 1] + 1), d[i - 1][j - 1] + 1);
        }
    }
    return d[n][m];
}

// CHANGE THIS. 20 should be changed to your number of commands.
#define NUMBER_OF_COMMANDS 20

new commands[NUMBER_OF_COMMANDS][] = {
    "help",
    "kill",
    "getplayer",
    "spawncar"
    // ALL OF YOUR COMMANDS
};

GetClosestCommand(string[])
{
    new match, // matching command with least changes
        distance, // number of changes to make command
        least = 1000; // random high number
   
    for(new i; i < sizeof(commands); i++)
    {
        if(strfind(commands[i], string, true) != -1)
        {
            distance = LevenshteinDistance(string, commands[i]);
           
            if(least > distance)
            {
                match = i;
                least = distance;
            }
        }
    }
   
    return commands[match];
}
`GetClosestCommand` will decide which of your commands take the least number of changes from the given typed command and return it as a string.



For OnPlayerCommandText this may look like this;
pawn Код:
public OnPlayerCommandText(playerid,cmdtext[])
{
    // all commands here
   
    new response[128];
    format(response, 128, "Error: This command didn't exist, did you mean /%s?", GetClosestCommand(cmdtext));
    SendClientMessage(playerid, -1, response);
    return 0; // this is still going to show the UnKnown command message unless you change this to return 1, however this this will break other scripts... Another reason to switch processors.
}
Again, you should definitely stop using OnPlayerCommandText. Switch to a better command processor and this entire process is a bit simpler. The strcmp method is SLOW AS HELL and has other issues. It's an outdated method that should've never existed.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)