Skip to the content
Docs

Default `chat` resource — a per-recipient `/me`

On this page4

A chat line is sent by the server, so it can carry a different name for every recipient: each listener sees the label their own character knows, and strangers see "Stranger".

We do not ship or modify the chat resource. This is a command of your own, in a resource of your own.

Proximity /me

lua
-- your own resource, server side
RegisterCommand('me', function(src, args)
    local text = table.concat(args, ' ')
    if text == '' then return end

    local origin = GetEntityCoords(GetPlayerPed(src))

    for _, id in ipairs(GetPlayers()) do
        local viewer = tonumber(id)
        if #(GetEntityCoords(GetPlayerPed(viewer)) - origin) <= 20.0 then
            local name = (viewer == src) and 'You'
                or exports['5code-recognition']:GetRecognitionLabel(viewer, src)
                or 'Stranger'

            TriggerClientEvent('chat:addMessage', viewer, {
                args = { name, text },
            })
        end
    end
end, false)

GetRecognitionLabel(viewer, speaker) returns the introduced name if the speaker told that listener one, else the automatic label, else nil — and never a real character name. minPct defaults to Config.Scoring.ActThreshold (80).

Only messaging the people who know you

GetRecognizers gives you the viewers with a live result of that player. It is server-only on purpose: use it to address people, never to publish a list.

lua
for _, viewer in ipairs(exports['5code-recognition']:GetRecognizers(src)) do
    TriggerClientEvent('chat:addMessage', viewer, {
        args = { exports['5code-recognition']:GetRecognitionLabel(viewer, src) or 'Stranger', text },
    })
end

Radio and phone calls

A voice on the radio is not a face in front of you, so IsRecognized will usually be false there. If you want radio names to follow recognition anyway, use a memory-based answer instead of a live scene by setting Config.Api.RecognitionSource = 'scene_or_memory' — but be aware this changes every name-display export on the server at once, including overhead nametags: a remembered player's name would then pop up the moment they walk into view, even with nobody looking at them.

A narrower option is to key radio names off the voice channel only, and keep 'scene' for everything you draw in the world.

Do not

  • Do not broadcast one chat:addMessage with the speaker's label to everybody and let each client filter it. The label would be on every client, and anyone reading their own chat traffic would learn what other people know.
  • Do not cache the per-viewer name in a state bag.