Mann56 Posted May 15, 2015 Share Posted May 15, 2015 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
Mann56 Posted May 15, 2015 Author Share Posted May 15, 2015 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
darhal Posted May 15, 2015 Share Posted May 15, 2015 (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 May 15, 2015 by Guest Link to comment
Mann56 Posted May 15, 2015 Author Share Posted May 15, 2015 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
Walid Posted May 15, 2015 Share Posted May 15, 2015 (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 May 15, 2015 by Guest Link to comment
Mann56 Posted May 15, 2015 Author Share Posted May 15, 2015 i used that -> local x,y = guiGetScreenSize () SO now should i set it to x- (1360-1080),y - (768-700) ? Link to comment
darhal Posted May 15, 2015 Share Posted May 15, 2015 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
Mann56 Posted May 15, 2015 Author Share Posted May 15, 2015 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
Mann56 Posted May 15, 2015 Author Share Posted May 15, 2015 (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 May 15, 2015 by Guest Link to comment
darhal Posted May 15, 2015 Share Posted May 15, 2015 (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 May 15, 2015 by Guest Link to comment
Mann56 Posted May 15, 2015 Author Share Posted May 15, 2015 Not working in 800 * 600 *32 :c Link to comment
GTX Posted May 15, 2015 Share Posted May 15, 2015 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
#RooTs Posted May 15, 2015 Share Posted May 15, 2015 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
-Doc- Posted May 15, 2015 Share Posted May 15, 2015 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
-Doc- Posted May 15, 2015 Share Posted May 15, 2015 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 Link to comment
#RooTs Posted May 15, 2015 Share Posted May 15, 2015 @-Blue-, my code is like yours, but it is simpler 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