Advertisement
Guest User

client

a guest
Jul 4th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.58 KB | None | 0 0
  1. sx,sy = guiGetScreenSize()
  2. x,y = (sx/1366), (sy/768)
  3.  
  4. messages = {}
  5. editBox = {}
  6. editBox.__index = editBox
  7. editBox.instances = {}
  8.  
  9. function onClientResourceStart()
  10. tick = getTickCount()
  11. font = dxCreateFont("gfx/sans-pro-regular.otf", 25)
  12. sound = playSound("sfx/music.mp3",true)
  13. showChat(false)
  14. showCursor(true)
  15. guiSetInputEnabled(true)
  16. toggleAllControls(false)
  17. g = {}
  18. g.user = editBox.new()
  19. g.user:setPosition(x*552,y*364,x*263,y*41)
  20. g.user.color = {79,86,94,160}
  21. g.user.font = font
  22. g.user.text = loadLoginFromXML()
  23. g.user.visible = true
  24. g.user.onInput = function()
  25. g.user.color = {87, 95, 104, 160}
  26. end
  27. g.user.onOutput = function()
  28. g.user.color = {79,86,94,160}
  29. end
  30.  
  31. g.pass = editBox.new()
  32. g.pass:setPosition(x*552,y*426,x*263,y*41)
  33. g.pass.color = {79,86,94,160}
  34. g.pass.font = font
  35. g.pass.masked = true
  36. g.pass.visible = true
  37. g.pass.onInput = function()
  38. g.pass.color = {87, 95, 104, 160}
  39. end
  40. g.pass.onOutput = function()
  41. g.pass.color = {79,86,94,160}
  42. end
  43.  
  44. g.rUser = editBox.new()
  45. g.rUser:setPosition(x*552,y*364,x*263,y*41)
  46. g.rUser.color = {79,86,94,160}
  47. g.rUser.font = font
  48. g.rUser.onInput = function()
  49. g.rUser.color = {87, 95, 104, 160}
  50. end
  51. g.rUser.onOutput = function()
  52. g.rUser.color = {79,86,94,160}
  53. end
  54.  
  55. g.rPass = editBox.new()
  56. g.rPass:setPosition(x*552,y*426,x*263,y*41)
  57. g.rPass.color = {79,86,94,160}
  58. g.rPass.font = font
  59. g.rPass.masked = true
  60. g.rPass.onInput = function()
  61. g.rPass.color = {87, 95, 104, 160}
  62. end
  63. g.rPass.onOutput = function()
  64. g.rPass.color = {79,86,94,160}
  65. end
  66.  
  67. addEventHandler("onClientRender", root, paint)
  68. end
  69. addEventHandler("onClientResourceStart",resourceRoot,onClientResourceStart)
  70.  
  71.  
  72. function paint()
  73. local rh,ry = interpolateBetween(0, (y*559/2)+y*105, 0, y*559, y*105, 0, (getTickCount()-tick)/1, "Linear")
  74. dxDrawImage(0,0,sx,sy,"gfx/wallpaper.png")
  75. dxDrawRectangle(x*0,ry,x*0,rh,tocolor(0,0,0,200))
  76. dxDrawBorder(x*0,ry,x*0,rh,tocolor(0,0,0,240),1.4)
  77. if getTickCount()-tick > 2 then
  78. local bColor = tocolor(0,139,255,200)
  79. if isMouseInPosition(x*552,y*504,x*262,y*44) then
  80. bColor = tocolor(0,154,255,200)
  81. end
  82. dxDrawImage(x*620,y*137,x*121,y*141,"gfx/logo.png",0,0,tocolor(255,255,255,200))
  83. if not inRegisterTab then
  84. dxDrawText("Login",x*150,y*220,x*552+x*262,y*504+y*44,tocolor(0,0,0),y*0.7,font,"center","center")
  85. dxDrawText("Haslo",x*150,y*350,x*552+x*262,y*504+y*44,tocolor(0,0,0),y*0.7,font,"center","center")
  86.  
  87. dxDrawRectangle(x*552,y*504,x*262,y*44,bColor)
  88. dxDrawBorder(x*552,y*504,x*262,y*44,tocolor(0,0,0,240),1.4)
  89. dxDrawText("Zaloguj",x*552,y*504,x*552+x*262,y*504+y*44,tocolor(0,0,0),y*1,font,"center","center")
  90.  
  91. dxDrawText([[Nie masz konta?
  92. #008BFFZarejestruj]],x*588,y*582,x*588+x*192,y*592+y*43,tocolor(0,0,0),y*0.6,font,"center","center",false,false,false,true)
  93. end
  94.  
  95. for k,self in pairs(editBox.instances) do
  96. if self.visible then
  97. local px,py,pw,ph = self:getPosition()
  98. local text = self.masked and string.gsub(self.text,".","•") or self.text
  99. local alignX = dxGetTextWidth(text,self.scale,self.font) <= pw and "left" or "right"
  100. dxDrawRectangle(px, py, pw, ph, tocolor(unpack(self.color)))
  101. dxDrawText(text,px+x*5, py,px-x*5+pw, py+ph,tocolor(unpack(self.textColor)),self.scale,self.font,alignX,"center",true)
  102. if self.input and dxGetTextWidth(text,self.scale,self.font) <= pw then
  103. local lx = dxGetTextWidth(text,self.scale,self.font)+px+x*8
  104. local lx = dxGetTextWidth(text,self.scale,self.font)+px+x*8
  105. dxDrawLine(lx, py+y*10, lx, py+ph-y*10, tocolor(255,255,255,math.abs(math.sin(getTickCount()/300))*200), 2)
  106. end
  107. end
  108. end
  109.  
  110. if not inRegisterTab then
  111. dxDrawBorder(x*552,y*364,x*262,y*41,tocolor(0,0,0,240),1)
  112. dxDrawBorder(x*552,y*426,x*262,y*41,tocolor(0,0,0,240),1)
  113. else
  114.  
  115. dxDrawBorder(x*552,y*364,x*262,y*41,tocolor(0,0,0,240),1)
  116. dxDrawBorder(x*552,y*426,x*262,y*41,tocolor(0,0,0,240),1)
  117.  
  118. dxDrawText("Login",x*150,y*220,x*552+x*262,y*504+y*44,tocolor(0,0,0),y*0.7,font,"center","center")
  119. dxDrawText("Haslo",x*150,y*350,x*552+x*262,y*504+y*44,tocolor(0,0,0),y*0.7,font,"center","center")
  120. dxDrawRectangle(x*552,y*504,x*262,y*44,bColor)
  121. dxDrawBorder(x*552,y*504,x*262,y*44,tocolor(0,0,0,240),1.4)
  122. dxDrawText("Zarejestruj",x*552,y*504,x*552+x*262,y*504+y*44,tocolor(0,0,0),y*1,font,"center","center")
  123. end
  124.  
  125. end
  126.  
  127. if getKeyState("backspace") then
  128. for k,self in pairs(editBox.instances) do
  129. if self.visible and self.input then
  130. if not keyState then
  131. keyState = getTickCount() + 400
  132. self.text = string.sub(self.text,1,string.len(self.text)-1)
  133. elseif keyState and keyState < getTickCount() then
  134. keyState = getTickCount()+100
  135. self.text = string.sub(self.text,1,string.len(self.text)-1)
  136. end
  137. return
  138. end
  139. end
  140. keyState = nil
  141. end
  142.  
  143. for i, v in pairs(messages) do
  144. if v.visible then
  145. dxDrawRectangle(sx-dxGetTextWidth(v.text, 1, "default-bold")-10, 35*i, dxGetTextWidth(v.text, 1, "default-bold")+50, 32,v.color)
  146. dxDrawBorder(sx-dxGetTextWidth(v.text, 1, "default-bold")-10, 35*i, dxGetTextWidth(v.text, 1, "default-bold")+20, 32,tocolor(255,255,255,200),1.6)
  147. dxDrawText(v.text,sx-dxGetTextWidth(v.text,1,"default-bold")-5, 9+35*i, dxGetTextWidth(v.text, 1, "default-bold"), 32, tocolor(255,255,255,255), 1, "default-bold", "left", "top", false, false ,false, true)
  148. end
  149. end
  150. end
  151.  
  152. function onClientClick(button,state,cX,cY)
  153. if not isCursorShowing() then
  154. return
  155. end
  156. if button == "left" and state == "up" then
  157. for k,self in pairs(editBox.instances) do
  158. if self.visible then
  159. if self.input then
  160. self.input = nil
  161. self.onOutput()
  162. end
  163. local x,y,w,h = self:getPosition()
  164. if isMouseInPosition(x,y,w,h) then
  165. self.input = true
  166. self.onInput()
  167. end
  168. end
  169. end
  170. if not inRegisterTab then
  171. if isMouseInPosition(x*552,y*504,x*262,y*44) then
  172. triggerServerEvent("onRequestLogin",localPlayer,g.user.text,g.pass.text)
  173. elseif isMouseInPosition(x*638,y*612,x*100,x*32) then
  174. g.user.visible = false
  175. g.pass.visible = false
  176.  
  177. inRegisterTab = true
  178. g.rUser.visible = true
  179. g.rPass.visible = true
  180. end
  181. else
  182. if isMouseInPosition(x*552,y*504,x*262,y*24) then
  183. triggerServerEvent("onRequestRegister",localPlayer,g.rUser.text,g.rPass.text)
  184. end
  185. end
  186. end
  187. end
  188. addEventHandler("onClientClick", root, onClientClick)
  189.  
  190. function onClientCharacter(character)
  191. if not isCursorShowing() then
  192. return
  193. end
  194. for k,self in pairs(editBox.instances) do
  195. if self.visible and self.input then
  196. if (string.len(self.text)) < self.maxLength then
  197. self.text = self.text..character
  198. end
  199. end
  200. end
  201. end
  202. addEventHandler("onClientCharacter", root, onClientCharacter)
  203.  
  204. function editBox.new()
  205. local self = setmetatable({}, editBox)
  206. self.text = ""
  207. self.maxLength = 20
  208. self.scale = y*0.8
  209. self.state = "normal"
  210. self.font = "sans"
  211. self.color = {255,255,255,220}
  212. self.textColor = {255,255,255,220}
  213. table.insert(editBox.instances, self)
  214. return self
  215. end
  216.  
  217. function editBox:getPosition()
  218. return self.x, self.y, self.w, self.h
  219. end
  220.  
  221. function editBox:setPosition(x,y,w,h)
  222. self.x, self.y, self.w, self.h = x,y,w,h
  223. return true
  224. end
  225.  
  226. function dxDrawBorder(posX, posY,posW,posH,color,scale)
  227. dxDrawLine(posX, posY, posX+posW, posY, color, scale,false)
  228. dxDrawLine(posX, posY, posX, posY+posH, color, scale,false)
  229. dxDrawLine(posX, posY+posH, posX+posW, posY+posH, color, scale,false)
  230. dxDrawLine(posX+posW, posY, posX+posW, posY+posH, color, scale,false)
  231. end
  232.  
  233. function isMouseInPosition(x,y,width,height)
  234. local cx, cy = getCursorPosition()
  235. local cx, cy = (cx*sx), (cy*sy)
  236. if (cx >= x and cx <= x + width) and (cy >= y and cy <= y + height) then
  237. return true
  238. else
  239. return false
  240. end
  241. end
  242.  
  243. function onLogin()
  244. showChat(true)
  245. showCursor(false)
  246. guiSetInputEnabled(false)
  247. toggleAllControls(true)
  248. stopSound(sound)
  249. removeEventHandler("onClientRender", root, paint)
  250. removeEventHandler("onClientClick",root,onClientClick)
  251. removeEventHandler("onClientCharacter",root,onClientCharacter)
  252. end
  253. addEvent("onLogin", true)
  254. addEventHandler("onLogin", localPlayer, onLogin)
  255.  
  256. function onRegister()
  257. g.user.visible = true
  258. g.pass.visible = true
  259. g.user.text = ""
  260. g.pass.text = ""
  261.  
  262. inRegisterTab = false
  263. g.rUser.visible = false
  264. g.rPass.visible = false
  265. g.rUser.text = ""
  266. g.rPass.text = ""
  267. end
  268. addEvent("onRegister", true)
  269. addEventHandler("onRegister", localPlayer, onRegister)
  270.  
  271. function loadLoginFromXML()
  272. local XML = xmlLoadFile ("userdata.xml")
  273. if not XML then
  274. XML = xmlCreateFile("userdata.xml", "login")
  275. end
  276.  
  277. local usernameNode = xmlFindChild (XML, "username", 0)
  278. if usernameNode then
  279. return xmlNodeGetValue(usernameNode)
  280. else
  281. return ""
  282. end
  283. xmlUnloadFile ( XML )
  284. end
  285.  
  286. function saveLoginToXML(username)
  287. local XML = xmlLoadFile ("userdata.xml")
  288. if not XML then
  289. XML = xmlCreateFile("userdata.xml", "login")
  290. end
  291. if (username ~= "") then
  292. local usernameNode = xmlFindChild (XML, "username", 0)
  293. if not usernameNode then
  294. usernameNode = xmlCreateChild(XML, "username")
  295. end
  296. xmlNodeSetValue (usernameNode, tostring(username))
  297. end
  298. xmlSaveFile(XML)
  299. xmlUnloadFile (XML)
  300. end
  301. addEvent("saveLoginToXML", true)
  302. addEventHandler("saveLoginToXML", root, saveLoginToXML)
  303.  
  304.  
  305. function login_text(result, text)
  306. if result == "sucess" then
  307. addNotification(text,1)
  308. elseif result == "error" then
  309. addNotification(text,2)
  310. end
  311. end
  312. addEvent("login_text",true)
  313. addEventHandler("login_text",root,login_text)
  314.  
  315. function addNotification(text, type)
  316. text = string.gsub(text,"#%x%x%x%x%x%x","")
  317. local i = 0
  318. if text == "" or text == nil or not type then
  319. return
  320. else
  321. for i = 0, #messages do
  322. if messages[i] then
  323. i = i+1
  324. else
  325. messages[i] = {}
  326. messages[i].text = text
  327. messages[i].visible = true
  328. if type == 1 then
  329. messages[i].color = tocolor(0,255,0,160)
  330. elseif type == 2 then
  331. messages[i].color = tocolor(255,0,0,160)
  332. end
  333. setTimer(removeNotify,1000,1,i)
  334. end
  335. end
  336. end
  337. end
  338.  
  339. function removeNotify(i)
  340. messages[i].visible = false
  341. messages[i] = nil
  342. end
  343.  
  344. function dxDrawBorder(posX, posY,posW,posH,color,scale)
  345. dxDrawLine(posX, posY, posX+posW, posY, color, scale,false)
  346. dxDrawLine(posX, posY, posX, posY+posH, color, scale,false)
  347. dxDrawLine(posX, posY+posH, posX+posW, posY+posH, color, scale,false)
  348. dxDrawLine(posX+posW, posY, posX+posW, posY+posH, color, scale,false)
  349. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement