Xeno Posted January 22, 2010 Share Posted January 22, 2010 im making a login gui and im a bit stuck.... look addEventHandler("onClientGUIClick",Cancel,CreateLoginWindow,false) function CreateLoginWindow() wdwLogin = guiCreateWindow(226,146,372,233,"[Admin Login System]",false) guiWindowSetMovable(wdwLogin,false) guiWindowSetSizable(wdwLogin,false) tabpanel = guiCreateTabPanel(0.0242,0.0858,0.9489,0.8755,true,wdwLogin) tab1 = guiCreateTab("Login",tabpanel) login = guiCreateButton(0.1000,0.8611,0.2436,0.1167,"Login",true,tab1) username = guiCreateLabel(0.0113,0.1167,0.3768,0.15,"UserName:",true,tab1) guiLabelSetColor(username,255,255,255) guiLabelSetVerticalAlign(username,"top") guiLabelSetHorizontalAlign(username,"left",false) guiSetFont(username,"default-bold-small") password = guiCreateLabel(0.0113,0.2889,0.3768,0.15,"Password:",true,tab1) guiLabelSetColor(password,255,255,255) guiLabelSetVerticalAlign(password,"top") guiLabelSetHorizontalAlign(password,"left",false) guiSetFont(password,"default-bold-small") username = guiCreateEdit(0.2266,0.1,0.3598,0.1389,localPlayerName,true,tab1) password = guiCreateEdit(0.2266,0.2611,0.3598,0.1389,"",true,tab1) Canel = guiCreateButton( 0.4, 0.85, 0.20, 0.15, "Cancel", true,tab1 ) guiEditSetMasked(password,true) tab2 = guiCreateTab("Info",tabpanel) guiSetVisible(wdwLogin,false) end Im trying to make the cancel button work so it cancels the window Link to comment
Xeno Posted January 22, 2010 Author Share Posted January 22, 2010 im making a login gui and im a bit stuck.... look addEventHandler("onClientGUIClick",Cancel,CreateLoginWindow,false) function CreateLoginWindow() wdwLogin = guiCreateWindow(226,146,372,233,"[Admin Login System]",false) guiWindowSetMovable(wdwLogin,false) guiWindowSetSizable(wdwLogin,false) tabpanel = guiCreateTabPanel(0.0242,0.0858,0.9489,0.8755,true,wdwLogin) tab1 = guiCreateTab("Login",tabpanel) login = guiCreateButton(0.1000,0.8611,0.2436,0.1167,"Login",true,tab1) username = guiCreateLabel(0.0113,0.1167,0.3768,0.15,"UserName:",true,tab1) guiLabelSetColor(username,255,255,255) guiLabelSetVerticalAlign(username,"top") guiLabelSetHorizontalAlign(username,"left",false) guiSetFont(username,"default-bold-small") password = guiCreateLabel(0.0113,0.2889,0.3768,0.15,"Password:",true,tab1) guiLabelSetColor(password,255,255,255) guiLabelSetVerticalAlign(password,"top") guiLabelSetHorizontalAlign(password,"left",false) guiSetFont(password,"default-bold-small") username = guiCreateEdit(0.2266,0.1,0.3598,0.1389,localPlayerName,true,tab1) password = guiCreateEdit(0.2266,0.2611,0.3598,0.1389,"",true,tab1) Canel = guiCreateButton( 0.4, 0.85, 0.20, 0.15, "Cancel", true,tab1 ) guiEditSetMasked(password,true) tab2 = guiCreateTab("Info",tabpanel) guiSetVisible(wdwLogin,false) end Im trying to make the cancel button work so it cancels the window Link to comment
dzek (varez) Posted January 22, 2010 Share Posted January 22, 2010 wow, a messy code.. try to get basics of Lua, its probably your 1st script and its too hard, i think you dont know any progamming logic function HideWindow() guiSetVisible(wdwLogin,false) showCursor (false) -- you forgeet about this end function createWindow ( res ) -- this function creates a login window and show the cursor wdwLogin = guiCreateWindow(226,146,372,233,"[Admin Login System]",false) guiWindowSetMovable(wdwLogin,false) guiWindowSetSizable(wdwLogin,false) tabpanel = guiCreateTabPanel(0.0242,0.0858,0.9489,0.8755,true,wdwLogin) tab1 = guiCreateTab("Login",tabpanel) login = guiCreateButton(0.1000,0.8611,0.2436,0.1167,"Login",true,tab1) username = guiCreateLabel(0.0113,0.1167,0.3768,0.15,"UserName:",true,tab1) guiLabelSetColor(username,255,255,255) guiLabelSetVerticalAlign(username,"top") guiLabelSetHorizontalAlign(username,"left",false) guiSetFont(username,"default-bold-small") password = guiCreateLabel(0.0113,0.2889,0.3768,0.15,"Password:",true,tab1) guiLabelSetColor(password,255,255,255) guiLabelSetVerticalAlign(password,"top") guiLabelSetHorizontalAlign(password,"left",false) guiSetFont(password,"default-bold-small") username = guiCreateEdit(0.2266,0.1,0.3598,0.1389,localPlayerName,true,tab1) password = guiCreateEdit(0.2266,0.2611,0.3598,0.1389,"",true,tab1) Canel = guiCreateButton( 0.4, 0.85, 0.20, 0.15, "Cancel", true,tab1 ) guiEditSetMasked(password,true) tab2 = guiCreateTab("Info",tabpanel) showCursor (true) -- you forgot about this addEventHandler("onClientGUIClick",Cancel,HideWindow,false) -- "HideWindow" will be fired when somebody hits cancel end addEventHandler ( "onResourceStart", getRootElement(), createWindow ) -- "createWindow" will be fired when resource starts/player join that is better, right? download MTA Script Editor, it will help you a lot, really and dont forget about https://wiki.multitheftauto.com/wiki/Main_Page (on the menu on the left, there are useful lists of Events/Functions) good luck ps. SCRIPT ABOVE NOT TESTED, if you messed something more than i think, try to fix it by yourself Link to comment
dzek (varez) Posted January 22, 2010 Share Posted January 22, 2010 wow, a messy code.. try to get basics of Lua, its probably your 1st script and its too hard, i think you dont know any progamming logic function HideWindow() guiSetVisible(wdwLogin,false) showCursor (false) -- you forgeet about this end function createWindow ( res ) -- this function creates a login window and show the cursor wdwLogin = guiCreateWindow(226,146,372,233,"[Admin Login System]",false) guiWindowSetMovable(wdwLogin,false) guiWindowSetSizable(wdwLogin,false) tabpanel = guiCreateTabPanel(0.0242,0.0858,0.9489,0.8755,true,wdwLogin) tab1 = guiCreateTab("Login",tabpanel) login = guiCreateButton(0.1000,0.8611,0.2436,0.1167,"Login",true,tab1) username = guiCreateLabel(0.0113,0.1167,0.3768,0.15,"UserName:",true,tab1) guiLabelSetColor(username,255,255,255) guiLabelSetVerticalAlign(username,"top") guiLabelSetHorizontalAlign(username,"left",false) guiSetFont(username,"default-bold-small") password = guiCreateLabel(0.0113,0.2889,0.3768,0.15,"Password:",true,tab1) guiLabelSetColor(password,255,255,255) guiLabelSetVerticalAlign(password,"top") guiLabelSetHorizontalAlign(password,"left",false) guiSetFont(password,"default-bold-small") username = guiCreateEdit(0.2266,0.1,0.3598,0.1389,localPlayerName,true,tab1) password = guiCreateEdit(0.2266,0.2611,0.3598,0.1389,"",true,tab1) Canel = guiCreateButton( 0.4, 0.85, 0.20, 0.15, "Cancel", true,tab1 ) guiEditSetMasked(password,true) tab2 = guiCreateTab("Info",tabpanel) showCursor (true) -- you forgot about this addEventHandler("onClientGUIClick",Cancel,HideWindow,false) -- "HideWindow" will be fired when somebody hits cancel end addEventHandler ( "onResourceStart", getRootElement(), createWindow ) -- "createWindow" will be fired when resource starts/player join that is better, right? download MTA Script Editor, it will help you a lot, really and dont forget about https://wiki.multitheftauto.com/wiki/Main_Page (on the menu on the left, there are useful lists of Events/Functions) good luck ps. SCRIPT ABOVE NOT TESTED, if you messed something more than i think, try to fix it by yourself Link to comment
Robert333 Posted January 22, 2010 Share Posted January 22, 2010 Thats more clearly: function CreateLoginWindow() wdwLogin = guiCreateWindow( 226, 146, 372, 233, "[Admin Login System]", false ) guiSetVisible( wdwLogin, false ) guiWindowSetMovable( wdwLogin, false ) guiWindowSetSizable( wdwLogin, false ) tabpanel = guiCreateTabPanel( 0.0242, 0.0858, 0.9489, 0.8755, true, wdwLogin ) tab1 = guiCreateTab( "Login", tabpanel ) login = guiCreateButton( 0.1000, 0.8611, 0.2436, 0.1167, "Login", true, tab1 ) username = guiCreateLabel( 0.0113, 0.1167, 0.3768, 0.15, "UserName:", true,tab1 ) guiSetFont(username,"default-bold-small") password = guiCreateLabel( 0.0113, 0.2889, 0.3768, 0.15, "Password:", true, tab1 ) guiSetFont( password, "default-bold-small" ) username = guiCreateEdit( 0.2266, 0.1, 0.3598, 0.1389, localPlayerName, true, tab1 ) password = guiCreateEdit( 0.2266, 0.2611, 0.3598, 0.1389,"", true, tab1 ) Cancel = guiCreateButton( 0.4, 0.85, 0.20, 0.15, "Cancel", true, tab1 ) -- you wrote "Canel" guiEditSetMasked( password, true ) tab2 = guiCreateTab( "Info", tabpanel ) addEventHandler( "onClientGUIClick", Cancel, CloseLoginWindow, false ) -- You must add the EventHandler in function, because before the button-element is nil -- call a new function for closing Window, but first you need a function to show the window, because of "guiSetVisible( wdwLogin, false )" in the top of this function end function openLoginWindow() -- call it when it should open, maybe with the Event "onClientResourceStart" guiSetVisible( wdwLogin, true ) showCursor( true ) -- You need this for clicking the Button end function closeLoginWindow() guiSetVisible( wdwLogin, false ) showCursor( false ) end You don't need to do this functions: tomdrum11 said: guiLabelSetColor(username,255,255,255)guiLabelSetVerticalAlign(username,"top") guiLabelSetHorizontalAlign(username,"left",false) Because that Arguments are the defaults of Labels I mean. // edit: I was too slow Link to comment
Robert333 Posted January 22, 2010 Share Posted January 22, 2010 Thats more clearly: function CreateLoginWindow() wdwLogin = guiCreateWindow( 226, 146, 372, 233, "[Admin Login System]", false ) guiSetVisible( wdwLogin, false ) guiWindowSetMovable( wdwLogin, false ) guiWindowSetSizable( wdwLogin, false ) tabpanel = guiCreateTabPanel( 0.0242, 0.0858, 0.9489, 0.8755, true, wdwLogin ) tab1 = guiCreateTab( "Login", tabpanel ) login = guiCreateButton( 0.1000, 0.8611, 0.2436, 0.1167, "Login", true, tab1 ) username = guiCreateLabel( 0.0113, 0.1167, 0.3768, 0.15, "UserName:", true,tab1 ) guiSetFont(username,"default-bold-small") password = guiCreateLabel( 0.0113, 0.2889, 0.3768, 0.15, "Password:", true, tab1 ) guiSetFont( password, "default-bold-small" ) username = guiCreateEdit( 0.2266, 0.1, 0.3598, 0.1389, localPlayerName, true, tab1 ) password = guiCreateEdit( 0.2266, 0.2611, 0.3598, 0.1389,"", true, tab1 ) Cancel = guiCreateButton( 0.4, 0.85, 0.20, 0.15, "Cancel", true, tab1 ) -- you wrote "Canel" guiEditSetMasked( password, true ) tab2 = guiCreateTab( "Info", tabpanel ) addEventHandler( "onClientGUIClick", Cancel, CloseLoginWindow, false ) -- You must add the EventHandler in function, because before the button-element is nil -- call a new function for closing Window, but first you need a function to show the window, because of "guiSetVisible( wdwLogin, false )" in the top of this function end function openLoginWindow() -- call it when it should open, maybe with the Event "onClientResourceStart" guiSetVisible( wdwLogin, true ) showCursor( true ) -- You need this for clicking the Button end function closeLoginWindow() guiSetVisible( wdwLogin, false ) showCursor( false ) end You don't need to do this functions: tomdrum11 said: guiLabelSetColor(username,255,255,255)guiLabelSetVerticalAlign(username,"top") guiLabelSetHorizontalAlign(username,"left",false) Because that Arguments are the defaults of Labels I mean. // edit: I was too slow Link to comment
subenji99 Posted January 22, 2010 Share Posted January 22, 2010 I'll just point this out too that was not mentioned in the code comments, as everyone makes this mistake. addEventHandler( "onClientGUIClick", Cancel, CloseLoginWindow, false ) Note the last argument is false. If you are familiar with the wiki description, you know that it is the "getPropagated" argument. If it was set to true, it would receive the click event from any parent or child of the button in the element tree. If you don't understand the element tree, it's worth learning, but I won't go into it now. What it results in is if the window is open, naturally your button is a "child" of the window. So with it set true, if you click anywhere within the window, the button will receive the event as if you clicked on the button itself. The mouse click event "propagated" down the element tree. And the problem is then multiplied with several GUIClick event handlers, if say, you had several buttons on this form and an event for each. getPropagated = false means the event has to directly involve this element - in this case, you have to click this button (your "Cancel" button element in the case of this code snippet) for the event to work. Note you use propagated all the time normally, so don't set it false all the time - for example any event attached to the root element is likely to use it, as a large majority of events don't trigger on the root element itself. (You may want to catch when any player is spawning for example, but that triggers on the player element involved.) Just remember to set it false when dealing with GUI. (I can't help making large posts) Link to comment
subenji99 Posted January 22, 2010 Share Posted January 22, 2010 I'll just point this out too that was not mentioned in the code comments, as everyone makes this mistake. addEventHandler( "onClientGUIClick", Cancel, CloseLoginWindow, false ) Note the last argument is false. If you are familiar with the wiki description, you know that it is the "getPropagated" argument. If it was set to true, it would receive the click event from any parent or child of the button in the element tree. If you don't understand the element tree, it's worth learning, but I won't go into it now. What it results in is if the window is open, naturally your button is a "child" of the window. So with it set true, if you click anywhere within the window, the button will receive the event as if you clicked on the button itself. The mouse click event "propagated" down the element tree. And the problem is then multiplied with several GUIClick event handlers, if say, you had several buttons on this form and an event for each. getPropagated = false means the event has to directly involve this element - in this case, you have to click this button (your "Cancel" button element in the case of this code snippet) for the event to work. Note you use propagated all the time normally, so don't set it false all the time - for example any event attached to the root element is likely to use it, as a large majority of events don't trigger on the root element itself. (You may want to catch when any player is spawning for example, but that triggers on the player element involved.) Just remember to set it false when dealing with GUI. (I can't help making large posts) Link to comment
dzek (varez) Posted January 23, 2010 Share Posted January 23, 2010 ive just copied this line, thinking its ok Link to comment
dzek (varez) Posted January 23, 2010 Share Posted January 23, 2010 ive just copied this line, thinking its ok Link to comment
Xeno Posted January 23, 2010 Author Share Posted January 23, 2010 Thanks guys i did it Link to comment
Xeno Posted January 23, 2010 Author Share Posted January 23, 2010 Thanks guys i did it 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