I am currently creating a script to display the player’s name above their head.
As you can see in the video, unlike existing name tag systems, this one is displayed at the player’s “head” and moves in accordance with emotes and other movements. Whether or not it is displayed when entering a vehicle can also be set in the config.
Now, a question has arisen here.
Currently, I am only testing in single player mode. So I am curious about how it will look to other people.
The specific code would be long, so I will only show a part of it, but because this displays the name on the client side, I am concerned that if there are other players, there may be an issue where my name is displayed above their heads as well.
function GetPlayerHeadCoords()
local playerPed = PlayerPedId()
local headCoords = GetPedBoneCoords(playerPed, 12844, 0.0, 0.0, 0.0)
return headCoords
end
function GetPlayerName()
local PlayerData = QBCore.Functions.GetPlayerData()
local gangname = PlayerData.gang.label
local firstname = PlayerData.charinfo.firstname
local lastname = PlayerData.charinfo.lastname
local fullname = firstname .. ' ' .. lastname
local playerid = GetPlayerServerId(PlayerId())
local playerName
if Config.NametagIDVisible then
playerName = playerid .. ' | ' .. fullname
else
playerName = fullname
end
return playerName, gangname
end
function Draw3DText(x, y, z, playerName, gangname)
local onScreen, _x, _y = World3dToScreen2d(x, y, z)
if onScreen then
SetTextFont(0)
SetTextScale(Config.NametagScale, Config.NametagScale)
if Config.TalkNameView then
if lastTalkingStatus then
SetTextColour(TalkNameColor.r, TalkNameColor.g, TalkNameColor.b, TalkNameColor.a)
else
SetTextColour(255, 255, 255, 255)
end
end
SetTextEntry('STRING')
SetTextCentre(true)
SetTextDropShadow(true)
AddTextComponentString(playerName)
DrawText(_x, _y)
_y = _y + -0.015 + Config.GangNamePosition
if gangname and gangname ~= 'No Gang' and GangNameVisible then
SetTextFont(0)
SetTextProportional(1)
SetTextScale(Config.NametagScale / 1.4, Config.NametagScale / 1.4)
SetTextColour(250, 250, 250, 255)
SetTextEntry('STRING')
SetTextCentre(true)
SetTextDropShadow(true)
AddTextComponentString('<' .. gangname .. '>')
DrawText(_x, _y)
end
end
end
function DrawNameText()
local headCoords = GetPlayerHeadCoords()
local playerName, gangname = GetPlayerName()
Draw3DText(headCoords.x, headCoords.y, headCoords.z + 0.3 + Config.NametagPositionZ, playerName, gangname)
end
-- I plan to change this code to something more organized.
-- Please forgive the messy code.
If anyone understands this code and knows the correct solution to the problem I’m having, I’d appreciate it if you could let me know.
Sorry for the text using Google translation.