Jump to content

Black screen on logon


Recommended Posts

  
function registerWindowCancel(button,state) 
    if(button == "left" and state == "up") then 
        if (source == btnCancel) then 
    guiSetVisible(wdwRegister, false) 
    guiSetVisible(wdwLogin, false) 
        end 
    end 
end 

Link to comment
  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Look, here's my code

client side

  
  
function createLoginWindow() 
    -- define the X and Y positions of the window 
    local X = 0.335 
    local Y = 0.375 
    -- define the width and height of the window 
    local Width = 0.35 
    local Height = 0.25 
    -- create the window and save it's element value into the variable "wdwLogin" 
    wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please login with your username and password", true) 
    -- define new X and Y positions for the first label. 
    X = 0.0825 
    Y = 0.230 
    -- define new Width and Height values for the first label. 
    Width = 0.50 
    Height = 0.50 
    -- create the first label, note the final argument passed is 'wdwLogin' meaning the window 
    -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window). 
    guiCreateLabel (X, Y, Width, Height, "Username", true, wdwLogin) 
    -- alter the Y value so the second label is slightly below the first. 
    Y = 0.53 
    guiCreateLabel (X, Y, Width, Height, "password", true, wdwLogin) 
    
    X = 0.415 
    Y = 0.2 
    Width = 0.5 
    Height = 0.15 
    edtUser = guiCreateEdit (X, Y, Width, Height, "", true, wdwLogin) 
    Y = 0.5 
    edtPass = guiCreateEdit (X, Y, Width, Height, "", true, wdwLogin) 
    -- set the maximum character length for the username and password fields to 50. 
    guiEditSetMaxLength(edtUser, 50) 
    guiEditSetMaxLength(edtPass, 50) 
    
    X = 0.415 
    Y = 0.7 
    Width = 0.25 
    Height = 0.2 
    btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) 
  
    X = 0.700 
    Y = 0.7 
    Width = 0.25 
    Height = 0.2    
    btnRegister = guiCreateButton(X, Y, Width, Height, "Register", true, wdwLogin) 
    
    -- now add our onClientGUIClick event to the buttons we just created. 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    addEventHandler("onClientGUIClick", btnRegister, createRegisterWindow1, false) 
    
    -- make the login window invisible 
    guiSetVisible(wdwLogin, false) 
end 
    
-- create the function and define the 'button' and 'state' parameters. 
-- (these are passed automatically by onClientGUIClick) 
function clientSubmitLogin(button,state) 
    -- if our login button was clicked with the left mouse button, and the state of the mousebutton is up: 
    if button == "left" and state == "up" then 
        -- get the text entered in the 'username' field. 
        local username = guiGetText(edtUser) 
        -- get the text entered in the 'password' field. 
        local password = guiGetText(edtPass) 
        
        -- 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", localPlayer, username, password) 
        
            -- move the input focus back on the game (allowing players to move arround, open the chatbox, etc) 
            guiSetInputEnabled(false) 
            -- hide the window and all the components. 
            guiSetVisible(wdwLogin, false) 
            -- hide the mouse cursor. 
            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 
  
--------------------------------------------------------------------------------------------------------- 
  
  
-- create the function and define the 'button' and 'state' parameters. 
-- (these are passed automatically by onClientGUIClick) 
function createRegisterWindow1(button,state) 
    -- if our login button was clicked with the left mouse button, and the state of the mousebutton is up: 
    if button == "left" and state == "up" then 
        createRegisterWindow() 
    end 
end 
  
function createRegisterWindow() 
    -- define the X and Y positions of the window 
    local X = 0.335 
    local Y = 0.325 
    -- define the width and height of the window 
    local Width = 0.35 
    local Height = 0.35 
    -- create the window and save it's element value into the variable "wdwLogin" 
    -- click on the function's name to read its documentation. 
    wdwRegister = guiCreateWindow(X, Y, Width, Height, "Please register with an username and password", true) 
    -- define new X and Y positions for the first label. 
    X = 0.0825 
    Y = 0.230 
    -- define new Width and Height values for the first label. 
    Width = 0.50 
    Height = 0.50 
    -- create the first label, note the final argument passed is 'wdwLogin' meaning the window 
    -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window). 
    guiCreateLabel (X, Y, Width, Height, "Username", true, wdwRegister) 
    -- alter the Y value so the second label is slightly below the first. 
    Y = 0.43 
    guiCreateLabel (X, Y, Width, Height, "password", true, wdwRegister) 
    Y = 0.63 
    guiCreateLabel (X, Y, Width, Height, "Confirm Password", true, wdwRegister)  
  
    X = 0.415 
    Y = 0.205 
    Width = 0.5 
    Height = 0.15 
    edtUser = guiCreateEdit (X, Y, Width, Height, "", true, wdwRegister) 
    Y = 0.40 
    edtPass = guiCreateEdit (X, Y, Width, Height, "", true, wdwRegister) 
    Y = 0.595 
    edtPass2 = guiCreateEdit (X, Y, Width, Height, "", true, wdwRegister) 
    -- set the maximum character length for the username and password fields to 50. 
    guiEditSetMaxLength(edtUser, 50) 
    guiEditSetMaxLength(edtPass, 50) 
    
    X = 0.415 
    Y = 0.8 
    Width = 0.25 
    Height = 0.2 
    btnCancel = guiCreateButton(X, Y, Width, Height, "Cancel", true, wdwRegister) 
  
    X = 0.700 
    Y = 0.8 
    Width = 0.25 
    Height = 0.2    
    btnRegister = guiCreateButton(X, Y, Width, Height, "Register", true, wdwRegister) 
    
    -- now add our onClientGUIClick event to the button we just created. 
    addEventHandler("onClientGUIClick", btnCancel, closeRegisterWindow, false) 
    addEventHandler("onClientGUIClick", btnRegister, registerPlayer1, false) 
    
    -- make the window visible 
    guiSetVisible(wdwRegister, true) 
     
    -- make the window invisible 
    guiSetVisible(wdwLogin, false) 
end 
  
-- create the function and define the 'button' and 'state' parameters. 
-- (these are passed automatically by onClientGUIClick) 
function registerPlayer1(button,state) 
    -- if our login button was clicked with the left mouse button, and the state of the mousebutton is up: 
    -- get the text entered in the 'username' field. 
    local username = guiGetText(edtUser) 
    -- get the text entered in the 'password' field. 
    local password = guiGetText(edtPass)     
    -- get the text entered in the 'password' field. 
    local password2 = guiGetText(edtPass2)   
    if button == "left" and state == "up" then 
    triggerServerEvent("registerPlayer",getLocalPlayer(),username,password, password2) 
    end 
end 
  
addEvent( "closeRegister", true ) 
addEventHandler( "closeRegister", getRootElement(), closeRegisterWindow ) 
  
function closeRegisterWindow() 
    -- make the Register window invisible. 
    guiSetVisible(wdwRegister, false) 
    -- make the login window visible again. 
    guiSetVisible(wdwLogin, true) 
end 
  
-- attach the event handler to the root element of the resource. 
-- this means it will only trigger when it's own resource is started. 
addEventHandler("onClientResourceStart", resourceRoot, 
    function () 
        -- create the log in window and it's components. 
        createLoginWindow() 
        
        -- output a brief welcome message to the player 
        outputChatBox("Welcome to BlackDeath's Alpha Server, Please log in with the login information provided to you") 
        
        -- if the GUI was successfully created, then show the GUI to the player. 
        if (wdwLogin ~= nil) then 
            guiSetVisible(wdwLogin, true) 
        else 
            -- if the GUI hasn't been properly been created, tell the player. 
            outputChatBox("An unexpected error has occurred and the login GUI has not been created.") 
        end 
        
        -- enable the players cursor (so that 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) 
    end 
) 

server side

-- create our loginHandler function, with username and password parameters (passed from the client GUI). 
  
function loginHandler(username,password) 
    -- check that the username and password are correct. 
    local acc = getAccount(username, password) 
        -- the player has succesfully logged in, so spawn them. 
        if (acc) then 
            logIn (source, acc, password) 
            spawnPlayer (source, 1959.55, -1714.46, 10) 
            fadeCamera(source, true) 
            setCameraTarget(source) 
            outputChatBox("Enjoy your time!", source) 
        else 
            -- if the username or password are not correct, output a message to the player. 
            outputChatBox("invalid username and password. Please re-connect and try again.", source) 
        end 
end 
  
-- define our costom event, and allow it to be triggered from the client ('true'). 
addEvent("submitLogin",true) 
-- add an event handler so that when submitLogin is triggered, the function loginHandler is called. 
addEventHandler("submitLogin",root, loginHandler) 
  
  
function registerPlayer(username,password, password2) 
    outputChatBox( "Username:"..username.." Password: "..password.."password confirm"..password2, source ) 
    -- if player not write username. 
    if not (username == "") then 
        -- if player not write password. 
        if not (password == "") then 
            -- verify that both passwords are the same. 
            if (password == password2) then 
                local account = getAccount (username,password) -- get account 
                if ( not getAccount ( username ) ) then 
                local accountAdded = addAccount(username, password)  -- added with username and pass from client 
                    if (accountAdded) then -- if account added write message 
                        outputChatBox ( "Thank you " ..username.. ", You can now login with your username and password.", source ) 
                        -- upon succesfull creation of the account this function will be called to set the the register screen to invisible and the login screen to visible.  
                        triggerClientEvent ( "closeRegister", getRootElement()) 
                    else -- if not -//- 
                        outputChatBox ( "Error creating account, contact the server admin.", source ) 
                    end 
                else 
                    outputChatBox ( "This account already exists..", source ) 
                end 
            else 
                outputChatBox ("The passwords do not match, please re-enter.") 
            end 
        else 
            outputChatBox ( "Please enter a password", source ) 
        end 
    else 
        outputChatBox ( "Please enter a username", source ) 
    end 
end 
  
addEvent("registerPlayer",true) 
addEventHandler("registerPlayer",getRootElement(),registerPlayer) 
  
  

Pressing the cancel button in the register screen will return you to the login window. but when you press the register button, it will create your account but it wont take you back to the login screen as the cancelbutton does.

Now the cancelbutton and the function that makes you go back to the loginscreen are both in client side. So I know I'm doing something wrong on server side as in there it tells to use clientside function to close the registerwindow after the account has been created (both by clicking the register button).

Link to comment

server

-- create our loginHandler function, with username and password parameters (passed from the client GUI). 
  
function loginHandler(username,password) 
    -- check that the username and password are correct. 
    local acc = getAccount(username, password) 
        -- the player has succesfully logged in, so spawn them. 
        if (acc) then 
            logIn (source, acc, password) 
            spawnPlayer (source, 1959.55, -1714.46, 10) 
            fadeCamera(source, true) 
            setCameraTarget(source) 
            outputChatBox("Enjoy your time!", source) 
        else 
            -- if the username or password are not correct, output a message to the player. 
            outputChatBox("invalid username and password. Please re-connect and try again.", source) 
        end 
end 
  
-- define our costom event, and allow it to be triggered from the client ('true'). 
addEvent("submitLogin",true) 
-- add an event handler so that when submitLogin is triggered, the function loginHandler is called. 
addEventHandler("submitLogin",root, loginHandler) 
  
  
function registerPlayer(username,password, password2) 
    outputChatBox( "Username:"..username.." Password: "..password.."password confirm"..password2, source ) 
    -- if player not write username. 
    if not (username == "") then 
        -- if player not write password. 
        if not (password == "") then 
            -- verify that both passwords are the same. 
            if (password == password2) then 
                local account = getAccount (username,password) -- get account 
                if ( not getAccount ( username ) ) then 
                local accountAdded = addAccount(username, password)  -- added with username and pass from client 
                    if (accountAdded) then -- if account added write message 
                        outputChatBox ( "Thank you " ..username.. ", You can now login with your username and password.", source ) 
                        -- upon succesfull creation of the account this function will be called to set the the register screen to invisible and the login screen to visible. 
                        triggerClientEvent(source,"closeRegister",getRootElement()) 
                    else -- if not -//- 
                        outputChatBox ( "Error creating account, contact the server admin.", source ) 
                    end 
                else 
                    outputChatBox ( "This account already exists..", source ) 
                end 
            else 
                outputChatBox ("The passwords do not match, please re-enter.") 
            end 
        else 
            outputChatBox ( "Please enter a password", source ) 
        end 
    else 
        outputChatBox ( "Please enter a username", source ) 
    end 
end 
  
addEvent("registerPlayer",true) 
addEventHandler("registerPlayer",getRootElement(),registerPlayer) 

client

function closeRegisterWindow() 
    -- make the Register window invisible. 
    guiSetVisible(wdwRegister, false) 
    -- make the login window visible again. 
    guiSetVisible(wdwLogin, true) 
end 
addEvent("closeRegister", true) 
addEventHandler("closeRegister", getRootElement(), closeRegisterWindow) 

some of your code by nextreme

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