Deixell Posted January 22, 2010 Share Posted January 22, 2010 Is it posible to create a nametag for ped? I tried attach a text above him but I fail . Link to comment
Deixell Posted January 22, 2010 Author Share Posted January 22, 2010 Is it posible to create a nametag for ped? I tried attach a text above him but I fail . Link to comment
robhol Posted January 22, 2010 Share Posted January 22, 2010 Not a "real" name tag, no. Your best bet is making a client side script that loops through the currently streamed peds and/or players and draws a nametag for them with dx drawing functions. Link to comment
robhol Posted January 22, 2010 Share Posted January 22, 2010 Not a "real" name tag, no. Your best bet is making a client side script that loops through the currently streamed peds and/or players and draws a nametag for them with dx drawing functions. Link to comment
Deixell Posted January 22, 2010 Author Share Posted January 22, 2010 How to attach text to ped? Text isn't element. And how to make text apear when player is near a ped? Link to comment
Deixell Posted January 22, 2010 Author Share Posted January 22, 2010 How to attach text to ped? Text isn't element. And how to make text apear when player is near a ped? Link to comment
Gamesnert Posted January 22, 2010 Share Posted January 22, 2010 How to attach text to ped? Text isn't element. And how to make text apear when player is near a ped? You don't "attach" text to peds. You just draw it on top of them every frame. - onClientRender - getElementPosition - getScreenFromWorldPosition - dxDrawText That should give you a general idea of how to do it. Link to comment
Gamesnert Posted January 22, 2010 Share Posted January 22, 2010 How to attach text to ped? Text isn't element. And how to make text apear when player is near a ped? You don't "attach" text to peds. You just draw it on top of them every frame. - onClientRender - getElementPosition - getScreenFromWorldPosition - dxDrawText That should give you a general idea of how to do it. Link to comment
Deixell Posted January 23, 2010 Author Share Posted January 23, 2010 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
Deixell Posted January 23, 2010 Author Share Posted January 23, 2010 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
Dark Dragon Posted January 23, 2010 Share Posted January 23, 2010 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) 1 Link to comment
Dark Dragon Posted January 23, 2010 Share Posted January 23, 2010 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
Deixell Posted January 23, 2010 Author Share Posted January 23, 2010 Thanks everything works fine now Link to comment
Deixell Posted January 23, 2010 Author Share Posted January 23, 2010 Thanks everything works fine now Link to comment
Deixell Posted January 23, 2010 Author Share Posted January 23, 2010 One small problem: how to make that nametag only apear when player is near a ped? I add processLineOfSight to script but i still see ped name tag. Link to comment
Deixell Posted January 23, 2010 Author Share Posted January 23, 2010 One small problem: how to make that nametag only apear when player is near a ped? I add processLineOfSight to script but i still see ped name tag. Link to comment
Dark Dragon Posted January 23, 2010 Share Posted January 23, 2010 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
Dark Dragon Posted January 23, 2010 Share Posted January 23, 2010 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
Deixell Posted January 23, 2010 Author Share Posted January 23, 2010 Thanks that should be all. Link to comment
Deixell Posted January 23, 2010 Author Share Posted January 23, 2010 Thanks that should be all. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now