Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: Gito Baloch on Apr 05, 2023, 09:13 AM

Title: [Snippet] a small useful feature.
Post by: Gito Baloch on Apr 05, 2023, 09:13 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.

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

P.S: Please let me know if you encounter any bugs or have any suggestions for improvement.
Title: Re: [Snippet] a small useful feature.
Post by: Ridwan Rz on Apr 13, 2023, 12:08 AM
Simple thing but yet a very useful snippet..