Jump to content

a function


Leo Messi

Recommended Posts

2 minutes ago, majdxd said:

I know this... How I can use it?

 

I HAVE ASKED YOU IN THE PREVIOUS POST TO READ THE : O WIKI PAGE : 

 

Using guiGetScreenSize to fit GUI & DX drawing in all resolutions

To get the precise coordinates of a GUI element or DX drawings, you need to decide which edges of the screen you want to have them positioned against, then you just need to find the difference between your screen size and your position values.

For example, there is a DX text. It fits on 1024x768 resolution.

function DXtext ()
dxDrawText(tostring "Hello World!",684.0,731.0,732.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false)
end

addEventHandler ( "onClientRender", getRootElement(), DXtext )

Now if you want it to fit on all resolutions. Then follow these steps:

1. Add width and height variables to get GUI's screen size, here we use sWidth and sHeight.

local sWidth,sHeight = guiGetScreenSize() -- The variables
dxDrawText( "Hello World!",684.0,731.0,732.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false)

2. Divide each of the DX text's position values by the screen size manually (remembering the resolution is 1024x768):

  • Left position value is 684, 684/1024 = 0.668
  • Top position value is 731, 731/768 = 0.952
  • Right position values is 732, 732/1024 = 0.715
  • Bottom position value is 766, 766/768 = 0.997

You may want to use a calculator to help you count.

3. Now with the answer above remove all of the position values and replace it with the width or height variable multiplied by the answer. Which would be:

local sWidth,sHeight = guiGetScreenSize() -- The variables
dxDrawText("Hello World!",sWidth*0.668, sHeight*0.952, sWidth*0.715, sHeight*0.997,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false)

So the final results will be a DX text which will fit on all resolutions which will be:

function DXtext ()
local sWidth,sHeight = guiGetScreenSize() -- The variables
dxDrawText("Hello World!",sWidth*0.668, sHeight*0.952, sWidth*0.715, sHeight*0.997,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false)
end

addEventHandler ( "onClientRender", getRootElement(), DXtext )

We can also do it by ourself doing some calculations in the code. This works in all resolution, adjusting the scale to all screen-sizes.

local sx, sy = guiGetScreenSize( )

addEventHandler( "onClientRender", root,
	function( )
	     dxDrawText( "Hello World!", sx*( 684/1024 ), sy*( 731/768 ), sx*( 732/1024 ), sy( 766/768 ), tocolor(0,255,255,175), sx/1000*1.0,"bankgothic","left","top",false,false,false ) 
	end
)
Link to comment

So you are saying  i didn't respect you? really? i asked you to read the wiki and the examples and you post how to do it , It's all in the wiki and in the examples i think you know how to do it now :) and that's why you asked to lock this topic anyway if you are not going to read the wiki you will not become a scripter ever so good luck!

Link to comment

this should be one of the easiest to use try to use it

local screenW,screenH = guiGetScreenSize()
local resW, resH = 1280,720  -- resolution creating the dxDraw
local x, y = (screenW/resW), (screenH/resH)

-- just add. -- x*width, y*height ...

dxDrawRectangle(x*303, y*158, x*579, y*27, tocolor(0, 255, 150, 255), false)
------
dxDrawText("Your Text", x*303, y*158, x*882, y*185, tocolor(255, 255, 255, 255), x*1.00, "default-bold", "center", "center", false, false, false, false, false)

 

Edited by raynner
Link to comment
21 hours ago, FaHaD said:

So you are saying  i didn't respect you? really? i asked you to read the wiki and the examples and you post how to do it , It's all in the wiki and in the examples i think you know how to do it now :) and that's why you asked to lock this topic anyway if you are not going to read the wiki you will not become a scripter ever so good luck!

You seem have a mind of kids, so I won't reply you because I already read wiki examples

By the way, I didn't register here to make fights with anyone, at the end it will stay a game @raynner thanks for your help, I am going to test it and I will reply you if it worked.

Edited by majdxd
Link to comment
Just now, majdxd said:

You seem have a mind of kids, so I won't reply you because I already read wiki examples

By the way, I didn't register here to make fights with anyone, at the end it will stay a game @raynner thanks for your help, I am going to test it and I will reply you if it's worked.

if you ever read the wiki as Dealman said you will know how to use it :) but i think you didn't even read the wiki examples because if you did you will know how to use that function but you are looking for someone to make it for you so yeah i waste my time in this topic trying give you some help.

Link to comment
9 minutes ago, majdxd said:

You seem have a mind of kids, so I won't reply you because I already read wiki examples

And you expect us to help you? Not only are you being rude to someone trying to help you, you're outright lying to us.

It's literally on the page he linked you, in bold text. It's described in detail how it works. Next time try and be a bit mature and appreciate the fact people are taking their time helping you.

  • Like 1
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...