[HELP] - /comms command

Hey.
I’ve made a /comms command for chat. I would like it to show the text I/other people enter, when it doesn’t. There are no script errors that show in F8, or in chat.

Is there any way I can show my entered text in the chat after typing /comms?

Ie:
image

/comms test.
It would show:
Central Comms (USER: Aussie Baguette) test.

Finally, is there any way to make it show a User ID rather than an in-game name?
ie:
Central Comms (ID: ***) test.

You feel me?
Hopefully someone can help. Thanks

Test
are you thinking of something like this?

  1. Stop using this outdated way of “listening” for commands and use RegisterCommand instead.
  2. You’re triggering the “chatMessage” event from inside the “chatMessage” event handler in a loop-like manner, and with 4 parameters, when the “chatMessage” event was declared 4 lines above having 3 parameters…
  3. CancelEvent() at the end of the control flow of the event/function doesn’t make sense since it will already finish when it gets there?

Simpler method would be:

RegisterCommand("comms", function(source, args, raw)

	local message = table.concat(args, " ")

	TriggerClientEvent('chat:addMessage', -1, {
		color = {255, 0, 0},
		multiline = true,
		args = {"^4Central Comms (^1ID: ^0" .. source .. "^4) ^0" .. message}
	  })
end)

I was just about to bring that up lol

1 Like

Legendary. Thankyou.

Exactly. Had L1CKS sort it though.

Can I replace the local id with something to bring out the Player’s ID? Ie. The ID from vMenu.
If not, that will be okay.

RegisterCommand("comms", function(command, args, raw)

	local message = table.concat(args, " ")
	
	local id = 1		-- Get the id from wherever..

	TriggerEvent('chat:addMessage', {
		color = {255, 0, 0},
		multiline = true,
		args = {"^4Central Comms (^1ID: ^0" .. id .. "^4) ^0" .. message}
	  })
end)

[/quote]

1 Like

Sorry about all of the messages, just found the quote function.
Nothing appears in chat with that above script. Any idea what might be causing it? No script errors, or anything.

Worked perfectly fine for me when I wrote it yesterday. Maybe some other resource is conflicting. Also, what artifacts version are you using?

yes.

local id = GetPlayerServerId(PlayerId())

Will get the server ID of the player. This ID though is not constant and will change when players join/leave or the server is restarted.

Will have to take a look for the artifacts.

Update them anyway, although I’m 90% sure it’s a resource conflicting

Get a script error with the:

local id = GetPlayerServerId(PlayerId())

part of the script.

What error? I kinda wrote it down without testing.

I now see that you want it on the server side, try this:
(untested)

RegisterCommand("comms", function(command, args, raw)

	local message = table.concat(args, " ")

	TriggerClientEvent('chat:addMessage', -1, {
		color = {255, 0, 0},
		multiline = true,
		args = {"^4Central Comms (^1ID: ^0" .. source .. "^4) ^0" .. message}
	  })
end)

Will try. Thanks

Edit:

image

yeah my bad forgot about source:

RegisterCommand("comms", function(source, args, raw)

	local message = table.concat(args, " ")

	TriggerClientEvent('chat:addMessage', -1, {
		color = {255, 0, 0},
		multiline = true,
		args = {"^4Central Comms (^1ID: ^0" .. source .. "^4) ^0" .. message}
	  })
end)