FerreusRemedium | 2013-03-02 00:28
Playername Tab-Completion
9
points ]
 (1 vote)
Use playername tab-completion for commands that use a client-number.

Description:

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 add

        exec "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 / ]

Usage:

    /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.

Example:
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.

Notes:

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]
]

playernamecomplete.cfg (7.53 KB)
9
points
 (1 vote)
User login
Users on Quadropolis
1 guest & no users online
30
points ]
 (3 votes)
Created 2019-05-17 21:51
5 years 27 weeks ago
30
points ]
 (3 votes)
Created 2020-06-13 21:05
4 years 23 weeks ago
20
points ]
 (2 votes)
Created 2021-05-24 00:01
3 years 26 weeks ago
8
points ]
 (1 vote)
Created 2024-06-02 14:26
24 weeks 5 days ago
8
points ]
 (1 vote)
Created 2024-06-02 22:13
24 weeks 4 days ago
vampirefrog
Created 2024-04-11 22:25
32 weeks 19 hours ago
vampirefrog
29
points ]
 (4 votes)
Created 2010-05-30 10:00
14 years 25 weeks ago
Gangler
36
points ]
 (4 votes)
Created 2020-10-22 00:50
4 years 4 weeks ago
Zoocata
10
points ]
 (1 vote)
Created 2024-02-11 21:20
40 weeks 4 days ago
vampirefrog
10
points ]
 (1 vote)
Created 2023-07-23 20:02
1 year 17 weeks ago
36
points ]
 (4 votes)
Created 2020-12-10 12:49
3 years 49 weeks ago
Created 2023-12-12 23:34
49 weeks 2 days ago
Zoocata
Created 2023-11-27 23:00
51 weeks 3 days ago
20
points ]
 (2 votes)
Created 2023-10-01 15:21
1 year 7 weeks ago
9
points ]
 (1 vote)
Created 2023-06-13 17:54
1 year 23 weeks ago
Zoocata
27
points ]
 (3 votes)
Created 2023-05-05 20:58
1 year 28 weeks ago
Zoocata
18
points ]
 (2 votes)
Created 2023-03-02 01:40
1 year 38 weeks ago
Getridou
Created 2023-01-29 23:27
1 year 42 weeks ago
Created 2023-01-19 19:36
1 year 43 weeks ago
Getridou
Created 2023-01-10 17:10
1 year 45 weeks ago
Who's new
  • ColdIV
  • Aidan
  • Hunk
  • letic86
  • BATMAN