aka Blue Posted April 24, 2017 Share Posted April 24, 2017 Buenas tardes. Estoy creando un pequeño sistema de nametags y me gustaría saber como es que podría dibujar una barra de vida usando las coordenadas que me ofrece la función getScreenFromWorldPosition Actualmente tengo ésto: local font = dxCreateFont( "Font.otf", 15 ) addEventHandler( "onClientRender", root, function() local cx, cy, cz = getCameraMatrix() local lx, ly, lz = getElementPosition( localPlayer ) local jugadores = getElementsByType( "player" ) for i=1, #jugadores do local p = jugadores[i] --if players[ p ] then local x, y, z = getElementPosition( p ) local dist = getDistanceBetweenPoints3D( lx, ly, lz, x, y, z ) if dist < 15 then if isLineOfSightClear( lx, ly, lz, x, y, z, true, false, false, true, false, false, false, localPlayer ) then local name = getPlayerName( p ) local bone = { getPedBonePosition( p, 5 ) } local c = { getScreenFromWorldPosition( bone[1], bone[2], bone[3]+0.3 ) } local r, g, b = getPlayerNametagColor ( p ) --local puntos = getElementData( p, "puntos" ) or 0 --local health = getElementHealth( p ) if c[1] and c[2] then dxDrawText(name, c[1], c[2]-38, c[1], c[2], tocolor( 0, 0, 0 ), 1.5, "default-bold", "center", "center") dxDrawText(name, c[1], c[2]-40, c[1], c[2], tocolor( 255, 255, 255 ), 1.5, "default-bold", "center", "center") if getElementData( p, "adminduty" ) == true then dxDrawImage( c[1], c[2]+22, 20, 20, "staff.png", 0, 0, 0, tocolor( 0, 0, 0 ) ) dxDrawImage( c[1], c[2]+20, 20, 20, "staff.png", 0, 0, 0, tocolor( 255, 145, 0 ) ) end end end end --end end end ) Gracias de antemano! Link to comment
DBY Posted April 24, 2017 Share Posted April 24, 2017 (edited) De la misma forma que dibujas el nombre. local width, health = 130, getElementHealth( p ) dxDrawRectangle( c[ 1 ] - ( width / 2 ), c[ 2 ] - 3, width, 15, tocolor( 0, 0, 0, 200 ) ) -- Fondo negro para poder apreciar el estado de la barra. dxDrawRectangle( c[ 1 ] - ( width / 2 ), c[ 2 ] - 3, width * ( health / 100 ), 15, tocolor( 255, 0, 0, 200 ) ) -- Barra de salud. Edited April 24, 2017 by danibayez Comentar el código. Link to comment
aka Blue Posted April 24, 2017 Author Share Posted April 24, 2017 Gracias @danibayez, justamente lo que quería hacer! 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