Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Login Form
- function createLoginWindow()
- -- Position for Window
- local X = 0.375
- local Y = 0.375
- local Width = 0.25
- local Height = 0.15
- -- Create Window
- wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true)
- -- Position for Labels
- X = 0.0825
- Y = 0.20
- Width = 0.25
- Height = 0.25
- -- Create Label
- guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin)
- Y = 0.5
- guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin)
- -- Position for Inputs
- X = 0.415
- Y = 0.20
- Width = 0.5
- Height = 0.25
- -- Create Inputs
- inputUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)
- Y = 0.5
- inputPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)
- -- Mask inputPass
- guiEditSetMasked ( inputPass, true )
- -- Max chars
- guiEditSetMaxLength(inputUser, 50)
- guiEditSetMaxLength(inputPass, 50)
- -- Position for Buttons
- X = 0.415
- Y = 0.8
- Width = 0.20
- Height = 0.2
- -- Create Buttons
- btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin)
- X = 0.650
- btnRegister = guiCreateButton(X, Y, Width, Height, "Register", true, wdwLogin)
- -- make the window invisible
- guiSetVisible(wdwLogin, false)
- addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false)
- addEventHandler("onClientGUIClick", btnRegister, clientShowRegister, false)
- end
- -- Register Form
- function createRegisterWindow()
- -- Position for Window
- local X = 0.375
- local Y = 0.375
- local Width = 0.25
- local Height = 0.25
- -- Create Window
- wdwRegister = guiCreateWindow(X, Y, Width, Height, "Please Register", true)
- -- Position for Labels
- X = 0.0825
- Y = 0.1
- Width = 0.25
- Height = 0.25
- -- Create Label
- guiCreateLabel(X, Y, Width, Height, "Username", true, wdwRegister)
- Y = 0.3
- guiCreateLabel(X, Y, Width, Height, "Password", true, wdwRegister)
- Y = 0.5
- guiCreateLabel(X, Y, Width, Height, "Repeat Password", true, wdwRegister)
- -- Position for Inputs
- X = 0.415
- Y = 0.1
- Width = 0.5
- Height = 0.15
- -- Create Inputs
- inputUserReg = guiCreateEdit(X, Y, Width, Height, "", true, wdwRegister)
- Y = 0.3
- inputPassReg = guiCreateEdit(X, Y, Width, Height, "", true, wdwRegister)
- Y = 0.5
- inputPassReg2 = guiCreateEdit(X, Y, Width, Height, "", true, wdwRegister)
- -- Mask inputPass
- guiEditSetMasked ( inputPassReg, true )
- guiEditSetMasked ( inputPassReg2, true )
- -- Max chars
- guiEditSetMaxLength(inputUserReg, 50)
- guiEditSetMaxLength(inputPassReg, 50)
- guiEditSetMaxLength(inputPassReg2, 50)
- -- Position for Buttons
- X = 0.415
- Y = 0.7
- Width = 0.20
- Height = 0.2
- -- Create Buttons
- btnRegister = guiCreateButton(X, Y, Width, Height, "Register", true, wdwRegister)
- X = 0.650
- btnLogin = guiCreateButton(X, Y, Width, Height, "Back", true, wdwRegister)
- -- make the window invisible
- guiSetVisible(wdwLogin, false)
- addEventHandler("onClientGUIClick", btnRegister, clientSubmitRegister, false)
- addEventHandler("onClientGUIClick", btnLogin, clientShowLogin, false)
- end
- -- Show Register Form
- function clientShowRegister(button,state)
- if button == "left" and state == "up" then
- guiSetVisible(wdwLogin, false)
- guiSetVisible(wdwRegister, true)
- end
- end
- -- Show Login Form
- function clientShowLogin(button,state)
- if button == "left" and state == "up" then
- guiSetVisible(wdwLogin, true)
- guiSetVisible(wdwRegister, false)
- end
- end
- -- Login Submit
- function clientSubmitLogin(button,state)
- if button == "left" and state == "up" then
- -- get the text entered in the 'username' field
- local username = guiGetText(inputUser)
- -- get the text entered in the 'password' field
- local password = guiGetText(inputPass)
- -- 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)
- -- hide the gui, hide the cursor and return control to the player
- 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
- -- Register Submit
- function clientSubmitRegister(button,state)
- if button == "left" and state == "up" then
- -- Get the text entered in the fields
- local username = guiGetText(inputUserReg)
- local password = guiGetText(inputPassReg)
- local password2 = guiGetText(inputPassReg2)
- -- If all fields contain text
- if username ~= "" and password ~= "" and password2 ~= "" then
- -- Trigger the server event 'submitLogin' and pass the details
- triggerServerEvent("submitRegister", getRootElement(), username, password, password2)
- -- hide the gui, hide the cursor and return control to the player
- guiSetInputEnabled(false)
- guiSetVisible(wdwRegister, false)
- showCursor(false)
- else
- -- otherwise, output a message to the player, do not trigger the server
- -- and do not hide the gui
- outputChatBox("Please fill out all the fields")
- end
- end
- end
- -- Define custom events
- addEvent("clientShowLogin",true)
- addEventHandler("clientShowLogin", root, clientShowLogin)
- addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),
- function ()
- -- create the log in window and its components
- createLoginWindow()
- createRegisterWindow()
- guiSetVisible(wdwRegister, false)
- -- output a brief welcome message to the player
- outputChatBox("Welcome to the Herts Gaming GTA Server, please log in.")
- -- if the GUI was successfully created, then show the GUI to the player
- if (wdwLogin ~= nil) then
- guiSetVisible(wdwLogin, true)
- else
- -- if the GUI hasnt been properly created, tell the player
- outputChatBox("An unexpected error has occurred and the log in GUI has not been created.")
- end
- -- enable the players cursor (so 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
- )
- -- 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 successfully logged in, so spawn them
- if (client) then
- local spawnX, spawnY, spawnZ = 2506, -1676, 14
- spawnPlayer(client, spawnX, spawnY, spawnZ
- )
- fadeCamera(client, true)
- setCameraTarget(client, client)
- createBlipAttachedTo ( client, 0 )
- outputChatBox("Welcome to My Server.", client)
- end
- else
- -- if the username or password are not correct, output a message to the player
- outputChatBox("Invalid username or password. Please try again.",client)
- triggerClientEvent ( "clientShowLogin", getRootElement())
- end
- end
- -- Define custom events
- addEvent("submitLogin",true)
- addEventHandler("submitLogin",root,loginHandler)
- addEvent("submitRegister",true)
- addEventHandler("submitRegister",root,registerHandler)
Add Comment
Please, Sign In to add comment