Guest User

Untitled

a guest
Jun 15th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.21 KB | None | 0 0
  1. -- Login Form
  2. function createLoginWindow()
  3.     -- Position for Window
  4.     local X = 0.375
  5.     local Y = 0.375
  6.     local Width = 0.25
  7.     local Height = 0.15
  8.     -- Create Window
  9.     wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true)
  10.  
  11.     -- Position for Labels
  12.     X = 0.0825
  13.     Y = 0.20
  14.     Width = 0.25
  15.     Height = 0.25
  16.     -- Create Label
  17.     guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin)
  18.     Y = 0.5
  19.     guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin)
  20.  
  21.     -- Position for Inputs
  22.     X = 0.415
  23.     Y = 0.20
  24.     Width = 0.5
  25.     Height = 0.25
  26.     -- Create Inputs
  27.     inputUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)
  28.     Y = 0.5
  29.     inputPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin)
  30.     -- Mask inputPass
  31.     guiEditSetMasked ( inputPass, true )
  32.     -- Max chars
  33.     guiEditSetMaxLength(inputUser, 50)
  34.     guiEditSetMaxLength(inputPass, 50)
  35.  
  36.     -- Position for Buttons
  37.     X = 0.415
  38.     Y = 0.8
  39.     Width = 0.20
  40.     Height = 0.2
  41.     -- Create Buttons
  42.     btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin)
  43.     X = 0.650
  44.     btnRegister = guiCreateButton(X, Y, Width, Height, "Register", true, wdwLogin)
  45.  
  46.     -- make the window invisible
  47.     guiSetVisible(wdwLogin, false)
  48.    
  49.     addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false)
  50.     addEventHandler("onClientGUIClick", btnRegister, clientShowRegister, false)
  51. end
  52.  
  53. -- Register Form
  54. function createRegisterWindow()
  55.     -- Position for Window
  56.     local X = 0.375
  57.     local Y = 0.375
  58.     local Width = 0.25
  59.     local Height = 0.25
  60.     -- Create Window
  61.     wdwRegister = guiCreateWindow(X, Y, Width, Height, "Please Register", true)
  62.    
  63.     -- Position for Labels
  64.     X = 0.0825
  65.     Y = 0.1
  66.     Width = 0.25
  67.     Height = 0.25
  68.     -- Create Label
  69.     guiCreateLabel(X, Y, Width, Height, "Username", true, wdwRegister)
  70.     Y = 0.3
  71.     guiCreateLabel(X, Y, Width, Height, "Password", true, wdwRegister)
  72.     Y = 0.5
  73.     guiCreateLabel(X, Y, Width, Height, "Repeat Password", true, wdwRegister)
  74.    
  75.     -- Position for Inputs
  76.     X = 0.415
  77.     Y = 0.1
  78.     Width = 0.5
  79.     Height = 0.15
  80.     -- Create Inputs
  81.     inputUserReg = guiCreateEdit(X, Y, Width, Height, "", true, wdwRegister)
  82.     Y = 0.3
  83.     inputPassReg = guiCreateEdit(X, Y, Width, Height, "", true, wdwRegister)
  84.     Y = 0.5
  85.     inputPassReg2 = guiCreateEdit(X, Y, Width, Height, "", true, wdwRegister)
  86.     -- Mask inputPass
  87.     guiEditSetMasked ( inputPassReg, true )
  88.     guiEditSetMasked ( inputPassReg2, true )
  89.     -- Max chars
  90.     guiEditSetMaxLength(inputUserReg, 50)
  91.     guiEditSetMaxLength(inputPassReg, 50)
  92.     guiEditSetMaxLength(inputPassReg2, 50)
  93.    
  94.     -- Position for Buttons
  95.     X = 0.415
  96.     Y = 0.7
  97.     Width = 0.20
  98.     Height = 0.2
  99.     -- Create Buttons
  100.     btnRegister = guiCreateButton(X, Y, Width, Height, "Register", true, wdwRegister)
  101.     X = 0.650
  102.     btnLogin = guiCreateButton(X, Y, Width, Height, "Back", true, wdwRegister)
  103.  
  104.     -- make the window invisible
  105.     guiSetVisible(wdwLogin, false)
  106.    
  107.     addEventHandler("onClientGUIClick", btnRegister, clientSubmitRegister, false)
  108.     addEventHandler("onClientGUIClick", btnLogin, clientShowLogin, false)
  109. end
  110.  
  111. -- Show Register Form
  112. function clientShowRegister(button,state)
  113.     if button == "left" and state == "up" then
  114.         guiSetVisible(wdwLogin, false)
  115.         guiSetVisible(wdwRegister, true)
  116.     end
  117. end
  118.  
  119. -- Show Login Form
  120. function clientShowLogin(button,state)
  121.     if button == "left" and state == "up" then
  122.         guiSetVisible(wdwLogin, true)
  123.         guiSetVisible(wdwRegister, false)
  124.     end
  125. end
  126.  
  127. -- Login Submit
  128. function clientSubmitLogin(button,state)
  129.     if button == "left" and state == "up" then
  130.         -- get the text entered in the 'username' field
  131.         local username = guiGetText(inputUser)
  132.         -- get the text entered in the 'password' field
  133.         local password = guiGetText(inputPass)
  134.  
  135.         -- if the username and password both exist
  136.         if username ~= "" and password ~="" then
  137.             -- trigger the server event 'submitLogin' and pass the username and password to it
  138.             triggerServerEvent("submitLogin", getRootElement(), username, password)
  139.  
  140.             -- hide the gui, hide the cursor and return control to the player
  141.             guiSetInputEnabled(false)
  142.             guiSetVisible(wdwLogin, false)
  143.             showCursor(false)
  144.         else
  145.             -- otherwise, output a message to the player, do not trigger the server
  146.             -- and do not hide the gui
  147.             outputChatBox("Please enter a username and password.")
  148.         end
  149.     end
  150. end
  151.  
  152. -- Register Submit
  153. function clientSubmitRegister(button,state)
  154.     if button == "left" and state == "up" then
  155.         -- Get the text entered in the fields
  156.         local username = guiGetText(inputUserReg)
  157.         local password = guiGetText(inputPassReg)
  158.         local password2 = guiGetText(inputPassReg2)
  159.  
  160.         -- If all fields contain text
  161.         if username ~= "" and password ~= "" and password2 ~= "" then
  162.             -- Trigger the server event 'submitLogin' and pass the details
  163.             triggerServerEvent("submitRegister", getRootElement(), username, password, password2)
  164.  
  165.             -- hide the gui, hide the cursor and return control to the player
  166.             guiSetInputEnabled(false)
  167.             guiSetVisible(wdwRegister, false)
  168.             showCursor(false)
  169.         else
  170.             -- otherwise, output a message to the player, do not trigger the server
  171.             -- and do not hide the gui
  172.             outputChatBox("Please fill out all the fields")
  173.         end
  174.     end
  175. end
  176.  
  177. -- Define custom events
  178. addEvent("clientShowLogin",true)
  179. addEventHandler("clientShowLogin", root, clientShowLogin)
  180.  
  181. addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),
  182.     function ()
  183.         -- create the log in window and its components
  184.         createLoginWindow()
  185.         createRegisterWindow()
  186.        
  187.         guiSetVisible(wdwRegister, false)
  188.  
  189.         -- output a brief welcome message to the player
  190.                 outputChatBox("Welcome to the Herts Gaming GTA Server, please log in.")
  191.  
  192.         -- if the GUI was successfully created, then show the GUI to the player
  193.         if (wdwLogin ~= nil) then
  194.             guiSetVisible(wdwLogin, true)
  195.         else
  196.             -- if the GUI hasnt been properly created, tell the player
  197.             outputChatBox("An unexpected error has occurred and the log in GUI has not been created.")
  198.             end
  199.  
  200.         -- enable the players cursor (so they can select and click on the components)
  201.             showCursor(true)
  202.         -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening
  203.             guiSetInputEnabled(true)
  204.     end
  205. )
  206.  
  207. -- create our loginHandler function, with username and password parameters (passed from the client gui)
  208. function loginHandler(username,password)
  209.     -- check that the username and password are correct
  210.     if username == "user" and password == "apple" then
  211.         -- the player has successfully logged in, so spawn them
  212.         if (client) then
  213.             local spawnX, spawnY, spawnZ = 2506, -1676, 14
  214.             spawnPlayer(client, spawnX, spawnY, spawnZ
  215.             )
  216.             fadeCamera(client, true)
  217.             setCameraTarget(client, client)
  218.            
  219.             createBlipAttachedTo ( client, 0 )
  220.            
  221.             outputChatBox("Welcome to My Server.", client)
  222.         end
  223.     else
  224.         -- if the username or password are not correct, output a message to the player
  225.         outputChatBox("Invalid username or password. Please try again.",client)
  226.         triggerClientEvent ( "clientShowLogin", getRootElement())
  227.         end        
  228. end
  229.  
  230. -- Define custom events
  231. addEvent("submitLogin",true)
  232. addEventHandler("submitLogin",root,loginHandler)
  233.  
  234. addEvent("submitRegister",true)
  235. addEventHandler("submitRegister",root,registerHandler)
Add Comment
Please, Sign In to add comment