Mann56 Posted May 15, 2015 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... "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"
Mann56 Posted May 15, 2015 Author 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? "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"
darhal Posted May 15, 2015 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 #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
Mann56 Posted May 15, 2015 Author 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 "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"
Walid Posted May 15, 2015 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 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
Mann56 Posted May 15, 2015 Author Posted May 15, 2015 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"
darhal Posted May 15, 2015 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 #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
Mann56 Posted May 15, 2015 Author 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? "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"
darhal Posted May 15, 2015 Posted May 15, 2015 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
Mann56 Posted May 15, 2015 Author 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 "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"
darhal Posted May 15, 2015 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 #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
Mann56 Posted May 15, 2015 Author Posted May 15, 2015 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"
GTX Posted May 15, 2015 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 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
#RooTs Posted May 15, 2015 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
-Doc- Posted May 15, 2015 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 ) My scripting skills
-Doc- Posted May 15, 2015 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 My scripting skills
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