Jump to content

Login GUI from wiki


maky55

Recommended Posts

Hello men!

Well as you know, i'm an lua newb. I was following the wiki on a basic login screen, and i've to the point where you can click login, and it knows you click it, but does nothing :D. I don't know what the problem is, but heres the script I tried to put together:

client

function clientSubmitLogin(button,state) 
    if button == "left" and state == "up" then 
     
        local username = guiGetText(edtUser) 
         
        local password = guiGetText(edtPass) 
  
  
        if username and password then 
             
            triggerServerEvent("submitLogin", getRootElement(), username, password) 
  
            guiSetInputEnabled(false) 
            guiSetVisible(wdwLogin, false) 
            showCursor(false) 
        else 
            outputChatBox("Please enter a username and password.") 
        end 
    end 
end 
  
function createLoginWindow() 
    local X = 0.375 
    local Y = 0.375 
    local Width = 0.25 
    local Height = 0.25 
    wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
     
    X = 0.0825 
    Y = 0.25 
    Width = 0.25 
    Height = 0.25 
    guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) 
    Y = 0.5 
    guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
     
    X = 0.415 
    Y = 0.25 
    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) 
    guiEditSetMaxLength(edtUser, 20) 
    guiEditSetMaxLength(edtpass, 20) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
     
    X = 0.415 
    Y = 0.7 
    Width = 0.25 
    Height = 0.20 
    bntLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) 
    guiSetVisible(wdwLogin, false) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(),  
    function () 
        createLoginWindow() 
                outputChatBox("Welcome to My MTA:SA Server, please log in.") 
            if (wdwLogin ~= nil) then 
            guiSetVisible(wdwLogin, true) 
        else 
            outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") 
            end  
  
         
            showCursor(true) 
            guiSetInputEnabled(true) 
    end 
) 
  

Server

local spawnX, spawnY, spawnZ = 2584.9523925781, -2209.318359375, 1.9927320480347 
function loginHandler(username, password) 
    if username =="" and password == "" then 
            if (client) then 
                    spawnPlayer(client, spawnX, spawnY, spawnZ) 
                    fadeCamera(client, true) 
                    setCameraTarget(client, cient) 
                    setElementModel(source, 287) 
                    setPedArmor (source, 100) 
                    outputChatBox("Welcome to the test server!", client) 
            end 
        else 
                    outputChatBox("Invalid username or password", client) 
        end 
end 

It looks really simple, but I don't know whats wrong. It's all from the wiki, but the wiki doesn't show you what the finished serverside and clientside should look like so I'm lost.

Also, what do I put in this bit for username and password?:

function loginHandler(username, password) 
    if username =="" and password == "" then 
            if (client) then 

Please help with this :D

Link to comment
So you want help make you the server side?

Really, all I want is to know what's wrong with this. It's just so I can log onto a local server for fun without having to type /login all the time.

The login window shows up, you can type things in and you can click the buttons, but the buttons don't do anything.

Link to comment

Client Side:

local localPlayer = getLocalPlayer() 
local playerName = getPlayerName(localPlayer) 
function clientSubmitLogin(button,state) 
    if button == "left" and state == "up" then 
    
        local username = guiGetText(edtUser) 
        
        local password = guiGetText(edtPass) 
  
  
        if username and password then 
            
            triggerServerEvent("submitLogin", getRootElement(), localPlayer, username, password) 
        else 
            outputChatBox("Please enter a username and password.") 
        end 
    end 
end 
  
function createLoginWindow() 
    local X = 0.375 
    local Y = 0.375 
    local Width = 0.25 
    local Height = 0.25 
    wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    X = 0.0825 
    Y = 0.25 
    Width = 0.25 
    Height = 0.25 
    guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) 
    Y = 0.5 
    guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    X = 0.415 
    Y = 0.25 
    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) 
    guiEditSetMaxLength(edtUser, 20) 
    guiEditSetMaxLength(edtpass, 20) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    X = 0.415 
    Y = 0.7 
    Width = 0.25 
    Height = 0.20 
    bntLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) 
    guiSetVisible(wdwLogin, false) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(), 
    function () 
        createLoginWindow() 
                outputChatBox("Welcome to My MTA:SA Server, please log in.") 
            if (wdwLogin ~= nil) then 
            guiSetVisible(wdwLogin, true) 
        else 
            outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") 
            end 
  
        
            showCursor(true) 
            guiSetInputEnabled(true) 
    end 
) 
function hideLoginWindow() 
      guiSetInputEnabled(false) 
      guiSetVisible(wdwLogin, false) 
      showCursor(false) 
end 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 

Server Side:

local spawnX, spawnY, spawnZ = 2584.9523925781, -2209.318359375, 1.9927320480347 
function loginHandler(player, username, password) 
             local account = getAccount(username, password) 
             if (account ~= false) then 
                 if (logIn(player, username, password) == true) then 
                     spawnPlayer(source, spawnX, spawnY, spawnZ) 
                     fadeCamera(source, true) 
                     setCameraTarget(source, source) 
                     setPedArmor(source, 100) 
                     outputChatBox("Welcome to the test server!", player) 
                     triggerClientEvent(player, "hideLoginWindow", getRootElement()) 
                   end 
            else 
                 outputChatBox("Invaild username or password", player) 
           end 
end 
addEvent("submitLogin", true) 
addEventHandler("submitLogin", getRootElement(), LoginHandler) 
  

Link to comment
Client Side:
local localPlayer = getLocalPlayer() 
local playerName = getPlayerName(localPlayer) 
function clientSubmitLogin(button,state) 
    if button == "left" and state == "up" then 
    
        local username = guiGetText(edtUser) 
        
        local password = guiGetText(edtPass) 
  
  
        if username and password then 
            
            triggerServerEvent("submitLogin", getRootElement(), localPlayer, username, password) 
        else 
            outputChatBox("Please enter a username and password.") 
        end 
    end 
end 
  
function createLoginWindow() 
    local X = 0.375 
    local Y = 0.375 
    local Width = 0.25 
    local Height = 0.25 
    wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    X = 0.0825 
    Y = 0.25 
    Width = 0.25 
    Height = 0.25 
    guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) 
    Y = 0.5 
    guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    X = 0.415 
    Y = 0.25 
    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) 
    guiEditSetMaxLength(edtUser, 20) 
    guiEditSetMaxLength(edtpass, 20) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    X = 0.415 
    Y = 0.7 
    Width = 0.25 
    Height = 0.20 
    bntLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) 
    guiSetVisible(wdwLogin, false) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(), 
    function () 
        createLoginWindow() 
                outputChatBox("Welcome to My MTA:SA Server, please log in.") 
            if (wdwLogin ~= nil) then 
            guiSetVisible(wdwLogin, true) 
        else 
            outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") 
            end 
  
        
            showCursor(true) 
            guiSetInputEnabled(true) 
    end 
) 
function hideLoginWindow() 
      guiSetInputEnabled(false) 
      guiSetVisible(wdwLogin, false) 
      showCursor(false) 
end 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 

Server Side:

local spawnX, spawnY, spawnZ = 2584.9523925781, -2209.318359375, 1.9927320480347 
function loginHandler(player, username, password) 
             local account = getAccount(username, password) 
             if (account ~= false) then 
                 if (logIn(player, username, password) == true) then 
                     spawnPlayer(source, spawnX, spawnY, spawnZ) 
                     fadeCamera(source, true) 
                     setCameraTarget(source, source) 
                     setPedArmor(source, 100) 
                     outputChatBox("Welcome to the test server!", player) 
                     triggerClientEvent(player, "hideLoginWindow", getRootElement()) 
                   end 
            else 
                 outputChatBox("Invaild username or password", player) 
           end 
end 
addEvent("submitLogin", true) 
addEventHandler("submitLogin", getRootElement(), LoginHandler) 
  

Hi, thanks for the reply. Sadly this didn't work and it still had the same problem. You also made an error in the script:

addEventHandler("submitLogin", getRootElement(), LoginHandler) 

It should be loginHandler, with lowercase l.

I changed it but it still doesnt work. This is the video of it:

https://www.youtube.com/watch?v=YEU5lz7Gj6g&feature=youtu.be

Link to comment
local localPlayer = getLocalPlayer() 
local playerName = getPlayerName(localPlayer) 
function clientSubmitLogin(button,state) 
    if button == "left" and state == "up" then 
    
        local username = guiGetText(edtUser) 
        
        local password = guiGetText(edtPass) 
  
  
        if username and password then 
            
            triggerServerEvent("submitLogin", getRootElement(), localPlayer, username, password) 
        else 
            outputChatBox("Please enter a username and password.") 
        end 
    end 
end 
  
function createLoginWindow() 
    local X = 0.375 
    local Y = 0.375 
    local Width = 0.25 
    local Height = 0.25 
    wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    X = 0.0825 
    Y = 0.25 
    Width = 0.25 
    Height = 0.25 
    guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) 
    Y = 0.5 
    guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    X = 0.415 
    Y = 0.25 
    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) 
    guiEditSetMaxLength(edtUser, 20) 
    guiEditSetMaxLength(edtpass, 20) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin) 
    X = 0.415 
    Y = 0.7 
    Width = 0.25 
    Height = 0.20 
    bntLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) 
    guiSetVisible(wdwLogin, false) 
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(), 
    function () 
        createLoginWindow() 
                outputChatBox("Welcome to My MTA:SA Server, please log in.") 
            if (wdwLogin ~= nil) then 
            guiSetVisible(wdwLogin, true) 
        else 
            outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") 
            end 
  
        
            showCursor(true) 
            guiSetInputEnabled(true) 
    end 
) 
function hideLoginWindow() 
      guiSetInputEnabled(false) 
      guiSetVisible(wdwLogin, false) 
      showCursor(false) 
end 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 

if you want your password not showed as number or text do that

guiEditSetMasked(edtPass, true) 

Link to comment
local localPlayer = getLocalPlayer() 
local playerName = getPlayerName(localPlayer) 
function clientSubmitLogin(button,state) 
    if button == "left" and state == "up" then 
    
        local username = guiGetText(edtUser) 
        
        local password = guiGetText(edtPass) 
  
  
        if username and password then 
            
            triggerServerEvent("submitLogin", getRootElement(), localPlayer, username, password) 
        else 
            outputChatBox("Please enter a username and password.") 
        end 
    end 
end 
  
function createLoginWindow() 
    local X = 0.375 
    local Y = 0.375 
    local Width = 0.25 
    local Height = 0.25 
    wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    X = 0.0825 
    Y = 0.25 
    Width = 0.25 
    Height = 0.25 
    guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) 
    Y = 0.5 
    guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    X = 0.415 
    Y = 0.25 
    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) 
    guiEditSetMaxLength(edtUser, 20) 
    guiEditSetMaxLength(edtpass, 20) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin) 
    X = 0.415 
    Y = 0.7 
    Width = 0.25 
    Height = 0.20 
    bntLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) 
    guiSetVisible(wdwLogin, false) 
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(), 
    function () 
        createLoginWindow() 
                outputChatBox("Welcome to My MTA:SA Server, please log in.") 
            if (wdwLogin ~= nil) then 
            guiSetVisible(wdwLogin, true) 
        else 
            outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") 
            end 
  
        
            showCursor(true) 
            guiSetInputEnabled(true) 
    end 
) 
function hideLoginWindow() 
      guiSetInputEnabled(false) 
      guiSetVisible(wdwLogin, false) 
      showCursor(false) 
end 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 

if you want your password not showed as number or text do that

guiEditSetMasked(edtPass, true) 

Thanks, but it now says:

ERROR: Client (asdf) triggered serverside event requestLODsClient, but event is not added serverside.

Link to comment

Meta:

<meta> 
    <info author="Tiger" version="1.0" type="gamemode" name="Server" description="a simple spawn script" /> 
     
    <script src="Server.lua" /> 
        <script src="Client.lua" /> 
</meta> 

Client:

local localPlayer = getLocalPlayer() 
local playerName = getPlayerName(localPlayer) 
function clientSubmitLogin(button,state) 
    if button == "left" and state == "up" then 
    
        local username = guiGetText(edtUser) 
        
        local password = guiGetText(edtPass) 
  
  
        if username and password then 
            
            triggerServerEvent("submitLogin", getRootElement(), localPlayer, username, password) 
        else 
            outputChatBox("Please enter a username and password.") 
        end 
    end 
end 
  
function createLoginWindow() 
    local X = 0.375 
    local Y = 0.375 
    local Width = 0.25 
    local Height = 0.25 
    wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    X = 0.0825 
    Y = 0.25 
    Width = 0.25 
    Height = 0.25 
    guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) 
    Y = 0.5 
    guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    X = 0.415 
    Y = 0.25 
    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) 
    guiEditSetMaxLength(edtUser, 20) 
    guiEditSetMaxLength(edtpass, 20) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin) 
    X = 0.415 
    Y = 0.7 
    Width = 0.25 
    Height = 0.20 
    bntLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) 
    guiSetVisible(wdwLogin, false) 
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(), 
    function () 
        createLoginWindow() 
                outputChatBox("Welcome to My MTA:SA Server, please log in.") 
            if (wdwLogin ~= nil) then 
            guiSetVisible(wdwLogin, true) 
        else 
            outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") 
            end 
  
        
            showCursor(true) 
            guiSetInputEnabled(true) 
    end 
) 
function hideLoginWindow() 
      guiSetInputEnabled(false) 
      guiSetVisible(wdwLogin, false) 
      showCursor(false) 
end 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 

Server:

local posX, posY, posZ = 2584.9523925781, -2209.318359375, 1.9927320480347 
function loginHandler(player, username, password) 
             local account = getAccount(username, password) 
             if (account ~= false) then 
                 if (logIn(player, username, password) == true) then 
                    spawnPlayer(source, posX, posY, posZ) 
                    fadeCamera(source, true) 
                    setCameraTarget(source, source) 
                    setPedArmor(source, 100) 
                    setElementModel(source, 287) 
                    outputChatBox("Wow, you actually made it on", player) 
                    triggerClientEvent(player, "hideLoginWindow", getRootElement()) 
                   end 
            else 
                outputChatBox("Invalid username or password!",player) 
           end 
end 
addEvent("submitLogin", true) 
addEventHandler("submitLogin", getRootElement(), loginHandler) 
  
function dieInServer() 
    spawnPlayer(source, posX, posY, posZ) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    setPedArmor(source, 100) 
    setElementModel(source, 287) 
    outputChatBox("And.... BAM! You're back!", source) 
end 
addEventHandler("onPlayerWasted",getRootElement(),dieInServer) 

Link to comment
<meta> 
    <info author="Tiger" version="1.0" type="gamemode" name="Server" description="a simple spawn script" /> 
    
    <script src="Server.lua" /> 
    <script src="Client.lua" type="client" /> 
</meta> 

You have to put the client type, if you dont put the type it will load as server side script. therefore, you got the error.

Link to comment

Hello again :D. I've only just had time to test it, and this time the login panel shows, but the same problem as before, when you click the button, it doesn't do anything.

When I activate debugscript 3, I get no errors, only 4 warnings:

-- WARNING: Server\Client.lua:26: Bad argument @ 'addEventHandler' [expected element at argument 2, got nil]

-- WARNING: Server\Client.lua:35: Bad argument @ 'addEventHandler' [expected element at argument 2, got nil]

-- WARNING: Server\Client.lua:45: Bad argument @ guiEditSetMaxLength' [expected gui-element at argument 1, got nil]

-- WARNING: Server\Client.lua:46: Bad argument @ 'addEventHandler' [expected element at argument 2, got nil]

these are the lines it's got problems with:

addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 

-- For 3 of them

guiEditSetMaxLength(edtUser, 20) 

-- For 1 of them.

here is the full client code:

local localPlayer = getLocalPlayer() 
local playerName = getPlayerName(localPlayer) 
function clientSubmitLogin(button,state) 
    if button == "left" and state == "up" then 
    
        local username = guiGetText(edtUser) 
        
        local password = guiGetText(edtPass) 
  
  
        if username and password then 
            
            triggerServerEvent("submitLogin", getRootElement(), localPlayer, username, password) 
        else 
            outputChatBox("Please enter a username and password.") 
        end 
    end 
end 
  
function createLoginWindow() 
    local X = 0.375 
    local Y = 0.375 
    local Width = 0.25 
    local Height = 0.25 
    wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    X = 0.0825 
    Y = 0.25 
    Width = 0.25 
    Height = 0.25 
    guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) 
    Y = 0.5 
    guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) 
    
    X = 0.415 
    Y = 0.25 
    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) 
    guiEditSetMaxLength(edtUser, 20) 
    guiEditSetMaxLength(edtpass, 20) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin) 
    X = 0.415 
    Y = 0.7 
    Width = 0.25 
    Height = 0.20 
    bntLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) 
    guiSetVisible(wdwLogin, false) 
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(), 
    function () 
        createLoginWindow() 
                outputChatBox("Welcome to My MTA:SA Server, please log in.") 
            if (wdwLogin ~= nil) then 
            guiSetVisible(wdwLogin, true) 
        else 
            outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") 
            end 
  
        
            showCursor(true) 
            guiSetInputEnabled(true) 
    end 
) 
function hideLoginWindow() 
      guiSetInputEnabled(false) 
      guiSetVisible(wdwLogin, false) 
      showCursor(false) 
end 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 

Link to comment

Try this, not tested but It could work.

local localPlayer = getLocalPlayer() 
local playerName = getPlayerName(localPlayer) 
function clientSubmitLogin(button,state) 
    if button == "left" and state == "up" then 
    
        local username = guiGetText(edtUser) 
        
        local password = guiGetText(edtPass) 
  
  
        if username and password then 
            
            triggerServerEvent("submitLogin", getRootElement(), localPlayer, username, password) 
        else 
            outputChatBox("Please enter a username and password.") 
        end 
    end 
end 
  
function createLoginWindow() 
    local X = 0.375 
    local Y = 0.375 
    local Width = 0.25 
    local Height = 0.25 
    wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) 
  
    X = 0.0825   
    Width = 0.25 
    Height = 0.25 
    guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) 
    Y = 0.5 
    guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) 
  
    X = 0.415 
    Y = 0.25 
    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) 
    guiEditSetMaxLength(edtUser, 20) 
    guiEditSetMaxLength(edtpass, 20) 
    X = 0.415                         
    Y = 0.7 
    Width = 0.25 
    Height = 0.20 
    bntLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) 
    guiSetVisible(wdwLogin, false) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin) 
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(), 
    function () 
        createLoginWindow() 
        outputChatBox("Welcome to My MTA:SA Server, please log in.") 
        if not guiGetVisible(wdwLogin) then 
            guiSetVisible(wdwLogin, true) 
        else 
            outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") 
        end 
            showCursor(true) 
            guiSetInputEnabled(true) 
    end 
) 
function hideLoginWindow() 
      guiSetInputEnabled(false) 
      guiSetVisible(wdwLogin, false) 
      showCursor(false) 
end 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 

Link to comment

No sadly it still isn't working :\.

Maybe it's a problem with the server side script?

local posX, posY, posZ = 2584.9523925781, -2209.318359375, 1.9927320480347 
function loginHandler(player, username, password) 
             local account = getAccount(username, password) 
             if (account ~= false) then 
                 if (logIn(player, username, password) == true) then 
                    spawnPlayer(source, posX, posY, posZ) 
                    fadeCamera(source, true) 
                    setCameraTarget(source, source) 
                    setPedArmor(source, 100) 
                    setElementModel(source, 287) 
                    outputChatBox("Wow, you actually made it on", player) 
                    triggerClientEvent(player, "hideLoginWindow", getRootElement()) 
                   end 
            else 
                outputChatBox("Invalid username or password!",player) 
           end 
end 
addEvent("submitLogin", true) 
addEventHandler("submitLogin", getRootElement(), loginHandler) 
  
function dieInServer() 
    spawnPlayer(source, posX, posY, posZ) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    setPedArmor(source, 100) 
    setElementModel(source, 287) 
    outputChatBox("And.... BAM! You're back!", source) 
end 
addEventHandler("onPlayerWasted",getRootElement(),dieInServer) 

Link to comment

How about tbis?

local localPlayer = getLocalPlayer() 
local playerName = getPlayerName(localPlayer) 
function clientSubmitLogin(button,state) 
    if button == "left" and state == "up" then 
    
        local username = guiGetText(edtUser) 
        
        local password = guiGetText(edtPass) 
  
  
        if username and password then 
            
            triggerServerEvent("submitLogin", getRootElement(), localPlayer, username, password) 
        else 
            outputChatBox("Please enter a username and password.") 
        end 
    end 
end 
addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin) 
  
function createLoginWindow() 
    local X = 0.375 
    local Y = 0.375 
    local Width = 0.25 
    local Height = 0.25 
    wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) 
  
    X = 0.0825   
    Width = 0.25 
    Height = 0.25 
    guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) 
    Y = 0.5 
    guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) 
  
    X = 0.415 
    Y = 0.25 
    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) 
    guiEditSetMaxLength(edtUser, 20) 
    guiEditSetMaxLength(edtpass, 20) 
    X = 0.415                         
    Y = 0.7 
    Width = 0.25 
    Height = 0.20 
    bntLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) 
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(), 
    function () 
        createLoginWindow() 
        outputChatBox("Welcome to My MTA:SA Server, please log in.") 
        showCursor(true) 
        guiSetInputEnabled(true) 
    end 
) 
function hideLoginWindow() 
      guiSetInputEnabled(false) 
      guiSetVisible(wdwLogin, false) 
      showCursor(false) 
end 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 

Link to comment
local localPlayer = getLocalPlayer() 
local playerName = getPlayerName(localPlayer) 
function clientSubmitLogin(button,state) 
    if button == "left" and state == "up" then 
    
        local username = guiGetText(edtUser) 
        
        local password = guiGetText(edtPass) 
  
  
        if username and password then 
            
            triggerServerEvent("submitLogin", getRootElement(), localPlayer, username, password) 
        else 
            outputChatBox("Please enter a username and password.") 
        end 
    end 
end 
  
function createLoginWindow() 
    local X = 0.375 
    local Y = 0.375 
    local Width = 0.25 
    local Height = 0.25 
    wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) 
  
    X = 0.0825   
    Width = 0.25 
    Height = 0.25 
    guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) 
    Y = 0.5 
    guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) 
  
    X = 0.415 
    Y = 0.25 
    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) 
    guiEditSetMaxLength(edtUser, 20) 
    guiEditSetMaxLength(edtpass, 20) 
    X = 0.415                         
    Y = 0.7 
    Width = 0.25 
    Height = 0.20 
    bntLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) 
    addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin) 
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(), 
    function () 
        createLoginWindow() 
        outputChatBox("Welcome to My MTA:SA Server, please log in.") 
        showCursor(true) 
        guiSetInputEnabled(true) 
    end 
) 
function hideLoginWindow() 
      guiSetInputEnabled(false) 
      guiSetVisible(wdwLogin, false) 
      showCursor(false) 
end 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 

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