Custom Chat System

Posted by KeySho
How would I go about making a custom chat system? I would rather a custom one so I can do more with it and have more control over how it works.

Replies (3)

Last message on 7 Jan 2018

Size43 (Administrator) on 7 Jan 2018, 17:09:43
I cleaned up the code a bit, since the code from gms_chat_draw contains a lot of internal variables. This should be a little more readable:

var i, xpos, ypos;
xpos = 100
ypos = 100
for(i = gms_chat_num() - 1; i >= gms_chat_num() - 10 && i >= 0; i -= 1)
{
    draw_set_color(gms_chat_get_color(i))
    if gms_chat_get_sendername(i) != ""
    {
        text = gms_chat_get_sendername(i) + ": "
    } else {
        text = ""
    }
    
    text += string_replace_all(gms_chat_get_text(i), "#", "\#")
    draw_text(xpos, ypos, text)
    
    ypos += string_height(text)
}
KeySho (Topicstarter) on 7 Jan 2018, 17:16:27
Hi,

The first code you sent confused me and another Developer quite a little bit, but this one has helped us alot.

Thanks Size.
Size43 (Administrator) on 7 Jan 2018, 16:08:00
There are a number of scripts under gms_chat_* that you can use to fetch all the chat messages. These scripts are also used by gms_chat_draw to draw the chat.

A small snippet from gms_chat_draw to show how this would work:
for(_i = gms_chat_num() - 1; _i >= 0 && _y > global.__chat_y1; _i -= 1)
{
    draw_set_color(gms_chat_get_color(_i))
    
    var _snder;
    if(gms_chat_get_sendername(_i) != "")
    {
        _snder = gms_chat_get_sendername(_i) + ": ";
    }else{
        _snder = "";
    }
    
    _t = string_replace_all(gms_chat_get_text(_i), "#", "\#");
    _y -= string_height_ext(_snder + _t, -1, global.__chat_x2 - global.__chat_x1);
    
    // [more things]
    draw_text_ext_transformed(global.__chat_x1 + 5, max(_y, global.__chat_y1), _snder + _t, -1, global.__chat_x2 - global.__chat_x1, 1, 1, 0);
    // [more things]
}