glowdemon1 Posted October 4, 2013 Share Posted October 4, 2013 (edited) This tutorial is not aimed for the community of advanced scripters, this is more of a tutorial for people who are new and do not know what to do. This tutorial will be really short. If you rather wish to skip this, head down to find the final code. If you're an advanced scripter, don't bother commenting with hate, people who are unknown to scripting and willing to get deeper into this could be helped by this. Please note that I did not made the centerWindow at first, credits go to laserlaser. Lets take the original code from https://wiki.multitheftauto.com/wiki/CenterWindow function centerWindow(center_window) local screenW,screenH=guiGetScreenSize() local windowW,windowH=guiGetSize(center_window,false) local x,y = (screenW-windowW)/2,(screenH-windowH)/2 guiSetPosition(center_window,x,y,false) end If I were to do centerWindow(myGUI), the GUI would be completely centered, but that's not what we want, what we want to do is center the window and then add x/y values to it. Lets first change the function's arguments first, simply add addX and addY to it. Like this : function centerWindow(center_window,addX,addY) After we're done with that we'll go and do our next step. simply add the arguments "addX, addY" to guiSetPosition so that the script knows we have to add these values. guiSetPosition(center_window,x+addX,y+addY,false) This was the final step to complete the script, congratulations. The syntax of this function : string centerWindow( element TheElement int addX int addY) For instance : centerWindow(yourWindow,0,50) Would center the window and then add a value of 50 to the Y axis, resulting in a centered window, yet the GUI would be 50 "units" down. Could come in handy for stuff like this : http://puu.sh/4HiK7.jpg Final code. function centerWindow(center_window,addX,addY) local screenW,screenH=guiGetScreenSize() local windowW,windowH=guiGetSize(center_window,false) local x,y = (screenW-windowW)/2,(screenH-windowH)/2 guiSetPosition(center_window,x+addX,y+addY,false) end Edited November 23, 2013 by Guest Link to comment
Saml1er Posted November 11, 2013 Share Posted November 11, 2013 centerWindow ( yourWindow, 0, 50 ) you forgot to add " ) " Add some spaces in these codes because newbies won't even try to read the tutorial when they see these codes, honestly saying. Link to comment
ZL|LuCaS Posted November 20, 2013 Share Posted November 20, 2013 centerWindow ( yourWindow, 0, 50 ) you forgot to add " ) " Add some spaces in these codes because newbies won't even try to read the tutorial when they see these codes, honestly saying. simple but useful @; Saml1er, not need of spaces. Link to comment
glowdemon1 Posted November 23, 2013 Author Share Posted November 23, 2013 centerWindow ( yourWindow, 0, 50 ) you forgot to add " ) " Add some spaces in these codes because newbies won't even try to read the tutorial when they see these codes, honestly saying. Fixed, ty for reminding me. On the other hand I find this one useful for when I first started and didn't use relative positioning yet. Link to comment
MannPro Posted May 23, 2014 Share Posted May 23, 2014 Well i can't' understand a bit of this Link to comment
xXMADEXx Posted May 23, 2014 Share Posted May 23, 2014 centerWindow ( yourWindow, 0, 50 ) you forgot to add " ) " Add some spaces in these codes because newbies won't even try to read the tutorial when they see these codes, honestly saying. simple but useful @; Saml1er, not need of spaces. Spaces aren't needed, but it makes the code look better and easier to read. That's why most scripters use a ton of spacing. Link to comment
Recommended Posts