Vice Underdogs

Scripting => Script Showroom => Topic started by: GiTo on April 05, 2023, 09:17:16 am

Title: [Snippet] a small useful feature.
Post by: GiTo on April 05, 2023, 09:17:16 am
Put this at the end of your onPlayerCommand & it should work correctly!


Code: [Select]
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.

(https://i.ibb.co/zVHjNvX/2023-04-05-13-35-49-0210.png) (http://"https://ibb.co/fdGBQwk")

P.S: Please let me know if you encounter any bugs or have any suggestions for improvement.