Suerte Posted June 9, 2009 Posted June 9, 2009 I decided to learn how to make a GUI today and it's coming along nicely. Just one thing, though.. I can't link up a fuction with a button on the GUI. Here is my code: function createWindow () outputChatBox("The buy menu is open! Make sure nobody attacks you.",255,0,255,255) mygui = guiCreateWindow(0.08, 0.18, 0.2, 0.3, "BUY MENU", true) showCursor(true) local X = 0.375 local Y = 0.375 local Width = 0.25 local Height = 0.25 buym4 = guiCreateButton(0.05, 0.1, 0.3, 0.1, "M4", true, mygui) buyak = guiCreateButton(0.05, 0.2, 0.3, 0.1, "AK47", true, mygui) buyde = guiCreateButton(0.05, 0.3, 0.3, 0.1, "Deagle", true, mygui) buypi = guiCreateButton(0.05, 0.4, 0.3, 0.1, "Pistol", true, mygui) buysi = guiCreateButton(0.05, 0.5, 0.3, 0.1, "Silenced", true, mygui) buymp = guiCreateButton(0.05, 0.6, 0.3, 0.1, "Mp5", true, mygui) buysn = guiCreateButton(0.05, 0.7, 0.3, 0.1, "Sniper", true, mygui) btnExit = guiCreateButton( 0.05, 0.8, 0.9, 0.2, "Exit", true, mygui ) guiCreateLabel(0.4,0.12, 0.5, 0.1, "$2000 for 50 bullets", true, mygui) guiCreateLabel(0.4,0.22, 0.5, 0.1, "$2000 for 40 bullets", true, mygui) guiCreateLabel(0.4,0.32, 0.5, 0.1, "$750 for 90 bullets", true, mygui) guiCreateLabel(0.4,0.42, 0.5, 0.1, "$750 for 140 bullets", true, mygui) guiCreateLabel(0.4,0.52, 0.5, 0.1, "$750 for 120 bullets", true, mygui) guiCreateLabel(0.4,0.62, 0.5, 0.1, "$1000 for 90 bullets", true, mygui) guiCreateLabel(0.4,0.72, 0.5, 0.1, "$1000 for 100 bullets", true, mygui) end addCommandHandler( "gui", createWindow ) function hide (button) outputChatBox("No") end addEventHandler ( "onClientGUIClick", btnExit, hide, false ) I'm trying to make it so that, when you click "Exit", the event handler will make it go to function 'hide'.
[DKR]silverfang Posted June 9, 2009 Posted June 9, 2009 Move the event handler into the create window function after you create the exit button.
knash94 Posted June 9, 2009 Posted June 9, 2009 function hide () guiSetVisible ( mygui, false ) showCursor( false ) end function createWindow () outputChatBox("The buy menu is open! Make sure nobody attacks you.",255,0,255,255) mygui = guiCreateWindow(0.08, 0.18, 0.2, 0.3, "BUY MENU", true) showCursor(true) local X = 0.375 local Y = 0.375 local Width = 0.25 local Height = 0.25 buym4 = guiCreateButton(0.05, 0.1, 0.3, 0.1, "M4", true, mygui) buyak = guiCreateButton(0.05, 0.2, 0.3, 0.1, "AK47", true, mygui) buyde = guiCreateButton(0.05, 0.3, 0.3, 0.1, "Deagle", true, mygui) buypi = guiCreateButton(0.05, 0.4, 0.3, 0.1, "Pistol", true, mygui) buysi = guiCreateButton(0.05, 0.5, 0.3, 0.1, "Silenced", true, mygui) buymp = guiCreateButton(0.05, 0.6, 0.3, 0.1, "Mp5", true, mygui) buysn = guiCreateButton(0.05, 0.7, 0.3, 0.1, "Sniper", true, mygui) btnExit = guiCreateButton( 0.05, 0.8, 0.9, 0.2, "Exit", true, mygui ) guiCreateLabel(0.4,0.12, 0.5, 0.1, "$2000 for 50 bullets", true, mygui) guiCreateLabel(0.4,0.22, 0.5, 0.1, "$2000 for 40 bullets", true, mygui) guiCreateLabel(0.4,0.32, 0.5, 0.1, "$750 for 90 bullets", true, mygui) guiCreateLabel(0.4,0.42, 0.5, 0.1, "$750 for 140 bullets", true, mygui) guiCreateLabel(0.4,0.52, 0.5, 0.1, "$750 for 120 bullets", true, mygui) guiCreateLabel(0.4,0.62, 0.5, 0.1, "$1000 for 90 bullets", true, mygui) guiCreateLabel(0.4,0.72, 0.5, 0.1, "$1000 for 100 bullets", true, mygui) addEventHandler( "onClientGUIClick", btnExit, hide ) end addCommandHandler( "gui", createWindow ) That should be it. If it dont work. Just say
Suerte Posted June 9, 2009 Author Posted June 9, 2009 Yes! You were both right. Thankyou very much. By the way, how do I use giveWeapon in a client LUA? It doesn't seem to work I can't find another command anywhere on the wiki edit: might have a solution!
50p Posted June 9, 2009 Posted June 9, 2009 Yes! You were both right. Thankyou very much.By the way, how do I use giveWeapon in a client LUA? It doesn't seem to work I can't find another command anywhere on the wiki There is no such function client-side. http://development.mtasa.com/index.php?title=GiveWeapon Server-only function BTW, if you want to create GUI easier then try my GUI lib created specially for you! You will find it easy. You won't have to use addEventHandler but :AddOnClick. Your code would look like this: function hide( ) myWnd:Visible( false ); showCursor( false ); end function createWindow( ) showCursor( true ); myWnd = Window:Create( .08, .18, .2, .3, "BUY MENU", true ); buym4 = myWnd:AddButton( .05, .1, .3, .1, "M4", true ); buyak = myWnd:AddButton( .05, .2, .3, .1, "AK47", true ); buyde = myWnd:AddButton( .05, .3, .3, .1, "Deagle", true ); buypi = myWnd:AddButton( .05, .4, .3, .1, "Pistol", true ); buysi = myWnd:AddButton( .05, .5, .3, .1, "Silenced", true ); buymp = myWnd:AddButton( .05, .6, .3, .1, "Mp5", true ); buysn = myWnd:AddButton( .05, .7, .3, .1, "Sniper", true ); exitBtn = myWnd:AddButton( .05, .8, .3, .1, "Exit", true ); exitBtn:AddOnClick( hide ); -- size for AddLabel() is not required because size will be as big as text size myWnd:AddLabel( .4, .12, "$2000 for 50 bullets", true ); myWnd:AddLabel( .4, .22, "$2000 for 40 bullets", true ); myWnd:AddLabel( .4, .32, "$750 for 90 bullets", true ); myWnd:AddLabel( .4, .42, "$750 for 140 bullets", true ); myWnd:AddLabel( .4, .52, "$750 for 120 bullets", true ); myWnd:AddLabel( .4, .62, "$1000 for 90 bullets", true ); myWnd:AddLabel( .4, .72, "$1000 for 100 bullets", true ); end addCommandHandler( "gui", createWindow ) I'd recommend binding key for showing hiding the GUI and create the GUI when resource starts.
darkdreamingdan Posted June 10, 2009 Posted June 10, 2009 function hide () guiSetVisible ( mygui, false ) showCursor( false ) end function createWindow () outputChatBox("The buy menu is open! Make sure nobody attacks you.",255,0,255,255) mygui = guiCreateWindow(0.08, 0.18, 0.2, 0.3, "BUY MENU", true) showCursor(true) local X = 0.375 local Y = 0.375 local Width = 0.25 local Height = 0.25 buym4 = guiCreateButton(0.05, 0.1, 0.3, 0.1, "M4", true, mygui) buyak = guiCreateButton(0.05, 0.2, 0.3, 0.1, "AK47", true, mygui) buyde = guiCreateButton(0.05, 0.3, 0.3, 0.1, "Deagle", true, mygui) buypi = guiCreateButton(0.05, 0.4, 0.3, 0.1, "Pistol", true, mygui) buysi = guiCreateButton(0.05, 0.5, 0.3, 0.1, "Silenced", true, mygui) buymp = guiCreateButton(0.05, 0.6, 0.3, 0.1, "Mp5", true, mygui) buysn = guiCreateButton(0.05, 0.7, 0.3, 0.1, "Sniper", true, mygui) btnExit = guiCreateButton( 0.05, 0.8, 0.9, 0.2, "Exit", true, mygui ) guiCreateLabel(0.4,0.12, 0.5, 0.1, "$2000 for 50 bullets", true, mygui) guiCreateLabel(0.4,0.22, 0.5, 0.1, "$2000 for 40 bullets", true, mygui) guiCreateLabel(0.4,0.32, 0.5, 0.1, "$750 for 90 bullets", true, mygui) guiCreateLabel(0.4,0.42, 0.5, 0.1, "$750 for 140 bullets", true, mygui) guiCreateLabel(0.4,0.52, 0.5, 0.1, "$750 for 120 bullets", true, mygui) guiCreateLabel(0.4,0.62, 0.5, 0.1, "$1000 for 90 bullets", true, mygui) guiCreateLabel(0.4,0.72, 0.5, 0.1, "$1000 for 100 bullets", true, mygui) addEventHandler( "onClientGUIClick", btnExit, hide ) end addCommandHandler( "gui", createWindow ) That should be it. If it dont work. Just say You havent set the propogated argument in addEventHandler to "false". This means that the event is propogated down from its parents when fired. The implications of this are that clicking the window rather than the button will also trigger this handler.
50p Posted June 10, 2009 Posted June 10, 2009 That's why use my GUI classes where you don't have to worry about addEventHandler and all its parameters, just AddOnClick( funcName ).
knash94 Posted June 10, 2009 Posted June 10, 2009 Well ive learnt a lesson. Thank you I aint a god at lua so i try my best and i know how annoying it is when you dont know how to do a script and i enjoy helping people that need the help. Thats why i joined the forums... MTA is also a good comunity.
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