Jump to content

HELP - Login panel


Norhy

Recommended Posts

Hi. I want a login / register panel for my server. I used the handler "onPlayerJoin", but for some reason, my GUI doesn't appear when a player joins. The next problem is, that the registration panel appears only when a player joins, and it should only appear when a player clicks on the button "Registracia" at the Login Panel.

Client:

wdwLogin = guiCreateWindow(0.375, 0.375, 0.70, 0.70, "Vitaj", true) 
    guiCreateLabel(0.0825, 0.1, 0.25, 0.25, "Meno", true, wdwLogin) 
    guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Heslo", true, wdwLogin) 
    guiCreateLabel(0.0825, 0.6, 0.25, 0.25, "Info", true, wdwLogin) 
    wdwRegister = guiCreateWindow(0.375, 0.375, 0.30, 0.30, "Registracia", true) 
    guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Meno", true, wdwRegister) 
    guiCreateLabel(0.0825, 0.4, 0.25, 0.25, "Heslo", true, wdwRegister) 
      
    edtUser = guiCreateEdit(0.160, 0.1, 0.3, 0.06, "", true, wdwLogin) 
    edtPass = guiCreateEdit(0.160, 0.2, 0.3, 0.06, "", true, wdwLogin) 
    guiCreateMemo( 118, 200, 850, 280, "", false, wdwLogin ) 
    guiEditSetMaxLength(edtUser, 50) 
    guiEditSetMaxLength(edtPass, 50) 
    edtUserS = guiCreateEdit(0.160, 0.2, 0.3, 0.06, "", true, wdwRegister) 
    edtPassS = guiCreateEdit(0.160, 0.4, 0.3, 0.06, "", true, wdwRegister) 
    guiEditSetMaxLength(edtUserS, 50) 
    guiEditSetMaxLength(edtPassS, 50) 
      
    btnLogin = guiCreateButton(0.500, 0.1, 0.25, 0.2, "Prihlasit", true, wdwLogin) 
    btnRegister = guiCreateButton(0.750, 0.1, 0.25, 0.2, "Registracia", true, wdwLogin) 
    btnRegisterS = guiCreateButton(0.750, 0.1, 0.25, 0.2, "Registrovat", true, wdwRegister) 
      
    guiSetVisible(wdwLogin, false) 
      
    addEventHandler("onPlayerJoin", resourceRoot, 
        function () 
             guiSetVisible(wdwLogin, true) 
             showCursor(true) 
             guiSetInputEnabled(true) 
        end 
    ) 
      
    addEventHandler('onClientGUIClick',root, 
            function() 
                     if source == btnLogin then 
                         local user = guiGetText(edtUser) 
                         local pass = guiGetText(edtPass) 
      
                             if user and pass then 
                                 triggerServerEvent('submitLogin',localPlayer,user,pass) 
                                 guiSetInputEnabled(false) 
                                 showCursor(false) 
                                 guiSetVisible(wdwLogin,false) 
                             else 
                                 outputChatBox("Prosim napis svoje meno a heslo.") 
                                 guiSetVisible(wdwLogin,true) 
                             end 
                   end 
         end 
    ) 
     
    addEventHandler('onClientGUIClick', root, 
            function() 
                     if source == btnRegister then 
                         guiSetVisible(wdwRegister,true) 
                     end 
            end 
    ) 

Server:

addEvent( "submitLogin",true ) 
  
function loginHandler( username,password ) 
    local account = getAccount ( username, password ) 
    if account then 
        logIn ( source, account, password ) 
    else 
        outputChatBox("Zle zadane Meno alebo Heslo, skus znova prosim.",source ) 
    end 
end 
addEventHandler( "submitLogin",root,loginHandler ) 

Link to comment

Try

    wdwLogin = guiCreateWindow(0.375, 0.375, 0.70, 0.70, "Vitaj", true) 
    guiCreateLabel(0.0825, 0.1, 0.25, 0.25, "Meno", true, wdwLogin) 
    guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Heslo", true, wdwLogin) 
    guiCreateLabel(0.0825, 0.6, 0.25, 0.25, "Info", true, wdwLogin) 
    wdwRegister = guiCreateWindow(0.375, 0.375, 0.30, 0.30, "Registracia", true) 
    guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Meno", true, wdwRegister) 
    guiCreateLabel(0.0825, 0.4, 0.25, 0.25, "Heslo", true, wdwRegister) 
      
    edtUser = guiCreateEdit(0.160, 0.1, 0.3, 0.06, "", true, wdwLogin) 
    edtPass = guiCreateEdit(0.160, 0.2, 0.3, 0.06, "", true, wdwLogin) 
    guiCreateMemo( 118, 200, 850, 280, "", false, wdwLogin ) 
    guiEditSetMaxLength(edtUser, 50) 
    guiEditSetMaxLength(edtPass, 50) 
    edtUserS = guiCreateEdit(0.160, 0.2, 0.3, 0.06, "", true, wdwRegister) 
    edtPassS = guiCreateEdit(0.160, 0.4, 0.3, 0.06, "", true, wdwRegister) 
    guiEditSetMaxLength(edtUserS, 50) 
    guiEditSetMaxLength(edtPassS, 50) 
      
    btnLogin = guiCreateButton(0.500, 0.1, 0.25, 0.2, "Prihlasit", true, wdwLogin) 
    btnRegister = guiCreateButton(0.750, 0.1, 0.25, 0.2, "Registracia", true, wdwLogin) 
    btnRegisterS = guiCreateButton(0.750, 0.1, 0.25, 0.2, "Registrovat", true, wdwRegister) 
          
    guiSetVisible(wdwRegister,false) 
    showCursor(true) 
    guiSetInputEnabled(true) 
      
    addEventHandler('onClientGUIClick',root, 
            function() 
                     if source == btnLogin then 
                         local user = guiGetText(edtUser) 
                         local pass = guiGetText(edtPass) 
      
                             if user ~= "" and pass ~= "" then 
                                 triggerServerEvent('submitLogin',localPlayer,user,pass) 
                                 guiSetInputEnabled(false) 
                                 showCursor(false) 
                                 guiSetVisible(wdwLogin,false) 
                             else 
                                 outputChatBox("Prosim napis svoje meno a heslo.") 
                                 guiSetVisible(wdwLogin,true) 
                             end 
                   end 
         end 
    ) 
    
    addEventHandler('onClientGUIClick', root, 
            function() 
                     if source == btnRegister then 
                         guiSetVisible(wdwRegister,true) 
                     end 
            end) 

Link to comment

i am sure you have problem, your login panel will be hidden whenever you click on the button even if the username/password are wrong. you have to trigger from server side to client side when the login successful to hide the gui.

Link to comment

And how to fix that? When i type a wrong username / pass to show the GUI again? I tried setGuiVisible, but that didn't worked..

Question: How to make the password hidden? So there won't be alphabetical letter but dots like on Facebook.

Another problem: I've tried to finish the register system so it adds a account, i copied from wiki, but it didn't worked. When i click on "Register" nothing happens..

function registerHandler( username,password ) 
        if( password ~= "" and password ~= nil and username ~= "" and username ~= nil ) then 
                local accountAdded = addAccount ( username, password ) 
                if ( accountAdded ) then 
                        outputChatBox ( "You are registered now, please login.", source ) 
                else 
                        outputChatBox ( "Account couldn't be created.", source ) 
                end 
        else 
                outputChatBox ( "Enter a username and a password.", source) 
        end 
end 
addEventHandler( "submitRegister",root,registerHandler ) 

Link to comment
And how to fix that? When i type a wrong username / pass to show the GUI again? I tried setGuiVisible, but that didn't worked..

Question: How to make the password hidden? So there won't be alphabetical letter but dots like on Facebook.

Another problem: I've tried to finish the register system so it adds a account, i copied from wiki, but it didn't worked. When i click on "Register" nothing happens..

function registerHandler( username,password ) 
        if( password ~= "" and password ~= nil and username ~= "" and username ~= nil ) then 
                local accountAdded = addAccount ( username, password ) 
                if ( accountAdded ) then 
                        outputChatBox ( "You are registered now, please login.", source ) 
                else 
                        outputChatBox ( "Account couldn't be created.", source ) 
                end 
        else 
                outputChatBox ( "Enter a username and a password.", source) 
        end 
end 
addEventHandler( "submitRegister",root,registerHandler ) 

Don't hide the gui when you click on the button, make a trigger to client side from server side if the login has successful and then hide it using setGuiVisible

To make the password hidden use

https://wiki.multitheftauto.com/wiki/GuiEditSetMasked

and to make your script register you need to give him ACL right, this can be done by add the resource to admin group.

also in your code you have forgot this

addEvent("submitRegister",true) 

and please next time use lua button not Code.

Lj1UB.png

Link to comment
addEvent( "submitLogin",true ) 
  
function loginHandler(username,password) 
    local account = getAccount (username, password) 
    if account then 
        logIn(source, account, password) 
        triggerClientEvent(source,"HideGui",source) 
    else 
        outputChatBox("Zle zadane Meno alebo Heslo, skus znova prosim.",source) 
    end 
end 
addEventHandler("submitLogin",root,loginHandler) 

   wdwLogin = guiCreateWindow(0.375, 0.375, 0.70, 0.70, "Vitaj", true) 
    guiCreateLabel(0.0825, 0.1, 0.25, 0.25, "Meno", true, wdwLogin) 
    guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Heslo", true, wdwLogin) 
    guiCreateLabel(0.0825, 0.6, 0.25, 0.25, "Info", true, wdwLogin) 
    wdwRegister = guiCreateWindow(0.375, 0.375, 0.30, 0.30, "Registracia", true) 
    guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Meno", true, wdwRegister) 
    guiCreateLabel(0.0825, 0.4, 0.25, 0.25, "Heslo", true, wdwRegister) 
      
    edtUser = guiCreateEdit(0.160, 0.1, 0.3, 0.06, "", true, wdwLogin) 
    edtPass = guiCreateEdit(0.160, 0.2, 0.3, 0.06, "", true, wdwLogin) 
    guiCreateMemo( 118, 200, 850, 280, "", false, wdwLogin ) 
    guiEditSetMaxLength(edtUser, 50) 
    guiEditSetMaxLength(edtPass, 50) 
    edtUserS = guiCreateEdit(0.160, 0.2, 0.3, 0.06, "", true, wdwRegister) 
    edtPassS = guiCreateEdit(0.160, 0.4, 0.3, 0.06, "", true, wdwRegister) 
    guiEditSetMaxLength(edtUserS, 50) 
    guiEditSetMaxLength(edtPassS, 50) 
      
    btnLogin = guiCreateButton(0.500, 0.1, 0.25, 0.2, "Prihlasit", true, wdwLogin) 
    btnRegister = guiCreateButton(0.750, 0.1, 0.25, 0.2, "Registracia", true, wdwLogin) 
    btnRegisterS = guiCreateButton(0.750, 0.1, 0.25, 0.2, "Registrovat", true, wdwRegister) 
          
    guiSetVisible(wdwRegister,false) 
    showCursor(true) 
    guiSetInputEnabled(true) 
      
    addEventHandler('onClientGUIClick',root, 
            function() 
                     if source == btnLogin then 
                         local user = guiGetText(edtUser) 
                         local pass = guiGetText(edtPass) 
  
                             if user ~= "" and pass ~= "" then 
                                 triggerServerEvent('submitLogin',localPlayer,user,pass) 
                             else 
                                 outputChatBox("Prosim napis svoje meno a heslo.") 
                             end 
                   end 
         end 
    ) 
  
  
addEvent("HideGui",true) 
addEventHandler("HideGui",root, 
function() 
     guiSetInputEnabled(false) 
     showCursor(false) 
     guiSetVisible(wdwLogin,false) 
     guiSetVisible(wdwRegister,false) 
end) 
  
addEventHandler('onClientGUIClick', root, 
function() 
     if source == btnRegister then 
          guiSetVisible(wdwRegister,true) 
     end 
end) 

Link to comment

Ok. Now, i have the register system, this is the code ( Server ):

function registerHandler(username, password) 
    local account = getAccount(username, password) 
    if (account ~= false) then 
        outputChatBox( "", root, 255, 255, 255 ) 
    else 
        account = addAccount(username, password) 
        if (logIn(source, account, password) == true) then 
            triggerClientEvent(source, "hidewdwRegister", getRootElement()) 
        end 
    end 
end 
addEventHandler("submitRegister", root, registerHandler) 

Now i typed in ACL Group "Admin" this:

    "Admin"> 
        "Moderator">
        "SuperModerator">
        "Admin">
        "RPC">
        "resource.admin"> 
        "resource.webadmin"> 
        "user.Norhy"> 
        "resource.rpg"> 
    

But it doesn't work when i try to register, what's wrong?

Link to comment
I got that in my code already..

can you show me where? what line?

function registerHandler(username, password) 
    local account = getAccount(username, password) 
    if (account ~= false) then 
        outputChatBox( "", root, 255, 255, 255 ) 
    else 
        account = addAccount(username, password) 
        if (logIn(source, account, password) == true) then 
            triggerClientEvent(source, "hidewdwRegister", getRootElement()) 
        end 
    end 
end 
addEventHandler("submitRegister", root, registerHandler) 

Link to comment
I got that in my code already..

can you show me where? what line?

function registerHandler(username, password) 
    local account = getAccount(username, password) 
    if (account ~= false) then 
        outputChatBox( "", root, 255, 255, 255 ) 
    else 
        account = addAccount(username, password) 
        if (logIn(source, account, password) == true) then 
            triggerClientEvent(source, "hidewdwRegister", getRootElement()) 
        end 
    end 
end 
addEventHandler("submitRegister", root, registerHandler) 

This is the full code, i got it on the Top of it:

addEvent( "submitLogin", true ) 
addEvent( "submitRegister", true ) 
  
function loginHandler(username,password) 
        local account = getAccount (username, password) 
        if account then 
            logIn(source, account, password) 
            triggerClientEvent(source,"HideGui",source) 
        else 
            outputChatBox("Zle zadane Meno alebo Heslo, skus znova prosim.",source) 
        end 
end 
addEventHandler("submitLogin",root,loginHandler) 
  
function registerHandler(username, password) 
    local account = getAccount(username, password) 
    if (account ~= false) then 
        outputChatBox( "", root, 255, 255, 255 ) 
    else 
        account = addAccount(username, password) 
        if (logIn(source, account, password) == true) then 
            triggerClientEvent(source, "hidewdwRegister", getRootElement()) 
        end 
    end 
end 
addEventHandler("submitRegister", root, registerHandler) 

Link to comment
    wdwLogin = guiCreateWindow(0.375, 0.375, 0.70, 0.70, "Vitaj", true) 
    guiCreateLabel(0.0825, 0.1, 0.25, 0.25, "Meno", true, wdwLogin) 
    guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Heslo", true, wdwLogin) 
    guiCreateLabel(0.0825, 0.6, 0.25, 0.25, "Info", true, wdwLogin) 
    wdwRegister = guiCreateWindow(0.375, 0.375, 0.40, 0.40, "Registracia", true) 
    guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Meno", true, wdwRegister) 
    guiCreateLabel(0.0825, 0.4, 0.25, 0.25, "Heslo", true, wdwRegister) 
      
    edtUser = guiCreateEdit(0.160, 0.1, 0.3, 0.06, "", true, wdwLogin) 
    edtPass = guiCreateEdit(0.160, 0.2, 0.3, 0.06, "", true, wdwLogin) 
    guiCreateMemo( 118, 200, 850, 280, "", false, wdwLogin ) 
    guiEditSetMaxLength(edtUser, 50) 
    guiEditSetMaxLength(edtPass, 50) 
    edtUserS = guiCreateEdit(0.160, 0.2, 0.4, 0.06, "", true, wdwRegister) 
    edtPassS = guiCreateEdit(0.160, 0.4, 0.5, 0.06, "", true, wdwRegister) 
    guiEditSetMaxLength(edtUserS, 50) 
    guiEditSetMaxLength(edtPassS, 50) 
    guiEditSetMasked ( edtPassS, true ) 
    guiEditSetMasked ( edtPass, true ) 
      
    btnLogin = guiCreateButton(0.500, 0.1, 0.25, 0.2, "Prihlasit", true, wdwLogin) 
    btnRegister = guiCreateButton(0.750, 0.1, 0.25, 0.2, "Registracia", true, wdwLogin) 
    btnRegisterS = guiCreateButton(0.750, 0.1, 0.25, 0.2, "Registrovat", true, wdwRegister) 
          
    guiSetVisible(wdwRegister,false) 
    showCursor(true) 
    guiSetInputEnabled(true) 
      
    addEventHandler('onClientGUIClick',root, 
            function() 
                     if source == btnLogin then 
                         local user = guiGetText(edtUser) 
                         local pass = guiGetText(edtPass) 
  
                             if user ~= "" and pass ~= "" then 
                                 triggerServerEvent('submitLogin',localPlayer,user,pass) 
                             else 
                                 outputChatBox("Prosim napis svoje meno a heslo.") 
                             end 
                   end 
         end 
    ) 
  
  
addEvent("HideGui",true) 
addEventHandler("HideGui",root, 
function() 
     guiSetInputEnabled(false) 
     showCursor(false) 
     guiSetVisible(wdwLogin,false) 
     guiSetVisible(wdwRegister,false) 
end) 
  
addEventHandler('onClientGUIClick', root, 
function() 
     if source == btnRegister then 
          guiSetVisible(wdwRegister,true) 
     end 
end) 

Link to comment

-- Client Side

    wdwLogin = guiCreateWindow(0.375, 0.375, 0.70, 0.70, "Vitaj", true) 
    guiCreateLabel(0.0825, 0.1, 0.25, 0.25, "Meno", true, wdwLogin) 
    guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Heslo", true, wdwLogin) 
    guiCreateLabel(0.0825, 0.6, 0.25, 0.25, "Info", true, wdwLogin) 
    wdwRegister = guiCreateWindow(0.375, 0.375, 0.40, 0.40, "Registracia", true) 
    guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Meno", true, wdwRegister) 
    guiCreateLabel(0.0825, 0.4, 0.25, 0.25, "Heslo", true, wdwRegister) 
    guiSetProperty(wdwRegister, "AlwaysOnTop", "true") 
    edtUser = guiCreateEdit(0.160, 0.1, 0.3, 0.06, "", true, wdwLogin) 
    edtPass = guiCreateEdit(0.160, 0.2, 0.3, 0.06, "", true, wdwLogin) 
    guiCreateMemo( 118, 200, 850, 280, "", false, wdwLogin ) 
    guiEditSetMaxLength(edtUser, 50) 
    guiEditSetMaxLength(edtPass, 50) 
    edtUserS = guiCreateEdit(0.160, 0.2, 0.4, 0.06, "", true, wdwRegister) 
    edtPassS = guiCreateEdit(0.160, 0.4, 0.5, 0.06, "", true, wdwRegister) 
    guiEditSetMaxLength(edtUserS, 50) 
    guiEditSetMaxLength(edtPassS, 50) 
    guiEditSetMasked ( edtPassS, true ) 
    guiEditSetMasked ( edtPass, true ) 
      
    btnLogin = guiCreateButton(0.500, 0.1, 0.25, 0.2, "Prihlasit", true, wdwLogin) 
    btnRegister = guiCreateButton(0.750, 0.1, 0.25, 0.2, "Registracia", true, wdwLogin) 
    btnRegisterS = guiCreateButton(0.750, 0.1, 0.25, 0.2, "Registrovat", true, wdwRegister) 
          
    guiSetVisible(wdwRegister,false) 
    showCursor(true) 
    guiSetInputEnabled(true) 
      
    addEventHandler('onClientGUIClick',root, 
            function() 
                     if source == btnLogin then 
                         local user = guiGetText(edtUser) 
                         local pass = guiGetText(edtPass) 
  
                             if user ~= "" and pass ~= "" then 
                                 triggerServerEvent('submitLogin',localPlayer,user,pass) 
                             else 
                                 outputChatBox("Prosim napis svoje meno a heslo.") 
                             end 
                     elseif source == btnRegisterS then 
                         local user = guiGetText(edtUserS) 
                         local pass = guiGetText(edtPassS) 
                                 triggerServerEvent('submitRegister',localPlayer,user,pass) 
                   end 
         end 
    ) 
  
addEvent("HideGui",true) 
addEventHandler("HideGui",root, 
function() 
     guiSetInputEnabled(false) 
     showCursor(false) 
     guiSetVisible(wdwLogin,false) 
     guiSetVisible(wdwRegister,false) 
end) 
  
addEventHandler('onClientGUIClick', root, 
function() 
     if source == btnRegister then 
          guiSetVisible(wdwRegister,true) 
     end 
end) 

-- Server Side --

addEvent( "submitLogin", true) 
addEvent("submitRegister", true) 
  
function loginHandler(username,password) 
        local account = getAccount (username, password) 
        if account then 
            logIn(source, account, password) 
            triggerClientEvent(source,"HideGui",source) 
        else 
            outputChatBox("Zle zadane Meno alebo Heslo, skus znova prosim.",source) 
        end 
end 
addEventHandler("submitLogin",root,loginHandler) 
  
function registerHandler(username, password) 
     local account = getAccount(username) 
     if (account) then 
          outputChatBox("Account with this name already exists!", source, 255, 255, 255) return end 
     account = addAccount(username, password) 
     if (logIn(source, account, password) == true) then 
          triggerClientEvent(source, "HideGui", source) 
     end 
end 
addEventHandler("submitRegister", root, registerHandler) 

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