Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I add recommendations for a command?

Asked by
n1bu 0
4 years ago

I want to make an admin GUI with commands and have it recommend and show what the player is maybe gonna type, for example,

if they type "exp" it will show a transparent light text layered under the command bar that shows the commands related to the users text. So in this case it would show "explode" if they are typing "exp" I cannot find any articles or sources on this so if someone could help me I would appreciate it!

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I haven't tested this or anything, but I have an idea.

Maybe you can call a function every time the player types in a new key. This can be done using the "Changed" event. Link to the Changed event

In the script, you should also have an array that contains all of the commands you are going to have.

Now this is where the magic happens. In the function, you should have an "i, v in pairs" loop that loops through the array of commands. In that loop you can use string.match. match is a function that looks in the first parameter (Which should be a string), and tries to find the second parameter (Which should also be a string) in it. If it isn't in there, it returns nil. If it is, it returns the second parameter. In this case, the first parameter would be the string that the player is typing, and the second would be v. If string.match finds a pair, you can display that command. If it doesn't, you don't. Link to string.match

This is only about half of it. The rest is displaying the suggestion, being able to press tab, or some other key to add that to what hes typing, and so on.

Hope this helps you out!

Mark this as the solution if this idea works!

Ad

Answer this question