Jump to content

[HELP] First Login Panel!


FlyingSpoon

Recommended Posts

I am getting a lot of errors as this is my first script, I don't know where the actual error is, and my login doesn't appear on player join neither. There seems to be an error somewhere.

CLIENT SIDE

 --- Main Menu 
  
function showMenu() 
loginMenu = guiCreateWindow(338, 288, 338, 189, "RaysMTA Login v0.1", false) 
guiWindowSetSizable(loginMenu, false) 
  
infoLbl = guiCreateLabel(37, 21, 275, 27, "Welcome to the server, to get started please login/register below! \nYou can view our news by click the news button!\n", false, loginMenu) 
guiSetFont(infoLbl, "default-small") 
guiLabelSetColor(infoLbl, 41, 201, 52) 
usrLbl = guiCreateLabel(147, 55, 48, 15, "Username", false, loginMenu) 
guiSetFont(usrLbl, "default-small") 
usrEdit = guiCreateEdit(90, 66, 162, 21, "", false, loginMenu) 
passLbl = guiCreateLabel(147, 94, 48, 15, "Password", false, loginMenu) 
guiSetFont(passLbl, "default-small") 
         
passEdit = guiCreateEdit(90, 105, 162, 21, "", false, loginMenu) 
loginBtn = guiCreateButton(10, 153, 69, 27, "Login", false, loginMenu) 
guiSetFont(loginBtn, "default-small") 
regBtn = guiCreateButton(260, 153, 69, 27, "Register", false, loginMenu) 
guiSetFont(regBtn, "default-small") 
newsBtn = guiCreateButton(137, 152, 68, 28, "News", false, loginMenu) 
guiSetFont(newsBtn, "default-small")     
end 
addEventHandler("onClientPlayerJoin", getRootElement(), showMenu) 
  
  
--- Register Menu 
function regPlayer(button,state) 
    if (button == "left" and state == "up") then 
        if (source == regBtn) then 
        username = guiGetText(usrEdit) 
        password = guiGetText(passEdit) 
    triggerServerEvent("acceptRegister", getLocalPlayer(), username, password) 
    end 
  end 
end 
addEventHandler("onClientGUIClick", getRootElement(), regPlayer) 
  
--- Login Menu 
function logPlayer(button,state) 
    if (button == "left" and state == "up") then 
    if (source == loginBtn) then 
    username = guiGetText(usrEdit) 
    password = guiGetText(passEdit) 
    triggerServerEvent("acceptLogin", getLocalPlayer(), username, password) 
    end 
  end 
end 
addEventHandler("onClientGUIClick", getRootElement(), logPlayer) 
  
--- Disable Login Menu 
function closeMenu() 
    guiSetVisible(loginMenu,false) 
    showCursor(false) 
    outputChatBox("You have successfully logged in!") 
    end 
end 
addEvent("hideMenu", true) 
addEventHandler("hideMenu", getRootElement(), closeMenu) 

SERVER SIDE

--- Registering Event 
function regPlayer(username,password) 
    if not username == "" then 
    if not password == "" then 
       local account = getAccount(username,password) 
    if account == false then 
       local addAcc = addAccount(username,password)  
    if (addAcC) then 
    triggerClientEvent(source,"hideMenu",getRootElement()) 
    outputChatBox("You have successfully registered!", source) 
    else 
    outputChatBox("There was an error! Please contact an administrator!", source) 
       end 
     end 
    end 
  end 
end  
addEvent("acceptRegister",true) 
addEventHandler("acceptRegister",getRootElement(),regPlayer) 
  
--- Logging Event 
function logPlayer(username,password) 
    if not username == "" then 
     if not password == "" then 
      local account = getAccount(username,password) 
       if ( account ~= false ) then 
        outputChatBox("You have successfully logged in!", source) 
         triggerClientEvent(source,"hideMenu",getRootElement()) 
       else 
         outputChatBox("There was an error! Please contact an administrator!", source) 
       end 
     end 
   end 
end 
addEvent("acceptLogin",true) 
addEventHandler("acceptLogin",getRootElement(),logPlayer) 

Link to comment
  • 1 month later...

CLIENT SIDE

--- Main Menu 
  
function showMenu() 
loginMenu = guiCreateWindow(338, 288, 338, 189, "RaysMTA Login v0.1", false) 
guiWindowSetSizable(loginMenu, false) 
  
infoLbl = guiCreateLabel(37, 21, 275, 27, "Welcome to the server, to get started please login/register below! \nYou can view our news by click the news button!\n", false, loginMenu) 
guiSetFont(infoLbl, "default-small") 
guiLabelSetColor(infoLbl, 41, 201, 52) 
usrLbl = guiCreateLabel(147, 55, 48, 15, "Username", false, loginMenu) 
guiSetFont(usrLbl, "default-small") 
usrEdit = guiCreateEdit(90, 66, 162, 21, "", false, loginMenu) 
passLbl = guiCreateLabel(147, 94, 48, 15, "Password", false, loginMenu) 
guiSetFont(passLbl, "default-small") 
        
passEdit = guiCreateEdit(90, 105, 162, 21, "", false, loginMenu) 
guiEditSetMasked(passEdit, true) 
loginBtn = guiCreateButton(10, 153, 69, 27, "Login", false, loginMenu) 
guiSetFont(loginBtn, "default-small") 
regBtn = guiCreateButton(260, 153, 69, 27, "Register", false, loginMenu) 
guiSetFont(regBtn, "default-small") 
newsBtn = guiCreateButton(137, 152, 68, 28, "News", false, loginMenu) 
guiSetFont(newsBtn, "default-small")     
  
showCursor(true) 
end 
addEventHandler("onClientResourceStart", getRootElement(), showMenu)  
  
--- Register Menu 
function regPlayer(button,state) 
    if (button == "left" and state == "up") then 
        if (source == regBtn) then 
        username = guiGetText(usrEdit) 
        password = guiGetText(passEdit) 
    triggerServerEvent("acceptRegister", localPlayer, username, password) 
    end 
  end 
end 
addEventHandler("onClientGUIClick", getRootElement(), regPlayer) 
  
--- Login Menu 
function logPlayer(button,state) 
    if (button == "left" and state == "up") then 
    if (source == loginBtn) then 
    username = guiGetText(usrEdit) 
    password = guiGetText(passEdit) 
    triggerServerEvent("acceptLogin", localPlayer, username, password) 
    end 
  end 
end 
addEventHandler("onClientGUIClick", getRootElement(), logPlayer) 
  
--- Disable Login Menu 
function closeMenu() 
    guiSetVisible(loginMenu,false) 
    showCursor(false) 
    outputChatBox("You have successfully logged in!") 
    end 
addEvent("hideMenu", true) 
addEventHandler("hideMenu", getRootElement(), closeMenu) 

SERVER SIDE

--- Registering Event 
function regPlayer(username,password) 
    if not username == "" then 
    if not password == "" then 
       local account = getAccount(username,password) 
    if account == false then 
       local addAcc = addAccount(username,password) 
    if (addAcc) then 
    triggerClientEvent(source,"hideMenu",getRootElement()) 
    outputChatBox("You have successfully registered!", source) 
    else 
    outputChatBox("There was an error! Please contact an administrator!", source) 
       end 
     end 
    end 
  end 
end 
addEvent("acceptRegister",true) 
addEventHandler("acceptRegister",getRootElement(),regPlayer) 
  
--- Logging Event 
function logPlayer(username,password) 
    if not username == "" then 
     if not password == "" then 
      local account = getAccount(username,password) 
       if ( account ~= false ) then 
        outputChatBox("You have successfully logged in!", source) 
         triggerClientEvent(source,"hideMenu",getRootElement()) 
       else 
         outputChatBox("There was an error! Please contact an administrator!", source) 
       end 
     end 
   end 
end 
addEvent("acceptLogin",true) 
addEventHandler("acceptLogin",getRootElement(),logPlayer) 

No errors are outputted, but GUI Appears successfully now, any help on how I can fix?

Link to comment

Server side

'not' is only used when it is false or nil

'~=' is only used when it is not equal to

  
--- Registering Event 
function regPlayer(username,password) 
    if username ~= "" then 
    if password ~= "" then 
       local account = getAccount(username,password) 
    if account == false then 
       local addAcc = addAccount(username,password) 
    if (addAcc) then 
    triggerClientEvent(source,"hideMenu",getRootElement()) 
    outputChatBox("You have successfully registered!", source) 
    else 
    outputChatBox("There was an error! Please contact an administrator!", source) 
       end 
     end 
    end 
  end 
end 
addEvent("acceptRegister",true) 
addEventHandler("acceptRegister",getRootElement(),regPlayer) 
  
--- Logging Event 
function logPlayer(username,password) 
    if username ~= "" then 
     if password ~= "" then 
      local account = getAccount(username,password) 
       if ( account ~= false ) then 
        logIn( source, account, password ) 
        outputChatBox("You have successfully logged in!", source) 
         triggerClientEvent(source,"hideMenu",getRootElement()) 
       else 
         outputChatBox("There was an error! Please contact an administrator!", source) 
       end 
     end 
   end 
end 
addEvent("acceptLogin",true) 
addEventHandler("acceptLogin",getRootElement(),logPlayer) 
  

edit: just found out you never used logIn function. lol

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