Advertisement
Guest User

Untitled

a guest
Aug 29th, 2013
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ---------------------------------
  2. --Project: Vitality Gaming
  3. --Author: sekoX
  4. --File: login_client.lua
  5. --Side: Client
  6. ---------------------------------
  7. loginGUI = {}
  8.  
  9. function loadLoginGUI()
  10.     loginGUI.window = guiCreateStaticImage(screen.x/2-512/2, screen.y/2-512/2, 512, 512, "files/images/login/background.png", false)
  11.     loginGUI.loginB = guiCreateStaticImage(113, 336, 128, 64, "files/images/login/login.png", false, loginGUI.window)
  12.     loginGUI.guestB = guiCreateStaticImage(272, 336, 128, 64, "files/images/login/playasguest.png", false, loginGUI.window)
  13.     loginGUI.username = guiCreateEdit(115, 245, 283, 26, "", false, loginGUI.window)
  14.     loginGUI.password = guiCreateEdit(115, 305, 283, 26, "", false, loginGUI.window)
  15.  
  16.     guiSetAlpha(loginGUI.window, 0)
  17.     guiEditSetMaxLength (loginGUI.username, 24)
  18.     guiEditSetMasked (loginGUI.password, true)
  19.     guiSetInputMode("no_binds_when_editing")
  20.     addEventHandler ("onClientGUIClick", loginGUI.loginB, onButtonClick, false)
  21.     addEventHandler ("onClientGUIClick", loginGUI.guestB, onButtonClick, false)
  22.     addEventHandler("onClientRender", getRootElement(), fadeLoginGUI)
  23.     showCursor(true)
  24. end
  25. addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), loadLoginGUI)
  26.  
  27. function fadeLoginGUI()
  28.     if guiGetAlpha(loginGUI.window) < 1 then
  29.         guiSetAlpha(loginGUI.window, guiGetAlpha(loginGUI.window) + 0.05)
  30.     end
  31.     if guiGetAlpha(loginGUI.window) > 0 then
  32.         guiSetAlpha(loginGUI.window, guiGetAlpha(loginGUI.window) - 0.05)
  33.     end
  34. end
  35.  
  36. function loginButtonHover()
  37.     if source == loginGUI.loginB then
  38.         guiStaticImageLoadImage(loginGUI.loginB, "files/images/login/login_hover.png")
  39.         playSound("files/sounds/buttonHover.mp3")
  40.     end
  41. end
  42.  
  43. function loginButtonLeave()
  44.     if source == loginGUI.loginB then
  45.         guiStaticImageLoadImage(loginGUI.loginB, "files/images/login/login.png")
  46.     end
  47. end
  48.  
  49. function guestButtonHover()
  50.     if source == loginGUI.guestB then
  51.         guiStaticImageLoadImage(loginGUI.guestB, "files/images/login/playasguest_hover.png")
  52.         playSound("files/sounds/buttonHover.mp3")
  53.     end
  54. end
  55.  
  56. function guestButtonLeave()
  57.     if source == loginGUI.guestB then
  58.         guiStaticImageLoadImage(loginGUI.guestB, "files/images/login/playasguest.png")
  59.     end
  60. end
  61.  
  62. addEventHandler("onClientMouseEnter", getRootElement(), loginButtonHover)
  63. addEventHandler("onClientMouseLeave", getRootElement(), loginButtonLeave)
  64. addEventHandler("onClientMouseEnter", getRootElement(), guestButtonHover)
  65. addEventHandler("onClientMouseLeave", getRootElement(), guestButtonLeave)
  66.  
  67. function onButtonClick(button)
  68.     if button == "left" then
  69.         if source == loginGUI.loginB then
  70.             triggerServerEvent("event_login", getLocalPlayer(), guiGetText(loginGUI.username), guiGetText(loginGUI.password))
  71.             playSound("files/sounds/click.mp3")
  72.         elseif source == loginGUI.guestB then
  73.             triggerServerEvent("event_guest", getLocalPlayer())
  74.             playSound("files/sounds/click.mp3")
  75.         end
  76.     end
  77. end
  78.  
  79. function successLogin(message)
  80.     showCursor(false)
  81.     destroyElement(loginGUI.window)
  82.     playSound("files/sounds/achievement.mp3")
  83.     addEventHandler("onClientRender", getRootElement(), fadeLoginGUI)
  84. end
  85. addEvent("event_success", true)
  86. addEventHandler("event_success", getResourceRootElement(getThisResource()), successLogin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement