Multilines kick reason

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1367
Gender:
United States of America

Multilines kick reason

Post by Archive-Poster »

Hi !

When you use the kick command on a server con, you can give a reason for that kick using the following scheme:

Code: Select all

kick (name | #userid) [reason]
The problem is that the reason message is a one line message. If you want it to be displayed on multiple lines, you can count how many characters can fit on each lines of the kick popup dialog, and then format your reason message accordingly. That's painfull since HL characters don't have the same width, thus that won't work with dynamic reason messages.

A better solution could be to forge a kick packet which contains a multilines reason message. This can be done using the following kick_ML method: way:

Code: Select all

#define SVC_DISCONNECT  2
/* SVC_DISCONNECT: ask the client to disconnect and show the given string in a popup dialog.
 *  -> (string) kick_reason: reason of the kick. It is shown to the client via
 *                           a popup dialog. Its content can't be large.
 *
 * Note: such messages are sent when using the <kick> command, or when the client
 *      disconnect himself. In the latter, no popup dialog is shown.
 */
/* Kick with a multilines reason. Return 0 if an error has occured. */
kick_ML(id, line1[] = "", line2[] = "", line3[] = "") {
    if(!is_valid_ent(id)) return 0

    new msg_content[1024], pl_name[32], pl_userid, pl_authid[35]
    
    /* grab logging infos */
    pl_userid = get_user_userid(id)
    get_user_name(id, pl_name, 31)
    get_user_authid(id, pl_authid, 34)
    
    /* do kick the player */
    format(msg_content, 1023, "%s^n%s^n%s", line1, line2, line3)
    message_begin(MSG_ONE, SVC_DISCONNECT, {0,0,0}, id)
    write_string(msg_content)
    message_end()
    
    /* log the kick as <kick> command do */
    log_message("Kick_ML: ^"%s<%d><%s><>^" was kicked by ^"Console^" (message ^"%s^" ^"%s^" ^"%s^")",
        pl_name, pl_userid, pl_authid, line1, line2, line3)

    return 1
}
There's only 3 lines available in the popup dialog. These lines should not contain a lot of text of course ...

I needed to do that for a plugin, so I though someone could need it too. The main interesting thing here is not that the ^n escape character create a new line, but that the SVC_KICK message do kick the player and show the reason message (without checking if it's a multines one or not).

I didn't find informations about HL specific message types anywhere, so I though it could be usefull. Here are some others message types I found:

Code: Select all

#define SVC_PRINT   8
/* SVC_PRINT: show the given string in the client console.
 *  -> (string) message: message to display in the client console.
 */
#define SVC_STUFFTEXT   9
/* SVC_STUFFTEXT: send command for the client to execute.
 *  -> (string) command_line: command to execute remotely.
 *
 * Note: commands correspond to the classic HL console commands.
 */
Sorry if such infos have already been posted before. I was just testing the layout of my post, and click on the "submit message" button instead of the "Preview Changes" one. I didn't want to post my message right now, but since you can't delete your own messages, I had no choice but to do it

Who is online

Users browsing this forum: No registered users and 1 guest