login
April 27, 2024, 01:59:34 pm

Author Topic: [Snippet] a small useful feature.  (Read 705 times)

0 Members and 1 Guest are viewing this topic.

GiTo

  • Regular
  • ***
  • Posts: 78
  • Country: pk
    • View Profile
[Snippet] a small useful feature.
« 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.


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 »
Winner Winner x 1 (list)
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

What happens when the poison expires?