Overkillz Posted August 28, 2014 Share Posted August 28, 2014 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 Link to comment
manawydan Posted August 28, 2014 Share Posted August 28, 2014 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
Overkillz Posted August 28, 2014 Author Share Posted August 28, 2014 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 Link to comment
Anubhav Posted August 28, 2014 Share Posted August 28, 2014 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
Overkillz Posted August 28, 2014 Author Share Posted August 28, 2014 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
#RooTs Posted August 29, 2014 Share Posted August 29, 2014 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
Moderators IIYAMA Posted August 29, 2014 Moderators Share Posted August 29, 2014 dxSetAspectRatioAdjustmentEnabled Must be enabled before using the render functions, not after. Link to comment
Overkillz Posted August 29, 2014 Author Share Posted August 29, 2014 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
Saml1er Posted August 29, 2014 Share Posted August 29, 2014 (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 August 29, 2014 by Guest Link to comment
Overkillz Posted August 29, 2014 Author Share Posted August 29, 2014 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
Moderators IIYAMA Posted August 29, 2014 Moderators Share Posted August 29, 2014 Missing an end. function, if, if, if = 4 Link to comment
Saml1er Posted August 29, 2014 Share Posted August 29, 2014 Thanks but I can't see any rectangle. Its something wrong ? Fixed, copy again. Thanks IYAMA. Link to comment
Overkillz Posted August 29, 2014 Author Share Posted August 29, 2014 Thanks but I can't see any rectangle. Its something wrong ? Fixed, copy again. Thanks IYAMA. Thanks, but its similar to my code, why ? I tested it in 2 resolutions: 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 IIYAMA Posted August 29, 2014 Moderators Share Posted August 29, 2014 If you read all comments(especially mine), your problems would be fixed already. code + a little: 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
Overkillz Posted August 29, 2014 Author Share Posted August 29, 2014 If you read all comments(especially mine), your problems would be fixed already.code + a little: 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 Link to comment
Moderators IIYAMA Posted August 29, 2014 Moderators Share Posted August 29, 2014 it does work as long the image is also relative and adjust to the ratio. Link to comment
Overkillz Posted August 29, 2014 Author Share Posted August 29, 2014 Thanks for ur help guys, I could fix it with somethings. Regards. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now