Charan Posted April 27, 2017 Share Posted April 27, 2017 (edited) i have a plugin which makes the nametag appear above the player and the own player and everyone too should be able to see it but it wont work heres the code addEventHandler("onClientRender",getRootElement(), function() local px,py,pz,tx,ty,tz,dist px,py,pz = getCameraMatrix() for k,v in ipairs(getElementsByType("player")) do if (v~=getLocalPlayer()) then tx,ty,tz = getElementPosition(v) dist = math.sqrt((px-tx)^2 + (py-ty)^2 + (pz-tz)^2) if dist < 30.0 then if isLineOfSightClear(px,py,pz,tx,ty,tz,true,false,false,true,false,false,getLocalPlayer()) then local sx,sy,sz = getPedBonePosition(v,5) local x,y = getScreenFromWorldPosition(sx,sy,sz+0.3) if x then dxDrawText(getPlayerName(v),x,y,x,y,tocolor(150,50,0),0.85+(15-dist)*0.02,"bankgothic") end end end end end end )addEventHandler("onClientRender",getRootElement(), function() local px,py,pz,tx,ty,tz,dist px,py,pz = getCameraMatrix() for k,v in ipairs(getElementsByType("player")) do tx,ty,tz = getElementPosition(v) dist = math.sqrt((px-tx)^2 + (py-ty)^2 + (pz-tz)^2) if dist < 30.0 then if isLineOfSightClear(px,py,pz,tx,ty,tz,true,false,false,true,false,false,getLocalPlayer()) then local sx,sy,sz = getPedBonePosition(v,5) local x,y = getScreenFromWorldPosition(sx,sy,sz+0.3) if x then dxDrawText(getPlayerName(v),x,y,x,y,tocolor(150,50,0),0.85+(15-dist)*0.02,"bankgothic") end end end end end ) Edited April 27, 2017 by Charan Link to comment
SheriFF Posted April 27, 2017 Share Posted April 27, 2017 This is just another idea( not tested ) , feel free to use and edit it as you wish --SERVER addEventHandler( "onPlayerSpawn", getRootElement(), function () triggerClientEvent( source, "player_onSpawn", source ) end ) --CLIENT addEvent( "player_onSpawn", true ) local SHOW_DIST = 50 local TAG_RADIUS = createColSphere( 0, 0, 0, SHOW_DIST ) function initialiseNametags() attachElements( TAG_RADIUS, localPlayer, 0, 0, 0 ) addEventHandler( "onClientRender", getRootElement(), renderNametags ) end addEventHandler( "player_onSpawn", getRootElement(), initialiseNametags ) local TAG_WIDTH, TAG_HEIGHT = 300, 50 function renderNametags() local CAM_X, CAM_Y, CAM_Z = getCameraMatrix() local PLAYERS_IN_RADIUS = getElementsWithinColShape( TAG_RADIUS, "player" ) for _, PLAYER in pairs ( PLAYERS_IN_RADIUS ) do local PLAYER_X, PLAYER_Y, PLAYER_Z = getElementPosition( PLAYER ) if isLineOfSightClear( PLAYER_X, PLAYER_Y, PLAYER_Z, CAM_X, CAM_Y, CAM_Z, true, false, false, true, false, false, localPlayer ) then local BONE_X, BONE_Y, BONE_Z = getPedBonePosition( PLAYER, 5 ) local TAG_X, TAG_Y = getScreenFromWorldPosition( BONE_X, BONE_Y, BONE_Z + 0.3 ) if ( TAG_X and TAG_Y ) then dxDrawText( getPlayerName( PLAYER ), TAG_X - TAG_WITH / 2, TAG_Y - TAG_HEIGHT / 2, TAG_X - TAG_WITH / 2 + TAG_WITH, TAG_Y - TAG_HEIGHT / 2 + TAG_HEIGHT, tocolor( 150, 50, 0 ), 1, "bankgothic" ) end end end end One mistake i saw was at dxDrawText.For example, if you want to draw a text at coords 10, 10 with the height of 50 and width of 100 you need to write something like dxDrawText( "text", 10, 10, 110, 60 ... ) ( the right and bottom must be coords, not the width and height ) 1 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