Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.25 KB | None | 0 0
  1. --[[----------------------------------------------------
  2. -- client script main
  3. -- @author Banex
  4. -- @update 25/03/2016
  5. ----------------------------------------------------]]--
  6.  
  7. sx,sy = guiGetScreenSize()
  8. x,y = (sx/1366), (sy/768)
  9.  
  10. messages = {}
  11. editBox = {}
  12. editBox.__index = editBox
  13. editBox.instances = {}
  14.  
  15. font2 = dxCreateFont("gfx/Roboto-Bold.ttf", 18)
  16.  
  17. function onClientResourceStart()
  18. tick = getTickCount()
  19. font = dxCreateFont("gfx/sans-pro-regular.ttf", 18)
  20. sound = playSound("sfx/music.mp3",true)
  21. g = {}
  22. g.user = editBox.new()
  23. g.user:setPosition(x*400,y*386,x*180,y*40)
  24. g.user.color = {0, 0, 0, 0} -- {0, 0, 0, 0}
  25. g.user.font = font
  26. g.user.text = loadLoginFromXML()
  27. g.user.visible = true
  28. g.user.onInput = function()
  29. -- g.user.color = {87, 95, 104, 160}
  30. g.user.color = {0, 0, 0, 0}
  31. end
  32. g.user.onOutput = function()
  33. g.user.color ={0, 0, 0, 0}
  34. end
  35.  
  36. g.pass = editBox.new()
  37. g.pass:setPosition(x*400,y*443,x*180,y*40)
  38. g.pass.color = {0, 0, 0, 0}
  39. g.pass.font = font
  40. g.pass.masked = true
  41. g.pass.visible = true
  42. g.pass.onInput = function()
  43. g.pass.color = {0, 0, 0, 0}
  44. end
  45. g.pass.onOutput = function()
  46. g.pass.color = {0, 0, 0, 0}
  47. end
  48.  
  49. g.rUser = editBox.new()
  50. g.rUser:setPosition(x*400,y*385,x*180,y*40)
  51. g.rUser.color = {0, 0, 0, 0}
  52. g.rUser.font = font
  53. g.rUser.onInput = function()
  54. g.rUser.color = {0, 0, 0, 0}
  55. end
  56. g.rUser.onOutput = function()
  57. g.rUser.color = {0, 0, 0, 0}
  58. end
  59.  
  60. g.rPass = editBox.new()
  61. g.rPass:setPosition(x*400,y*443,x*180,y*40)
  62. g.rPass.color = {0, 0, 0, 0}
  63. g.rPass.font = font
  64. g.rPass.masked = true
  65. g.rPass.onInput = function()
  66. g.rPass.color = {0, 0, 0, 0}
  67. end
  68. g.rPass.onOutput = function()
  69. g.rPass.color = {0, 0, 0, 0}
  70. end
  71.  
  72. showChat(false)
  73. showCursor(true)
  74. addEventHandler("onClientRender", root, paint)
  75. end
  76. addEventHandler("onClientResourceStart",resourceRoot,onClientResourceStart)
  77.  
  78. function paint()
  79. local rh,ry = interpolateBetween(0, (y*370/2)+y*105, 0, y*370, y*105, 0, (getTickCount()-tick)/1400, "Linear")
  80. local posix, posiy, posiz = interpolateBetween(1296.9630126953, -1400.4029541016, 33.24066925048, 649.66790771484, -1400.8580322266, 28.23228263855, (getTickCount()-tick)/90000, "Linear")
  81. setCameraMatrix(posix, posiy, posiz, getTickCount()/100, 355.14211)
  82. exports["fx_blur"]:dxDrawBluredRectangle(0,0,sx,sy, tocolor(255, 255, 255, 255))
  83. dxDrawRectangle(x*597,y*208,x*391,y*352,tocolor(0,0,0,255))
  84.  
  85. local atual = 1
  86. local limite = 5
  87. local tempo = 5000
  88. setTimer(function()
  89. atual = (atual == limite) and 1 or atual + 1
  90. end, tempo, 0 )
  91.  
  92. dxDrawImage(x*597,y*208,x*391,y*352,"gfx/slider/"..tostring(atual)..".png", 0, 0, 0)
  93. dxDrawImage(0,0,sx,sy,"gfx/fundo.png",0,0,0)
  94.  
  95.  
  96.  
  97. if getTickCount()-tick > 0 then -- Tempo para aparecer os itens abaixo:
  98. local bColor = tocolor(255,255,255)
  99. if isMouseInPosition(x*394,y*510,x*190,y*31) then
  100. bColor = tocolor(230,230,255)
  101. end
  102. -- dxDrawImage(x*580,y*180,x*198,y*198,"gfx/logo.png", 0, 0, 0)
  103.  
  104. --dxDrawRectangle(x*552,y*364,x*49,y*41,tocolor(0,0,0,130))
  105. -- dxDrawRectangle(x*597,y*370,x*2,y*28,tocolor(255,255,255,255))
  106.  
  107.  
  108. --dxDrawImage(x*550,y*363,x*263,y*44,"gfx/barra.png",0, 0, 0, tocolor(0,0,0,130))
  109.  
  110. --dxDrawRectangle(x*552,y*426,x*49,y*41,tocolor(0,0,0,130))
  111. -- dxDrawRectangle(x*597,y*432,x*2,y*28,tocolor(255,255,255,255))
  112.  
  113. --dxDrawImage(x*550,y*425,x*263,y*44,"gfx/barra.png",0, 0, 0, tocolor(0,0,0,130))
  114.  
  115. if not inRegisterTab then
  116.  
  117. -- dxDrawRectangle(x*552,y*440,x*262,y*44,bColor)
  118. -- dxDrawBorder(x*552,y*440,x*262,y*44,tocolor(0,0,0,240),1.4)
  119. dxDrawImage(x*392,y*514,x*190,y*31,"gfx/buttom.png", 0, 0, 0, bColor)
  120. dxDrawText("Entrar",x*165,y*511,x*552+x*262,y*504+y*44,tocolor(255,255,255),y*0.7,font2,"center","center")
  121.  
  122. dxDrawText([[Não tem conta? #365678Registra-se#FFFFFF]],x*210,y*345,x*588+x*192,y*592+y*43,tocolor(255,255,255),y*0.6,font,"center","center",false,false,false,true)
  123. end
  124.  
  125. for k,self in pairs(editBox.instances) do
  126. if self.visible then
  127. local px,py,pw,ph = self:getPosition()
  128. local text = self.masked and string.gsub(self.text,".","•") or self.text
  129. local alignX = dxGetTextWidth(text,self.scale,self.font) <= pw and "left" or "right"
  130. dxDrawRectangle(px, py, pw, ph, tocolor(unpack(self.color)))
  131. dxDrawText(text,px+x*5, py,px-x*5+pw, py+ph,tocolor(unpack(self.textColor)),self.scale,self.font,alignX,"center",true)
  132. if self.input and dxGetTextWidth(text,self.scale,self.font) <= pw then
  133. local lx = dxGetTextWidth(text,self.scale,self.font)+px+x*8
  134. local lx = dxGetTextWidth(text,self.scale,self.font)+px+x*8
  135. dxDrawLine(lx, py+y*10, lx, py+ph-y*10, tocolor(255,255,255,math.abs(math.sin(getTickCount()/300))*200), 2)
  136. end
  137. end
  138. end
  139.  
  140. if not inRegisterTab then
  141.  
  142. -- Bordas do icon do login
  143.  
  144. -- Barra dps do aqui
  145.  
  146. -- dxDrawRectangle(x*555,y*510,x*250,y*1,tocolor(255,255,255,255))
  147.  
  148. -- dxDrawBorder(x*552,y*364,x*262,y*41,tocolor(0,0,0,240),1)
  149. -- dxDrawBorder(x*552,y*426,x*262,y*41,tocolor(0,0,0,240),1)
  150. else
  151.  
  152. dxDrawText([[Voltar ao login? #365678Sim#FFFFFF]],x*169,y*345,x*588+x*192,y*592+y*43,tocolor(255,255,255),y*0.6,font,"center","center",false,false,false,true)
  153.  
  154. -- Fundo do icon do registro
  155.  
  156. -- dxDrawRectangle(x*552,y*364,x*49,y*41,tocolor(40,45,48,160))
  157. -- dxDrawImage(x*560,y*369,x*33,y*31,"gfx/user.png")
  158. -- dxDrawRectangle(x*552,y*426,x*49,y*41,tocolor(40,45,48,160))
  159.  
  160. -- Bordas do icon do registro
  161.  
  162. -- dxDrawImage(x*565,y*431,x*23,y*31,"gfx/pass.png")
  163. -- dxDrawBorder(x*552,y*364,x*262,y*41,tocolor(0,0,0,240),1)
  164. -- dxDrawBorder(x*552,y*426,x*262,y*41,tocolor(0,0,0,240),1)
  165.  
  166. -- Botões do registro
  167.  
  168. dxDrawImage(x*392,y*514,x*190,y*31,"gfx/buttom.png", 0, 0, 0, bColor)
  169. dxDrawText("Registrar",x*165,y*511,x*552+x*262,y*504+y*44,tocolor(255,255,255),y*0.7,font2,"center","center")
  170.  
  171. -- dxDrawRectangle(x*552,y*504,x*262,y*44,bColor)
  172. -- dxDrawBorder(x*552,y*504,x*262,y*44,tocolor(0,0,0,240),1.4)
  173. -- dxDrawText("Registrar",x*552,y*504,x*552+x*262,y*504+y*44,tocolor(255,255,255),y*1,font,"center","center")
  174.  
  175. -- dxDrawRectangle(x*552,y*504+65,x*262,y*44,bColor)
  176. -- dxDrawBorder(x*552,y*504+65,x*262,y*44,tocolor(0,0,0,240),1.4)
  177. -- dxDrawText("Voltar",x*552,y*504+65*2,x*552+x*262,y*504+y*44,tocolor(255,255,255),y*1,font,"center","center")
  178. end
  179.  
  180. end
  181.  
  182. if getKeyState("backspace") then
  183. for k,self in pairs(editBox.instances) do
  184. if self.visible and self.input then
  185. if not keyState then
  186. keyState = getTickCount() + 400
  187. self.text = string.sub(self.text,1,string.len(self.text)-1)
  188. elseif keyState and keyState < getTickCount() then
  189. keyState = getTickCount()+100
  190. self.text = string.sub(self.text,1,string.len(self.text)-1)
  191. end
  192. return
  193. end
  194. end
  195. keyState = nil
  196. end
  197.  
  198. for i, v in pairs(messages) do
  199. if v.visible then
  200. -- dxDrawRectangle(sx-dxGetTextWidth(v.text, 1, "default-bold")-10, 35*i, dxGetTextWidth(v.text, 1, "default-bold")+50, 32,v.color)
  201. -- 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)
  202. -- dxDrawText(v.text,sx-dxGetTextWidth(v.text,1,"default-bold")-5, 9+35*i, dxGetTextWidth(v.text, 1, "default-bold"), 32, v.color, 1, "default-bold", "left", "top", false, false ,false, true)
  203. dxDrawText(v.text,x*666,y*110,x*588+x*192,y*592+y*43,v.color,y*0.5,font,"left","center",false,false,false,true)
  204. end
  205. end
  206. end
  207.  
  208. -- Botoes
  209.  
  210. function onClientClick(button,state,cX,cY)
  211. if not isCursorShowing() then
  212. return
  213. end
  214. if button == "left" and state == "up" then
  215. for k,self in pairs(editBox.instances) do
  216. if self.visible then
  217. if self.input then
  218. self.input = nil
  219. self.onOutput()
  220. end
  221. local x,y,w,h = self:getPosition()
  222. if isMouseInPosition(x,y,w,h) then
  223. self.input = true
  224. self.onInput()
  225. end
  226. end
  227. end
  228. if not inRegisterTab then
  229. -- dxDrawText([[Registre-se #008BFFaqui#FFFFFF.]],x*898,y*450,x*588+x*192,y*592+y*43,tocolor(255,255,255),y*0.6,font,"center","center",false,false,false,true)
  230. if isMouseInPosition(x*394,y*514,x*190,y*31) then
  231. triggerServerEvent("onRequestLogin",localPlayer,g.user.text,g.pass.text)
  232. -- Posição do botão "Registre-se Aqui!"
  233. elseif isMouseInPosition(x*515,y*475,x*69,y*29) then
  234. g.user.visible = false
  235. g.pass.visible = false
  236.  
  237. inRegisterTab = true
  238. g.rUser.visible = true
  239. g.rPass.visible = true
  240. end
  241. else
  242. -- Botão para registrar
  243. if isMouseInPosition(x*394,y*514,x*190,y*31) then
  244. triggerServerEvent("onRequestRegister",localPlayer,g.rUser.text,g.rPass.text)
  245. end
  246. -- Botão para voltar
  247. --dxDrawText([[#008BFFVoltar#FFFFFF]],x*970,y*450,x*588+x*192,y*592+y*43,tocolor(255,255,255),y*0.6,font,"center","center",false,false,false,true)
  248. if isMouseInPosition(x*515,y*475,x*31,y*17) then
  249.  
  250. inRegisterTab = false
  251. g.user.visible = true
  252. g.pass.visible = true
  253. g.rUser.visible = false
  254. g.rPass.visible = false
  255. g.rUser.text = ""
  256. g.rPass.text = ""
  257. end
  258. end
  259. end
  260. end
  261. addEventHandler("onClientClick", root, onClientClick)
  262.  
  263. function onClientCharacter(character)
  264. if not isCursorShowing() then
  265. return
  266. end
  267. for k,self in pairs(editBox.instances) do
  268. if self.visible and self.input then
  269. if (string.len(self.text)) < self.maxLength then
  270. self.text = self.text..character
  271. end
  272. end
  273. end
  274. end
  275. addEventHandler("onClientCharacter", root, onClientCharacter)
  276.  
  277. function editBox.new()
  278. local self = setmetatable({}, editBox)
  279. self.text = ""
  280. self.maxLength = 20
  281. self.scale = y*0.8
  282. self.state = "normal"
  283. self.font = "sans"
  284. self.color = {255,255,255,220}
  285. self.textColor = {255,255,255,220}
  286. table.insert(editBox.instances, self)
  287. return self
  288. end
  289.  
  290. function editBox:getPosition()
  291. return self.x, self.y, self.w, self.h
  292. end
  293.  
  294. function editBox:setPosition(x,y,w,h)
  295. self.x, self.y, self.w, self.h = x,y,w,h
  296. return true
  297. end
  298.  
  299. function dxDrawBorder(posX, posY,posW,posH,color,scale)
  300. dxDrawLine(posX, posY, posX+posW, posY, color, scale,false)
  301. dxDrawLine(posX, posY, posX, posY+posH, color, scale,false)
  302. dxDrawLine(posX, posY+posH, posX+posW, posY+posH, color, scale,false)
  303. dxDrawLine(posX+posW, posY, posX+posW, posY+posH, color, scale,false)
  304. end
  305.  
  306. function isMouseInPosition(x,y,width,height)
  307. local cx, cy = getCursorPosition()
  308. local cx, cy = (cx*sx), (cy*sy)
  309. if (cx >= x and cx <= x + width) and (cy >= y and cy <= y + height) then
  310. return true
  311. else
  312. return false
  313. end
  314. end
  315.  
  316. function onLogin()
  317. showChat(true)
  318. showCursor(false)
  319. stopSound(sound)
  320. setCameraTarget(localPlayer, localPlayer)
  321. removeEventHandler("onClientRender", root, paint)
  322. removeEventHandler("onClientClick",root,onClientClick)
  323. removeEventHandler("onClientCharacter",root,onClientCharacter)
  324. end
  325. addEvent("onLogin", true)
  326. addEventHandler("onLogin", localPlayer, onLogin)
  327.  
  328. function onRegister()
  329. g.user.visible = true
  330. g.pass.visible = true
  331. g.user.text = ""
  332. g.pass.text = ""
  333.  
  334. inRegisterTab = false
  335. g.rUser.visible = false
  336. g.rPass.visible = false
  337. g.rUser.text = ""
  338. g.rPass.text = ""
  339. end
  340. addEvent("onRegister", true)
  341. addEventHandler("onRegister", localPlayer, onRegister)
  342.  
  343. function loadLoginFromXML()
  344. local XML = xmlLoadFile ("userdata.xml")
  345. if not XML then
  346. XML = xmlCreateFile("userdata.xml", "login")
  347. end
  348.  
  349. local usernameNode = xmlFindChild (XML, "username", 0)
  350. if usernameNode then
  351. return xmlNodeGetValue(usernameNode)
  352. else
  353. return ""
  354. end
  355. xmlUnloadFile ( XML )
  356. end
  357.  
  358. function saveLoginToXML(username)
  359. local XML = xmlLoadFile ("userdata.xml")
  360. if not XML then
  361. XML = xmlCreateFile("userdata.xml", "login")
  362. end
  363. if (username ~= "") then
  364. local usernameNode = xmlFindChild (XML, "username", 0)
  365. if not usernameNode then
  366. usernameNode = xmlCreateChild(XML, "username")
  367. end
  368. xmlNodeSetValue (usernameNode, tostring(username))
  369. end
  370. xmlSaveFile(XML)
  371. xmlUnloadFile (XML)
  372. end
  373. addEvent("saveLoginToXML", true)
  374. addEventHandler("saveLoginToXML", root, saveLoginToXML)
  375.  
  376.  
  377. function login_text(result, text)
  378. if result == "sucess" then
  379. addNotification(text,1)
  380. elseif result == "error" then
  381. addNotification(text,2)
  382. end
  383. end
  384. addEvent("login_text",true)
  385. addEventHandler("login_text",root,login_text)
  386.  
  387. function addNotification(text, type)
  388. text = string.gsub(text,"#%x%x%x%x%x%x","")
  389. local i = 0
  390. if text == "" or text == nil or not type then
  391. return
  392. else
  393. for i = 0, #messages do
  394. if messages[i] then
  395. i = i+1
  396. else
  397. messages[i] = {}
  398. messages[i].text = text
  399. messages[i].visible = true
  400. if type == 1 then
  401. messages[i].color = tocolor(0,255,0,200)
  402. elseif type == 2 then
  403. messages[i].color = tocolor(255,0,0,200)
  404. end
  405. setTimer(removeNotify,5000,1,i)
  406. end
  407. end
  408. end
  409. end
  410.  
  411. function removeNotify(i)
  412. messages[i].visible = false
  413. messages[i] = nil
  414. end
  415.  
  416. function dxDrawBorder(posX, posY,posW,posH,color,scale)
  417. dxDrawLine(posX, posY, posX+posW, posY, color, scale,false)
  418. dxDrawLine(posX, posY, posX, posY+posH, color, scale,false)
  419. dxDrawLine(posX, posY+posH, posX+posW, posY+posH, color, scale,false)
  420. dxDrawLine(posX+posW, posY, posX+posW, posY+posH, color, scale,false)
  421. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement