Send msg to all players



im trying to send a msg in the chat with a msg from a client script


RegisterCommand('test', function()
	local name = GetPlayerName(i)
	local msg = "test"
	TriggerServerEvent("test1", name, msg)
end, false)


	AddEventHandler("test1", function(name, msg)
	TriggerClientEvent("chatMessage", -1, "test | " .. name,{ 255, 0, 0 }, string.sub(msg,5))


Why not do it all server sided? Would be much more efficient.


What is I?



It prints all content after args.

/911 fd this is a message that will be printed when you use that.


Or, y’know just msg… and use table.remove()


No I don’t know. Maybe you should make a tutorial on it, so you can share your wisdom because just about every chat command in every script on this site that I’ve seen uses string.sub(msg,5); and to be honest with you I don’t even know what it means.


Literally only seen this in commands that check for chatMessages rather than using RegisterCommand() which aren’t even allowed anymore:


The FiveM docs “Create your first script in Lua/C#” has an example of how to properly use RegisterCommand.

Usage of all other chat events is in the works to be added to the docs as well. I PR’ed it, but have to make some adjustments. They’ll be on there before the weekend is over.