Jump to content

Black screen on logon


Recommended Posts

Hello people,

I'm totally new to scripting and thougt of doing some basic tutorials for it to make my own MTA server.

So I've been working trough the wiki pages with some basic scripting. These are the wiki pages i've been trough so far.

https://wiki.multitheftauto.com/wiki/Scr ... troduction

https://wiki.multitheftauto.com/wiki/Int ... ng_the_GUI

Now that i've finished those 2 pages I tried to login to my server and as a result got a black screen. I've been trying quite some stuff myself to be able to find out what's not right in my code, but couldn't find the solution. So I hope some of you guys can help me with it.

Here's my code so far.

script.lua

-- 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. 
    if username == "user" and password =="apple" then 
        -- the player has succesfully logged in, so spawn them. 
        if (client) then 
            spawnPlayer (client, 1959.55, -1714.46, 10) 
            faceCamera(client, true) 
            setCameraTarget(client, client) 
            outputChatBox("Enjoy your time!", client) 
        end 
    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.", client) 
    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) 

and my gui.lua

function createLoginWindow() 
    -- define the X and Y positions of the window 
    local X = 0.375 
    local Y = 0.375 
    -- define the width and height of the window 
    local Width = 0.25 
    local Height = 0.25 
    -- create the window and save it's element value into the variable "wdwLogin" 
    -- click on the function's name to read its documentation. 
    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.2 
    -- define new Width and Height values for the first label. 
    Width = 0.25 
    Height = 0.25 
    -- 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.5 
    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) 
     
    -- now add our onClientGUIClick event to the button we just created. 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
     
    -- make the window invisible 
    guiSetVisible(wdwLogin, false) 
     
    -- 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", getRootElement(), 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 
  
  
-- 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", getResourceRootElement(getThisResource()), 
    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 
) 
  
-- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. 
addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) 

Link to comment
  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

use /debugscript 3, syntax errors.

gui.lua

function createLoginWindow() 
    -- define the X and Y positions of the window 
    local X = 0.375 
    local Y = 0.375 
    -- define the width and height of the window 
    local Width = 0.25 
    local Height = 0.25 
    -- create the window and save it's element value into the variable "wdwLogin" 
    -- click on the function's name to read its documentation. 
    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.2 
    -- define new Width and Height values for the first label. 
    Width = 0.25 
    Height = 0.25 
    -- 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.5 
    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) 
    
    -- now add our onClientGUIClick event to the button we just created. 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    -- make the window invisible 
    guiSetVisible(wdwLogin, false) 
    
    -- 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", getRootElement(), 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 
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", getResourceRootElement(getThisResource()), 
    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 
) 
  
-- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. 
addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) 

And like Draken said, this script wont work.

Link to comment
Because your script is totally copied from Wiki. Your code verify if username is user and password apple.

You need delete this and use getAccount to verify if account exists, if exists login, else output error. You must start learn:

https://wiki.multitheftauto.com/

http://lua-users.org/wiki/TutorialDirectory

How exactly should i use the getAccount ? can you explain?

use /debugscript 3, syntax errors.

gui.lua

function createLoginWindow() 
    -- define the X and Y positions of the window 
    local X = 0.375 
    local Y = 0.375 
    -- define the width and height of the window 
    local Width = 0.25 
    local Height = 0.25 
    -- create the window and save it's element value into the variable "wdwLogin" 
    -- click on the function's name to read its documentation. 
    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.2 
    -- define new Width and Height values for the first label. 
    Width = 0.25 
    Height = 0.25 
    -- 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.5 
    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) 
    
    -- now add our onClientGUIClick event to the button we just created. 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    -- make the window invisible 
    guiSetVisible(wdwLogin, false) 
    
    -- 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", getRootElement(), 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 
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", getResourceRootElement(getThisResource()), 
    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 
) 
  
-- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. 
addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) 

And like Draken said, this script wont work.

Did you change something in the code or?

Link to comment

So, like this?

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 
            spawnPlayer (client, 1959.55, -1714.46, 10) 
            faceCamera(client, true) 
            setCameraTarget(client, client) 
            outputChatBox("Enjoy your time!", client) 
        end 
    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.", client) 
    end 
end 

Link to comment

Client-side:

function createLoginWindow() 
    -- define the X and Y positions of the window 
    local X = 0.375 
    local Y = 0.375 
    -- define the width and height of the window 
    local Width = 0.25 
    local Height = 0.25 
    -- create the window and save it's element value into the variable "wdwLogin" 
    -- click on the function's name to read its documentation. 
    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.2 
    -- define new Width and Height values for the first label. 
    Width = 0.25 
    Height = 0.25 
    -- 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.5 
    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) 
    
    -- now add our onClientGUIClick event to the button we just created. 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    -- make the window invisible 
    guiSetVisible(wdwLogin, false) 
    
    -- 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", getRootElement(), 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 
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", getResourceRootElement(getThisResource()), 
    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 
) 
  
-- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. 
addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) 

Server-side:

function loginHandler(client,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 
            spawnPlayer (client, 1959.55, -1714.46, 10) 
            faceCamera(client, true) 
            setCameraTarget(client, client) 
            outputChatBox("Enjoy your time!", client) 
    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.", client) 
    end 
end 
addEvent('submitLogin',true) 
addEventHandler('submitLogin',root,loginHandler) 

Link to comment
function loginHandler(client,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 
            spawnPlayer (client, 1959.55, -1714.46, 10) 
            fadeCamera(client, true) -- It's 'fadeCamera', not 'faceCamera'. 
            setCameraTarget(client) 
            outputChatBox("Enjoy your time!", client) 
    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.", client) 
    end 
end 
addEvent('submitLogin',true) 
addEventHandler('submitLogin',root,loginHandler) 

Link to comment

Ok I fixed all things you guys told my and my script now looks like this:

script.lua

-- create our loginHandler function, with username and password parameters (passed from the client GUI). 
  
function loginHandler(client,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 
            spawnPlayer (client, 1959.55, -1714.46, 10) 
            fadeCamera(client, true) 
            setCameraTarget(client) 
            outputChatBox("Enjoy your time!", client) 
        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.", client) 
        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) 

gui.lua

  
  
function createLoginWindow() 
    -- define the X and Y positions of the window 
    local X = 0.375 
    local Y = 0.375 
    -- define the width and height of the window 
    local Width = 0.25 
    local Height = 0.25 
    -- create the window and save it's element value into the variable "wdwLogin" 
    -- click on the function's name to read its documentation. 
    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.2 
    -- define new Width and Height values for the first label. 
    Width = 0.25 
    Height = 0.25 
    -- 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.5 
    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) 
     
    -- now add our onClientGUIClick event to the button we just created. 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
     
    -- make the window invisible 
    guiSetVisible(wdwLogin, false) 
     
    -- 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", getRootElement(), 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 
  
  
-- 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", getResourceRootElement(getThisResource()), 
    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 
) 
  
-- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. 
addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) 
  

But the black screen on login still remains, anyone knows why?

Link to comment
Because you fade camera but don't put normal again.

So I need to put back fadecamera on false again afterwards?

That would be weird cause when I use an script like this:

local spawnX, spawnY, spawnZ = 1959.55, -1714.46, 10 
function joinHandler() 
    spawnPlayer(source, spawnX, spawnY, spawnZ) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    outputChatBox("Welcome to My Server", source) 
end 
addEventHandler("onPlayerJoin", getRootElement(), joinHandler) 

the screen isn't black, while fadecamera is also on true in that script and does not go false afterwards.

Link to comment

You forgot a end to end function.

function createLoginWindow() 
    -- define the X and Y positions of the window 
    local X = 0.375 
    local Y = 0.375 
    -- define the width and height of the window 
    local Width = 0.25 
    local Height = 0.25 
    -- create the window and save it's element value into the variable "wdwLogin" 
    -- click on the function's name to read its documentation. 
    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.2 
    -- define new Width and Height values for the first label. 
    Width = 0.25 
    Height = 0.25 
    -- 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.5 
    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) 
     
    -- now add our onClientGUIClick event to the button we just created. 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
     
    -- 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 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", getRootElement(), 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 
  
  
-- 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", getResourceRootElement(getThisResource()), 
    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 
) 
  
-- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. 
addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) 

Link to comment
    local acc = getAccount(username, password) 
        -- the player has succesfully logged in, so spawn them. 
        if (acc) then 
            spawnPlayer (client, 1959.55, -1714.46, 10) 
            setTimer ( fadeCamera, 5000, 1, source, true, 0.5 ) 
            setCameraTarget(client) 
            outputChatBox("Enjoy your time!", client) 
        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.", client) 
        end 

So like this?

Link to comment

1: Did your script ever worked? because I got many errors in the client side.

2: You we're using 'client' argument, but you never triggered it.

3: You forgot about logIn function to login the player.

-- client side:

function createLoginWindow() 
    -- define the X and Y positions of the window 
    local X = 0.375 
    local Y = 0.375 
    -- define the width and height of the window 
    local Width = 0.25 
    local Height = 0.25 
    -- create the window and save it's element value into the variable "wdwLogin" 
    -- click on the function's name to read its documentation. 
    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.2 
    -- define new Width and Height values for the first label. 
    Width = 0.25 
    Height = 0.25 
    -- 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.5 
    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) 
    
    -- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    -- make the window invisible 
    guiSetVisible(wdwLogin, false) 
    
    -- create the function and define the 'button' and 'state' parameters. 
    -- (these are passed automatically by onClientGUIClick) 
end 
     
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 
  
  
-- 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) 

Link to comment

I editted my code again, it's like this now

script.lua

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

gui.lua

  
  
function createLoginWindow() 
    -- define the X and Y positions of the window 
    local X = 0.375 
    local Y = 0.375 
    -- define the width and height of the window 
    local Width = 0.25 
    local Height = 0.25 
    -- create the window and save it's element value into the variable "wdwLogin" 
    -- click on the function's name to read its documentation. 
    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.2 
    -- define new Width and Height values for the first label. 
    Width = 0.25 
    Height = 0.25 
    -- 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.5 
    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) 
     
    -- now add our onClientGUIClick event to the button we just created. 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
     
    -- 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 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", getRootElement(), 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 
  
  
-- 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 
) 
  
-- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. 
addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) 
  

Problem of a black screen on connect still remains :(

Link to comment
I editted my code again, it's like this now

script.lua

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

gui.lua

  
  
function createLoginWindow() 
    -- define the X and Y positions of the window 
    local X = 0.375 
    local Y = 0.375 
    -- define the width and height of the window 
    local Width = 0.25 
    local Height = 0.25 
    -- create the window and save it's element value into the variable "wdwLogin" 
    -- click on the function's name to read its documentation. 
    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.2 
    -- define new Width and Height values for the first label. 
    Width = 0.25 
    Height = 0.25 
    -- 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.5 
    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) 
     
    -- now add our onClientGUIClick event to the button we just created. 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
     
    -- 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 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", getRootElement(), 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 
  
  
-- 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 
) 
  
-- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. 
addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) 
  

Problem of a black screen on connect still remains :(

I posted clientside on page #1

    btnLogin = guiCreateButton(X, Y, Width, Height, "Log In" true, wdwLogin) 

line 39, missed comma, 'end' on line 76

Link to comment

Ok been messing arround a bit...

my login screen looks like this now

30j47k7.jpg

Now i tried movind the username and password text up.. but no matter where to i change the x and y amounts, it wont move. it does respond to the y amount between username and password tough.

My code is like this:

    X = 0.0825 
    y = 0.2 
    -- 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.7 
    guiCreateLabel (X, Y, Width, Height, "password", true, wdwLogin) 

Link to comment
    X = 0.0825 
    Y = 0.2 -- Lua is case sensitive. 
    -- 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.7 
    guiCreateLabel (X, Y, Width, Height, "password", true, wdwLogin) 

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