Hello. I wanted to implement 3dme script to esx_rpchat but the 3d text doesn’t appear. Here is my script:
client.lua
RegisterNetEvent('sendProximityMessageMe')
AddEventHandler('sendProximityMessageMe', function(id, name, message)
local myId = PlayerId()
local pid = GetPlayerFromServerId(id)
local text = message
TriggerServerEvent('esx-qalle-chat:shareDisplay', text) -- 3D /me
if pid == myId then
TriggerEvent('chatMessage', "", {255, 0, 0}, " ^6 " .. name .." ".."^6 " .. message)
elseif GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(myId)), GetEntityCoords(GetPlayerPed(pid)), true) < 19.999 then
TriggerEvent('chatMessage', "", {255, 0, 0}, " ^6 " .. name .." ".."^6 " .. message)
end
end)
RegisterNetEvent('esx-qalle-chat:triggerDisplay')
AddEventHandler('esx-qalle-chat:triggerDisplay', function(text, source)
local offset = 1 + (nbrDisplaying*0.14)
Display(GetPlayerFromServerId(source), text, offset)
end)
function Display(mePlayer, text, offset)
local displaying = true
Citizen.CreateThread(function()
Wait(time)
displaying = false
end)
Citizen.CreateThread(function()
nbrDisplaying = nbrDisplaying + 1
print(nbrDisplaying)
while displaying do
Wait(0)
local coordsMe = GetEntityCoords(GetPlayerPed(mePlayer), false)
local coords = GetEntityCoords(PlayerPedId(), false)
local dist = Vdist2(coordsMe, coords)
if dist < 2500 then
DrawText3D(coordsMe['x'], coordsMe['y'], coordsMe['z']+offset, text)
end
end
nbrDisplaying = nbrDisplaying - 1
end)
end
function DrawText3D(x,y,z, text)
local onScreen,_x,_y = World3dToScreen2d(x,y,z)
local px,py,pz = table.unpack(GetGameplayCamCoord())
local dist = GetDistanceBetweenCoords(px,py,pz, x,y,z, 1)
local scale = ((1/dist)*2)*(1/GetGameplayCamFov())*100
if onScreen then
-- Formalize the text
SetTextColour(color.r, color.g, color.b, color.alpha)
SetTextScale(0.0*scale, 0.55*scale)
SetTextFont(font)
SetTextProportional(1)
SetTextCentre(true)
if dropShadow then
SetTextDropshadow(10, 100, 100, 100, 255)
end
-- Calculate width and height
BeginTextCommandWidth("STRING")
AddTextComponentString(text)
local height = GetTextScaleHeight(0.55*scale, font)
local width = EndTextCommandGetWidth(font)
-- Diplay the text
SetTextEntry("STRING")
AddTextComponentString(text)
EndTextCommandDisplayText(_x, _y)
end
end
server.lua
RegisterServerEvent('esx-qalle-chat:shareDisplay')
AddEventHandler('esx-qalle-chat:shareDisplay', function(text)
TriggerClientEvent('esx-qalle-chat:triggerDisplay', -1, text, source)
end)
TriggerEvent('es:addCommand', 'me', function(source, args, user)
local name = getIdentity(source)
local text = args
table.remove(args, 2)
TriggerClientEvent('esx-qalle-chat:me', -1, source, name.firstname, table.concat(args, " "))
TriggerClientEvent('esx-qalle-chat:triggerDisplay', -1, text, source) -- I tried adding this here instead of using shareDisplay but that doesn't work too
end)
So basically chat message works great, but the 3d text above my character doesn’t appear as it should. Any tips appreciated.