Player id!


#1

Hello guys, can someone help me? I am trying to make player id to show up in the chat window, but it doesn’t work…i’m not so good at scripting, i start doing it 2 days ago, sorry for my English…
[Edit] I add this to chat client, now it shows the player id in cat windows when I’m sending messages, but the thing is, If i disconnect from server and reconnect again instead of id 1 It will give me id 2, 3 or 4, depends how many time i reconnect. Does someone know what i have to do to show only 1 single id everytime when i connect or reconnect ?

RegisterNUICallback(‘chatResult’, function(data, cb)
chatInputActive = false
SetNuiFocus(false)

if not data.canceled then
local id = PlayerId()
local serverID = GetPlayerServerId(PlayerId())

--deprecated
local r, g, b = 0, 0x99, 255

if data.message:sub(1, 1) == '/' then
  ExecuteCommand(data.message:sub(2))
else
  TriggerServerEvent('_chat:messageEntered', '['..serverID..'] '.. GetPlayerName(id), { r, g, b }, data.message)
end

end

cb(‘ok’)
end)


#2

Why don’t you show people the code you already wrote


#3

Oh, yes, sorry. That’s the part with the id: AddEventHandler(‘chat:addTemplate’, function(id, html)
SendNUIMessage({
type = ‘ON_TEMPLATE_ADD’,
template = {
id = id,
html = html
}
})
end)


#4

And you want this to be all the time?


#5

Maybe you could try this on a server script?

AddEventHandler("chatMessage", function(source, color, message)
	if #message[1] ~= "/" then
		CancelEvent()
		TriggerClientEvent("chatMessage", -1, tostring("^1[ "..source.." ] " .. GetPlayerName(source)))
	end
end)

I don’t mess with the chat events at all… So I am just kinda guessing.


#6

I will try it now, thank you!
Edit: I tried, it doesn’t work, i will keep looking on forums.


#7

Did it give you an error at all?


#8

No, console is clean, no errors in it!


#9

Server:

RegisterCommand('showid', function(source)
	print(source)
end)

#10

He wants it to be in their messages.


#11

Oh. :man_facepalming:as in when a user just sends a message?


#12

I believe so yes.



#13

Is when players talk in chat to see their id…


#14

thanks for help, but it’s still doesn’t work…


#15

you need to create a new chat template, cant help you with that as ive never done it but should be easy to research :smiley: