Advertisement
Guest User

Untitled

a guest
Mar 12th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.19 KB | None | 0 0
  1. function dxDrawLoginPanel( )
  2. -- default: 350, 266
  3. if ( isOpen ) then
  4. dxDrawRectangle(pX, pY, 485, 231, tocolor(0, 0, 0, 180), false)
  5. dxDrawText("Login", pX, pY, 870, 314, tocolor(255, 255, 255, 255), 1.50, "bankgothic", "center", "top", false, false, false, false, false)
  6. dxDrawLine(pX, pY+48, pX+485, pY+48, tocolor(255, 255, 255, 255), 1, false)
  7. dxDrawText("Username:", pX+10, pY+69, 506, 368, tocolor(255, 255, 255, 255), 0.80, "bankgothic", "left", "top", false, false, false, false, false)
  8. dxDrawText("Password:", pX+10, pY+129, 506, 428, tocolor(255, 255, 255, 255), 0.80, "bankgothic", "left", "top", false, false, false, false, false)
  9. dxDrawLine(pX+281, pY+168, pX+281, pY+168+34, tocolor(255, 255, 255, 255), 1, false)
  10.  
  11. local r, g, b = unpack ( data.login.colors )
  12. dxDrawText("Login", pX+166, pY+167, 600, 468, tocolor( r, g, b, data.login.loginTextAlpha), 1.00, "bankgothic", "left", "top", false, false, false, false, false)
  13. local r, g, b = unpack ( data.reg.colors )
  14. dxDrawText("Register", pX+305, pY+167, 794, 468, tocolor(r, g, b, data.reg.loginTextAlpha), 1.00, "bankgothic", "left", "top", false, false, false, false, false)
  15.  
  16. if ( enableGuest ) then
  17. local r, g, b = unpack ( data.guest.colors )
  18. dxDrawText("Guest", pX+40, pY+167, 600, 468, tocolor( r, g, b, data.guest.loginTextAlpha), 1.00, "bankgothic", "left", "top", false, false, false, false, false)
  19. dxDrawLine(pX+155, pY+168, pX+155, pY+168+34, tocolor(255, 255, 255, 255), 1, false)
  20. end
  21.  
  22. -- give fade effect
  23. if ( data.login.hovering ) then
  24. data.login.colors = { 255, 140, 0 }
  25. local alpha = data.login.loginTextAlpha
  26. if ( not data.login.alphaMode ) then
  27. data.login.loginTextAlpha = alpha - 5
  28. if ( data.login.loginTextAlpha <= 50 ) then
  29. data.login.alphaMode = true
  30. end
  31. else
  32. data.login.loginTextAlpha = alpha + 5
  33. if ( data.login.loginTextAlpha >= 235 ) then
  34. data.login.alphaMode = false
  35. end
  36. end
  37. elseif ( data.reg.hovering ) then
  38. data.reg.colors = { 255, 140, 0 }
  39. local alpha = data.reg.loginTextAlpha
  40. if ( not data.reg.alphaMode ) then
  41. data.reg.loginTextAlpha = alpha - 5
  42. if ( data.reg.loginTextAlpha <= 50 ) then
  43. data.reg.alphaMode = true
  44. end
  45. else
  46. data.reg.loginTextAlpha = alpha + 5
  47. if ( data.reg.loginTextAlpha >= 235 ) then
  48. data.reg.alphaMode = false
  49. end
  50. end
  51. elseif ( data.guest.hovering ) then
  52. data.guest.colors = { 255, 140, 0 }
  53. local alpha = data.guest.loginTextAlpha
  54. if ( not data.guest.alphaMode ) then
  55. data.guest.loginTextAlpha = alpha - 5
  56. if ( data.guest.loginTextAlpha <= 50 ) then
  57. data.guest.alphaMode = true
  58. end
  59. else
  60. data.guest.loginTextAlpha = alpha + 5
  61. if ( data.guest.loginTextAlpha >= 235 ) then
  62. data.guest.alphaMode = false
  63. end
  64. end
  65. else
  66. data.login.loginTextAlpha = 235
  67. data.guest.loginTextAlpha = 235
  68. data.reg.loginTextAlpha = 235
  69. data.login.colors = { 255, 255, 255 }
  70. data.guest.colors = { 255, 255, 255 }
  71. data.reg.colors = { 255, 255, 255 }
  72. end
  73. end
  74. end
  75.  
  76. function cursorMove ( _, _, x, y )
  77. if ( isCursorShowing ( ) and not guiGetVisible ( window ) and isOpen) then
  78. if ( y >= pY+170 and y <= pY+200 ) then
  79. if ( x >= pX+161 and x <= pX+251 ) then
  80. data.login.hovering = true
  81. return
  82. elseif ( x >= pX+305 and x <= pX+445 ) then
  83. data.reg.hovering = true
  84. return
  85. elseif ( x >= pX+40 and x <= pX+135 ) then
  86. data.guest.hovering = true
  87. return
  88. end
  89. end
  90. end
  91. data.login.hovering = false
  92. data.reg.hovering = false
  93. data.guest.hovering = false
  94. end
  95.  
  96. function openLogin ( )
  97. addEventHandler ( "onClientPreRender", root, dxDrawLoginPanel )
  98. addEventHandler ( 'onClientCursorMove', root, cursorMove )
  99. addEventHandler ( "onClientClick", root, clientClicking )
  100. guiSetInputMode ( "no_binds_when_editing" )
  101. guiSetVisible ( password, true )
  102. guiSetVisible ( username, true )
  103. showCursor ( true )
  104. addEventHandler ( 'onClientGUIClick', root, clientClosingErrorWindowEvent )
  105. isOpen = true
  106. showChat(false)
  107. showPlayerHudComponent ( 'all', false )
  108. end
  109. addEvent ( "onClientPlayerLogout", true )
  110. addEventHandler ( 'onClientPlayerLogout', root, openLogin )
  111.  
  112. function closeLogin ( )
  113. removeEventHandler ( "onClientPreRender", root, dxDrawLoginPanel )
  114. removeEventHandler ( 'onClientCursorMove', root, cursorMove )
  115. removeEventHandler ( "onClientClick", root, clientClicking )
  116. guiSetVisible ( password, false )
  117. guiSetVisible ( username, false )
  118. showCursor ( false )
  119. removeEventHandler ( 'onClientGUIClick', root, clientClosingErrorWindowEvent )
  120. guiSetVisible ( window, false )
  121. isOpen = false
  122. isLoggedin = true
  123. showChat(true)
  124. showPlayerHudComponent ( 'all', true )
  125. end
  126. addEvent ( "onClientPlayerLogin", true )
  127. addEventHandler ( "onClientPlayerLogin", root, closeLogin )
  128.  
  129. function sendError ( msg )
  130. if ( not guiGetVisible ( window ) ) then
  131. guiSetVisible ( window, true )
  132. guiSetText ( infoLbl, msg )
  133. guiBringToFront ( window )
  134. end
  135. end
  136. addEvent ( "onPlayerLoginPanelError", true )
  137. addEventHandler ( "onPlayerLoginPanelError", root, sendError )
  138.  
  139. function clientClicking ( btn, state, x, y )
  140. if ( btn == 'left' and not guiGetVisible ( window ) and state == 'down' and isOpen ) then
  141. if ( y >= pY+170 and y <= pY+200 ) then
  142. local user, pass = guiGetText ( username ), guiGetText ( password )
  143. -- Login Button --
  144. if ( x >= pX+156 and x <= pX+246 ) then
  145. if ( string.gsub ( user, ' ', '' ) ~= '' and string.gsub ( pass, ' ', '' ) ~= '' ) then
  146. if ( string.find ( user, '%s' ) ) then
  147. return sendError ( "Spaces (' ') are not allowed\nin the username." )
  148. end if ( string.find ( pass, '%s' ) ) then
  149. return sendError ( "Spaces (' ') are not allowed\nin the password." )
  150. end
  151. triggerServerEvent ( "Login:onClientAttemptLogin", localPlayer, user, pass )
  152. else
  153. sendError ( "A username and password are\nrequired to access the server." )
  154. end
  155.  
  156. -- register button
  157. elseif ( x >= pX+300 and x <= pX+440 ) then
  158. if ( string.gsub ( user, ' ', '' ) ~= '' and string.gsub ( pass, ' ', '' ) ~= '' ) then
  159. if ( string.find ( user, '%s' ) ) then
  160. return sendError ( "Spaces are not allowed\nin the username." )
  161. end if ( string.find ( pass, '%s' ) ) then
  162. return sendError ( "Spaces are not allowed\nin the password." )
  163. end if ( string.len ( user ) < 5 ) then
  164. return sendError ( "You're username must be at\nleast 5 characters long." )
  165. end if ( string.len ( pass ) < 6 ) then
  166. return sendError ( "You're password must be at\nleast 6 characters long." )
  167. end
  168. triggerServerEvent ( "Login:onClientAttemptRegistration", localPlayer, user, pass )
  169. else
  170. sendError ( "A username and password are\nrequired to access the server." )
  171. end
  172.  
  173. -- play as guest
  174. elseif ( x >= pX+40 and x <= pX+135 ) then
  175. closeLogin ( )
  176. triggerServerEvent ( "Login:doClientGuestLogin", localPlayer )
  177. end
  178. end
  179. end
  180. end
  181.  
  182. function clientClosingErrorWindowEvent( )
  183. if ( source == exitBtn ) then
  184. guiSetVisible ( window, false )
  185. end
  186. end
  187.  
  188. function isClientLoggedin ( )
  189. return isLoggedin
  190. end
  191.  
  192. setTimer ( function ( )
  193. openLogin ( )
  194. end, 700, 1 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement