tommymaster Posted December 30, 2017 Share Posted December 30, 2017 Hi! If i want to make a let's say a rectangle, and i want to put it to my up-right corner that would not show up for the players, who have a resolution of 1366x768. The average screen resolution in my country is 1366x768, but i am not really sure that players won't have a bigger resolution, anyone i asked had a resolution which is smaller than mine. (1920x1080) So if i would put a rectangle to (1700, 1000) it would not even show up on 1366x768. I know that there is a trick, when i divide the pixel cound than multiply it by the player's pixel count it would show up on the right spot (its like 1700/my x pixel count*players x pixel count), but i have to write this everywhere in my scripts, and whenever i make a mistake in maths it makes me puzzle up to half an hour to look for that mistake, for example if i put numbers between () at the wrong spot and stuff like these. So basicly what i want to ask, is there an easier way to arrange the items to the same-like positions on other people's screen with proportional size and height & width? Sorry that i wrote a lot here, please ask if you have any question in connection with this. Link to comment
AlvarO Posted December 30, 2017 Share Posted December 30, 2017 (edited) I usually use that trick: (In my case, my resolution is 1920 x 1080, so if you have any other resolution just change the values instead of yours.) local sX, sY = guiGetScreenSize() function drawRectangle() dxDrawRectangle((1770/1920)*sX, (25/1080)*sY, (100/1920)*sX, (50/1080)*sY, tocolor(0, 0, 0, 200), false) end addEventHandler("onClientRender", root, drawRectangle) But you said if there was a method that made it easier, only comes to my mind to do something like this: local sx, sy = guiGetScreenSize() local px, py = 1920, 1080 local x, y = (sx/px), (sy/py) function drawRectangle() dxDrawRectangle(x*285, y*143, x*800, y*350, tocolor(0, 0, 0, 220), true) end addEventHandler("onClientRender", root, drawRectangle) In px and py you just have to put your resolution and just draw any element as is shown up. Hope I helped you! Edited December 30, 2017 by AlvarO 1 Link to comment
Tails Posted December 31, 2017 Share Posted December 31, 2017 (edited) Even simpler: local sw, sh = 1920, 1080; local cw, ch = guiGetScreenSize(); function rect(...) return dxDrawRectangle(arg[1]/sw*cw, arg[2]/sh*ch, arg[3]/sw*cw, arg[4]/sh*ch, arg[5], arg[6], arg[7]); end EDIT: By the way, there are many threads about the same issue with different solutions. Try the search button. Edited December 31, 2017 by Tails Link to comment
ShayF2 Posted December 31, 2017 Share Posted December 31, 2017 local sx,sy = guiGetScreenSize() local sw,sh = 1360,780-- if u change the values in the relative() funcs, be sure to set this to your res and change the other ones as well. function relative(x,y,w,h) -- this allows for perfect relative values, mta only sizes them to your res so it would be funky for other resolutions. x = x/sx*sw y = y/sy*sh w = w/sx*sw h = h/sy*sh return x,y,w,h end -- then input absolute values into the relative function like so local x,y,w,h = relative(300,400,100,200)-- whatever u want, x,y,w,h, will be relative values for every res, just be sure to change the res above to your res. 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