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
4 guests & no users online
Created 2017-04-15 03:38
1 week 1 day ago
30
points ]
 (9 votes)
Created 2011-06-16 13:56
5 years 44 weeks ago
Created 2017-02-02 00:22
11 weeks 3 days ago
74
points ]
 (9 votes)
Created 2012-07-01 13:12
4 years 42 weeks ago
Flitzpiepe
Created 2017-01-28 22:59
12 weeks 22 hours ago
214
points ]
 (22 votes)
Created 2012-10-20 09:56
4 years 26 weeks ago
AtlasSteal
31
points ]
 (4 votes)
Created 2016-12-27 04:35
16 weeks 5 days ago
theradical
Created 2016-12-26 16:25
16 weeks 6 days ago
theradical
11
points ]
 (2 votes)
Created 2016-12-20 14:15
17 weeks 5 days ago
20
points ]
 (3 votes)
Created 2010-03-04 23:30
7 years 7 weeks ago
KATZ_2142
13
points ]
 (2 votes)
Created 2016-09-06 23:34
32 weeks 4 days ago
50
points ]
 (5 votes)
Created 2010-02-18 22:58
7 years 9 weeks ago
DeathStarPC
Created 2016-10-09 12:48
28 weeks 8 hours ago
Created 2016-05-10 23:14
49 weeks 4 days ago
Created 2016-07-28 12:06
38 weeks 3 days ago
7
points ]
 (1 vote)
Created 2016-08-19 06:04
35 weeks 2 days ago
92
points ]
 (10 votes)
Created 2010-06-23 21:33
6 years 43 weeks ago
Fatality
50
points ]
 (6 votes)
Created 2014-05-14 01:01
2 years 49 weeks ago
Pyccna
31
points ]
 (4 votes)
Created 2015-09-22 23:19
1 year 30 weeks ago
Fatality
86
points ]
 (10 votes)
Created 2014-09-03 23:36
2 years 33 weeks ago
Who's new
  • Flitzpiepe
  • M16
  • theradical
  • torben
  • KATZ_2142