Jump to content

[HELP] dxText above player's head


HeK

Recommended Posts

Posted

Hello there forum,

I'd like to know how i could put some text above a player's head?

I'm working on a damage display script, and i'd like to have it displayed above the player that's getting shot.

local screenWidth, screenHeight = guiGetScreenSize ( ) 
  
kill = {} 
  
addEventHandler("onClientPedDamage",root, 
    function ( attaker, weapon) 
        local lostHealth = "-" .. math.ceil(getElementHealth(source)) 
        if ( attaker and attaker == localPlayer ) then 
            if ( kill[localPlayer] ) then 
                killTimer(displayTimer) 
            end 
            dxDrawText ( lostHealth, 700, screenHeight - 545, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.12, "default-small" ) 
            dxDrawText ( lostHealth, 700, screenHeight - 545, screenWidth, screenHeight, tocolor ( 0, 255, 0, 255 ), 1.1, "default-small" ) 
            displayTimer = setTimer(dxDrawText,5000,1) 
        end 
    end 
) 

Posted

Draws a string of text on the screen for one frame. In order for the text to stay visible continuously, you need to call this function with the same parameters on each frame update (see onClientRender).

Posted

Well, and how can i make it show above the player's head? With onClientRender it doesn't even show the text anymore.

Posted

local screenWidth, screenHeight = guiGetScreenSize ( ) 
setElementData(localPlayer,"EventHandler",false) 
  
addEventHandler("onClientPedDamage",root, 
    function ( attaker, weapon) 
         lostHealth = "-" .. math.ceil(getElementHealth(source)) 
        if ( attaker and attaker == localPlayer ) then 
        setTimer(function()  
        if getElementData(localPlayer,"EventHandler") == true then return setElementData(localPlayer,"EventHandler",false) and removeEventHandler("onClientRender",root,Draw)  end; 
        setElementData(localPlayer,"EventHandler",true) 
        addEventHandler("onClientRender",root,Draw)  
        end,5000,1) 
        end 
    end 
) 
  
function Draw() 
            dxDrawText ( lostHealth, 700, screenHeight - 545, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.12, "default-small" ) 
            dxDrawText ( lostHealth, 700, screenHeight - 545, screenWidth, screenHeight, tocolor ( 0, 255, 0, 255 ), 1.1, "default-small" ) 
end 
  
  
  

Try this will show the ped health after 5 sec!

Posted

That's showing random numbers on the screen, and i want it to show instantly not 5 secs after i shot him, what i need is to make that text show above the ped's head.

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