Jump to content

How to link my Gui button to another GUI Button?


Jaysds1

Recommended Posts

Posted
function onClick() 
guiSetVisible(myWindow,true) 
end 
addEventHandler("onClientGUIClick",yourButtonElement,onClick,false) 

Do you mean that?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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.

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted

Woot? i gave you the code to do that... :roll: , 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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I said, post the code.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 
  

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted

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 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Post the server side part.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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) 

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted
-- 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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

  • 2 weeks later...

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...