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
Gangler
36
points ]
 (4 votes)
Created 2020-10-22 00:50
3 years 19 weeks ago
Zoocata
10
points ]
 (1 vote)
Created 2024-02-11 21:20
3 weeks 2 days ago
vampirefrog
10
points ]
 (1 vote)
Created 2023-07-23 20:02
32 weeks 2 days ago
36
points ]
 (4 votes)
Created 2020-12-10 12:49
3 years 12 weeks ago
Created 2023-12-12 23:34
12 weeks 11 hours ago
Zoocata
Created 2023-11-27 23:00
14 weeks 1 day ago
20
points ]
 (2 votes)
Created 2023-10-01 15:21
22 weeks 2 days ago
20
points ]
 (2 votes)
Created 2021-05-24 00:01
2 years 41 weeks ago
9
points ]
 (1 vote)
Created 2023-06-13 17:54
38 weeks 16 hours ago
Zoocata
27
points ]
 (3 votes)
Created 2023-05-05 20:58
43 weeks 4 days ago
Zoocata
18
points ]
 (2 votes)
Created 2023-03-02 01:40
1 year 5 days ago
Getridou
Created 2023-01-29 23:27
1 year 5 weeks ago
Created 2023-01-19 19:36
1 year 6 weeks ago
Getridou
Created 2023-01-10 17:10
1 year 7 weeks ago
Getridou
Created 2023-01-01 14:30
1 year 9 weeks ago
Getridou
Created 2023-01-01 10:58
1 year 9 weeks ago
Getridou
Created 2023-01-01 10:49
1 year 9 weeks ago
afroninja
17
points ]
 (2 votes)
Created 2023-01-01 06:32
1 year 9 weeks ago
36
points ]
 (7 votes)
Created 2010-04-01 07:57
13 years 49 weeks ago
57
points ]
 (6 votes)
Created 2020-12-04 12:05
3 years 13 weeks ago
Who's new
  • ColdIV
  • Aidan
  • Hunk
  • letic86
  • BATMAN