I’ve just recently started working on a new small project to learn more about lua and fivem resource development. I can’t figure out how I change the chat name to use the current ESX character instead of regular Steam name. The code I use for both server.lua and client.lua is pasted bellow.
Client.lua
RegisterNetEvent('sendLokalOOC')
AddEventHandler('sendLokalOOC', function(id, name, message)
local myId = PlayerId()
local pid = GetPlayerFromServerId(id)
if pid == myId then
TriggerEvent('chatMessage', "LOKAL OOC | ", {0, 177, 177}, " ^7 " .. name .." ".."^7 " .. message)
elseif GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(myId)), GetEntityCoords(GetPlayerPed(pid)), true) < 19.999 then
TriggerEvent('chatMessage', "LOKAL OOC | ", {0, 177, 177}, " ^7 " .. name .." ".."^7 " .. message)
end
end)
Server.lua
-- LOKAL OOC --
RegisterCommand('lokalooc', function(source, args, user)
local name = GetPlayerName(source)
TriggerClientEvent("sendLokalOOC", -1, source, name, table.concat(args, " "))
end, false)
-- TWITTER --
RegisterCommand("twitter", function(source, args, raw)
local _source = source
local name = GetPlayerName(_source)
local message = table.concat(args, " ")
TriggerClientEvent('chatMessage', -1, "TWITTER | " .. name, { 30, 144, 255 }, message)
end, false)
RegisterCommand("twt", function(source, args, raw)
local _source = source
local name = GetPlayerName(_source)
local message = table.concat(args, " ")
TriggerClientEvent('chatMessage', -1, "TWITTER | " .. name, { 30, 144, 255 }, message)
end, false)
-- BLOCKET --
RegisterCommand("blocket", function(source, args, raw)
local _source = source
local name = GetPlayerName(_source)
local message = table.concat(args, " ")
TriggerClientEvent('chatMessage', -1, "BLOCKET | " .. name, { 255, 0, 0 }, message)
end, false)
-- ENCRO --
RegisterCommand("encro", function(source, args, raw)
local _source = source
local message = table.concat(args, " ")
TriggerClientEvent('chatMessage', -1, "ENCROCHAT | @Anonym", { 136, 59, 204 }, message)
end, false)
-- RÖR EJ --
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
Btw this is supposed to be a swedish translated script if your wondering, that’s why there is a “blocket” server command.
So to be clear I want to change local name = GetPlayerName(_source)
to get the CURRENT ESX CHARACTER name instead of steam.