Jump to content

Custom characters in text above the player's head.


DywanPL

Recommended Posts

Hello! I can't figure out the problem about non-standard characters in the text... Any ideas?

https://i.imgur.com/YkLXtCQ.png

 

Code:

const EVENT_NAME = "SRV::CL::OverlayMessage"
const POSITION_OFFSET = 1.0
const MESSAGE_COLORS = [
    // wiadomość nad głową
    [255,255,255,255],
    // me
    [224,102,255,255],
    // do
    [224,102,255,255],
    // try
    [224,102,255,255]
]
const MESSAGE_SCALE = 0.25
const MESSAGE_FONT = 0
const DISSAPEAR_TIME = 5

mp.events.add(EVENT_NAME, (data) => {
    let info = JSON.parse(data)
    let sender = mp.players.atRemoteId(info.sender)
    if (sender === undefined) return
    sender.overlayMessage = info
    setTimeout(() => {
        if (sender.overlayMessage !== info) return
        else sender.overlayMessage = null
    }, 1000 * DISSAPEAR_TIME)
})

mp.events.add('render', () => {
    mp.players.forEachInRange(mp.players.local.position, 10, (player) => {
        if (player.overlayMessage) {
            let info = player.overlayMessage
            let pos = player.position
            pos.z += POSITION_OFFSET

            let additionalText = info.type == 4 ? getAdditionalText(info.result) : ''
            let text = info.text + additionalText

            mp.game.graphics.drawText(text, [pos.x,pos.y,pos.z], {
                font: MESSAGE_FONT,
                color: MESSAGE_COLORS[info.type - 1],
                scale: [MESSAGE_SCALE, MESSAGE_SCALE],
                centre: true,
                outline: false,
            })
        }
    })
})


function getAdditionalText(result) {
    return result ? " | ~g~Pomyślnie" : " | ~r~Nieudane";
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...