Jump to content

dxDrawRectangle For all resolutions


Overkillz

Recommended Posts

Posted

Hello dear community, I have a problem with a health using dxDrawRectangle, there isn't in the same position in all resolutions, how I can do it ?

local sx,sy = guiGetScreenSize() 
local px,py = 1920,1080 
local x,y =  (sx/px), (sy/py) 
addEventHandler("onClientRender", root, 
function ( source ) 
    local playerVehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
    if playerVehicle then 
    local vehicleHealth = getElementHealth ( playerVehicle ) 
    dxDrawRectangle(x*58, y*997, x*83/1000*vehicleHealth, y*4, tocolor(100, 254, 46, 255), true) -- Health 
    end 
end) 

I hope u can help me, thanks :D

Posted

try(no tested):

local sx,sy = guiGetScreenSize() 
addEventHandler("onClientRender", root, 
function ( ) 
    local playerVehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
    if playerVehicle then 
    local vehicleHealth = getElementHealth ( playerVehicle ) 
    dxDrawRectangle(sx*58, sy*997, sx*83/1000*vehicleHealth, sy*4, tocolor(100, 254, 46, 255), true) -- Health 
    end 
end) 

560x95_FFFFFF_09FF00_050505_000000.png

"Querer não é poder, mas tentar é avançar"!

Posted
try(no tested):
local sx,sy = guiGetScreenSize() 
addEventHandler("onClientRender", root, 
function ( ) 
    local playerVehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
    if playerVehicle then 
    local vehicleHealth = getElementHealth ( playerVehicle ) 
    dxDrawRectangle(sx*58, sy*997, sx*83/1000*vehicleHealth, sy*4, tocolor(100, 254, 46, 255), true) -- Health 
    end 
end) 

Doesn't work, Now I can't see the bar :D

Posted
  
local sx,sy = guiGetScreenSize() 
addEventHandler("onClientRender", root, 
function ( ) 
    local playerVehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
    if playerVehicle then 
    local vehicleHealth = getElementHealth ( playerVehicle ) 
    dxDrawRectangle(sx*58, sy*997, sx*83/1000*vehicleHealth, sy*4, tocolor(100, 254, 46, 255), true) -- Health 
    dxSetAspectRatioAdjustmentEnabled( true ) 
    end 
end) 
  

Posted
  
local sx,sy = guiGetScreenSize() 
addEventHandler("onClientRender", root, 
function ( ) 
    local playerVehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
    if playerVehicle then 
    local vehicleHealth = getElementHealth ( playerVehicle ) 
    dxDrawRectangle(sx*58, sy*997, sx*83/1000*vehicleHealth, sy*4, tocolor(100, 254, 46, 255), true) -- Health 
    dxSetAspectRatioAdjustmentEnabled( true ) 
    end 
end) 
  

If Im using this

dxDrawRectangle(sx*0.9, sy*0.9, sx*83/1000*vehicleHealth, sy*4, tocolor(100, 254, 46, 255), true) -- Health 
    dxSetAspectRatioAdjustmentEnabled( true ) 

I cant put a right position

Posted

try this

local sx,sy = guiGetScreenSize() 
local px,py = 1600,900 
local x,y =  (sx/px), (sy/py) 
addEventHandler("onClientRender", root, 
function ( source ) 
    local playerVehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
    if playerVehicle then 
    local vehicleHealth = getElementHealth ( playerVehicle ) 
    dxDrawRectangle(x*58, y*997, x*83/1000*vehicleHealth, y*4, tocolor(100, 254, 46, 255), true) -- Health 
    end 
end) 

 DUyJ810.gif

  • Moderators
Posted

dxSetAspectRatioAdjustmentEnabled Must be enabled before using the render functions, not after. :!:

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
try this
local sx,sy = guiGetScreenSize() 
local px,py = 1600,900 
local x,y =  (sx/px), (sy/py) 
addEventHandler("onClientRender", root, 
function ( source ) 
    local playerVehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
    if playerVehicle then 
    local vehicleHealth = getElementHealth ( playerVehicle ) 
    dxDrawRectangle(x*58, y*997, x*83/1000*vehicleHealth, y*4, tocolor(100, 254, 46, 255), true) -- Health 
    end 
end) 

I put a position in 1920x1080 and after I change to 1440x900 and it has a different size.

Posted (edited)

You can modify my code.

  
local sx,sy = guiGetScreenSize() 
  
addEventHandler("onClientRender",root, 
function ()  
if isPedInVehicle(localPlayer) then   
local veh = getPedOccupiedVehicle(localPlayer) 
if veh and isElement(veh) then  
  
local ch,tw = getElementHealth(veh)-250, sx*(170/1920)    
   
local ch = ch / 750 * 100 
        dxDrawRectangle(sx*(844/1920), sy*(10/1080), tw, sy*(24/1080), tocolor(0, 0, 0, 150), true) 
if ch >= 0 then  
    ------------------------- HEALTH ------------------------- 
       dxDrawRectangle(sx*(844/1920), sy*(10/1080), ch*tw/100, sy*(24/1080), tocolor(0, 0, 0, 255), true) 
    end  
        end  
           end  
              end ) 

Edited by Guest
Posted
You can modify my code.
  
local sx,sy = guiGetScreenSize() 
  
addEventHandler("onClientRender",root, 
function ()  
if isPedInVehicle(localPlayer) then   
local veh = getPedOccupiedVehicle(localPlayer) 
if veh and isElement(veh) then  
  
local ch,tw = getElementHealth(veh)-250, sx*(170/1920)    
   
local ch = ch / 750 * 100 
        dxDrawRectangle(sx*(844/1920), sy*(10/1080), tw, sy*(24/1080), tocolor(0, 0, 0, 150), true) 
if ch >= 0 then  
    ------------------------- HEALTH ------------------------- 
       dxDrawRectangle(sx*(844/1920), sy*(10/1080), ch*tw/100, sy*(24/1080), tocolor(0, 0, 0, 255), true) 
    end  
        end  
           end ) 

Thanks but I can't see any rectangle.

Its something wrong ?

  • Moderators
Posted

Missing an end. function, if, if, if = 4

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

Thanks but I can't see any rectangle.

Its something wrong ?

Fixed, copy again. Thanks IYAMA. :mrgreen:

Thanks, but its similar to my code, why ?

I tested it in 2 resolutions:

b069195bfc.png

Script:

local sx,sy = guiGetScreenSize() 
  
addEventHandler("onClientRender",root, 
function () 
if isPedInVehicle(localPlayer) then   
local veh = getPedOccupiedVehicle(localPlayer) 
if veh and isElement(veh) then 
  
local ch,tw = getElementHealth(veh)-250, sx*(170/1920)   
  
local ch = ch / 750 * 50 
        --dxDrawRectangle(sx*(844/1920), sy*(10/1080), tw, sy*(24/1080), tocolor(0, 255, 0, 150), true) 
if ch >= 0 then 
    ------------------------- HEALTH ------------------------- 
       dxDrawRectangle(sx*(57/1920), sy*(994/1080), ch*tw/100, sy*(7/1080), tocolor(0, 255, 0, 255), true) 
    end 
        end 
           end 
              end ) 
---------------------------- 

Regards.

  • Moderators
Posted

If you read all comments(especially mine), your problems would be fixed already.

code + a little: :idea:

local sx,sy = guiGetScreenSize() 
  
addEventHandler("onClientRender",root, 
function () 
    if isPedInVehicle(localPlayer) then   
        local veh = getPedOccupiedVehicle(localPlayer) 
        if veh and isElement(veh) then 
  
            local ch,tw = getElementHealth(veh)-250, sx*(170/1920)   
            local ch = ch / 750 * 100 
             
            -- before the directX FUNCTIONS!!!!! 
            dxSetAspectRatioAdjustmentEnabled (true) -- here we fix this resolution problem <<<<< 
            -- before the directX FUNCTIONS!!!!! 
             
            dxDrawRectangle(sx*(844/1920), sy*(10/1080), tw, sy*(24/1080), tocolor(0, 0, 0, 150), true) 
            if ch >= 0 then 
                ------------------------- HEALTH ------------------------- 
                dxDrawRectangle(sx*(844/1920), sy*(10/1080), ch*tw/100, sy*(24/1080), tocolor(0, 0, 0, 255), true) 
            end 
        end 
    end 
end) 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted
If you read all comments(especially mine), your problems would be fixed already.

code + a little: :idea:

local sx,sy = guiGetScreenSize() 
  
addEventHandler("onClientRender",root, 
function () 
    if isPedInVehicle(localPlayer) then   
        local veh = getPedOccupiedVehicle(localPlayer) 
        if veh and isElement(veh) then 
  
            local ch,tw = getElementHealth(veh)-250, sx*(170/1920)   
            local ch = ch / 750 * 100 
             
            -- before the directX FUNCTIONS!!!!! 
            dxSetAspectRatioAdjustmentEnabled (true) -- here we fix this resolution problem <<<<< 
            -- before the directX FUNCTIONS!!!!! 
             
            dxDrawRectangle(sx*(844/1920), sy*(10/1080), tw, sy*(24/1080), tocolor(0, 0, 0, 150), true) 
            if ch >= 0 then 
                ------------------------- HEALTH ------------------------- 
                dxDrawRectangle(sx*(844/1920), sy*(10/1080), ch*tw/100, sy*(24/1080), tocolor(0, 0, 0, 255), true) 
            end 
        end 
    end 
end) 

Ops, I had forgotten add dxSetAspectRatioAdjustmentEnabled , but It doesn't work too

It is showing the same problem fro 1440 x 900

b069195bfc.png

  • Moderators
Posted

it does work as long the image is also relative and adjust to the ratio.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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