Jump to content

dxDrawRectangle For all resolutions


Overkillz

Recommended Posts

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

Link to comment

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) 

Link to comment
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

Link to comment
  
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) 
  

Link to comment
  
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

Link to comment

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) 

Link to comment
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.

Link to comment

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
Link to comment
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 ?

Link to comment

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.

Link to comment
  • Moderators

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) 

Link to comment
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

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