bencskrisz

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

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)

Share this post


Link to post

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)

 

Share this post


Link to post

Thank you so much! Now it appears but.. once I get close to it and then leave from the ped, the nametag wont disappear, its gonna be visible no matter how far im going away from the ped.. can you resolve this? I guess we should need a kinda maxrange or idk.... :(

Share this post


Link to post
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)

 

Share this post


Link to post

Thank you so much!! It still needs a lot of work to make it perfect but I can do that now. God bless you brother!

Share this post


Link to post

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!

Share this post


Link to post

A bit off-topic (if you're still here) 

Can you check this for me out? -> 

It is the script what you solved for me, I just tried to add rotation but it does not rotate.. :/ Can you check this too? I have no idea what is the wrong..

Share this post


Link to post

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.