Jonty Posted December 30, 2017 Share Posted December 30, 2017 Hello I've been making a GUI first time doing this and I've got the code to work but I've tried using a button to hide the GUI after it is clicked. Can anyone help me, please? -- Made by Jonty / First Lua code for Tables. Skins = { "Cj - 0", "", "" } Vehicle = { "", "" } function setupSkinSelection (theResource) -- Creats GUI window spawnScreenMenu = guiCreateWindow ( 0.15, 0.33, 0.7, 0.34, "Find the ID's you want!", true ) -- Button spawnScreenOKButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "Done", true, spawnScreenMenu ) guiWindowSetMovable ( spawnScreenMenu, false ) guiWindowSetSizable ( spawnScreenMenu, false ) spawnScreenGridList = guiCreateGridList ( 0, 0.1, 1, 0.9, true, spawnScreenMenu ) guiGridListSetSelectionMode ( spawnScreenGridList, 2 ) guiGridListAddColumn ( spawnScreenGridList, "Skins", 0.3 ) guiGridListAddColumn ( spawnScreenGridList, "Vehicle", 0.3 ) for key,skinName in pairs(Skins) do local row = guiGridListAddRow ( spawnScreenGridList ) guiGridListSetItemText ( spawnScreenGridList, row, 1, skinName, false, false ) end -- Rows for the GUI window row = 0 for key,skinName in pairs(Vehicle) do guiGridListSetItemText ( spawnScreenGridList, row, 2, skinName, false, false ) row = row + 1 end end -- Command to launch the GUI addCommandHandler('IDSelection', function() setupSkinSelection(true) showCursor ( true ) end ) addEventHandler('onClientGUIClick' , spawnScreenOKButton, function ( ) if ( source == 'Done' ) then guiSetVisible (spawnScreenMenu , false) showCursor ( false ) end Link to comment
AlvarO Posted December 30, 2017 Share Posted December 30, 2017 I think this is your solution: guiSetVisible ( guiElement, state ) Link to comment
Jonty Posted December 31, 2017 Author Share Posted December 31, 2017 1 hour ago, AlvarO said: I think this is your solution: guiSetVisible ( guiElement, state ) I've tried that and it still seems to not work. Got anything else. Link to comment
KaMi Posted December 31, 2017 Share Posted December 31, 2017 You can re-make the gui with this resource https://community.multitheftauto.com/index.php?p=resources&s=details&id=141 and this tutorial Link to comment
Jonty Posted December 31, 2017 Author Share Posted December 31, 2017 2 minutes ago, <~KaMiKaZe~> said: You can re-make the gui with this resource https://community.multitheftauto.com/index.php?p=resources&s=details&id=141 and this tutorial ah thanks, But I would rather code it myself and learn Lua while I go along. But thank you so much for the suggestion. Link to comment
Storm-Hanma Posted December 31, 2017 Share Posted December 31, 2017 I used that link resources abov ones all good but now I stuck with panel the panel open when ever player reconnect it open without pressing f4(bindedkey)don't know how to fix 1 Link to comment
ShayF2 Posted December 31, 2017 Share Posted December 31, 2017 -- Made by Jonty / First Lua code for Tables. 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 data = { {'CJ','Infernus',0,411} } local x1,y1,w1,h1 = relative(204,253,952,261) spawnScreenMenu = guiCreateWindow(x1,y1,w1,h1,'Find the IDs you want!',false) guiWindowSetMovable(spawnScreenMenu,false) guiWindowSetSizable(spawnScreenMenu,false) local x2,y2,w2,h2 = relative(9,26,933,195) spawnScreenGridList = guiCreateGridList(x2,y2,w2,h2,false,spawnScreenMenu) guiGridListAddColumn(spawnScreenGridList,'Skins',0.5) guiGridListAddColumn(spawnScreenGridList,'Vehicle',0.48) local x3,y3,w3,h3 = relative(381,222,190,30) spawnScreenOKButton = guiCreateButton(x3,y3,w3,h3,'Done',false,spawnScreenMenu) guiSetVisible(spawnScreenMenu,false) for i=1,#data do local row = guiGridListAddRow(spawnScreenGridList) guiGridListSetItemText(spawnScreenGridList,row,1,data[i][1],false,false) guiGridListSetItemText(spawnScreenGridList,row,2,data[i][2],false,false) end -- Command to launch the GUI addCommandHandler('idselection',function() if guiGetVisible(spawnScreenMenu) then guiSetVisible(spawnScreenMenu,false) showCursor(false) else guiSetVisible(spawnScreenMenu,true) showCursor(true) end end) addEventHandler('onClientGUIClick',spawnScreenOKButton,function() guiSetVisible(spawnScreenMenu,false) showCursor(false) end) I've added a relative function, you'll have to change the resolution as well as the numbers in the relative() functions to match your resolution, after that they should be working just fine, inputting absolute values and getting relative values, I just tested this code and it is working perfectly. I did this whole relative thing because MTA relative values are only based off of your resolution, I made it so its based off of all resolutions, that way you wont have any problems with resizing or moving the GUI on another persons screen. It'll look the same on your screen as a phone screen haha. Have a nice day. Link to comment
Jonty Posted December 31, 2017 Author Share Posted December 31, 2017 29 minutes ago, ShayF said: -- Made by Jonty / First Lua code for Tables. 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 data = { {'CJ','Infernus',0,411} } local x1,y1,w1,h1 = relative(204,253,952,261) spawnScreenMenu = guiCreateWindow(x1,y1,w1,h1,'Find the IDs you want!',false) guiWindowSetMovable(spawnScreenMenu,false) guiWindowSetSizable(spawnScreenMenu,false) local x2,y2,w2,h2 = relative(9,26,933,195) spawnScreenGridList = guiCreateGridList(x2,y2,w2,h2,false,spawnScreenMenu) guiGridListAddColumn(spawnScreenGridList,'Skins',0.5) guiGridListAddColumn(spawnScreenGridList,'Vehicle',0.48) local x3,y3,w3,h3 = relative(381,222,190,30) spawnScreenOKButton = guiCreateButton(x3,y3,w3,h3,'Done',false,spawnScreenMenu) guiSetVisible(spawnScreenMenu,false) for i=1,#data do local row = guiGridListAddRow(spawnScreenGridList) guiGridListSetItemText(spawnScreenGridList,row,1,data[i][1],false,false) guiGridListSetItemText(spawnScreenGridList,row,2,data[i][2],false,false) end -- Command to launch the GUI addCommandHandler('idselection',function() if guiGetVisible(spawnScreenMenu) then guiSetVisible(spawnScreenMenu,false) showCursor(false) else guiSetVisible(spawnScreenMenu,true) showCursor(true) end end) addEventHandler('onClientGUIClick',spawnScreenOKButton,function() guiSetVisible(spawnScreenMenu,false) showCursor(false) end) I've added a relative function, you'll have to change the resolution as well as the numbers in the relative() functions to match your resolution, after that they should be working just fine, inputting absolute values and getting relative values, I just tested this code and it is working perfectly. I did this whole relative thing because MTA relative values are only based off of your resolution, I made it so its based off of all resolutions, that way you wont have any problems with resizing or moving the GUI on another persons screen. It'll look the same on your screen as a phone screen haha. Have a nice day. it works very well. Thank you very much for me help Link to comment
ÆBKV Posted January 2, 2018 Share Posted January 2, 2018 (edited) addEventHandler("onClientGUIClick",root, function() if source == spawnScreenOKButton then guiSetVisible(spawnScreenMenu,false) showCursor(false) end end ) Edited January 2, 2018 by ÆBKV 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