Jump to content

What is wrong with my script? Nametag should appear above ped but it doesn't..


bencskrisz

Recommended Posts

  1. local rootElement = getRootElement() 
  2. local NPC = createPed(124,0,0,5)
  3. local screenWidth, screenHeight = guiGetScreenSize() 
  4. function NPCnametag()
  5. local sx,sy = getScreenFromWorldPosition (getElementPosition(NPC))
  6. if sx then 
  7. dxDrawText("Bob",sx,sy,screenWidth, screenHeight,tocolor ( 255, 255, 0, 255 ), 2,"sans") 
  8. end
  9. end
  10.  
  11. function HandleTheRendering()
  12. addEventHandler("onClientRender",rootElement, NPCnametag)
  13. end
  14. addEventHandler("onClientResourceStart",rootElement, HandleTheRendering)
Link to comment

Try this

    local NPC = createPed(124,0,0,5)
    local screenWidth, screenHeight = guiGetScreenSize() 
    function NPCnametag()
    local x,y,z = getPedBonePosition(NPC,6)
    local sx,sy = getScreenFromWorldPosition(x,y,z)
	    if sx then 
	   		dxDrawText("Bob",sx,sy,sx,sy,tocolor ( 255, 255, 0, 255 ), 2,"sans") 
	    end
    end
     
    function HandleTheRendering()
   		addEventHandler("onClientRender",getRootElement(), NPCnametag)
    end
    addEventHandler("onClientResourceStart",resourceRoot, HandleTheRendering)

 

Link to comment
local NPC = createPed(124,0,0,5)
local screenWidth, screenHeight = guiGetScreenSize()
local range = 15
function NPCnametag()
    local x,y,z = getPedBonePosition(NPC,6)
    local px,py,pz = getElementPosition(localPlayer)
    if getDistanceBetweenPoints3D(x,y,z,px,py,pz) <= range then
        local sx,sy = getScreenFromWorldPosition(x,y,z)
        	if sx then 
        	   	dxDrawText("Bob",sx,sy,sx,sy,tocolor ( 255, 255, 0, 255 ), 2,"sans") 
            end
        end
    end

function HandleTheRendering()
   	addEventHandler("onClientRender",getRootElement(), NPCnametag)
end
addEventHandler("onClientResourceStart",resourceRoot, HandleTheRendering)

 

Link to comment

One more question: why does the created ped spawns a bit far from the scripted coordinates? There wasn't any problem with the positioning with the first script what u sent me and now the nametag works perfectly but it does not spawn accurately according to the written coordinates. It spawns a few meters away. What value affected it?? Its strange

Nothing nothing, I solved it!

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...