[SOLVED] ID above head blinks with vRP.getUserId(source)

Hi there, i made a litle modification from this script https://forum.cfx.re/t/release-changed-player-name-tags-distance-names/19204 it is workin but the id blink whet i get the player id from vRP.getUserId(source), so i would like to know if there is a way to create a buffer or somenting like that to avoid the blinking…

Also i believe the command only works with the id 1 of the server, not sure yet 'cause i’ve tested it in my friend server and only the id number 1 was able to toogle it on/off with /idon

Client script:

local Tunnel = module("vrp","lib/Tunnel")
local Proxy = module("vrp","lib/Proxy")
vRP = Proxy.getInterface("vRP")
iDON = Tunnel.getInterface("idonlyforadmin")

local showPlayerBlips = false
local ignorePlayerNameDistance = true
local playerNamesDist = 15
local displayIDHeight = 1.2 --Height of ID above players head(starts at center body mass)
--Set Default Values for Colors
local red = 255
local green = 255
local blue = 255
local group = 0



RegisterNetEvent('setgroup')
AddEventHandler('setgroup', function()
    if group == 0 then
        group = true
        TriggerEvent("Notify","Sucesso","Você ativou o id dos players.")
    elseif group == true then
        group = 0
        TriggerEvent("Notify","Sucesso","Você desativou o id dos players.")
    end
    --local _id = iDON.getPlayerID()
    --TriggerEvent("Notify", "sucesso", "_id: ".._id)
end)	


function DrawText3D(x,y,z, text) 
    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())*50
    local scale = scale*fov
    
    if onScreen then
        SetTextScale(1*scale, 2*scale)
        SetTextFont(0)
        SetTextProportional(1)
        SetTextColour(red, green, blue, 255)
        SetTextDropshadow(0, 0, 0, 0, 255)
        SetTextEdge(2, 0, 0, 0, 150)
        SetTextDropShadow()
        SetTextOutline()
        SetTextEntry("STRING")
        SetTextCentre(1)
        AddTextComponentString(text)
		World3dToScreen2d(x,y,z, 0) --Added Here
        DrawText(_x,_y)
    end
end

Citizen.CreateThread(function ()
    while true do
        for i=0,99 do
            N_0x31698aa80e0223f8(i)
        end
        for _, id in ipairs(GetActivePlayers()) do
        --for id = 0, 31 do
            --if GetPlayerPed( id ) ~= GetPlayerPed( -1 ) then
                ped = GetPlayerPed( id )
                blip = GetBlipFromEntity( ped ) 

                local _id = iDON.getPlayerID()

                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
					if group == true then 
						red = 255
						green = 255
						blue = 255
                        DrawText3D(x2, y2, z2 + displayIDHeight, GetPlayerServerId(id))
                        --DrawText3D(x2, y2, z2 + displayIDHeight, tostring(_id))
					end						        
                end
                if ((distance < playerNamesDist)) then
                    if not (ignorePlayerNameDistance) then
						if group == true then 
							red = 255
							green = 255
							blue = 255
							DrawText3D(x2, y2, z2 + displayIDHeight, GetPlayerServerId(id))
					    end					
                    end
                end  
            --end
        end
        Citizen.Wait(0)
    end
end)

Server script:

local Tunnel = module("vrp","lib/Tunnel")
local Proxy = module("vrp","lib/Proxy")
vRP = Proxy.getInterface("vRP")

iDON = {}
Tunnel.bindInterface("idonlyforadmin",iDON)

RegisterCommand('idon', function(source, args)
    local id = source
    --if isAdmin(id) then
    if vRP.hasPermission(id,"kick.permissao") then
		TriggerClientEvent("setgroup", id)
	end
end, false)

RegisterServerEvent('checkadmin')
AddEventHandler('checkadmin', function()
	local id = source
    --if isAdmin(id) then
    if vRP.hasPermission(id,"kick.permissao") then
		TriggerClientEvent("setgroup", source)
	end
end)

function iDON.getPlayerID()
	local source = source
	local user_id = vRP.getUserId(source)
	if user_id then
        return user_id
    else return nil
	end
end

__resource:

resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'

dependency "vrp"

client_scripts{
    "@vrp/lib/utils.lua",
    "client.lua"
} 

server_scripts {
	"@vrp/lib/utils.lua",
    "server.lua"
}

Thanks for any help and if i post i wrong place please forgive me i am new here and not sure if this is the right place for posting help topics, if it is in wrong session please don’t delete it, just move to correct place…
Sorry my bad english i am Brazilian and again thanks for any help…
Regards

I am not familiar with that native… but since it is doing it 99 times… your drawtext isn’t drawing every tick which is why it is flashing. I dont use vRP framework so i can’t test it personally … but just from the glace i did over the code that seems like it would be causing a break in the code long enough for the text to stop drawing and flash.

SpikE

1 Like

Thanks for your reply man, i have no idea what that function does either, i will remove it and test the code again…

I’ve removed that native but it keeps blinking :sob:

looking back over the code

local _id = iDON.getPlayerID()

That is not being used anywhere in the client code… why it is being called… and could that be causing the flashing since it has to wait for a response from the server for no reason.

SpikE

1 Like

Thanks for your reply man, i realised that after some time and notice that local _id = iDON.getPlayerID() was there doing nothing, so i made a litle change:

Server:

function iDON.getPlayerID(id)
	--local source = id
	local user_id = vRP.getUserId(id)
	--local identity = vRP.getUserIdentity(user_id)
	--local result = tostring("ID: "..user_id.. " | "..identity.name.." "..identity.firstname)
	if user_id then
      return user_id
    else return nil
	end
end

client:

DrawText3D(x2, y2, z2 + displayIDHeight, tostring(iDON.getPlayerID(parseInt(GetPlayerServerId(id)))))

i have some pint() for debuging and seems to be sending the correct id now, but it keeps blinking, i believe that is blinking for some kind of latence or somenting like that, because if i use the GetPlayerServerId(id) the text does not blink, maybe the blink now is due to latence in mysql and server as i am getting the id from database…

I realy apreciate your help man, you are awesome, sorry my bad english

I wish I knew about VRP to be able to help you with this… but as i have never used it I have no idea. The code you have shown does not seem to have any pauses in the code so it should not flash… the only reason i could stay it is flashing is becuase it needs to get a response from the server as to what to display. A way around this… would be on load up… have everyone send a command to iDON.getPlayerID(id) … and store that as a list on the server side. And update every list on clients as they load up… so would be something like this.

server:

local playerId = {}
function iDON.getPlayerID(id)
	local _source = source
	local user_id = vRP.getUserId(id)
	if user_id then
		playerId[_source] = user_id
		TriggerClientEvent('scriptname:updateids', -1, playerId)
	end
end

client:

PlayerIDs = {}

RegisterNetEvent('scriptname:updateids')
AddEventHandler('scriptname:updateids', function(updatedlist)
	PlayerIDs = updatedlist
end)

in your display code try this:

DrawText3D(x2, y2, z2 + displayIDHeight, tostring(PlayerIDs[GetPlayerServerId(id)]))

I am sure there might be a better way of doing this… but as i dont know the vRP framework i am not sure what that would be. This would result in your server having list stored for all players and would build up over time… so if you can access the onplayerdrop function you could use that to nil out the id’s that are not longer needed to keep the list only as long as the number of players on your server.

Hopefully this helps,

SpikE

1 Like

Thanks for your help man, i am sure this will help, i did not tryed it yet but i understud what you mean, basiclly it would load mysql info only when player connect on server and then keep that info in a global var wich would be much faster to read than executing a query in database every time the loop run, what i am not sure is, do i have to use the playerConnecting from vrp or can i call it from another script…
i will try this and see what i can do here, i will be posting results, thanks man i really apreciate your help

You get the general idea… this will cause your server to use a bit more ram as it is storing the information in a list… but should do better with overall performance since you will not have as many calls to the sql database.

I use 2 separate functions when dealing with a list like the example i gave:

AddEventHandler('playerDropped', function(player)
     local _source = source 
     if playerID[_source] ~= nil then
          playerID[_source] = nil
     end
     TriggerClientEvent('scriptname:updateids', -1, playerId)
end)

and then i use

AddEventHandler('esx:playerLoaded', function(xPlayer)

not sure what vRP would have that would be the same as this… but i am sure it has a loaded function you can use to get the information passed around.

SpikE

1 Like

It is working man, thanks for you help, i really apreciate it, for real thank you so much, sory for my late reply i was having some problems with my internet and i was unable to test the code at my friend server…

Here is the final script working and tested in case someone else want to use in your onw server:

Client:

local Tunnel = module("vrp","lib/Tunnel")
local Proxy = module("vrp","lib/Proxy")
vRP = Proxy.getInterface("vRP")
iDON = Tunnel.getInterface("idon")

local showPlayerBlips = false
local ignorePlayerNameDistance = true
local playerNamesDist = 15
local displayIDHeight = 1.6 --Height of ID above players head(starts at center body mass)
--Set Default Values for Colors
local red = 255
local green = 0
local blue = 255
local group
local multiplier = 150
local playerSVID
local pidon
local playerId = {}
local debugidON = nil
AddEventHandler('onClientResourceStart', function (resourceName)
    if(GetCurrentResourceName() ~= resourceName) then
      return
    end
    group = 0
    pidon = 0
    playerSVID =  GetPlayerServerId(NetworkGetEntityOwner(GetPlayerPed(-1)))
    TriggerServerEvent("idon:putplayerinvar", playerSVID)
    --TriggerServerEvent("idon:checkadmin")

    print('The resource ' .. resourceName .. ' has been started on the client id: ' .. GetPlayerServerId(NetworkGetEntityOwner(GetPlayerPed(-1))))
  end)

RegisterNetEvent('idon:updateids')
AddEventHandler('idon:updateids', function(updatedlist)
	PlayerID = updatedlist
end)

function DrawText3D(x,y,z, text) 
    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()) * multiplier
    local scale = scale*fov
    
    if onScreen then
        SetTextScale(1*scale, 2*scale)
        SetTextFont(0)
        SetTextProportional(1)
        SetTextColour(red, green, blue, 255)
        SetTextDropshadow(0, 0, 0, 0, 255)
        SetTextEdge(2, 0, 0, 0, 150)
        SetTextDropShadow()
        SetTextOutline()
        SetTextEntry("STRING")
        SetTextCentre(1)
        AddTextComponentString(text)
		World3dToScreen2d(x,y,z, 0) --Added Here
        DrawText(_x,_y)
    end
end

Citizen.CreateThread(function()
    
	while true do
		 -- Wait 5 seconds after player has loaded in and trigger the event.
        Citizen.Wait( 2000 )
        if debugidON == true then
            print("DEBUG > Client: group: "..tostring(group))
            for _, id in ipairs(GetActivePlayers()) do
                print("DEBUG > Client: PlayerServerId: "..tostring(GetPlayerServerId(id)).. " PlayerID: "..tostring(PlayerID[GetPlayerServerId(id)]))
            end
        end
    end
    
end )

Citizen.CreateThread(function ()
    while true do
        --for i=0,99 do
        --    N_0x31698aa80e0223f8(i)
        --end
        --if pidon == true then
            for _, id in ipairs(GetActivePlayers()) do
            --for id = 0, 31 do
                --if 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
                        if group == true then 
                            local piD = PlayerID[GetPlayerServerId(id)]
                            --local _id = iDON.GetOtherUserID(GetPlayerServerId(id))
                            --print(GetPlayerServerId(id))
						    red = 255
						    green = 255
						    blue = 255
                            --DrawText3D(x2, y2, z2 + displayIDHeight, GetPlayerServerId(id))
                            --DrawText3D(x2, y2, z2 + displayIDHeight, tostring("~r~".._id))
                            if piD ~= nil then
                                DrawText3D(x2, y2, z2 + displayIDHeight, tostring("~r~"..piD))
                                --SetBlipSprite( blip, 1 )
					            --Citizen.InvokeNative( 0x5FBCA48327B914DF, blip, true ) -- Player Blip indicator
                            end
                            
                        
					    end						        
                    end
                    if ((distance < playerNamesDist)) then
                        if not (ignorePlayerNameDistance) then
                            if group == true then 
                                local piD = PlayerID[GetPlayerServerId(id)]
							    red = 255
							    green = 255
                                blue = 255
                                if piD ~= nil then
                                    DrawText3D(x2, y2, z2 + displayIDHeight, tostring("~r~"..piD))
                                end
					        end					
                        end
                    end  
                --end
            end
        
        --end
        Citizen.Wait(10)
    end
end)


function chatMessage(msg)
	TriggerEvent("chatMessage", "", {255, 255, 255}, msg)
end

RegisterCommand("idon",function(source,args,rawCommand)
    
    local id = GetPlayerServerId(NetworkGetEntityOwner(GetPlayerPed(-1)))
    print("DEBUG > Client: Source: "..id)
    --chatMessage("DEBUG > Client: GetPlayerServerId:" .. GetPlayerServerId(NetworkGetEntityOwner(GetPlayerPed(-1))))
    if iDON.getPlayerID(id) then
        --TriggerServerEvent('txaLogger:CommandExecuted', rawCommand)
        if group == 0 then
            group = true
            print("DEBUG > Client: group: "..tostring(group))
            TriggerEvent("Notify","Sucesso","Você ativou o id dos players.")
            --TriggerEvent("Notify","importante","Use somente quando suspeitar que alguém está invisível ou não puder pegar o id usando /id pois consome memória do servidor.")
        elseif group == true then
            group = 0
            print("DEBUG: group: "..tostring(group))
            TriggerEvent("Notify","Sucesso","Você desativou o id dos players.")
        end
    end
end)

RegisterCommand("debugidon",function(source,args,rawCommand)

    local id = GetPlayerServerId(NetworkGetEntityOwner(GetPlayerPed(-1)))
    print("DEBUG > Client: Source: "..id)
    --chatMessage("DEBUG : GetPlayerServerId:" .. GetPlayerServerId(NetworkGetEntityOwner(GetPlayerPed(-1))))
    if iDON.getPlayerID(id) then
        --TriggerServerEvent('txaLogger:CommandExecuted', rawCommand)
        if debugidON == nil then
            debugidON = true
            print("DEBUG > Client: debugidON: "..tostring(debugidON))
            TriggerEvent("Notify","Sucesso","Você ativou o DEBUG IDON.")
            Notification("Você ativou o DEBUG IDON")
            --TriggerEvent("Notify","importante","Use somente quando suspeitar que alguém está invisível ou não puder pegar o id usando /id pois consome memória do servidor.")
        elseif debugidON == true then
            debugidON = nil
            print("DEBUG > Client: debugidON: "..tostring(debugidON))
            TriggerEvent("Notify","Sucesso","Você desativou o DEBUG IDON.")
            Notification("Você desativou o DEBUG IDON")
        end
    end
end)

function Notification(msg)
	SetNotificationTextEntry("STRING")
	AddTextComponentString(msg)
	DrawNotification(0,1)
end

Server:

local Tunnel = module("vrp","lib/Tunnel")
local Proxy = module("vrp","lib/Proxy")
vRP = Proxy.getInterface("vRP")

iDON = {}
Tunnel.bindInterface("idon",iDON)
local playerId = {}

RegisterNetEvent("idon:putplayerinvar")
AddEventHandler("idon:putplayerinvar", function(plID)
    local _source = source
    print(' SERVER putplayerinvar > DEBUG: source: ' .. _source .. ' has reached the server')
    print('SERVER putplayerinvar > DEBUG: plID: ' .. plID .. ' has reached the server')
    local user_id = vRP.getUserId(plID)
    print('SERVER putplayerinvar > DEBUG: user_id: ' .. user_id .. ' has been returned from getUserId ')
	if user_id then
		playerId[_source] = user_id
		TriggerClientEvent('idon:updateids', -1, playerId)
	end
end)

function iDON.getPlayerID(id)
    --local source = id
    --local teste = GetPlayerFromServerId(id)
    --print( "GetPlayerFromServerId: " ..teste)
    local user_id = vRP.getUserId(id)

	if vRP.hasPermission(user_id,"kick.permissao") then
        return true
    else return nil
	end
end

AddEventHandler('playerDropped', function(source)
    print("DEBUG > SERVER source: "..parseInt(source).. "dropped")
    local _source = source 
    --print("DEBUG > SERVER playerId[_source]: "..playerId[_source])
    if playerId[_source] ~= nil then
        print("DEBUG > SERVER playerId[_source]: "..playerId[_source].. "dropped")
        playerId[_source] = nil
    end
    TriggerClientEvent('idon:updateids', -1, playerId)

end)

__resource:

resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'

dependency "vrp"

client_scripts{
    "@vrp/lib/utils.lua",
    "client.lua"
} 

server_scripts {
	"@vrp/lib/utils.lua",
    "server.lua"
}

The AddEventHandler(‘playerDropped’, function(source) seems to work ok but when some player disconnect from server the client script was showing an erron saying that the PlayerID[GetPlayerServerId(id)] var was trying to print a nil value and the script stop showing id for admin, and it was driving me crazy hahaha, so i realized that in order to fix that i just needed to write a condition to not print nil values, then i have used:

local piD = PlayerID[GetPlayerServerId(id)]

if piD ~= nil then
    DrawText3D(x2, y2, z2 + displayIDHeight, tostring("~r~"..piD))                         
end

I am so happy that this is working fine, thanks man without your help i would not have it done, i hope you have a great day and i wish you luck, for real thanks man…

Here is a picture:

glad you got it all sorted out :slight_smile:

1 Like

can you help … when someone want to see admin ID or other staff member … it will show different color or like Admin : ID .

sorry, i did not understand your question… Normal players don’t see the id, only the staff members who use a command /idon wich i have set, if you need this script pm me and i will share it with you… Regards.

PS: if you want to see the admins id with different colors it would need just a lit bit change…