MTASA TÜRK
Türkiye'nin En Güncel MTA Platformu


[YARDIM] Login Panelde Tuşlara Basılması

0 Üye ve 1 Ziyaretçi konuyu incelemekte.

Çevrimdışı #ScottCoder

  • Acemi Üye
  • *
    • İleti: 111
  • 👑 AXE FREEROAM 👑
: 06 Kasım 2017, 20:48:41
Arkadaşlar benim sorunum login panelde kullanıcı ad yazarken ve ya şifre yazarken tuşlara bastıgımızda panellerin açılması bunu nasıl önleyebilirim.

Örnek: "O" Tuşuna basıyorum login panelde tag panel açılıyor.


Client kodu:

Spoiler for Hiden:
--[[----------------------------------------------------
-- client script main
-- @author Banex
-- @update 25/03/2016
----------------------------------------------------]]--

sx,sy = guiGetScreenSize()
x,y =  (sx/1366), (sy/768)

messages = {}
editBox = {}
editBox.__index = editBox
editBox.instances = {}

guiSetInputMode("no_binds_when_editing")

function onClientResourceStart()
   tick = getTickCount()
   font = dxCreateFont("gfx/sans-pro-regular.ttf", 20)
   sound = playSound("sfx/music.mp3",true)
   g = {}
   g.user = editBox.new()
   g.user:setPosition(x*601,y*364,x*213,y*41)
   g.user.color = {79,86,94,160}
   g.user.font = font
   g.user.text = loadLoginFromXML()
   g.user.visible = true
   g.user.onInput = function()
      g.user.color = {87, 95, 104, 160}
   end
   g.user.onOutput = function()
      g.user.color = {79,86,94,160}
   end
   
   g.pass = editBox.new()
   g.pass:setPosition(x*601,y*426,x*213,y*41)
   g.pass.color = {79,86,94,160}
   g.pass.font = font
   g.pass.masked = true
   g.pass.visible = true
   g.pass.onInput = function()
      g.pass.color = {87, 95, 104, 160}
   end
   g.pass.onOutput = function()
      g.pass.color = {79,86,94,160}
   end
   
   g.rUser = editBox.new()
   g.rUser:setPosition(x*601,y*364,x*213,y*41)
   g.rUser.color = {79,86,94,160}
   g.rUser.font = font
   g.rUser.onInput = function()
      g.rUser.color = {87, 95, 104, 160}
   end
   g.rUser.onOutput = function()
      g.rUser.color = {79,86,94,160}
   end
   
   g.rPass = editBox.new()
   g.rPass:setPosition(x*601,y*426,x*213,y*41)
   g.rPass.color = {79,86,94,160}
   g.rPass.font = font
   g.rPass.masked = true
   g.rPass.onInput = function()
      g.rPass.color = {87, 95, 104, 160}
   end
   g.rPass.onOutput = function()
      g.rPass.color = {79,86,94,160}
   end

   showChat(false)
   showCursor(true)
   addEventHandler("onClientRender", root, paint)
end
addEventHandler("onClientResourceStart",resourceRoot,onClientResourceStart)

function paint()
   local rh,ry = interpolateBetween(0, (y*559/2)+y*105, 0, y*559, y*105, 0, (getTickCount()-tick)/1400, "Linear")

   dxDrawImage(0,0,sx,sy,"gfx/wallpaper.png")
   dxDrawRectangle(x*508,ry,x*350,rh,tocolor(0,0,0,200))
   dxDrawBorder(x*508,ry,x*350,rh,tocolor(0,0,0,240),1.4)
   if getTickCount()-tick > 1500 then
      local bColor = tocolor(0,139,255,200)
      if isMouseInPosition(x*552,y*504,x*262,y*44) then
         bColor = tocolor(0,154,255,200)
      end
      dxDrawImage(x*584,y*137,x*199,y*198,"gfx/logo.png",getTickCount()/100,0,0,tocolor(255,255,255,200))
      
      if not inRegisterTab then
         dxDrawRectangle(x*552,y*364,x*49,y*41,tocolor(40,45,48,160))
         dxDrawImage(x*560,y*369,x*33,y*31,"gfx/user.png")
         dxDrawRectangle(x*552,y*426,x*49,y*41,tocolor(40,45,48,160))
         dxDrawImage(x*565,y*431,x*23,y*31,"gfx/pass.png")
      
         dxDrawRectangle(x*552,y*504,x*262,y*44,bColor)
         dxDrawBorder(x*552,y*504,x*262,y*44,tocolor(0,0,0,240),1.4)
         dxDrawText("Entrar",x*552,y*504,x*552+x*262,y*504+y*44,tocolor(255,255,255),y*1,font,"center","center")
      
         dxDrawText([[Não possui uma conta?
registre-se #008BFFaqui#FFFFFF.]],x*588,y*582,x*588+x*192,y*592+y*43,tocolor(255,255,255),y*0.6,font,"center","center",false,false,false,true)
      end

      for k,self in pairs(editBox.instances) do
         if self.visible then
            local px,py,pw,ph = self:getPosition()
            local text = self.masked and string.gsub(self.text,".","•") or self.text
            local alignX = dxGetTextWidth(text,self.scale,self.font) <= pw and "left" or "right"
            dxDrawRectangle(px, py, pw, ph, tocolor(unpack(self.color)))
            dxDrawText(text,px+x*5, py,px-x*5+pw, py+ph,tocolor(unpack(self.textColor)),self.scale,self.font,alignX,"center",true)      
            if self.input and dxGetTextWidth(text,self.scale,self.font) <= pw then
               local lx = dxGetTextWidth(text,self.scale,self.font)+px+x*8
               local lx = dxGetTextWidth(text,self.scale,self.font)+px+x*8
               dxDrawLine(lx, py+y*10, lx, py+ph-y*10, tocolor(255,255,255,math.abs(math.sin(getTickCount()/300))*200), 2)
            end
         end
      end
      
   if not inRegisterTab then
      dxDrawBorder(x*552,y*364,x*262,y*41,tocolor(0,0,0,240),1)
      dxDrawBorder(x*552,y*426,x*262,y*41,tocolor(0,0,0,240),1)
   else
   
      dxDrawRectangle(x*552,y*364,x*49,y*41,tocolor(40,45,48,160))
      dxDrawImage(x*560,y*369,x*33,y*31,"gfx/user.png")
      dxDrawRectangle(x*552,y*426,x*49,y*41,tocolor(40,45,48,160))
      dxDrawImage(x*565,y*431,x*23,y*31,"gfx/pass.png")
      dxDrawBorder(x*552,y*364,x*262,y*41,tocolor(0,0,0,240),1)
      dxDrawBorder(x*552,y*426,x*262,y*41,tocolor(0,0,0,240),1)
      
      dxDrawRectangle(x*552,y*504,x*262,y*44,bColor)
      dxDrawBorder(x*552,y*504,x*262,y*44,tocolor(0,0,0,240),1.4)
      dxDrawText("Registrar",x*552,y*504,x*552+x*262,y*504+y*44,tocolor(255,255,255),y*1,font,"center","center")
   end
   
   end
      
   if getKeyState("backspace") then
      for k,self in pairs(editBox.instances) do
         if self.visible and self.input then
            if not keyState then
               keyState = getTickCount() + 400
               self.text = string.sub(self.text,1,string.len(self.text)-1)
            elseif keyState and keyState < getTickCount() then
               keyState = getTickCount()+100
               self.text = string.sub(self.text,1,string.len(self.text)-1)
            end
            return
         end
      end
      keyState = nil
   end
   
   for i, v in pairs(messages) do
      if v.visible then
         dxDrawRectangle(sx-dxGetTextWidth(v.text, 1, "default-bold")-10, 35*i, dxGetTextWidth(v.text, 1, "default-bold")+50, 32,v.color)
         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)
         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)
      end
   end
end

function onClientClick(button,state,cX,cY)
   if not isCursorShowing() then
      return
   end
   if button == "left" and state == "up" then
      for k,self in pairs(editBox.instances) do
         if self.visible then
            if self.input then
               self.input = nil
               self.onOutput()
            end
            local x,y,w,h = self:getPosition()
            if isMouseInPosition(x,y,w,h) then
               self.input = true
               self.onInput()
            end
         end
      end
      if not inRegisterTab then
         if isMouseInPosition(x*552,y*504,x*262,y*44) then
            triggerServerEvent("onRequestLogin",localPlayer,g.user.text,g.pass.text)
         elseif isMouseInPosition(x*700,y*609,x*44,y*22) then
            g.user.visible = false
            g.pass.visible = false
            
            inRegisterTab = true
            g.rUser.visible = true
            g.rPass.visible = true
         end
      else
         if isMouseInPosition(x*552,y*504,x*262,y*44) then
            triggerServerEvent("onRequestRegister",localPlayer,g.rUser.text,g.rPass.text)
         end
      end
   end
end
addEventHandler("onClientClick", root, onClientClick)

function onClientCharacter(character)
   if not isCursorShowing() then
      return
   end
   for k,self in pairs(editBox.instances) do
      if self.visible and self.input then
         if (string.len(self.text)) < self.maxLength then
            self.text = self.text..character
         end
      end
   end
end
addEventHandler("onClientCharacter", root, onClientCharacter)

function editBox.new()
   local self = setmetatable({}, editBox)
   self.text = ""
   self.maxLength = 20
   self.scale = y*0.8
   self.state = "normal"
   self.font = "sans"
   self.color = {255,255,255,220}
   self.textColor = {255,255,255,220}
   table.insert(editBox.instances, self)
   return self
end

function editBox:getPosition()
   return self.x, self.y, self.w, self.h
end

function editBox:setPosition(x,y,w,h)
   self.x, self.y, self.w, self.h = x,y,w,h
   return true
end

function dxDrawBorder(posX, posY,posW,posH,color,scale)
   dxDrawLine(posX, posY, posX+posW, posY, color, scale,false)
   dxDrawLine(posX, posY, posX, posY+posH, color, scale,false)
   dxDrawLine(posX, posY+posH, posX+posW, posY+posH, color, scale,false)
   dxDrawLine(posX+posW, posY, posX+posW, posY+posH, color, scale,false)
end

function isMouseInPosition(x,y,width,height)
    local cx, cy = getCursorPosition()
    local cx, cy = (cx*sx), (cy*sy)
    if (cx >= x and cx <= x + width) and (cy >= y and cy <= y + height) then
        return true
    else
        return false
    end
end

function onLogin()
   showChat(true)
   showCursor(false)
   stopSound(sound)
   removeEventHandler("onClientRender", root, paint)
   removeEventHandler("onClientClick",root,onClientClick)
   removeEventHandler("onClientCharacter",root,onClientCharacter)
end
addEvent("onLogin", true)
addEventHandler("onLogin", localPlayer, onLogin)

function onRegister()
   g.user.visible = true
   g.pass.visible = true
   g.user.text = ""
   g.pass.text = ""
      
   inRegisterTab = false
   g.rUser.visible = false
   g.rPass.visible = false
   g.rUser.text = ""
   g.rPass.text = ""
end
addEvent("onRegister", true)
addEventHandler("onRegister", localPlayer, onRegister)

function loadLoginFromXML()
   local XML = xmlLoadFile ("userdata.xml")
    if not XML then
        XML = xmlCreateFile("userdata.xml", "login")
    end
   
    local usernameNode = xmlFindChild (XML, "username", 0)
    if usernameNode then
        return xmlNodeGetValue(usernameNode)
    else
      return ""
    end
    xmlUnloadFile ( XML )
end

function saveLoginToXML(username)
    local XML = xmlLoadFile ("userdata.xml")
    if not XML then
        XML = xmlCreateFile("userdata.xml", "login")
    end
   if (username ~= "") then
      local usernameNode = xmlFindChild (XML, "username", 0)
      if not usernameNode then
         usernameNode = xmlCreateChild(XML, "username")
      end
      xmlNodeSetValue (usernameNode, tostring(username))
   end
    xmlSaveFile(XML)
    xmlUnloadFile (XML)
end
addEvent("saveLoginToXML", true)
addEventHandler("saveLoginToXML", root, saveLoginToXML)


function login_text(result, text)
   if result == "sucess" then
       addNotification(text,1)
   elseif result == "error" then
       addNotification(text,2)
   end
end
addEvent("login_text",true)
addEventHandler("login_text",root,login_text)

function addNotification(text, type)
    text = string.gsub(text,"#%x%x%x%x%x%x","")
   local i = 0
   if text == "" or text == nil or not type then
      return
   else
      for i = 0, #messages+1 do
         if messages then
            i = i+1
         else
            messages = {}
            messages.text = text
            messages.visible = true
            if type == 1 then
               messages.color = tocolor(0,255,0,160)
            elseif type == 2 then
               messages.color = tocolor(255,0,0,160)
            end
            setTimer(removeNotify,5000,1,i)
         end
      end
   end
end

function removeNotify(i)
   messages.visible = false
   messages = nil
end

function dxDrawBorder(posX, posY,posW,posH,color,scale)
   dxDrawLine(posX, posY, posX+posW, posY, color, scale,false)
   dxDrawLine(posX, posY, posX, posY+posH, color, scale,false)
   dxDrawLine(posX, posY+posH, posX+posW, posY+posH, color, scale,false)
   dxDrawLine(posX+posW, posY, posX+posW, posY+posH, color, scale,false)
end
« Son Düzenleme: 10 Kasım 2017, 20:05:22 Gönderen: Narkoz »
 


MTASA TÜRK

[YARDIM] Login Panelde Tuşlara Basılması
« : 06 Kasım 2017, 20:48:41 »

Çevrimiçi ertrldtcu

  • Uzman Üye
  • *
    • İleti: 631
Yanıtla #1 : 06 Kasım 2017, 20:55:50
Bi dene bakalım.
Kod: lua
--[[----------------------------------------------------
-- client script main
-- @author Banex
-- @update 25/03/2016
----------------------------------------------------]]--

sx,sy = guiGetScreenSize()
x,y =  (sx/1366), (sy/768)
guiSetInputMode("no_binds")

messages = {}
editBox = {}
editBox.__index = editBox
editBox.instances = {}

function onClientResourceStart()
   tick = getTickCount()
   font = dxCreateFont("gfx/sans-pro-regular.ttf", 20)
   sound = playSound("sfx/music.mp3",true)
   g = {}
   g.user = editBox.new()
   g.user:setPosition(x*601,y*364,x*213,y*41)
   g.user.color = {79,86,94,160}
   g.user.font = font
   g.user.text = loadLoginFromXML()
   g.user.visible = true
   g.user.onInput = function()
      g.user.color = {87, 95, 104, 160}
   end
   g.user.onOutput = function()
      g.user.color = {79,86,94,160}
   end
   
   g.pass = editBox.new()
   g.pass:setPosition(x*601,y*426,x*213,y*41)
   g.pass.color = {79,86,94,160}
   g.pass.font = font
   g.pass.masked = true
   g.pass.visible = true
   g.pass.onInput = function()
      g.pass.color = {87, 95, 104, 160}
   end
   g.pass.onOutput = function()
      g.pass.color = {79,86,94,160}
   end
   
   g.rUser = editBox.new()
   g.rUser:setPosition(x*601,y*364,x*213,y*41)
   g.rUser.color = {79,86,94,160}
   g.rUser.font = font
   g.rUser.onInput = function()
      g.rUser.color = {87, 95, 104, 160}
   end
   g.rUser.onOutput = function()
      g.rUser.color = {79,86,94,160}
   end
   
   g.rPass = editBox.new()
   g.rPass:setPosition(x*601,y*426,x*213,y*41)
   g.rPass.color = {79,86,94,160}
   g.rPass.font = font
   g.rPass.masked = true
   g.rPass.onInput = function()
      g.rPass.color = {87, 95, 104, 160}
   end
   g.rPass.onOutput = function()
      g.rPass.color = {79,86,94,160}
   end

   showChat(false)
   showCursor(true)
   addEventHandler("onClientRender", root, paint)
end
addEventHandler("onClientResourceStart",resourceRoot,onClientResourceStart)

function paint()
   local rh,ry = interpolateBetween(0, (y*559/2)+y*105, 0, y*559, y*105, 0, (getTickCount()-tick)/1400, "Linear")

   dxDrawImage(0,0,sx,sy,"gfx/wallpaper.png")
   dxDrawRectangle(x*508,ry,x*350,rh,tocolor(0,0,0,200))
   dxDrawBorder(x*508,ry,x*350,rh,tocolor(0,0,0,240),1.4)
   if getTickCount()-tick > 1500 then
      local bColor = tocolor(0,139,255,200)
      if isMouseInPosition(x*552,y*504,x*262,y*44) then
         bColor = tocolor(0,154,255,200)
      end
      dxDrawImage(x*584,y*137,x*199,y*198,"gfx/logo.png",getTickCount()/100,0,0,tocolor(255,255,255,200))
     
      if not inRegisterTab then
         dxDrawRectangle(x*552,y*364,x*49,y*41,tocolor(40,45,48,160))
         dxDrawImage(x*560,y*369,x*33,y*31,"gfx/user.png")
         dxDrawRectangle(x*552,y*426,x*49,y*41,tocolor(40,45,48,160))
         dxDrawImage(x*565,y*431,x*23,y*31,"gfx/pass.png")
     
         dxDrawRectangle(x*552,y*504,x*262,y*44,bColor)
         dxDrawBorder(x*552,y*504,x*262,y*44,tocolor(0,0,0,240),1.4)
         dxDrawText("Entrar",x*552,y*504,x*552+x*262,y*504+y*44,tocolor(255,255,255),y*1,font,"center","center")
     
         dxDrawText([[Não possui uma conta?
registre-se #008BFFaqui#FFFFFF.]],x*588,y*582,x*588+x*192,y*592+y*43,tocolor(255,255,255),y*0.6,font,"center","center",false,false,false,true)
      end

      for k,self in pairs(editBox.instances) do
         if self.visible then
            local px,py,pw,ph = self:getPosition()
            local text = self.masked and string.gsub(self.text,".","•") or self.text
            local alignX = dxGetTextWidth(text,self.scale,self.font) <= pw and "left" or "right"
            dxDrawRectangle(px, py, pw, ph, tocolor(unpack(self.color)))
            dxDrawText(text,px+x*5, py,px-x*5+pw, py+ph,tocolor(unpack(self.textColor)),self.scale,self.font,alignX,"center",true)     
            if self.input and dxGetTextWidth(text,self.scale,self.font) <= pw then
               local lx = dxGetTextWidth(text,self.scale,self.font)+px+x*8
               local lx = dxGetTextWidth(text,self.scale,self.font)+px+x*8
               dxDrawLine(lx, py+y*10, lx, py+ph-y*10, tocolor(255,255,255,math.abs(math.sin(getTickCount()/300))*200), 2)
            end
         end
      end
     
   if not inRegisterTab then
      dxDrawBorder(x*552,y*364,x*262,y*41,tocolor(0,0,0,240),1)
      dxDrawBorder(x*552,y*426,x*262,y*41,tocolor(0,0,0,240),1)
   else
   
      dxDrawRectangle(x*552,y*364,x*49,y*41,tocolor(40,45,48,160))
      dxDrawImage(x*560,y*369,x*33,y*31,"gfx/user.png")
      dxDrawRectangle(x*552,y*426,x*49,y*41,tocolor(40,45,48,160))
      dxDrawImage(x*565,y*431,x*23,y*31,"gfx/pass.png")
      dxDrawBorder(x*552,y*364,x*262,y*41,tocolor(0,0,0,240),1)
      dxDrawBorder(x*552,y*426,x*262,y*41,tocolor(0,0,0,240),1)
     
      dxDrawRectangle(x*552,y*504,x*262,y*44,bColor)
      dxDrawBorder(x*552,y*504,x*262,y*44,tocolor(0,0,0,240),1.4)
      dxDrawText("Registrar",x*552,y*504,x*552+x*262,y*504+y*44,tocolor(255,255,255),y*1,font,"center","center")
   end
   
   end
     
   if getKeyState("backspace") then
      for k,self in pairs(editBox.instances) do
         if self.visible and self.input then
            if not keyState then
               keyState = getTickCount() + 400
               self.text = string.sub(self.text,1,string.len(self.text)-1)
            elseif keyState and keyState < getTickCount() then
               keyState = getTickCount()+100
               self.text = string.sub(self.text,1,string.len(self.text)-1)
            end
            return
         end
      end
      keyState = nil
   end
   
   for i, v in pairs(messages) do
      if v.visible then
         dxDrawRectangle(sx-dxGetTextWidth(v.text, 1, "default-bold")-10, 35*i, dxGetTextWidth(v.text, 1, "default-bold")+50, 32,v.color)
         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)
         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)
      end
   end
end

function onClientClick(button,state,cX,cY)
   if not isCursorShowing() then
      return
   end
   if button == "left" and state == "up" then
      for k,self in pairs(editBox.instances) do
         if self.visible then
            if self.input then
               self.input = nil
               self.onOutput()
            end
            local x,y,w,h = self:getPosition()
            if isMouseInPosition(x,y,w,h) then
               self.input = true
               self.onInput()
            end
         end
      end
      if not inRegisterTab then
         if isMouseInPosition(x*552,y*504,x*262,y*44) then
            triggerServerEvent("onRequestLogin",localPlayer,g.user.text,g.pass.text)
         elseif isMouseInPosition(x*700,y*609,x*44,y*22) then
            g.user.visible = false
            g.pass.visible = false
           
            inRegisterTab = true
            g.rUser.visible = true
            g.rPass.visible = true
         end
      else
         if isMouseInPosition(x*552,y*504,x*262,y*44) then
            triggerServerEvent("onRequestRegister",localPlayer,g.rUser.text,g.rPass.text)
         end
      end
   end
end
addEventHandler("onClientClick", root, onClientClick)

function onClientCharacter(character)
   if not isCursorShowing() then
      return
   end
   for k,self in pairs(editBox.instances) do
      if self.visible and self.input then
         if (string.len(self.text)) < self.maxLength then
            self.text = self.text..character
         end
      end
   end
end
addEventHandler("onClientCharacter", root, onClientCharacter)

function editBox.new()
   local self = setmetatable({}, editBox)
   self.text = ""
   self.maxLength = 20
   self.scale = y*0.8
   self.state = "normal"
   self.font = "sans"
   self.color = {255,255,255,220}
   self.textColor = {255,255,255,220}
   table.insert(editBox.instances, self)
   return self
end

function editBox:getPosition()
   return self.x, self.y, self.w, self.h
end

function editBox:setPosition(x,y,w,h)
   self.x, self.y, self.w, self.h = x,y,w,h
   return true
end

function dxDrawBorder(posX, posY,posW,posH,color,scale)
   dxDrawLine(posX, posY, posX+posW, posY, color, scale,false)
   dxDrawLine(posX, posY, posX, posY+posH, color, scale,false)
   dxDrawLine(posX, posY+posH, posX+posW, posY+posH, color, scale,false)
   dxDrawLine(posX+posW, posY, posX+posW, posY+posH, color, scale,false)
end

function isMouseInPosition(x,y,width,height)
    local cx, cy = getCursorPosition()
    local cx, cy = (cx*sx), (cy*sy)
    if (cx >= x and cx <= x + width) and (cy >= y and cy <= y + height) then
        return true
    else
        return false
    end
end

function onLogin()
   showChat(true)
   stopSound(sound)
   guiSetInputMode("allow_binds")
   removeEventHandler("onClientRender", root, paint)
   removeEventHandler("onClientClick",root,onClientClick)
   removeEventHandler("onClientCharacter",root,onClientCharacter)
   showCursor(false)
end
addEvent("onLogin", true)
addEventHandler("onLogin", localPlayer, onLogin)

function onRegister()
   g.user.visible = true
   g.pass.visible = true
   g.user.text = ""
   g.pass.text = ""
     
   inRegisterTab = false
   g.rUser.visible = false
   g.rPass.visible = false
   g.rUser.text = ""
   g.rPass.text = ""
end
addEvent("onRegister", true)
addEventHandler("onRegister", localPlayer, onRegister)

function loadLoginFromXML()
   local XML = xmlLoadFile ("userdata.xml")
    if not XML then
        XML = xmlCreateFile("userdata.xml", "login")
    end
   
    local usernameNode = xmlFindChild (XML, "username", 0)
    if usernameNode then
        return xmlNodeGetValue(usernameNode)
    else
      return ""
    end
    xmlUnloadFile ( XML )
end

function saveLoginToXML(username)
    local XML = xmlLoadFile ("userdata.xml")
    if not XML then
        XML = xmlCreateFile("userdata.xml", "login")
    end
   if (username ~= "") then
      local usernameNode = xmlFindChild (XML, "username", 0)
      if not usernameNode then
         usernameNode = xmlCreateChild(XML, "username")
      end
      xmlNodeSetValue (usernameNode, tostring(username))
   end
    xmlSaveFile(XML)
    xmlUnloadFile (XML)
end
addEvent("saveLoginToXML", true)
addEventHandler("saveLoginToXML", root, saveLoginToXML)


function login_text(result, text)
   if result == "sucess" then
       addNotification(text,1)
   elseif result == "error" then
       addNotification(text,2)
   end
end
addEvent("login_text",true)
addEventHandler("login_text",root,login_text)

function addNotification(text, type)
    text = string.gsub(text,"#%x%x%x%x%x%x","")
   local i = 0
   if text == "" or text == nil or not type then
      return
   else
      for i = 0, #messages+1 do
         if messages then
            i = i+1
         else
            messages = {}
            messages.text = text
            messages.visible = true
            if type == 1 then
               messages.color = tocolor(0,255,0,160)
            elseif type == 2 then
               messages.color = tocolor(255,0,0,160)
            end
            setTimer(removeNotify,5000,1,i)
         end
      end
   end
end

function removeNotify(i)
   messages.visible = false
   messages = nil
end

function dxDrawBorder(posX, posY,posW,posH,color,scale)
   dxDrawLine(posX, posY, posX+posW, posY, color, scale,false)
   dxDrawLine(posX, posY, posX, posY+posH, color, scale,false)
   dxDrawLine(posX, posY+posH, posX+posW, posY+posH, color, scale,false)
   dxDrawLine(posX+posW, posY, posX+posW, posY+posH, color, scale,false)
end
« Son Düzenleme: 06 Kasım 2017, 21:29:47 Gönderen: ertrldtcu »
Pazar gününe kadar tüm systemlerimizde %20 indirim var! Ayrıca herhangi bi systemi alana yanında asla kullanmayacağı saçma bi system hediye!
© dutcy copying 2020
 


Çevrimdışı #ScottCoder

  • Acemi Üye
  • *
    • İleti: 111
  • 👑 AXE FREEROAM 👑
Yanıtla #2 : 06 Kasım 2017, 21:02:04
Hala aynı dostum :/

Mesaj Birleştirildi: [time]06 Kasım 2017, 22:11:33[/time]
Düzeldi dostum saol :)

Konu kilit pls

Mesaj Birleştirildi: [time]06 Kasım 2017, 22:34:09[/time]
Bir sorun daha çıktı başka konu açmiyim dedim.
Giriş yaptıktan sonra mause imleçi ekranda kalıyor

Mesaj Birleştirildi: 06 Kasım 2017, 21:29:30
client

Kod: lua
local screenW, screenH = guiGetScreenSize()
local x, y = (screenW/1366), (screenH/768)
guiSetInputMode("no_binds")

checkBox1 = guiCreateCheckBox(x*599, y*537, x*17, y*15, "", false, false)
checkBox2 = guiCreateCheckBox(x*599, y*568, x*17, y*15, "", false, false)

guiSetVisible(checkBox1, false)
guiSetVisible(checkBox2, false)

guiSetAlpha(checkBox1, 0)
guiSetAlpha(checkBox2, 0)

userAlpha = 150
passAlpha = 150

cor = {}

local font_Text = dxCreateFont("files/font/font_Text.ttf", 20)
local font_Text2 = dxCreateFont("files/font/font_Text.ttf", 15)
local dxfont0_font1 = dxCreateFont("files/font/font1.ttf", 26)
local dxfont1_font1 = dxCreateFont("files/font/font1.ttf", 29)
local dxfont2_font1 = dxCreateFont("files/font/font1.ttf", 22)

local fontScale = false

editBox = {}
editBox.__index = editBox
editBox.instances = {}

function onClientResourceStart()
local font_EditBox = dxCreateFont("files/font/font_EditBox.ttf", 20)

user = editBox.new()
user:setPosition(x*550, y*283, x*137, y*37)
user.color = {0, 0, 0, 0}
user.font = font_EditBox
user.text = ""
user.visible = true
user.onInput = function()
userAlpha = 255
end
user.onOutput = function()
userAlpha = 150
end

pass = editBox.new()
pass:setPosition(x*550, y*335, x*316, y*40)
pass.color = {0, 0, 0, 0}
pass.font = font_EditBox
pass.masked = true
pass.visible = true
pass.onInput = function()
passAlpha = 255
end
pass.onOutput = function()
passAlpha = 150
end

setTimer(function()
showChat(false)
end, 2500, 1)
showCursor(true)
guiSetVisible(checkBox1, true)
guiSetVisible(checkBox2, true)
addEventHandler("onClientRender", getRootElement(), dxLogin)
addEventHandler("onClientRender", getRootElement(), renderMensagesLogin)

if not fontScale then fontScale = screenH/100 end

local username, password = loadLoginFromXML()

if not(username == "" or password == "") then
guiCheckBoxSetSelected(checkBox1, true)
user.text = tostring(username)
pass.text = tostring(password)
else
guiCheckBoxSetSelected(checkBox1, false)
user.text = tostring(username)
pass.text = tostring(password)
end
end
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), onClientResourceStart)

function dxLogin()

dxDrawImage(x*0, y*0, x*1366, y*768, "files/img/fundo.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
        dxDrawLine(x*503 - 1, y*158 - 1, x*503 - 1, y*668, tocolor(0, 0, 0, 255), 1, false)
        dxDrawLine(x*871, y*158 - 1, x*503 - 1, y*158 - 1, tocolor(0, 0, 0, 255), 1, false)
        dxDrawLine(x*503 - 1, y*668, x*871, y*668, tocolor(0, 0, 0, 255), 1, false)
        dxDrawLine(x*871, y*668, x*871, y*158 - 1, tocolor(0, 0, 0, 255), 1, false)
        dxDrawRectangle(x*503, y*158, x*368, y*510, tocolor(0, 0, 0, 90), false)
        dxDrawText("#ffffffGöktürk #00dbc4Freeroam", x*513, y*201, x*861, y*239, tocolor(225, 0, 0, 254), 1.00, dxfont0_font1, "center", "top", false, false, false, true, false)
        dxDrawLine(x*550 - 1, y*430 - 1, x*550 - 1, y*482, tocolor(225, 0, 0, 254), 1, false)
        dxDrawLine(x*688, y*430 - 1, x*550 - 1, y*430 - 1, tocolor(225, 0, 0, 254), 1, false)
        dxDrawLine(x*550 - 1, y*482, x*688, y*482, tocolor(225, 0, 0, 254), 1, false)
        dxDrawLine(x*688, y*482, x*688, y*430 - 1, tocolor(225, 0, 0, 254), 1, false)
        dxDrawRectangle(x*550, y*430, x*138, y*52, tocolor(225, 0, 0, 0), false)
        dxDrawText("#ffffffGiris#00dbc4 Yap", x*550, y*427, x*688, y*482, tocolor(225, 0, 0, 254), 1.00, dxfont1_font1, "center", "bottom", false, false, false, true, false)
        dxDrawLine(x*698 - 1, y*430 - 1, x*698 - 1, y*482, tocolor(225, 0, 0, 254), 1, false)
        dxDrawLine(x*836, y*430 - 1, x*698 - 1, y*430 - 1, tocolor(225, 0, 0, 254), 1, false)
        dxDrawLine(x*698 - 1, y*482, x*836, y*482, tocolor(225, 0, 0, 254), 1, false)
        dxDrawLine(x*836, y*482, x*836, y*430 - 1, tocolor(225, 0, 0, 254), 1, false)
        dxDrawRectangle(x*698, y*430, x*138, y*52, tocolor(225, 0, 0, 0), false)
        dxDrawText("#ffffffKayıt#00dbc4 Ol", x*698, y*427, x*836, y*482, tocolor(225, 0, 0, 254), 1.00, dxfont1_font1, "center", "bottom", false, false, false, true, false)
        dxDrawText("#ffffffHesabımı #00dbc4kaydet#ffffff", x*622, y*533, x*751, y*562, tocolor(225, 0, 0, 254), 1.00, dxfont2_font1, "left", "center", false, false, false, true, false)
        dxDrawText("#ffffffSifreyi #00dbc4göster#ffffff", x*622, y*564, x*751, y*593, tocolor(225, 0, 0, 254), 1.00, dxfont2_font1, "left", "center", false, false, false, true, false)
        dxDrawLine(x*540 - 1, y*279 - 1, x*540 - 1, y*323, tocolor(254, 0, 0, 255), 1, false)
        dxDrawLine(x*845, y*279 - 1, x*540 - 1, y*279 - 1, tocolor(254, 0, 0, 255), 1, false)
        dxDrawLine(x*540 - 1, y*323, x*845, y*323, tocolor(254, 0, 0, 255), 1, false)
        dxDrawLine(x*845, y*323, x*845, y*279 - 1, tocolor(254, 0, 0, 255), 1, false)
        dxDrawRectangle(x*540, y*279, x*305, y*44, tocolor(254, 0, 0, 0), false)
        dxDrawLine(x*541 - 1, y*333 - 1, x*541 - 1, y*377, tocolor(254, 0, 0, 254), 1, false)
        dxDrawLine(x*846, y*333 - 1, x*541 - 1, y*333 - 1, tocolor(254, 0, 0, 254), 1, false)
        dxDrawLine(x*541 - 1, y*377, x*846, y*377, tocolor(254, 0, 0, 254), 1, false)
        dxDrawLine(x*846, y*377, x*846, y*333 - 1, tocolor(254, 0, 0, 254), 1, false)
        dxDrawRectangle(x*541, y*333, x*305, y*44, tocolor(254, 0, 0, 0), false)

dxDrawEmptyRec(x*599, y*537, x*17, y*15, tocolor(225, 0, 0, 254), 1)
dxDrawEmptyRec(x*599, y*568, x*17, y*15, tocolor(225, 0, 0, 254), 1)


if guiCheckBoxGetSelected(checkBox1) == true then
dxDrawText("X", x*597, y*634, x*620, y*454, tocolor(0, 255, 255, 255), x*1.00, font_Text2, "center", "center", false, false, false, false, false)
else
end

if guiCheckBoxGetSelected(checkBox2) == true then
pass.masked = false
dxDrawText("X", x*597, y*665, x*620, y*486, tocolor(0, 255, 255, 255), x*1.00, font_Text2, "center", "center", false, false, false, false, false)
else
pass.masked = true
end

for k, self in pairs(editBox.instances) do
if self.visible then
local px, py, pw, ph = self:getPosition()
local text = self.masked and string.gsub(self.text, ".", "•") or self.text
local alignX = dxGetTextWidth(text, self.scale, self.font) <= pw and "left" or "right"
dxDrawRectangle(px, py, pw, ph, tocolor(unpack(self.color)))
dxDrawText(text, px + x*5, py, px - x*5 + pw, py + ph, tocolor(unpack(self.textColor)), self.scale, self.font, alignX, "center", true)
if self.input and dxGetTextWidth(text, self.scale, self.font) <= pw then
local lx = dxGetTextWidth(text, self.scale, self.font) + px + x*8
local lx = dxGetTextWidth(text, self.scale, self.font) + px + x*8
dxDrawLine(lx, py + y*10, lx, py + ph - y*10, tocolor(255, 255, 255, math.abs(math.sin(getTickCount() / 300))*200), 1)
end
end
end

if getKeyState("backspace") then
for k, self in pairs(editBox.instances) do
if self.visible and self.input then
if not keyState then
keyState = getTickCount() + 400
self.text = string.sub(self.text, 1, string.len(self.text) - 1)
elseif keyState and keyState < getTickCount() then
keyState = getTickCount() + 100
self.text = string.sub(self.text, 1, string.len(self.text) - 1)
end
return
end
end
keyState = nil
end
end

function loginClick(botao, state)
if botao == "left" and state == "down" then
for k, self in pairs(editBox.instances) do
if self.visible then
if self.input then
self.input = nil
self.onOutput()
end
local x, y, w, h = self:getPosition()
if cursorPosition(x, y, w, h) then
self.input = true
self.onInput()
end
end
end
elseif cursorPosition(x*550, y*430, x*138, y*52) then
if guiCheckBoxGetSelected(checkBox1) == true then
checksave = true
else
checksave = false
end
triggerServerEvent("login", getLocalPlayer(), user.text, pass.text, checksave)
elseif cursorPosition(x*698, y*430, x*138, y*52) then
triggerServerEvent("registrar", getLocalPlayer(), user.text, pass.text)
end
end
addEventHandler("onClientClick", getRootElement(), loginClick)

function cursorPosition(x, y, width, height)
if (not isCursorShowing()) then
return false
end
local sx, sy = guiGetScreenSize()
local cx, cy = getCursorPosition()
local cx, cy = (cx*sx), (cy*sy)
if (cx >= x and cx <= x + width) and (cy >= y and cy <= y + height) then
return true
else
return false
end
end

function onClientCharacter(character)
if not isCursorShowing() then
return
end
for k, self in pairs(editBox.instances) do
if self.visible and self.input then
if (string.len(self.text)) < self.maxLength then
self.text = self.text..character
end
end
end
end
addEventHandler("onClientCharacter", getRootElement(), onClientCharacter)

function editBox.new()
local self = setmetatable({}, editBox)
self.text = ""
self.maxLength = 30
self.scale = y*0.8
self.state = "normal"
self.font = "sans"
self.color = {255, 255, 255, 255}
self.textColor = {255, 255, 255, 255}
table.insert(editBox.instances, self)
return self
end

function editBox:getPosition()
return self.x, self.y, self.w, self.h
end

function editBox:setPosition(x, y, w,h)
self.x, self.y, self.w, self.h = x, y, w, h
return true
end

function dxDrawEmptyRec(absX, absY, sizeX, sizeY, color, ancho)
dxDrawRectangle(absX, absY, sizeX, ancho, color)
dxDrawRectangle(absX, absY + ancho, ancho, sizeY - ancho, color)
dxDrawRectangle(absX + ancho, absY + sizeY - ancho, sizeX - ancho, ancho, color)
dxDrawRectangle(absX + sizeX-ancho, absY + ancho, ancho, sizeY - ancho*2, color)
end

function loadLoginFromXML()
local xml_save_log_File = xmlLoadFile("files/xml/userdata.xml")
if not xml_save_log_File then
xml_save_log_File = xmlCreateFile("files/xml/userdata.xml", "login")
end
local usernameNode = xmlFindChild(xml_save_log_File, "username", 0)
local passwordNode = xmlFindChild(xml_save_log_File, "password", 0)
if usernameNode and passwordNode then
return xmlNodeGetValue(usernameNode), xmlNodeGetValue(passwordNode)
else
return "", ""
end
xmlUnloadFile(xml_save_log_File)
end

function saveLoginToXML(username, password)
local xml_save_log_File = xmlLoadFile("files/xml/userdata.xml")
if not xml_save_log_File then
xml_save_log_File = xmlCreateFile("files/xml/userdata.xml", "login")
end
if (username ~= "") then
local usernameNode = xmlFindChild(xml_save_log_File, "username", 0)
if not usernameNode then
usernameNode = xmlCreateChild(xml_save_log_File, "username")
end
xmlNodeSetValue(usernameNode, tostring(username))
end
if (password ~= "") then
local passwordNode = xmlFindChild(xml_save_log_File, "password", 0)
if not passwordNode then
passwordNode = xmlCreateChild(xml_save_log_File, "password")
end
xmlNodeSetValue(passwordNode, tostring(password))
end
xmlSaveFile(xml_save_log_File)
xmlUnloadFile(xml_save_log_File)
end
addEvent("saveLoginToXML", true)
addEventHandler("saveLoginToXML", getRootElement(), saveLoginToXML)

function resetSaveXML()
local xml_save_log_File = xmlLoadFile("files/xml/userdata.xml")
if not xml_save_log_File then
xml_save_log_File = xmlCreateFile("files/xml/userdata.xml", "login")
end
if (username ~= "") then
local usernameNode = xmlFindChild(xml_save_log_File, "username", 0)
if not usernameNode then
usernameNode = xmlCreateChild(xml_save_log_File, "username")
end
xmlNodeSetValue(usernameNode, "")
end
if (password ~= "") then
local passwordNode = xmlFindChild(xml_save_log_File, "password", 0)
if not passwordNode then
passwordNode = xmlCreateChild(xml_save_log_File, "password")
end
xmlNodeSetValue(passwordNode, "")
end
xmlSaveFile(xml_save_log_File)
xmlUnloadFile(xml_save_log_File)
end
addEvent("resetSaveXML", true)
addEventHandler("resetSaveXML", getRootElement(), resetSaveXML)

function removeLogin()
user.visible = false
pass.visible = false

guiSetVisible(checkBox1, false)
guiSetVisible(checkBox2, false)

removeEventHandler("onClientRender", getRootElement(), dxLogin)
removeEventHandler("onClientRender", getRootElement(), renderMensagesLogin)
removeEventHandler("onClientClick", getRootElement(), loginClick)
removeEventHandler("onClientCharacter", getRootElement(), onClientCharacter)

showCursor(false)
showChat(true)
end
addEvent("removeLogin", true)
addEventHandler("removeLogin", getRootElement(), removeLogin)

local fontMsg = dxCreateFont("files/font/font_Text.ttf", 20, true) or "default-bold"

mensages = {}
messagetick = 0

function servermessagesLogin(message, type)
table.insert(mensages, {message, type or "confirm", getTickCount(), dxGetTextWidth(message, fontScale*0.08, fontMsg) + screenW*0.01, 0, 0, 0})
messagetick = getTickCount()
end
addEvent("servermessagesLogin", true)
addEventHandler("servermessagesLogin", getRootElement(), servermessagesLogin)

function renderMensagesLogin()
local msgd = mensages
if #msgd ~= 0 then
local startY = screenH*0.5
local i = 1
repeat
mData = msgd[i]
local drawThis = true
if i~= 1 then
startY = startY + screenH*0.0425
end
if mData[5] == 0 and mData[6] == 0 then
mData[5] = - mData[4] - screenW*0.015
mData[6] = startY
mData[7] = startY
end
local tick = getTickCount() - mData[3]
local posX, posY, alpha
if tick < 1000 then
local progress = math.min(tick/1000,1)
mData[5] = interpolateBetween(mData[5], 0, 0, 0, 0, 0, progress, "Linear")
elseif tick >= 1000 and tick <= 7000 then
mData[5] = 0
elseif tick > 7000 then
local progress = math.min((tick - 7000)/1000,1)
mData[5] = interpolateBetween(mData[5], 0, 0, - mData[4] - mData[4] - screenW*0.015, 0, 0, progress, "Linear")
if progress >= 1 then
table.remove(msgd, i)
drawThis = false
messagetick = getTickCount()
end
end
local globalTick = getTickCount() - messagetick
if drawThis then
mData[7] = startY
mData[6] = interpolateBetween(mData[6], 0, 0, mData[7], 0, 0, math.min(globalTick/1000,1), "Linear")
posX = mData[5]
posY = mData[6]
alpha = 255
dxDrawRectangle(posX, posY, mData[4], screenH*0.04, tocolor(0, 0, 0, 100), true)
local r, g, b = 0, 255, 0
if mData[2] == "warning" then
r, g, b = 255, 0, 0
end
dxDrawRectangle(posX + mData[4], posY, screenW*0.006, screenH*0.04, tocolor(r, g, b, alpha), true)
dxDrawText(mData[1], posX, posY, posX + mData[4], posY + screenH*0.04, tocolor(255, 255, 255, alpha), fontScale*0.07, fontMsg, "center", "center", false, false, true, false, false)
end
i = i + 1
until i > #msgd
mensages = msgd
end
end

function apagarScript()
if fileExists("client.lua") then
fileDelete("client.lua")
end
end
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), apagarScript)
addEventHandler("onClientPlayerQuit", getRootElement(), apagarScript)
addEventHandler("onClientPlayerJoin", getRootElement(), apagarScript)
« Son Düzenleme: 06 Kasım 2017, 21:29:30 Gönderen: ScottCoders »
 


Çevrimiçi ertrldtcu

  • Uzman Üye
  • *
    • İleti: 631
Yanıtla #3 : 06 Kasım 2017, 21:34:01
server kodları da atar mısın? buraya atmak istemiyorsan pm yolla.
Pazar gününe kadar tüm systemlerimizde %20 indirim var! Ayrıca herhangi bi systemi alana yanında asla kullanmayacağı saçma bi system hediye!
© dutcy copying 2020
 


Çevrimdışı #ScottCoder

  • Acemi Üye
  • *
    • İleti: 111
  • 👑 AXE FREEROAM 👑
Yanıtla #4 : 07 Kasım 2017, 19:03:59
Linki görebilmek için Kayıt olun yada Giriş yapın.
server kodları da atar mısın? buraya atmak istemiyorsan pm yolla.

dostum test ettim

bu kodda sıkıntı var.

guiSetInputMode("no_binds")
 


Çevrimiçi ertrldtcu

  • Uzman Üye
  • *
    • İleti: 631
Yanıtla #5 : 07 Kasım 2017, 20:34:29
Linki görebilmek için Kayıt olun yada Giriş yapın.
dostum test ettim

bu kodda sıkıntı var.

guiSetInputMode("no_binds")
Bu kodun imleçle herhangi bir alakası yok. Bu kod bindlerin devre dışı kalmasını sağlıyor.
Pazar gününe kadar tüm systemlerimizde %20 indirim var! Ayrıca herhangi bi systemi alana yanında asla kullanmayacağı saçma bi system hediye!
© dutcy copying 2020
 


MTASA TÜRK

Ynt: [YARDIM] Login panelde tuşlara basılması
« Yanıtla #5 : 07 Kasım 2017, 20:34:29 »