Jump to content

Ped nametag


Deixell

Recommended Posts

It doesn't work and i dont know why. Here is my script:

NPC = createPed(124,0,0,5)

function NPCnametag()

local screenWidth, screenHeight = guiGetScreenSize()

local sx,sy = getScreenFromWorldPosition (getElementPosition(NPC))

dxDrawText("Bob",sx,sy,screenWidth, screenHeight,tocolor ( 255, 255, 0, 0 ), 2,"sans")

end

function HandleTheRendering()

addEventHandler("onClientRender",rootElement, NPCnametag)

end

addEventHandler("onClientResourceStart",rootElement, HandleTheRendering)

Link to comment

It doesn't work and i dont know why. Here is my script:

NPC = createPed(124,0,0,5)

function NPCnametag()

local screenWidth, screenHeight = guiGetScreenSize()

local sx,sy = getScreenFromWorldPosition (getElementPosition(NPC))

dxDrawText("Bob",sx,sy,screenWidth, screenHeight,tocolor ( 255, 255, 0, 0 ), 2,"sans")

end

function HandleTheRendering()

addEventHandler("onClientRender",rootElement, NPCnametag)

end

addEventHandler("onClientResourceStart",rootElement, HandleTheRendering)

Link to comment
local rootElement = getRootElement() --define what rootElement is (that's probably your main problem)
local NPC = createPed(124,0,0,5)
local screenWidth, screenHeight = guiGetScreenSize() --you don't need to get this every frame, it will not change
function NPCnametag()
local sx,sy = getScreenFromWorldPosition (getElementPosition(NPC))
if sx then --this will check if the ped is actually on screen (without this check you would have many errors in your debug log)
dxDrawText("Bob",sx,sy,screenWidth, screenHeight,tocolor ( 255, 255, 0, 255 ), 2,"sans") --I'm not sure if the text was supposed to be invisible but I think I'll just change that too
end
end
 
function HandleTheRendering()
addEventHandler("onClientRender",rootElement, NPCnametag)
end
addEventHandler("onClientResourceStart",rootElement, HandleTheRendering)

  • Thanks 1
Link to comment
local rootElement = getRootElement() --define what rootElement is (that's probably your main problem)local NPC = createPed(124,0,0,5)local screenWidth, screenHeight = guiGetScreenSize() --you don't need to get this every frame, it will not changefunction NPCnametag()    local sx,sy = getScreenFromWorldPosition (getElementPosition(NPC))    if sx then --this will check if the ped is actually on screen (without this check you would have many errors in your debug log)        dxDrawText("Bob",sx,sy,screenWidth, screenHeight,tocolor ( 255, 255, 0, 255 ), 2,"sans") --I'm not sure if the text was supposed to be invisible but I think I'll just change that too    endend function HandleTheRendering()    addEventHandler("onClientRender",rootElement, NPCnametag)endaddEventHandler("onClientResourceStart",rootElement, HandleTheRendering)

Link to comment
local rootElement = getRootElement() --define what rootElement is (that's probably your main problem)
local NPC = createPed(124,0,0,5)
local screenWidth, screenHeight = guiGetScreenSize() --you don't need to get this every frame, it will not change
local maxrange = 45 -- the max range the text can be seen (modify to your preferences, i believe normal nametags use 45 too)
function NPCnametag()
local pedX,pedY,pedZ = getElementPosition(NPC)
local sx,sy = getScreenFromWorldPosition (pedX,pedY,pedZ)
local cameraX,cameraY,cameraZ = getCameraMatrix()
if sx then --this will check if the ped is actually on screen (without this check you would have many errors in your debug log)
if getDistanceBetweenPoints3D(cameraX,cameraY,cameraZ,pedX,pedY,pedZ) <= maxrange then --get the distance between two points in the 3d environment and check if it is smaller or the same as our maxrange
dxDrawText("Bob",sx,sy,screenWidth, screenHeight,tocolor ( 255, 255, 0, 255 ), 2,"sans") --I'm not sure if the text was supposed to be invisible but I think I'll just change that too
end
end
end
 
function HandleTheRendering()
addEventHandler("onClientRender",rootElement, NPCnametag)
end
addEventHandler("onClientResourceStart",rootElement, HandleTheRendering)

Link to comment
local rootElement = getRootElement() --define what rootElement is (that's probably your main problem)local NPC = createPed(124,0,0,5)local screenWidth, screenHeight = guiGetScreenSize() --you don't need to get this every frame, it will not changelocal maxrange = 45 -- the max range the text can be seen (modify to your preferences, i believe normal nametags use 45 too)function NPCnametag()    local pedX,pedY,pedZ = getElementPosition(NPC)    local sx,sy = getScreenFromWorldPosition (pedX,pedY,pedZ)    local cameraX,cameraY,cameraZ = getCameraMatrix()    if sx then --this will check if the ped is actually on screen (without this check you would have many errors in your debug log)        if getDistanceBetweenPoints3D(cameraX,cameraY,cameraZ,pedX,pedY,pedZ) <= maxrange then --get the distance between two points in the 3d environment and check if it is smaller or the same as our maxrange            dxDrawText("Bob",sx,sy,screenWidth, screenHeight,tocolor ( 255, 255, 0, 255 ), 2,"sans") --I'm not sure if the text was supposed to be invisible but I think I'll just change that too        end    endend function HandleTheRendering()    addEventHandler("onClientRender",rootElement, NPCnametag)endaddEventHandler("onClientResourceStart",rootElement, HandleTheRendering)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...