This is a script i wrote that lets you use tab-completion using playernames for any command that takes a client-number.
Basically, you create a wrapper-command that calls the real command. On this wrapper you can use tab-completion.
The completion lists the names of connected players as follows:playername~<cn>
The wrapper then cuts everything including the last ~ from the first argument and uses the remainder as the argument for the real command.
You can add additional arguments after that. They are passed directly to the real command.
How to install:
1. Put playernamecomplete.cfg into your sauerbraten directory and addexec "playernamecomplete.cfg"
to your autoexec.cfg
2. Create a command in your autoexec.cfg that updates the completion lists. See "Usage" below on how the command works.
Example:updatecompletion = [ // use /f for /follow, completes non-spectators, and excludes the // currently followed one playernamecomplete f follow "SF" // use /ig for /ignore, completes non-ignored players, excludes // the player himself playernamecomplete ig ignore "PI" // use /unig for /unignore, completes ignored players playernamecomplete unig unignore "i" // use /ki for /kick, completes players with lower privilege, // excludes player himself, but it's not really needed. playernamecomplete ki kick "Pl" ]
3. Add binds that call this function before you enter the prompt.
I am using CARET (^):bind CARET [ updatecompletion; saycommand / ] specbind CARET [ updatecompletion; saycommand / ] editbind CARET [ updatecompletion; saycommand / ]
/playernamecomplete <ALIAS> <COMMAND> [<FLAGS>] [<ARGNUM>]
Create a command called <ALIAS> which calls <COMMAND> supporting tab-completion of connected players.
<FLAGS> specify which players appear in the list. Every character is a condition that is checked when the list is created. When all are true, the player is included.
Example:"SF" - S: excludes spectators F: excludes the currently spectated player
A List of all flags can be found below.
<ARGNUM> tells the wrapper as which argument the client number should be passed to. If this is not specified, it is passed as the first argument.
Using the following to create command "c"playernamecomplete c command "SP" 2
then/c anything~42 a b c
would call/command a 42 b c
If you pass less than <ARGNUM> arguments to the wrapper, empty arguments (like "") are inserted before the cn.
The player names are transformed to lower case, which makes typing easier. After that, they are cleaned from invalid or hard to type characters using a whitelist.
Completion also works when the player name contains the delimiter, since the last occurrence of the delimiter is used.
You can also just type the cn without a name, since nothing is cut when there is no delimiter.
You can change the character whitelist by editing _pnc_allowedchars at the top of the script. There are also two variables which can be advanced to translate special characters to easy-to-type ones.
List of flags:
s/S - spectator/not spectator b/B - bot/not bot i/I - ignored/not ignored e/E - enemy/not enemy p/P - current player/not current player f/F - followed player/not followed player m/M - master or admin/not master and not admin a/A - admin/not admin l/L - lower privilege/equal or higher privilege than player h/H - higher privilege/equal or lower privilege than player
Update 1: Changed some of the @'s and uses more concat(word). Also, new loopchar.
Update 2: Use TABs for indenting and changed the wrappers so they don't take as much space in config.cfg.
// what i'm using in my autoexec.cfg updatecompletion = [ playernamecomplete f _my_follow "PSF" playernamecomplete ig ignore "PI" playernamecomplete unig unignore "i" playernamecomplete ki kick "Pl" playernamecomplete myteam _my_myteam "e" playernamecomplete otherteam _my_otherteam "E" playernamecomplete switchteam _my_switchteam "S" playernamecomplete goteam _my_goteam "PS" playernamecomplete voteki _my_votekick "PM" playernamecomplete s _my_stats "B" playernamecomplete st _my_statstotal "B" ] bind CARET [ updatecompletion; saycommand / ] specbind CARET [ updatecompletion; saycommand / ] editbind CARET [ updatecompletion; saycommand / ] _my_follow = [ if (! (isspectator (getclientnum))) [ spectator 1 sleep 200 [ follow @arg1 ] ] [ follow $arg1 ] ] _my_myteam = [ setteam $arg1 (getteam) ] _my_otherteam = [ setteam $arg1 (? (=s (getteam) "good") "evil" "good") ] _my_switchteam = [ setteam $arg1 (? (=s (getclientteam $arg1) "good") "evil" "good") ] _my_goteam = [ team (getclientteam $arg1) ] _my_votekick = [ say [#votekick @arg1] ] _my_stats = [ say [#stats @arg1] ] _my_statstotal = [ say [#stats total @arg1] ]