var renderedText = null;
var textTime = null;
var render = false;
var textString;
var stringLength = null;
var boxWidth;

function ClearText() {
    render = false;
    clearInterval(textTime);
    textTime = null;
}

mp.events.add('render', () => {
    if (render) {

        mp.game.graphics.drawRect(0.5, 0, boxWidth, 0.07, 0, 0, 0, 183);
        renderedText = mp.game.graphics.drawText(textString, [0.5, 0], {
            font: 4,
            centre: true,
            color: [255, 255, 255, 255],
            scale: [0.5, 0.5],
            outline: true
        });
    }

});

mp.events.add('renderHelpTextOnScreen', (msg) => {
    if (textTime != null) {
        clearInterval(textTime);
        textTime = null;
    }
    textString = msg;
    stringLength = textString.length;
    boxWidth = stringLength * 0.004 + 0.002;
    render = true;
    textTime = setInterval(ClearText, 7000)
});