[Help] Show numbers above players head?

Citizen.CreateThread(function()
	while true do
		Wait( 1 )

		-- show blips
		for id = 0, 32 do
			if NetworkIsPlayerActive( id ) then -- and GetPlayerPed( id ) ~= GetPlayerPed( -1 )

				ped = GetPlayerPed( id )
				--blip = GetBlipFromEntity( ped )

				-- HEAD DISPLAY STUFF --

				-- Create head display (this is safe to be spammed)
				if GetPlayerPed( id ) ~= GetPlayerPed( -1 ) then
						headDisplayId = SetMpGamerTagVisibility(ped, "tonumber(GetPlayerId)", false, false, "", false )
				end

				if (GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1)), GetEntityCoords(GetPlayerPed(id))) < 30.0001) and HasEntityClearLosToEntity(GetPlayerPed(-1),  GetPlayerPed(id),  17) then
					SetMpGamerTagVisibility(headDisplayId, 9, true)
					SetMpGamerTagAlpha(headDisplayId, 9, 255)
				else
					SetMpGamerTagVisibility(headDisplayId, 0, false)
				end

				if NetworkIsPlayerTalking(id) then
					SetMpGamerTagVisibility(headDisplayId, 9, true) -- Speaker
					SetMpGamerTagAlpha(headDisplayId, 9, 255) -- Alpha
				else
					SetMpGamerTagAlpha(headDisplayId, 9, false) -- Speaker Off
				end
			end
		end
	end
end)

Now it looks like that, my problem is actually the code to get it to display the user id instead of what I have written in the quotes…

headDisplayId = SetMpGamerTagVisibility(ped, “tonumber(GetPlayerId)”, false, false, “”, false )

^ how do I get that line to pull the user’s id and display it above their head? As it sits right now it just says “tonumber” above everyone’s head. There’s something wrong with the syntax in that line, but I’m not exactly sure how it should be written.

Are you tying to display the player’s server ID?

If so, there’s a native for that :wink:

You can use it in the loop using “id” as the player parameter (the same way you’re using GetPlayerPed)

Edit: all you’d have to do is transform it into a string. E.g.

SetMpGamerTagVisibility(ped, GetPlayerServerId( player ) .. "", false, false, "", false )

So the 2 periods before the quotes tell the script to insert the called id numer INTO the quotes and display it?

Not exactly, it’s the operator to concat two strings together (read more here).

Basically, it tells Lua to concatenate the number with an empty string (turns the number into a string).

Its called concatenation. Its not exactly putting it into the quotes. Its just displaying it. https://www.lua.org/pil/3.4.html

I guess that’s what I’m failing to understand. How exactly do I pull that user id and get it to display like that? What do you mean by transforming it into a string? I’m trying to understand, my brain just hurts lol.

edit Well, I found one problem. Accidentally named the wrong function at first.

Citizen.CreateThread(function()
	while true do
		Wait( 1 )

		-- show blips
		for id = 0, 32 do
			if NetworkIsPlayerActive( id ) then -- and GetPlayerPed( id ) ~= GetPlayerPed( -1 )

				ped = GetPlayerPed( id )
				--blip = GetBlipFromEntity( ped )

				-- HEAD DISPLAY STUFF --

				-- Create head display (this is safe to be spammed)
				if GetPlayerPed( id ) ~= GetPlayerPed( -1 ) then
						headDisplayId = SetMpGamerTagVisibility(ped, GetPlayerServerId( player ) .. "", false, false, "", false )
				end

				if (GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1)), GetEntityCoords(GetPlayerPed(id))) < 30.0001) and HasEntityClearLosToEntity(GetPlayerPed(-1),  GetPlayerPed(id),  17) then
					SetMpGamerTagVisibility(headDisplayId, 9, true)
					SetMpGamerTagAlpha(headDisplayId, 9, 255)
				else
					SetMpGamerTagVisibility(headDisplayId, 0, false)
				end

				if NetworkIsPlayerTalking(id) then
					SetMpGamerTagVisibility(headDisplayId, 9, true) -- Speaker
					SetMpGamerTagAlpha(headDisplayId, 9, 255) -- Alpha
				else
					SetMpGamerTagAlpha(headDisplayId, 9, false) -- Speaker Off
				end
			end
		end
	end
end)

That is my current script and nothing is working now.

Yea, I tried to explain how to use the native, I must’ve failed somehow.
You see how you’re using the GetPlayerPed function? That’s got a similar signature to the GetPlayerServerId (as in, they both accept Player as a parameter). This means, if you can do GetPlayerPed( id ) (id being the number from the loop) then, you can also do GetPlayerServerId( id ).

So, that’s how you get the player’s server ID. Now, the native your calling to actually set the gamer tag (SetMpGamerTagVisibility) requires a string as the second parameter to work. This means we need to transform the number into a string. Concatenation is one such way of doing this (you basically tell Lua you want this number at the front of an empty string). Or, if you prefer, you can call the tostring method.

The tostring function will take the number input and output the string. So, in the example below,

local test = tostring(1) -- or "".. 1

could be written as

local test = "1"
					headDisplayId = CreateMpGamerTag(ped, GetPlayerServerId(id) .. "", false, false, "", false )

So is this the correct syntax for what I’m doing? I think I’m having a mental disability day. All I wanna do is smash my head on my desk. It’s frustrating for me because I’m happy you guys are willing to help, but I don’t wanna run you guys off by asking stupid questions.

Haha, I’m happy to help. And yes! Assuming that native is actually called CreateMpGamerTag (it could have a underscore at the beginning).

So, when you’re tranforming natives into PascalCase and there’s an underscore at the beginning, you need to leave that one?

I believe so, you can always check the “natives.lua” file that is in the client folder (located at citizen/scripting/lua/natives.lua) as it should contain all the natives. I’m not at a computer at the moment so, I can’t speak definitively on this.

He only asked a question, no need to put him down like that. Dick

If anyone else is looking, I was able to dig around and find a script. I was unable to get mine working. I have no idea who authored it, so my apologies if this belongs to you, but it works fine for me.

local showPlayerBlips = false
local ignorePlayerNameDistance = false
local disPlayerNames = 15
local playerSource = 0
 
function DrawText3D(x,y,z, text) -- some useful function, use it if you want!
    local onScreen,_x,_y=World3dToScreen2d(x,y,z)
    local px,py,pz=table.unpack(GetGameplayCamCoords())
    local dist = GetDistanceBetweenCoords(px,py,pz, x,y,z, 1)
 
    local scale = (1/dist)*2
    local fov = (1/GetGameplayCamFov())*100
    local scale = scale*fov
   
    if onScreen then
        SetTextScale(0.0*scale, 0.55*scale)
        SetTextFont(0)
        SetTextProportional(1)
        -- SetTextScale(0.0, 0.55)
        SetTextColour(255, 255, 255, 255)
        SetTextDropshadow(0, 0, 0, 0, 255)
        SetTextEdge(2, 0, 0, 0, 150)
        SetTextDropShadow()
        SetTextOutline()
        SetTextEntry("STRING")
        SetTextCentre(1)
        AddTextComponentString(text)
        DrawText(_x,_y)
    end
end
 
Citizen.CreateThread(function()
    while true do
        for i=0,99 do
            N_0x31698aa80e0223f8(i)
        end
        for id = 0, 31 do
            if  ((NetworkIsPlayerActive( id )) and GetPlayerPed( id ) ~= GetPlayerPed( -1 )) then
                ped = GetPlayerPed( id )
                blip = GetBlipFromEntity( ped )
 
                x1, y1, z1 = table.unpack( GetEntityCoords( GetPlayerPed( -1 ), true ) )
                x2, y2, z2 = table.unpack( GetEntityCoords( GetPlayerPed( id ), true ) )
                distance = math.floor(GetDistanceBetweenCoords(x1,  y1,  z1,  x2,  y2,  z2,  true))
 
                if(ignorePlayerNameDistance) then
				DrawText3D(x2, y2, z2+1, tostring(GetPlayerServerId(id)))
                end
 
                if ((distance < disPlayerNames)) then
                    if not (ignorePlayerNameDistance) then
                        DrawText3D(x2, y2, z2+1, tostring(GetPlayerServerId(id)))
                    end
                end  
            end
        end
        Citizen.Wait(0)
    end
end)
1 Like

no, this ‘script’ is delayed by 1 frame in drawing and will look absolutely ridiculous, you should not use World3dToScreen2d to draw 3D text, but instead SetDrawOrigin: http://runtime.fivem.net/doc/reference.html#_0xAA0008F3BBB8F416


here you go.

Wow you are an assholes

Thanks, I appreciate that.

fucking dick

Thanks, I appreciate that.

---- DISPLAY ID -----

local disPlayerNames = 5

local playerDistances = {}

local showID = true

local function DrawText3D(x,y,z, text, r,g,b) 

    local onScreen,_x,_y=World3dToScreen2d(x,y,z)

    local px,py,pz=table.unpack(GetGameplayCamCoords())

    local dist = #(vector3(px,py,pz)-vector3(x,y,z))

 

    local scale = (1/dist)*2

    local fov = (1/GetGameplayCamFov())*100

    local scale = scale*fov

   

    if onScreen then

        if not useCustomScale then

            SetTextScale(0.0*scale, 0.55*scale)

        else 

            SetTextScale(0.0*scale, customScale)

        end

        SetTextFont(0)

        SetTextProportional(1)

        SetTextColour(r, g, b, 255)

        SetTextDropshadow(0, 0, 0, 0, 255)

        SetTextEdge(2, 0, 0, 0, 150)

        SetTextDropShadow()

        SetTextOutline()

        SetTextEntry("STRING")

        SetTextCentre(1)

        AddTextComponentString(text)

        DrawText(_x,_y)

    end

end

Citizen.CreateThread(function()

    Wait(500)

    while true do

        Citizen.Wait(0)

        if showID then

            for _, id in ipairs(GetActivePlayers()) do

                    if GetPlayerPed(id) ~= GetPlayerPed(-1) then

                        if playerDistances[id] then

                            if (playerDistances[id] < disPlayerNames) then

                                x2, y2, z2 = table.unpack(GetEntityCoords(GetPlayerPed(id), true))

                                if NetworkIsPlayerTalking(id) then

                                    DrawText3D(x2, y2, z2+1, GetPlayerServerId(id), 65,65,65)

                                else

                                    DrawText3D(x2, y2, z2+1, GetPlayerServerId(id), 255,255,255)

                                end

                            elseif (playerDistances[id] < 25) then

                                x2, y2, z2 = table.unpack(GetEntityCoords(GetPlayerPed(id), true))                      

                                if NetworkIsPlayerTalking(id) then

                                end

                            end

                        end

                    end

            end

        end   

    end

end)

Citizen.CreateThread(function()

    while true do

        Citizen.Wait(1000)

        if showID then

            for _, id in ipairs(GetActivePlayers()) do

                if GetPlayerPed(id) ~= GetPlayerPed(-1) then

                    x1, y1, z1 = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))

                    x2, y2, z2 = table.unpack(GetEntityCoords(GetPlayerPed(id), true))

                    distance = math.floor(#(vector3(x1,  y1,  z1)-vector3(x2,  y2,  z2)))

                    playerDistances[id] = distance

                end

            end

        end

    end

end)

Citizen.CreateThread(function()

    while true do

        Citizen.Wait(0)

        if IsControlJustReleased(0, Keys["F9"]) then ----- WHAT KEY ARE WE GOING TO USE FOR THIS FUNCTION?

            showID = not showID

            PlaySound(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 0, 0, 1)

            if showID then

            exports['mythic_notify']:SendAlert('inform', 'GOV IDS ON', 2500, { ['background-color'] = '#29a30d', ['color'] = '#ffffff' })

            else exports['mythic_notify']:SendAlert('inform', 'GOV IDS OFF', 2500, { ['background-color'] = '#ff0000', ['color'] = '#ffffff' })

            end

        end

    end

end)

add that to any client side script you have, hit F9 should do everything else for you. Does utilize mythic notify. Enjoy! :slight_smile: