Jump to content

login window from mta wiki tutorials


Recommended Posts

hi guys :)

Thing is, either i dont understand english well, or i did some stupid error in typing.

https://wiki.multitheftauto.com/wiki/In ... _the_click

mta wiki says add the eventHandler in the createLoginWindow function, so i added it!

but my button is not workin

and no errors in debugscript

my code

-- makin a login window 
-- makin a simple window with 2 input boxes and a button 
-- window will appear when the player joins the game 
-- once button is clicked, player is spawned 
  
  
-- Drawin the window 
--all the gui must be made client side, its a good practice to keep all client scripts in a separate folder 
  
function createLoginWindow() 
-- we could have locally define our x,y, width and height for the position of the window, but i prefer to use it directly, i mean usin it in the window creation function 
    wdwLogin = guiCreateWindow(0.375,0.375,0.25,0.25, "Please Log In", true) 
    --we created our window and save its element value into the variable "wdwLogin" 
    --final argument passed to guiCreateWindow is true, meanin the coordinates and dimensions of the window are relative, which means that they are a percentage of the total screen size 
     
    --.now we could have define more x,y, width and height for our label, but lets do it directly 
    guiCreateLabel(0.0825,0.2,0.25,0.25, "username", true, wdwLogin) 
    guiCreateLabel(0.0825,0.5,0.25,0.25, "password",true, wdwLogin) 
     
    -- now lets create our edit boxes, but without defining the dimensions (x,y,..) 
    edtUser = guiCreateEdit(0.415,0.2,0.5,0.15, "", true, wdwLogin) 
    edtPass = guiCreateEdit(0.415,0.5,0.5,0.15, "", true, wdwLogin) 
    guiEditSetMaxLength(edtUser, 15) 
    guiEditSetMaxLength(edtPass, 15) 
     
    --the button now 
    btnLogin = guiCreateButton(0.415,0.7,0.25,0.2, "Log in", true, wdwLogin) 
     
     
    -- make the window invisible 
    guiSetVisible(wdwLogin, false) 
     
    --add our onClientGuiClick event to the button we just created 
    addEventHandler("onClientGuiClick", btnLogin, clientSubmitLogin, false) 
     
end 
  
  
  
  
--this is a log in window, so we need to show the window when the player joins the game, and this can be done using the onClientResourceStart 
--attach the event handler to the root element of the resource 
--this means it will only trigger when its own resource is started 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), 
        function () 
                -- create the log in window and its components 
                createLoginWindow() 
                 
                outputChatBox("Welcome to my mta sa server, please log in") 
                --this is important now! 
                --how to know if the gui was successfully created or not 
                --by usin this : 
                if (wdwLogin ~= nil ) then -- if the gui isnt nil, meanint its true, that is it was created 
                    guiSetVisible(wdwLogin, true) 
                else 
                    -- the gui wasnt well created or did not create !!! 
                    outputChatBox("an unexpected error has occured, and the log in guyi has not been created.") 
                    end 
                     
                    --enable the players cursor 
                    showCursor(true) 
                    -- set the input focus onto the gui, allowin players to press T without the chatbox opening 
                    guiSetInputEnabled(true) 
                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 and the state of the mouse button is up  
        if button == "left" and state == "up" then 
                -- get the text entered in the username and password field 
                local username = guiGetText(edtUser) 
                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 onto the game(allowin players to move around, open the chatbox, etc) 
                guiSetInputEnabled(false) 
                guiSetVisible(wdwLogin, false) 
                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 
  
  
  
     
         

yup :roll: no errors in debugscript

help me plz :oops:

thanks in advance guys

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