Jump to content

DxDrawText


Mann56

Recommended Posts

Posted

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

"When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag"

"Have confidence in yourself, no problem is impossible in life"

Posted

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?

"When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag"

"Have confidence in yourself, no problem is impossible in life"

Posted (edited)

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

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted

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

"When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag"

"Have confidence in yourself, no problem is impossible in life"

Posted (edited)

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

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

i used that ->

local x,y = guiGetScreenSize () 

SO now should i set it to x- (1360-1080),y - (768-700) ?

"When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag"

"Have confidence in yourself, no problem is impossible in life"

Posted

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 
  
  
  

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted
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?

"When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag"

"Have confidence in yourself, no problem is impossible in life"

Posted

I edited the code test it

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted (edited)
I edited the code test it

I changed the resolution to 800 * 600 * 32 but i dont see the speedometer

EDIT : i see it in 1360 * 600 * 32

Edited by Guest

"When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag"

"Have confidence in yourself, no problem is impossible in life"

Posted (edited)

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

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted

Not working in 800 * 600 *32 :c

"When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag"

"Have confidence in yourself, no problem is impossible in life"

Posted
  
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 
  

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

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 

 DUyJ810.gif

Posted

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 ) 
  

My scripting skills

 


76561198189590622.pngAddFriend.png

Posted
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)

My scripting skills

 


76561198189590622.pngAddFriend.png

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