Customizing Chat Question Regarding Implementing

Hey, so I am curious how I go about making a / command show up different in the chat box for example /me shows up like a purple box and inside it would display its text… I know I need to modify the css but implementing it is the problem I’m having right now anyone have a clue?

No, you don’t ‘need to modify the css’, all you have to do is pass a template in the resource where you’re handling /me.

Example (albeit somewhat inefficient):

-- on the server
RegisterCommand('me', function(source, args, rawCommand)
    local playerName = GetPlayerName(source)
    local msg = rawCommand:sub(4)

    TriggerClientEvent('chat:addMessage', -1, {
        template = '<div style="padding: 0.5vw; margin: 0.5vw; background-color: rgba(100, 79, 142, .6);">* {0} {1}</div>',
        args = { playerName, msg }
    })
end, false)

1 Like

Thank you so much, So I’ve tried that with F8 cause Im using custom chat but sadly, when I try to use my command style it wont work any idea how to go about converting it to work with this?

AddEventHandler('chatMessage', function(source, name, msg)
    sm = stringsplit(msg, " ");
	
	if sm[1] == "/tweet" then
	    CancelEvent()
		local name = getIdentity(source)
		fal = name.firstname .. " " .. name.lastname
		TriggerClientEvent('chatMessage', -1, "^0[^4Twitter^0] (^5@" .. fal .. "^0)", {30, 144, 255}, string.sub(msg,7))
	end	
end)  
  

Stop using any ‘custom chat’, you’ll need at least a chat resource from the past year or so to be able to use templates.

You can apply whatever chat customizations using chat themes, there is absolutely no reason whatsoever you should be replacing the chat resource or even changing anything in it.

ahh ok, Im just afraid of lossing the first name and last name when they tweet or do /me so thats why I’ve not converted to the newer versions.

chatMessage is still supported for compatibility, so you can still use that fine without having to convert everything to RegisterCommand at once. Similarly, you can just use your getIdentity function in a RegisterCommand as well. :stuck_out_tongue:

For an example chat theme, you could look at the default chat-theme-gtao, though there’s more options in a chat theme that sadly aren’t documented yet.

Yea, I took a look at the new chat-theme-gtao I like it alot I just need to dive deeper into that when I get some more time cause I have a feeling theres a few tricks in there that could be useful

This works great problem is there is no way for it to only show up for the person making the command go threw? Considering for example if I don’t have permissions to do something it will send the chat that msg
saying I don’t have permissions the entire server sees that. Like the proximity

RegisterCommand('me', function(source, args, rawCommand)
    local playerName = GetPlayerName(source)
    local msg = rawCommand:sub(4)

    TriggerClientEvent('chat:addMessage', -1, {
        template = '<div style="padding: 0.5vw; margin: 0.5vw; background-color: rgba(100, 79, 142, .6);">* {0} {1}</div>',
        args = { playerName, msg }
    })
end, false)

Where can i found this beautiful chat?