Jaysds1 Posted May 18, 2011 Share Posted May 18, 2011 I need help on how to create a link from a button to another Gui. Example: If the person clicks on register button and goes on to the register gui. Link to comment
Castillo Posted May 18, 2011 Share Posted May 18, 2011 function onClick() guiSetVisible(myWindow,true) end addEventHandler("onClientGUIClick",yourButtonElement,onClick,false) Do you mean that? Link to comment
Jaysds1 Posted May 19, 2011 Author Share Posted May 19, 2011 No Say I was a new member and I was trying to register my account, right now it's on the Login GUI and if I clicked the Register Button on the Login GUI, I want it to go to the register Gui then the login after. Link to comment
Castillo Posted May 19, 2011 Share Posted May 19, 2011 Woot? i gave you the code to do that... , as far as i understand you want to show up the register window when he click's on some button called "Register", right? Post your full code here. Link to comment
Jaysds1 Posted May 19, 2011 Author Share Posted May 19, 2011 When people register on Register GUI and it closes and go to the Login Gui and login the gui is still shown. How do you put it down too? Link to comment
Jaysds1 Posted May 19, 2011 Author Share Posted May 19, 2011 Here -- Login/Register local newUser local localPlayer = getLocalPlayer() local localPlayerName = getPlayerName(localPlayer) local localRootElement = getRootElement() local passwordAttempts = 0 GUIEditor_Window = {} GUIEditor_Button = {} GUIEditor_Edit = {} function CreateLoginWindow() GUIEditor_Window[1] = guiCreateWindow(230,160,336,265,"J Login",false) guiSetAlpha(GUIEditor_Window[1],1) guiWindowSetMovable(GUIEditor_Window[1],false) guiWindowSetSizable(GUIEditor_Window[1],false) -- Buttons GUIEditor_Button[1] = guiCreateButton(22,184,143,40,"Login",false,GUIEditor_Window[1]) GUIEditor_Button[2] = guiCreateButton(201,184,123,44,"Register",false,GUIEditor_Window[1]) -- Labels guiCreateLabel(35,48,87,21,"Username:",false,GUIEditor_Window[1]) guiCreateLabel(37,90,53,17,"Password:",false,GUIEditor_Window[1]) -- Type in... GUIEditor_Edit[1] = guiCreateEdit(133,45,171,27,"",false,GUIEditor_Window[1]) guiEditSetMaxLength(GUIEditor_Edit[1],23) GUIEditor_Edit[2] = guiCreateEdit(128,95,186,28,"",false,GUIEditor_Window[1]) guiEditSetMasked(GUIEditor_Edit[2],true) guiEditSetMaxLength(GUIEditor_Edit[2],13) end GUIEditor_Window = {} GUIEditor_Button = {} GUIEditor_Edit = {} function CreateRegisterWindow() GUIEditor_Window[1] = guiCreateWindow(197,122,369,330,"Register",false) guiSetAlpha(GUIEditor_Window[1],1) guiWindowSetMovable(GUIEditor_Window[1],false) guiWindowSetSizable(GUIEditor_Window[1],false) guiCreateLabel(39,48,64,15,"Username:",false,GUIEditor_Window[1]) guiCreateLabel(43,119,66,15,"Password:",false,GUIEditor_Window[1]) -- Type in... GUIEditor_Edit[1] = guiCreateEdit(122,49,205,26,"",false,GUIEditor_Window[1]) guiEditSetMaxLength(GUIEditor_Edit[1],23) GUIEditor_Edit[2] = guiCreateEdit(121,114,205,29,"",false,GUIEditor_Window[1]) guiEditSetMasked(GUIEditor_Edit[2],true) guiEditSetMaxLength(GUIEditor_Edit[2],13) -- Image guiCreateStaticImage(19,168,117,114,"images/mtalogo.png",false,GUIEditor_Window[1]) -- Buton GUIEditor_Button[1] = guiCreateButton(154,270,111,45,"Login",false,GUIEditor_Window[1]) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() CreateLoginWindow() -- if the GUI was successfully created, then show the GUI to the player if (GUIEditor_Window[1] ~= nil) then guiSetVisible(GUIEditor_Window[1], true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening guiSetInputEnabled(true) -- now add our onClientGUIClick event to the button we just created addEventHandler("onClientGUIClick",GUIEditor_Button[1], clientSubmitLogin, false) addEventHandler("onClientGUIClick",GUIEditor_Button[2], clientClickReg,false) end ) -- create the function and define the 'button' and 'state' parameters -- (these are passed automatically by onClientGUIClick) function clientSubmitLogin(button,state) if button == "left" and state == "up" then -- get the text entered in the 'username' field local username = guiGetText(GUIEditor_Edit[1]) -- get the text entered in the 'password' field local password = guiGetText(GUIEditor_Edit[2]) -- if the username and password both exist if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it triggerServerEvent("submitLogin", getRootElement(), username, password) -- hide the gui, hide the cursor and return control to the player guiSetInputEnabled(false) guiSetVisible(GUIEditor_Window[1], false) showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui outputChatBox("Please enter a username and password.") end end end function clientClickReg() guiSetVisible(CreateRegisterWindow(),true) if (GUIEditor_Window[1] ~= nil) then guiSetVisible(GUIEditor_Window[1], true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening guiSetInputEnabled(true) -- now add our onClientGUIClick event to the button we just created addEventHandler("onClientGUIClick",GUIEditor_Button[1], clientSubmitRegister, false) end -- create the function and define the 'button' and 'state' parameters -- (these are passed automatically by onClientGUIClick) function clientSubmitRegister(button,state) if button == "left" and state == "up" then -- get the text entered in the 'username' field local username = guiGetText(GUIEditor_Edit[1]) -- get the text entered in the 'password' field local password = guiGetText(GUIEditor_Edit[2]) -- if the username and password both exist if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it triggerServerEvent("submitRegister", getRootElement(), username, password) -- hide the gui, hide the cursor and return control to the player guiSetInputEnabled(false) guiSetVisible(GUIEditor_Window[1], false) showCursor(false) end end end Link to comment
Castillo Posted May 19, 2011 Share Posted May 19, 2011 Try this: -- Login/Register local newUser local localPlayer = getLocalPlayer() local localPlayerName = getPlayerName(localPlayer) local localRootElement = getRootElement() local passwordAttempts = 0 GUIEditor_Window = {} GUIEditor_Button = {} GUIEditor_Edit = {} function CreateLoginWindow() GUIEditor_Window[1] = guiCreateWindow(230,160,336,265,"J Login",false) guiSetAlpha(GUIEditor_Window[1],1) guiWindowSetMovable(GUIEditor_Window[1],false) guiWindowSetSizable(GUIEditor_Window[1],false) -- Buttons GUIEditor_Button[1] = guiCreateButton(22,184,143,40,"Login",false,GUIEditor_Window[1]) GUIEditor_Button[2] = guiCreateButton(201,184,123,44,"Register",false,GUIEditor_Window[1]) -- Labels guiCreateLabel(35,48,87,21,"Username:",false,GUIEditor_Window[1]) guiCreateLabel(37,90,53,17,"Password:",false,GUIEditor_Window[1]) -- Type in... GUIEditor_Edit[1] = guiCreateEdit(133,45,171,27,"",false,GUIEditor_Window[1]) guiEditSetMaxLength(GUIEditor_Edit[1],23) GUIEditor_Edit[2] = guiCreateEdit(128,95,186,28,"",false,GUIEditor_Window[1]) guiEditSetMasked(GUIEditor_Edit[2],true) guiEditSetMaxLength(GUIEditor_Edit[2],13) end function CreateRegisterWindow() GUIEditor_Window[2] = guiCreateWindow(197,122,369,330,"Register",false) guiSetAlpha(GUIEditor_Window[2],1) guiWindowSetMovable(GUIEditor_Window[2],false) guiWindowSetSizable(GUIEditor_Window[2],false) guiCreateLabel(39,48,64,15,"Username:",false,GUIEditor_Window[2]) guiCreateLabel(43,119,66,15,"Password:",false,GUIEditor_Window[2]) -- Type in... GUIEditor_Edit[3] = guiCreateEdit(122,49,205,26,"",false,GUIEditor_Window[2]) guiEditSetMaxLength(GUIEditor_Edit[3],23) GUIEditor_Edit[4] = guiCreateEdit(121,114,205,29,"",false,GUIEditor_Window[2]) guiEditSetMasked(GUIEditor_Edit[4],true) guiEditSetMaxLength(GUIEditor_Edit[4],13) -- Image guiCreateStaticImage(19,168,117,114,"images/mtalogo.png",false,GUIEditor_Window[2]) -- Buton GUIEditor_Button[2] = guiCreateButton(154,270,111,45,"Login",false,GUIEditor_Window[2]) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() CreateLoginWindow() -- if the GUI was successfully created, then show the GUI to the player if (GUIEditor_Window[1] ~= nil) then guiSetVisible(GUIEditor_Window[1], true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening guiSetInputEnabled(true) -- now add our onClientGUIClick event to the button we just created addEventHandler("onClientGUIClick",GUIEditor_Button[1], clientSubmitLogin, false) addEventHandler("onClientGUIClick",GUIEditor_Button[2], clientClickReg,false) end ) -- create the function and define the 'button' and 'state' parameters -- (these are passed automatically by onClientGUIClick) function clientSubmitLogin(button,state) if button == "left" and state == "up" then -- get the text entered in the 'username' field local username = guiGetText(GUIEditor_Edit[1]) -- get the text entered in the 'password' field local password = guiGetText(GUIEditor_Edit[2]) -- if the username and password both exist if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it triggerServerEvent("submitLogin", getRootElement(), username, password) -- hide the gui, hide the cursor and return control to the player guiSetInputEnabled(false) guiSetVisible(GUIEditor_Window[1], false) showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui outputChatBox("Please enter a username and password.") end end end function clientClickReg() CreateRegisterWindow() if (GUIEditor_Window[2] ~= nil) then guiSetVisible(GUIEditor_Window[2], true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening guiSetInputEnabled(true) -- now add our onClientGUIClick event to the button we just created addEventHandler("onClientGUIClick",GUIEditor_Button[2], clientSubmitRegister, false) end -- create the function and define the 'button' and 'state' parameters -- (these are passed automatically by onClientGUIClick) function clientSubmitRegister(button,state) if button == "left" and state == "up" then -- get the text entered in the 'username' field local username = guiGetText(GUIEditor_Edit[3]) -- get the text entered in the 'password' field local password = guiGetText(GUIEditor_Edit[4]) -- if the username and password both exist if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it triggerServerEvent("submitRegister", getRootElement(), username, password) -- hide the gui, hide the cursor and return control to the player guiSetInputEnabled(false) guiSetVisible(GUIEditor_Window[2], false) showCursor(false) end end end Link to comment
Jaysds1 Posted May 19, 2011 Author Share Posted May 19, 2011 it didn't work. This time it removed the cursor when it went back on to the Login GUI. Link to comment
Jaysds1 Posted May 19, 2011 Author Share Posted May 19, 2011 Server-side --Login/Register Gui function clientAttemptLogin(username,password) local userAccount = getAccount(username) local tryToLog if (client) then tryToLog = logIn(client,userAccount,password) if (tryToLog) then spawnPlayer(client,x,y,z) fadeCamera(client,true) end end end addEvent("submitLogin",true) addEventHandler("submitLogin",root,loginHandler) function clientAttemptCreate(username,password) if (username ~= "" and password ~= "") then addAccount(username,password) outputChatBox("ACCOUNT CREATED, NOW LOGIN!", client) else outputChatBox("REGISTER WASN'T SUCCESSFUL!", client) end end addEvent("submitRegister",true) addEventHandler("submitRegister",getRootElement(),clientAttemptCreate) Link to comment
Castillo Posted May 19, 2011 Share Posted May 19, 2011 -- Login/Register local newUser local localPlayer = getLocalPlayer() local localPlayerName = getPlayerName(localPlayer) local localRootElement = getRootElement() local passwordAttempts = 0 GUIEditor_Window = {} GUIEditor_Button = {} GUIEditor_Edit = {} function CreateLoginWindow() GUIEditor_Window[1] = guiCreateWindow(230,160,336,265,"J Login",false) guiSetAlpha(GUIEditor_Window[1],1) guiWindowSetMovable(GUIEditor_Window[1],false) guiWindowSetSizable(GUIEditor_Window[1],false) -- Buttons GUIEditor_Button[1] = guiCreateButton(22,184,143,40,"Login",false,GUIEditor_Window[1]) GUIEditor_Button[2] = guiCreateButton(201,184,123,44,"Register",false,GUIEditor_Window[1]) -- Labels guiCreateLabel(35,48,87,21,"Username:",false,GUIEditor_Window[1]) guiCreateLabel(37,90,53,17,"Password:",false,GUIEditor_Window[1]) -- Type in... GUIEditor_Edit[1] = guiCreateEdit(133,45,171,27,"",false,GUIEditor_Window[1]) guiEditSetMaxLength(GUIEditor_Edit[1],23) GUIEditor_Edit[2] = guiCreateEdit(128,95,186,28,"",false,GUIEditor_Window[1]) guiEditSetMasked(GUIEditor_Edit[2],true) guiEditSetMaxLength(GUIEditor_Edit[2],13) end function CreateRegisterWindow() GUIEditor_Window[2] = guiCreateWindow(197,122,369,330,"Register",false) guiSetAlpha(GUIEditor_Window[2],1) guiWindowSetMovable(GUIEditor_Window[2],false) guiWindowSetSizable(GUIEditor_Window[2],false) guiCreateLabel(39,48,64,15,"Username:",false,GUIEditor_Window[2]) guiCreateLabel(43,119,66,15,"Password:",false,GUIEditor_Window[2]) -- Type in... GUIEditor_Edit[3] = guiCreateEdit(122,49,205,26,"",false,GUIEditor_Window[2]) guiEditSetMaxLength(GUIEditor_Edit[3],23) GUIEditor_Edit[4] = guiCreateEdit(121,114,205,29,"",false,GUIEditor_Window[2]) guiEditSetMasked(GUIEditor_Edit[4],true) guiEditSetMaxLength(GUIEditor_Edit[4],13) -- Image guiCreateStaticImage(19,168,117,114,"images/mtalogo.png",false,GUIEditor_Window[2]) -- Buton GUIEditor_Button[2] = guiCreateButton(154,270,111,45,"Login",false,GUIEditor_Window[2]) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() CreateLoginWindow() -- if the GUI was successfully created, then show the GUI to the player if (GUIEditor_Window[1] ~= nil) then guiSetVisible(GUIEditor_Window[1], true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening guiSetInputEnabled(true) -- now add our onClientGUIClick event to the button we just created addEventHandler("onClientGUIClick",GUIEditor_Button[1], clientSubmitLogin, false) addEventHandler("onClientGUIClick",GUIEditor_Button[2], clientClickReg,false) end ) -- create the function and define the 'button' and 'state' parameters -- (these are passed automatically by onClientGUIClick) function clientSubmitLogin(button,state) if button == "left" and state == "up" then -- get the text entered in the 'username' field local username = guiGetText(GUIEditor_Edit[1]) -- get the text entered in the 'password' field local password = guiGetText(GUIEditor_Edit[2]) -- if the username and password both exist if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it triggerServerEvent("submitLogin", getRootElement(), username, password) -- hide the gui, hide the cursor and return control to the player guiSetInputEnabled(false) guiSetVisible(GUIEditor_Window[1], false) showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui outputChatBox("Please enter a username and password.") end end end function clientClickReg() CreateRegisterWindow() if (GUIEditor_Window[2] ~= nil) then guiSetVisible(GUIEditor_Window[2], true) else -- if the GUI hasnt been properly created, tell the player outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end -- enable the players cursor (so they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening guiSetInputEnabled(true) -- now add our onClientGUIClick event to the button we just created addEventHandler("onClientGUIClick",GUIEditor_Button[2], clientSubmitRegister, false) end -- create the function and define the 'button' and 'state' parameters -- (these are passed automatically by onClientGUIClick) function clientSubmitRegister(button,state) if button == "left" and state == "up" then -- get the text entered in the 'username' field local username = guiGetText(GUIEditor_Edit[3]) -- get the text entered in the 'password' field local password = guiGetText(GUIEditor_Edit[4]) -- if the username and password both exist if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it triggerServerEvent("submitRegister", getRootElement(), username, password) -- hide the gui, hide the cursor and return control to the player guiSetVisible(GUIEditor_Window[2], false) guiSetVisible(GUIEditor_Window[1], false) end end end As far as I understand, you want to show the Login window after register, right? if so, that should work fine. Link to comment
Jaysds1 Posted May 19, 2011 Author Share Posted May 19, 2011 now I'm trying to change something in here and it's the server-side If a person all ready has and account and someone else want's it. How do you stop them from taking the reserved Username? Link to comment
karlis Posted May 28, 2011 Share Posted May 28, 2011 if not getAccount(name) then --register end Link to comment
Jaysds1 Posted May 28, 2011 Author Share Posted May 28, 2011 thnx and how do you make a button that makes the person logout? Link to comment
karlis Posted May 28, 2011 Share Posted May 28, 2011 do you know what wiki is? https://wiki.multitheftauto.com/ 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