[Snippet] a small useful feature.

Started by Gito Baloch, Apr 05, 2023, 09:13 AM

Previous topic - Next topic

Gito Baloch

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.
Programming is the language I speak, the world I shape, and the future I code

Ridwan Rz

Simple thing but yet a very useful snippet..