Jump to content

DxDrawText


Mann56

Recommended Posts

Hey guys!

I have been working on a hud where i am going to use dxtext for the first time. I saw the wiki but i have no idea how to get those absolute x and absolute y position where i want the text. Can someone help me?

Thanks...

Link to comment

Nvm above thing i found how to sort it out i did this ->

speedx,speedy,speedz = getElementVelocity(getPedOccupiedVehicle(localPlayer)) 
kmh = math.floor(((speedx^2 + speedy^2 + speedz^2) ^ (0.5)) * 180) 
dxDrawText (""..tostring(kmh).."km/h" , 1050,700,x,y,tocolor(255,255,255,255),2,"bankgothic") 
end 

Now, how can i make it general for all resolutions?

Link to comment

tell me your current resolution ?

  
local screenWidth, screenHeight = guiGetScreenSize() 
cResolutionY = 600 -- put your current resoultion Y here  for me it s 600 
cResolutionX = 800 -- put your current resoultion X here  for me it s 800 
function correctResolutinY(y) 
    if y then 
        return (y/cResolutionY )*screenHeight 
    end 
end 
  
function correctResolutinX(x) 
    if x then 
        return (x/cResolutionX)*screenWidth 
    end 
end 
  
  

Edited by Guest
Link to comment

1360 * 768 * 32

and i changed the thing again ->

speedx,speedy,speedz = getElementVelocity(getPedOccupiedVehicle(localPlayer)) 
kmh = math.floor(((speedx^2 + speedy^2 + speedz^2) ^ (0.5)) * 180) 
dxDrawText (""..tostring(kmh).." km/h" , 1080,700,x,y,tocolor(255,255,0,255),2,"pricedown") 
end 

Thank you for helping

Link to comment

Now, how can i make it general for all resolutions?

use

guiGetScreenSize() 
  
-- Example 
local sxW,syW = guiGetScreenSize() 
  
dxDrawText("text", sxW*(posX/1366),syW*(posY/768),sxW*(1244.0/1366),syW*(750.0/768), tocolor(255,0,0,255),2, "default-bold")  

Edited by Guest
Link to comment

try this

  
  
--- Use render event here please ! 
speedx,speedy,speedz = getElementVelocity(getPedOccupiedVehicle(localPlayer)) 
kmh = math.floor(((speedx^2 + speedy^2 + speedz^2) ^ (0.5)) * 180) 
dxDrawText (""..tostring(kmh).." km/h" , correctResolutinX(1080),correctResolutinY(700),x,y,tocolor(255,255,0,255),2,"pricedown") 
-- 
  
  
local screenWidth, screenHeight = guiGetScreenSize() 
cResolutionY = 768-- put your current resoultion Y here   
cResolutionX = 1360 -- put your current resoultion X here   
function correctResolutinY(y) 
    if y then 
        return (y/cResolutionY )*screenHeight 
    end 
end 
  
function correctResolutinX(x) 
    if x then 
        return (x/cResolutionX)*screenWidth 
    end 
end 
  
  
  

Link to comment
try this
  
speedx,speedy,speedz = getElementVelocity(getPedOccupiedVehicle(localPlayer)) 
kmh = math.floor(((speedx^2 + speedy^2 + speedz^2) ^ (0.5)) * 180) 
dxDrawText (""..tostring(kmh).." km/h" , correctResolutinX(1080),correctResolutinY(700),x,y,tocolor(255,255,0,255),2,"pricedown") 
end 
  
  
local screenWidth, screenHeight = guiGetScreenSize() 
cResolutionY = 768-- put your current resoultion Y here   
cResolutionX = 1360 -- put your current resoultion X here   
function correctResolutinY(y) 
    if y then 
        return (y/cResolutionY )*screenHeight 
    end 
end 
  
function correctResolutinX(x) 
    if x then 
        return (x/cResolutionX)*screenWidth 
    end 
end 
  
  
  

dude how does that work?

Link to comment

EDIT : code has been edited

  
--- Use render event here please ! 
speedx,speedy,speedz = getElementVelocity(getPedOccupiedVehicle(localPlayer)) 
kmh = math.floor(((speedx^2 + speedy^2 + speedz^2) ^ (0.5)) * 180) 
dxDrawText (""..tostring(kmh).." km/h" , 1080,700,correctResolutinX(x),correctResolutinY(y),tocolor(255,255,0,255),2,"pricedown") 
-- 
  
  
local screenWidth, screenHeight = guiGetScreenSize() 
cResolutionY = 768-- put your current resoultion Y here   
cResolutionX = 1360 -- put your current resoultion X here   
function correctResolutinY(y) 
    if y then 
        return (y/cResolutionY )*screenHeight 
    end 
end 
  
function correctResolutinX(x) 
    if x then 
        return (x/cResolutionX)*screenWidth 
    end 
end 
  

It should work now I forget to correct the position x and y

Edited by Guest
Link to comment
  
local screenWidth, screenHeight = guiGetScreenSize() 
cResolutionY = 768-- put your current resoultion Y here   
cResolutionX = 1360 -- put your current resoultion X here   
function correctResolutinY(y) 
    if y then 
        return (screenHeight/cResolutionY )*y 
    end 
end 
  
function correctResolutinX(x) 
    if x then 
        return (screenWidth/cResolutionX)*x 
    end 
end 
  

Link to comment

try this

local sx,sy = guiGetScreenSize() 
local px,py = 1280,720 -- all a screen in HD 
local x,y =  (sx/px), (sy/py) 
  
function HUD () 
dxDrawText("Example text", x*990, y*153, x*40, y*40, tocolor(255,255,255,255),1.0,"pricedown",false,false,false,true) 
end 

Link to comment

Try this

  
sWidth,sHeight = guiGetScreenSize() 
function    hudvisible () 
vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
    if ( vehicle ) then --checking 
        -- Gets some vehicle elements (gear, speed in MPH and KMH and health) 
        speedx, speedy, speedz = getElementVelocity ( vehicle  ) 
        actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5)  
        kmh = math.floor(actualspeed*180) -- Kilometers per hour 
        mph = math.floor(actualspeed * 111.847) -- Milles per hour 
        mps = math.floor (actualspeed) -- Metres per second 
         
        if getElementHealth(vehicle) >= 999 then 
        vehiclehealth = 100 
        else 
        vehiclehealth = math.floor(getElementHealth ( vehicle )/10) 
        end 
  
        dxDrawText("HEALTH: #FF0000"..vehiclehealth.."%", sWidth*(1031/1280), sHeight*(646/720), sWidth*(1204/1280), sHeight*(672/720), tocolor(0, 0, 0, 255), 0.8, "bankgothic", "center", "top", false, false, true, true, false) 
        dxDrawText("KM/H: "..kmh, sWidth*(1031/1280), sHeight*(620/720), sWidth*(1204/1280), sHeight*(646/720), tocolor(0, 0, 0, 255), 0.8 , "bankgothic", "center", "top", false, false, true, true, false) 
    end 
end 
addEventHandler ("onClientRender", root, hudvisible ) 
  

Link to comment
Try this
  
sWidth,sHeight = guiGetScreenSize() 
function    hudvisible () 
vehicle = getPedOccupiedVehicle(getLocalPlayer()) 
    if ( vehicle ) then --checking 
        -- Gets some vehicle elements (gear, speed in MPH and KMH and health) 
        speedx, speedy, speedz = getElementVelocity ( vehicle  ) 
        actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5)  
        kmh = math.floor(actualspeed*180) -- Kilometers per hour 
        mph = math.floor(actualspeed * 111.847) -- Milles per hour 
        mps = math.floor (actualspeed) -- Metres per second 
         
        if getElementHealth(vehicle) >= 999 then 
        vehiclehealth = 100 
        else 
        vehiclehealth = math.floor(getElementHealth ( vehicle )/10) 
        end 
  
        dxDrawText("HEALTH: #FF0000"..vehiclehealth.."%", sWidth*(1031/1280), sHeight*(646/720), sWidth*(1204/1280), sHeight*(672/720), tocolor(0, 0, 0, 255), 0.8, "bankgothic", "center", "top", false, false, true, true, false) 
        dxDrawText("KM/H: "..kmh, sWidth*(1031/1280), sHeight*(620/720), sWidth*(1204/1280), sHeight*(646/720), tocolor(0, 0, 0, 255), 0.8 , "bankgothic", "center", "top", false, false, true, true, false) 
    end 
end 
addEventHandler ("onClientRender", root, hudvisible ) 
  

Wrong post i posted for digital speedometer :D:D8)

Link to comment

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