Jump to content

2 actions with one GUI Button


Recommended Posts

Hi I have a problem I am making a Login/register script the login works but now I want to make the Register.

I want to use 2 GUIs (one for Login one for Register) On the Main Gui where the login is on I have a second button for Register.

And now I want to use the button. I added an addEventHandler to the first GUI function. Then I did a function that handles the click to close the LoginGUI. That works but when I want to add a second action(start the Register GUI) it only executes the first command. How can I handle this?

Link to comment
function createLoginWindow() 
    Fenster = guiCreateWindow(421,138,675,486,"Login",false) 
    LoginButton = guiCreateButton(72,404,159,58,"Login",false,Fenster) 
    addEventHandler("onClientGUIClick", LoginButton, clientSubmitLogin, false) 
    RegButton = guiCreateButton(285,404,159,58,"Registrieren",false,Fenster) 
    Box1 = guiCreateEdit(33,90,208,31,"",false,Fenster) 
    addEventHandler("onClientGUIClick", RegButton, clientNewGUI1, false) 
     
    Box2 = guiCreateEdit(34,147,208,31,"",false,Fenster) 
    Label1 = guiCreateLabel(42,72,111,15,"Benutzername:",false,Fenster) 
    Label2 = guiCreateLabel(39,128,111,15,"Passwort:",false,Fenster) 
    guiSetVisible(Fenster, false) 
end 
     
function createRegWindow() 
  
         
  
        Reg_window =        guiCreateWindow(364,178,689,440,"Registrieren!",false) 
        Send_Button =       guiCreateButton(34,371,161,52,"Abschicken!",false,Reg_window) 
        Name_Feld =         guiCreateEdit(27,60,168,28,"",false,Reg_window) 
        Passwort_Feld =     guiCreateEdit(26,113,168,28,"",false,Reg_window) 
        Passwort2_Feld =    guiCreateEdit(28,166,168,28,"",false,Reg_window) 
        GUIEditor_Label[1] = guiCreateLabel(38,44,97,13,"Name:",false,Reg_window) 
        GUIEditor_Label[2] = guiCreateLabel(35,149,124,16,"Passwort bestätigen",false,Reg_window) 
        GUIEditor_Label[3] = guiCreateLabel(33,96,97,13,"Passwort:",false,Reg_window) 
        GUIEditor_Image[1] = guiCreateStaticImage(337,80,341,280,"images/mtalogo.png",false,Reg_window) 
        guiSetVisible(Reg_window, false) 
         
    end 
     
     
     
     
     
function thisResourceStarts() 
    createLoginWindow() 
    outputChatBox("Willkommen!!!") 
    if (Fenster ~= nil) then 
        guiSetVisible(Fenster, true) 
        showCursor(true) 
        guiSetInputEnabled(true) 
    else 
        outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") 
    end  
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), thisResourceStarts) 
  
function clientSubmitLogin(button, state) 
    if button == "left" and state == "up" then 
        local username = guiGetText(Box1) 
        local password = guiGetText(Box2) 
        if username and password then  
             
            if source == LoginButton then 
                triggerServerEvent("submitLogin", getRootElement(), username, password) 
            end 
            guiSetInputEnabled(false) 
            guiSetVisible(Fenster, false) 
            showCursor(false) 
        else 
            outputChatBox("Bitte fülle die Felder aus!") 
        end 
    end 
end 
  
function clientNewGUI(button, state) 
  
if button == "left" and state == "up" then 
  
        guiSetVisible(Fenster, false) 
         
         
    end 
  
     
         
         
end 

Edited by Guest
Link to comment
function createLoginWindow() 
    Fenster = guiCreateWindow(421,138,675,486,"Login",false) 
    LoginButton = guiCreateButton(72,404,159,58,"Login",false,Fenster) 
    RegButton = guiCreateButton(285,404,159,58,"Registrieren",false,Fenster) 
    Box1 = guiCreateEdit(33,90,208,31,"",false,Fenster)    
    Box2 = guiCreateEdit(34,147,208,31,"",false,Fenster) 
    Label1 = guiCreateLabel(42,72,111,15,"Benutzername:",false,Fenster) 
    Label2 = guiCreateLabel(39,128,111,15,"Passwort:",false,Fenster) 
    guiSetVisible(Fenster, false) 
end 
    
function createRegWindow() 
    Reg_window =        guiCreateWindow(364,178,689,440,"Registrieren!",false) 
    Send_Button =       guiCreateButton(34,371,161,52,"Abschicken!",false,Reg_window) 
    Name_Feld =         guiCreateEdit(27,60,168,28,"",false,Reg_window) 
    Passwort_Feld =     guiCreateEdit(26,113,168,28,"",false,Reg_window) 
    Passwort2_Feld =    guiCreateEdit(28,166,168,28,"",false,Reg_window) 
    guiCreateLabel(38,44,97,13,"Name:",false,Reg_window) 
    guiCreateLabel(35,149,124,16,"Passwort bestätigen",false,Reg_window) 
    guiCreateLabel(33,96,97,13,"Passwort:",false,Reg_window) 
    guiCreateStaticImage(337,80,341,280,"images/mtalogo.png",false,Reg_window) 
    guiSetVisible(Reg_window, false) 
end 
  
function thisResourceStarts() 
    createLoginWindow() 
    createRegWindow() 
    outputChatBox("Willkommen!!!") 
    if (Fenster ~= nil) then 
        guiSetVisible(Fenster, true) 
        showCursor(true) 
        guiSetInputEnabled(true) 
    else 
        outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") 
    end 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), thisResourceStarts) 
  
function onButtonClick ( button, state ) 
    if ( button == "left" and state == "up" ) then 
        if ( source == LoginButton ) then 
            local username = guiGetText ( Box1 ) 
            local password = guiGetText ( Box2 ) 
            if ( username ~= "" and password ~= "" ) then 
                triggerServerEvent ( "submitLogin", getRootElement(), username, password ) 
                guiSetInputEnabled ( false ) 
                guiSetVisible ( Fenster, false ) 
                showCursor ( false ) 
            else 
                outputChatBox("Bitte fülle die Felder aus!") 
            end 
        elseif ( source == RegButton ) then 
            guiSetVisible ( Reg_window, true ) 
        elseif ( source == Send_Button ) then 
            local username = guiGetText ( Name_Feld ) 
            local password = guiGetText ( Passwort_Feld ) 
            local passwordConfirm = guiGetText ( Passwort2_Feld ) 
            if ( username ~= "" and password ~= "" and passwordConfirm ~= "" ) then 
                triggerServerEvent ( "submitRegister", getRootElement(), username, password, passwordConfirm ) 
            else 
                outputChatBox("Bitte fülle die Felder aus!") 
            end 
        end 
    end 
end 
addEventHandler ( "onClientGUIClick", root, onButtonClick ) 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...