Send msg to all players

help
helpme
needhelp
quickhelp

#1

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

client.lua

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

server.lua

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

#2

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


#3

What is I?

Why??


#4

It prints all content after args.

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


#5

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


#6

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.


#7

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


#8

The FiveM docs “Create your first script in Lua/C#” has an example of how to properly use RegisterCommand. https://docs.fivem.net/scripting-manual/introduction/creating-your-first-script/

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.