[Help] ServerID

Hello,
Just needed a little help scripting my commands. So what i need help with is the serverID to show up in the chat as well as the commands, for example if typed /do test into my chat i receive Do | Valk: test. Whereas I would like to type /do test and receive Do | Valk (serverID): test.

My commands are written like this:

do.lua
AddEventHandler('chatMessage', function(source, name, msg)
	sm = stringsplit(msg, " ");
	if sm[1] == "/do" then
		CancelEvent()
		TriggerClientEvent('chatMessage', -1, "Do | " .. name, { 255, 0, 0 }, string.sub(msg,5))
	end
end)

function stringsplit(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end
__resource.lua
server_script 'ooc.lua'
server_script '999.lua'
server_script 'dispatch.lua'
server_script 'ad.lua'
server_script 'announcment.lua'
server_script 'run.lua'
server_script 'searchp.lua'
server_script 'searchv.lua'
server_script 'do.lua'

Could I get some help?

Replace that with
TriggerClientEvent('chatMessage', -1, "Do | " .. name .. '(' .. source .. ')', { 255, 0, 0 }, string.sub(msg,5))

1 Like

Thank you my guy.

Would it be possible to add a proximity for it as well so where only a certain radius on the map can see it?

Yes,

TriggerClientEvent('chatMessage', -1, "Do | " .. name, { 255, 0, 0 }, string.sub(msg,5), source)

and on client side you would have something like this

AddEventHandler('chatMessage', function(author, color, text, serverID)
  local myCoords = GetEntityCoords(GetPlayerPed(-1))
  local pedCoords = GetEntityCoords(GetPlayerPed(GetPlayerFromServerId(serverID))
  local dist = #(myCoords - pedCoords)
  if dist > 100 then
    return
  end
  local args = { text }
  if author ~= "" then
    table.insert(args, 1, author)
  end
  SendNUIMessage({
    type = 'ON_MESSAGE',
    message = {
      color = color,
      multiline = true,
      args = args
    }
  })
end)

You would change the dist > to whatever you want the max distance for it to draw to be so it doesn’t show for distances greater than that.

I’m kinda new to lua but would I make that into a client.lua?

sorry

Yes you would replace the client.lua event with what I gave you

okay.