« on: April 05, 2023, 09:17:16 am »
Put this at the end of your onPlayerCommand & it should work correctly!
else {
local Commands = ["register", "login", "changepass", "stats", "givecash"]; // Add your commands here...
if (cmd.len() >= 3) {
local matchFound = false;
local indexCmd = "";
for (local i = 0; i < Commands.len(); i++) {
if (cmd == Commands[i]) {
matchFound = true;
break;
}
indexCmd += cmd.slice(i, i + 1);
if (i == 1) {
break;
}
}
if (!matchFound) {
for (local i = 0; i < Commands.len(); i++) {
local currentCmd = Commands[i].slice(0, 2);
if (indexCmd == currentCmd) {
MessagePlayer("Invalid Command, did you mean '"+Commands[i]+"'", player);
matchFound = true;
break;
}
}
if (!matchFound) {
MessagePlayer("Invalid Command, check /cmds for available list of commands.", player);
}
}
} else {
MessagePlayer("Invalid Command, check /cmds for available list of commands.", player);
}
}
Explanation:This code block checks if the player has entered a valid command if the player enters an incorrect command it suggests the correct command this helps prevent errors and confusion for the player.
P.S: Please let me know if you encounter any bugs or have any suggestions for improvement.
« Last Edit: April 05, 2023, 09:19:14 am by GiTo »
![](https://viceunderdogs.com/Themes/ViceUnderdogs/images/ip.gif)
Logged
Winner x 1 (list)
What happens when the poison expires?