Xierra Posted June 5, 2010 Share Posted June 5, 2010 Hi guys! I have another question, I got confused on getting correct place with guiGetScreenSize. I want to do this to fit my HUD on the proper place on every resolutions. After this is solved, I will upload this resource to the community, codenamed: alternate_hud For now I wanna learn about guiGetScreenSize. Can you give me a specific tutorial? Because I don't understand it at all. Script: -- All the Direct X Drawings (plus health & armor) function DXdraw() local x1,y1 = guiGetScreenSize() health = getElementHealth( getLocalPlayer() ) lineLength1 = 114 * ( health / 100 ) -- Health bar armor = getPedArmor( getLocalPlayer() ) lineLength2 = 114 * ( armor / 100 ) -- Armor bar ammoinclip = getPedAmmoInClip (getLocalPlayer()) totalammo = getPedTotalAmmo (getLocalPlayer()) showammo1=ammoinclip showammo2=totalammo dxDrawText("",646.0,731.0,694.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","right","top",false,false,false) --Ammo (for shotgun, grenades, etc) dxDrawRectangle(818.0,725.0,lineLength2,14.0,tocolor(200,200,200,200),true) dxDrawRectangle(818.0,745.0,114.0,14.0,tocolor(50,0,0,150),false) dxDrawText(tostring (showammo2),684.0,731.0,732.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false) --Total Ammo dxDrawText("|",665.0,731.0,677.0,762.0,tocolor(255,200,0,200),1.0,"bankgothic","left","top",false,false,false) --Separator dxDrawText(tostring (showammo1),611.0,731.0,659.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","right","top",false,false,false) --Ammo in clip dxDrawRectangle(818.0,725.0,114.0,14.0,tocolor(50,50,50,150),false) dxDrawRectangle(818.0,745.0,lineLength1,14.0,tocolor(175,0,0,200),false) end addEventHandler("onClientRender",getRootElement(),DXdraw) function hudChanger () showPlayerHudComponent ( "armour", false ) showPlayerHudComponent ( "health", false ) showPlayerHudComponent ( "money", false ) showPlayerHudComponent ( "clock", false ) showPlayerHudComponent ( "weapon", false ) showPlayerHudComponent ("ammo", false) showPlayerHudComponent ( "money", false ) end addCommandHandler ( "hidehud", hudChanger ) addEventHandler( "onClientResourceStart", getRootElement(), hudChanger ) -- Hide the HUD (except oxygen) on resource start. function hudChanger2 () showPlayerHudComponent ( "armour", true ) showPlayerHudComponent ( "health", true ) showPlayerHudComponent ( "money", true ) showPlayerHudComponent ( "clock", true ) showPlayerHudComponent ( "weapon", true ) showPlayerHudComponent ("ammo", true) showPlayerHudComponent ( "money", true) end addCommandHandler ( "showhud", hudChanger2) -- Show all the HUD if you want to. You saw those DX texts? The X and Y for the Ammo In clip (line 22) is 611 and 731, and The X and Y for total ammo (line 20) is 684 and 731. A little Screen for the results ingame: (It's not really glowing ingame, just edited in Picasa to make it glow. Man I want glows like that! HQ ftw!) And location on full image (1024x768): Link to comment
Andre9977 Posted June 5, 2010 Share Posted June 5, 2010 I once read a similiar topic about guiGetScreenSize which wanted to place a GUI in the middle of the screen. Had to divide the height and width of the screen and then subtract GUI's height and width divided by 2. middle height GUI = (screen height)/2 - (GUI's height)/2 middle width GUI = (screen width)/2 - (GUI's width)/2 That starts making some sense. But seeing that you don't want to have it in the center. I'm sure you saw the dxDrawText wiki page. There you see this: local screenWidth, screenHeight = guiGetScreenSize() -- Get the screen resolution [..] dxDrawText( playerZoneName, 44, screenHeight-41, screenWidth, screenHeight, [..] This might come helpful? Link to comment
Callum Posted June 5, 2010 Share Posted June 5, 2010 To place something in the middle of the screen I usually do something like; local resX,resY = guiGetScreenSize() guiCreateWindow(resX/10*4,resY/10*3.5,resX/10*2,resY/10*3,"A window",false) Link to comment
Remp Posted June 5, 2010 Share Posted June 5, 2010 you need to decide which edges of the screen you want to have them positioned against (looking at the screenshot, probably bottom/right) then you just need to find the difference between your screen size and your position values for example, for your ammo line: dxDrawText(tostring (showammo2),684.0,731.0,732.0,766.0,tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false) --Total Ammo we subtract each of your position values from your screen size (remembering your resolution is 1024x768): left position value is 684, 1024-684 = 340 top position value is 731, 768-731 = 37 right position values is 732, 1024-732 = 292 bottom position value is 766, 768-766 = 2 which then gives us: dxDrawText(tostring (showammo2),sWidth-340, sHeight-37, sWidth-292, sHeight-2, tocolor(0,255,255,175),1.0,"bankgothic","left","top",false,false,false) --Total Ammo this clamps the dx to the same position (relative to the edges of the screen) on every resolution repeat this process for all your dx items (rectangles will be easier because you only need to do the first 2 values) Link to comment
DEFCON1 Posted June 5, 2010 Share Posted June 5, 2010 Here is a small example resource to display an image on the screen. The image will be scaled and positioned proportionally with any resolution, as shown in the screenshots (please disregard the cheat info bar,it is another script which doesn't scale anything ) [attachment=0]test_scale.zip[/attachment] 640*480 1920*1080 (but resized to 50% to keep file small..) Link to comment
Xierra Posted June 6, 2010 Author Share Posted June 6, 2010 Thanks very much R3mp! I'll remember these maths. So this way it can be done in all GUI elements & DX drawings. All the others: thanks, that helps me too, but R3mp helps the most. Now I understood about guiGetScreenSize and why not put it on the wiki as the way to count it? And R3mp, thanks to your guieditor, I could make GUIs and master it! I'm just a newcomer in scripting world in the beginning, but here it goes along the way. Yeah! Now for another question: How to hide or show a GUI element or DX drawings? Link to comment
dzek (varez) Posted June 6, 2010 Share Posted June 6, 2010 why not put it on the wiki as the way to count it? i didnt read whole topic, but if you think something can be useful on wiki - just edit page on wiki and add it Link to comment
Xierra Posted June 6, 2010 Author Share Posted June 6, 2010 Now for another question: How to hide or show a GUI element or DX drawing? Link to comment
dzek (varez) Posted June 6, 2010 Share Posted June 6, 2010 guiSetVisible or just dont draw a dx object (set another boolean value for it maybe? like showMoneyBar = true, then on render handler do "if") 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