Jump to content

Login GUI from wiki


maky55

Recommended Posts

What is the error now?

No error comes up. The same two warnings are there.

I created a new account to test it on and gave it admin. Username: admin Password: password.

I typed it all in, and clicked the button. The button could be clicked, but it didn't do anything. Normally if the password/username was bad, it would put in the chatbox 'Invalid username or password!' but it didn't. I think the problem is the button.

Link to comment

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) 

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

Meta:

(For the meta, I've tried both gamemode and script. Neither work

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

Link to comment

Server

local posX, posY, posZ = 2584.9523925781, -2209.318359375, 1.9927320480347 
function loginHandler(username, password) 
    local account = getAccount(username, password) 
        if (account ~= false) then 
            if (logIn(source, 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", source) 
                triggerClientEvent(source, "hideLoginWindow", source) 
            end 
        else 
            outputChatBox("Invalid username or password!",source) 
        end 
    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) 

By they way, localPlayer is predefinied variable in MTA, so you don't have to add this in the top of code.

Personnaly I would do something like that:

local playerName = getPlayerName(localPlayer) 
  
function clientSubmitLogin() 
    local username = guiGetText(edtUser) 
    local password = guiGetText(edtPass) 
        if ( username ~= "" and password ~= "" ) then 
            triggerServerEvent("submitLogin", 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, false) 
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) 
      destroyElement ( wdwLogin ) 
      showCursor(false) 
end 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 
  

Link to comment

Oh, damn. Sorry, my bad

local posX, posY, posZ = 2584.9523925781, -2209.318359375, 1.9927320480347 
function loginHandler(username, password) 
    local account = getAccount(username, password) 
    if (account ~= false) then 
        if (logIn(source, 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", source) 
            triggerClientEvent(source, "hideLoginWindow", source) 
        end 
    else 
       outputChatBox("Invalid username or password!",source) 
    end 
end 
addEvent("submitLogin", true) 
addEventHandler("submitLogin", getRootElement(), loginHandler) 

Link to comment

Sorry again xD

function clientSubmitLogin() 
    local username = guiGetText(edtUser) 
    local password = guiGetText(edtPass) 
    if ( username ~= "" and password ~= "" ) then 
        triggerServerEvent("submitLogin", localPlayer, username, password) 
    else 
        outputChatBox("Please enter a username and password.") 
    end 
end 
  

Link to comment

It still doesn't seem to be working :3. Same problem as before, it doesn't tell my my username and password is wrong, and the button doesn't do anything.

Still the same warnings as before :(.

Sorry if this is bothering anyone i'm just a beginner at doing this xD.

Maybe if anyone other then me could test the scripts to see if I'm doing something wrong?

Link to comment

Client

local posX, posY, posZ = 2584.9523925781, -2209.318359375, 1.9927320480347 
function loginHandler(username, password) 
    outputChatBox ( username .. ":" .. password ) 
    local account = getAccount(username, password) 
    if (account ~= false) then 
        local loggin = logIn(source, username, password) 
        if ( loggin ) 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", source) 
            triggerClientEvent(source, "hideLoginWindow", source) 
        end 
    else 
       outputChatBox("Invalid username or password!",source) 
    end 
end 
addEvent("submitLogin", true) 
addEventHandler("submitLogin", getRootElement(), loginHandler) 

Server

local playerName = getPlayerName(localPlayer) 
local guiElements = { } 
  
function clientSubmitLogin() 
    local username = guiGetText(guiElements["edit_user"]) 
    local password = guiGetText(guiElements["edit_pass"]) 
        if ( username ~= "" and password ~= "" ) then 
            triggerServerEvent("submitLogin", localPlayer, username, password) 
            outputChatBox ( username .. ":" .. password ) 
        else 
            outputChatBox("Please enter a username and password.") 
        end 
    end 
end 
  
function createLoginWindow() 
    guiElements["login_window"] = guiCreateWindow(0.375, 0.375, 0.25, 0.25, "Please Log In", true) 
    guiCreateLabel(0.0825, 0.375, 0.25, 0.25, "Username", true, guiElements["login_window"]) 
    guiCreateLabel(0.0825, 0.5, 0.25, 0.25, "Password", true, guiElements["login_window"]) 
     
    guiElements["edit_user"] = guiCreateEdit(0.415, 0.25, 0.5, 0.15, "", true, guiElements["login_window"]) 
    guiElements["edit_pass"] = guiCreateEdit(0.415, 0.5, 0.5, 0.15, "", true, guiElements["login_window"]) 
    guiEditSetMaxLength(guiElements["edit_user"], 20) 
    guiEditSetMaxLength(guiElements["edit_pass"], 20) 
     
    guiElements["login_button"] = guiCreateButton(0.415, 0.7, 0.25, 0.20, "Log In", true, guiElements["login_window"]) 
    addEventHandler("onClientGUIClick", guiElements["login_button"], clientSubmitLogin, false) 
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) 
    showCursor(false) 
     
    if ( isElement ( guiElements["login_window"] ) ) then 
        destroyElement ( guiElements["login_window"] ) 
    end 
end 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 

Tell me if in chat it shows "login:password" two times.

Link to comment
So it should work. If it doesn't add this resource in admin group in acl.xml
<object name="resource.resource_name" /> 

I've already added it. Problem is, it doesn't actually log me in, and the gui doesn't disapeer either.

And also, this is a warning about it:

WARNING:[gameplay]\server\server.lua:5: Bad argument @ 'logIn' [Expected account at argument 2, got string 'admin']

Edited by Guest
Link to comment

Server

local posX, posY, posZ = 2584.9523925781, -2209.318359375, 1.9927320480347 
function loginHandler(username, password) 
    local account = getAccount(username, password) 
    outputChatBox ( "1" ) 
    if ( account ) then 
        local loggin = logIn(source, username, password) 
        outputChatBox ( "2" ) 
        if ( loggin ) then 
        outputChatBox ( "3" ) 
            spawnPlayer(source, posX, posY, posZ) 
            fadeCamera(source, true) 
            setCameraTarget(source, source) 
            setPedArmor(source, 100) 
            setElementModel(source, 287) 
            outputChatBox("Wow, you actually made it on", source) 
            triggerClientEvent(source, "hideLoginWindow", source) 
        end 
    else 
       outputChatBox("Invalid username or password!",source) 
    end 
end 
addEvent("submitLogin", true) 
addEventHandler("submitLogin", getRootElement(), loginHandler) 

Client

local playerName = getPlayerName(localPlayer) 
local guiElements = { } 
  
function clientSubmitLogin() 
    local username = guiGetText(guiElements["edit_user"]) 
    local password = guiGetText(guiElements["edit_pass"]) 
    if ( username ~= "" and password ~= "" ) then 
        triggerServerEvent("submitLogin", localPlayer, username, password) 
        outputChatBox ( username .. ":" .. password ) 
     else 
        outputChatBox("Please enter a username and password.") 
    end 
end 
  
function createLoginWindow() 
    guiElements["login_window"] = guiCreateWindow(0.375, 0.375, 0.25, 0.25, "Please Log In", true) 
    guiCreateLabel(0.0825, 0.375, 0.25, 0.25, "Username", true, guiElements["login_window"]) 
    guiCreateLabel(0.0825, 0.5, 0.25, 0.25, "Password", true, guiElements["login_window"]) 
    
    guiElements["edit_user"] = guiCreateEdit(0.415, 0.25, 0.5, 0.15, "", true, guiElements["login_window"]) 
    guiElements["edit_pass"] = guiCreateEdit(0.415, 0.5, 0.5, 0.15, "", true, guiElements["login_window"]) 
    guiEditSetMaxLength(guiElements["edit_user"], 20) 
    guiEditSetMaxLength(guiElements["edit_pass"], 20) 
    
    guiElements["login_button"] = guiCreateButton(0.415, 0.7, 0.25, 0.20, "Log In", true, guiElements["login_window"]) 
    addEventHandler("onClientGUIClick", guiElements["login_button"], clientSubmitLogin, false) 
end 
  
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function () 
        createLoginWindow() 
        outputChatBox("Welcome to My MTA:SA Server, please log in.") 
        showCursor(true) 
        guiSetInputEnabled(true) 
    end 
) 
function hideLoginWindow() 
    guiSetInputEnabled(false) 
    showCursor(false) 
    
    if ( isElement ( guiElements["login_window"] ) ) then 
        destroyElement ( guiElements["login_window"] ) 
    end 
end 
addEvent("hideLoginWindow", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 

Tell me how many number it will show in chatbox.

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