Jump to content

Tela de Login Ajuda


Recommended Posts

Ola estou com um problema com minha tela de login ela funciona perfeitamente mas quem esta em download nao pode jogar tem que dar /register pra consegui mas eu nao ter que precisar fazer isso alguem me ajuda ae os codigos

ServerSide 
function PlayerLogin(username,password,checksave) 
    if not (username == "") then 
        if not (password == "") then 
            local account = getAccount ( username, password ) 
            if ( account ~= false ) then 
                logIn(source, account, password) 
  
                triggerClientEvent (source,"hideLoginWindow",getRootElement()) 
                 
                    if checksave == true then 
                        triggerClientEvent(source,"saveLoginToXML",getRootElement(),username,password) 
                    else 
                        triggerClientEvent(source,"resetSaveXML",getRootElement(),username,password) 
                    end 
                 
            else 
                triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Nome de usuário inccorreto /ou senha errada") 
            end 
        else 
            triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Por favor insira sua senha!") 
        end 
    else 
        triggerClientEvent(source,"set_warning_text",getRootElement(),"Login","Digite seu nome de usuário!") 
    end 
end 
addEvent("onRequestLogin",true) 
addEventHandler("onRequestLogin",getRootElement(),PlayerLogin) 
  
  
  
function registerPlayer(username,password,passwordConfirm) 
    if not (username == "") then 
        if not (password == "") then 
            if not (passwordConfirm == "") then 
                if password == passwordConfirm then 
                    local account = getAccount (username,password) 
                    if (account == false) then 
                        local accountAdded = addAccount(tostring(username),tostring(password)) 
                        if (accountAdded) then 
                            outputChatBox ("" .. username .. " #00FF00| Password: #FFFFFF" .. password .. "#00FF00 ]",source,255,255,255,true ) 
                            outputChatBox ("",source,255,255,255,true ) 
                        else 
                            triggerClientEvent(source,"set_warning_text",getRootElement(),"Register","tente novamente com o novo nome de usuário ou senha!") 
                        end 
                    else 
                        triggerClientEvent(source,"set_warning_text",getRootElement(),"Register","Este nome de usuário já esta registrado!") 
                    end 
                else 
                    triggerClientEvent(source,"set_warning_text",getRootElement(),"Register","As senhas não combinam!") 
                end 
            else 
                triggerClientEvent(source,"set_warning_text",getRootElement(),"Register","Por favor, confirme sua senha!") 
            end 
        else 
            triggerClientEvent(source,"set_warning_text",getRootElement(),"Register","Por favor, digite a sua senha!") 
        end 
    else 
        triggerClientEvent(source,"set_warning_text",getRootElement(),"Register","Digite seu nome de usuário!") 
    end 
end 
addEvent("onRequestRegister",true) 
addEventHandler("onRequestRegister",getRootElement(),registerPlayer) 
  

ClientSide 
 
font1 = guiCreateFont ("font.ttf",12)
font2 = guiCreateFont ("font.ttf",30)
wdwLogin_Pannel = {}
tabPannel_Main = {}
tab_Login = {}
tab_Register = {}
 
 
function open_log_reg_pannel()
if not(isElement(wdwLogin_Pannel)) then
     
    showChat(false)
   
    x,y = guiGetScreenSize()
   
    local sWidth,sHeight = guiGetScreenSize()
    local Width,Height = 550,500
    local X = (sWidth/2) - (Width/2)
    local Y = (sHeight/2) - (Height/2)
   
   
 
   
    guiSetEnabled (Image, false)
   
    Login_img = guiCreateStaticImage( X, Y + 120, 612, 316, "login_window.png", false )
    guiSetEnabled (Login_img, false)
   
    --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    shLoginLogo = guiCreateLabel( X + 0, Y + 80, 550, 60, "", false )
    guiLabelSetColor(shLoginLogo,0,0,0)
    guiSetFont (shLoginLogo, font2)
   
   
   
   
    shLogin = guiCreateStaticImage( X + 450, Y + 249, 105, 35, "login.png", false )
    addEventHandler("onClientGUIClick",shLogin,onClickBtnLogin)
    addEventHandler( "onClientMouseEnter",shLogin,LoginSH)
    addEventHandler("onClientMouseLeave",shLogin,SErem)
   
    edit_Login = guiCreateEdit(X + 45,Y + 202,363,44,"",false)
    guiSetFont (edit_Login, font1)
    edit_password = guiCreateEdit(X + 45,Y + 307,363,45,"",false)
    guiSetFont (edit_password, font1)
    guiEditSetMaxLength ( edit_Login,25)
    guiEditSetMaxLength ( edit_password,25)
    guiEditSetMasked ( edit_password, true )
   
   
   
    lbl_about_legth = guiCreateLabel(142,70,184,18,"",false)
    guiLabelSetColor(lbl_about_legth,255,255,255)
    guiLabelSetVerticalAlign(lbl_about_legth,"center")
    guiLabelSetHorizontalAlign(lbl_about_legth,"center",false)
   
    checkbox_save = guiCreateCheckBox(X + 386,Y + 365,150,20,"",false,false)
    guiSetFont(checkbox_save,font1)
   
   
   
    login_tab_error_msg = guiCreateLabel(X,Y + 400,450,31,"Error_login_tab",false)
    guiLabelSetColor(login_tab_error_msg,255,255,255)
    guiLabelSetVerticalAlign(login_tab_error_msg,"center")
    guiLabelSetHorizontalAlign(login_tab_error_msg,"center",false)
    guiSetFont(login_tab_error_msg,font1)
 
 
       
    --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  
    shGuest = guiCreateStaticImage( X + 450, Y + 311, 105, 35, "guest.png", false ) -- A gomb
    addEventHandler("onClientGUIClick",shGuest,onClickGuest)
    addEventHandler( "onClientMouseEnter",shGuest,GuestSH)
    addEventHandler("onClientMouseLeave",shGuest,SErem)
   
    lbl_reg_top_info = guiCreateLabel(X - 80,Y + 290,45,0,"",false)
    guiLabelSetColor(lbl_reg_top_info,255,255,255)
    guiLabelSetVerticalAlign(lbl_reg_top_info,"center")
    guiLabelSetHorizontalAlign(lbl_reg_top_info,"center",false)
    guiSetVisible(lbl_reg_top_info,false)
   
    edit_account_name = guiCreateEdit(X + 38,Y + 184,363,46,"",false)
    guiEditSetMaxLength ( edit_account_name,25)
    guiSetVisible(edit_account_name,false)
    guiSetFont (edit_account_name, font1)
   
    edit__reg_tab_password = guiCreateEdit(X + 38,Y + 275,363,46,"",false)
    guiEditSetMaxLength ( edit__reg_tab_password,25)
    guiEditSetMasked ( edit__reg_tab_password, true )
    guiSetVisible(edit__reg_tab_password,false)
    guiSetFont (edit__reg_tab_password, font1)
   
   
    edit__reg_tab_Repassword = guiCreateEdit(X + 38,Y + 361,363,46,"",false)
    guiSetFont (edit__reg_tab_Repassword, font1)
    guiEditSetMaxLength ( edit__reg_tab_Repassword,25)
    guiEditSetMasked ( edit__reg_tab_Repassword, true )
    guiSetVisible(edit__reg_tab_Repassword,false)
    guiSetEnabled (edit__reg_tab_Repassword, true)  
   
    --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    shRegister = guiCreateStaticImage( X + 450, Y + 280, 105, 35, "register.png", false )
    addEventHandler("onClientGUIClick",shRegister,OnBtnRegister)
    addEventHandler( "onClientMouseEnter",shRegister,RegisterSH)
    addEventHandler("onClientMouseLeave",shRegister,SErem)
   
    --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    shRegister2 = guiCreateStaticImage( X + 450, Y + 350, 105, 35, "register2.png", false )
    addEventHandler("onClientGUIClick",shRegister2,onClickBtnRegister)
    addEventHandler( "onClientMouseEnter",shRegister2,Register2SH)
    addEventHandler("onClientMouseLeave",shRegister2,SErem)
   
    guiSetVisible(shRegister2,false)
   
    reg_tab_error_msg = guiCreateLabel(X,Y + 400,450,31,"Error_reg_ttab",false)
    guiLabelSetColor(reg_tab_error_msg,0,0,0)
    guiLabelSetVerticalAlign(reg_tab_error_msg,"center")
    guiLabelSetHorizontalAlign(reg_tab_error_msg,"center",false)
    guiSetFont(reg_tab_error_msg,font1)
   
   
    showCursor(true)
   
    guiSetText(reg_tab_error_msg, "")
    guiSetText(login_tab_error_msg, "")
   
   
    local username, password = loadLoginFromXML()
   
    if not( username == "" or password == "") then
        guiCheckBoxSetSelected ( checkbox_save, true )
        guiSetText ( edit_Login, tostring(username))
        guiSetText ( edit_password, tostring(password))
    else
        guiCheckBoxSetSelected ( checkbox_save, false )
        guiSetText ( edit_Login, tostring(username))
        guiSetText ( edit_password, tostring(password))
    end
    end
   
end
 
function LoginSH ()
    guiStaticImageLoadImage(shLogin, "sh.png" )
end
 
function RegisterSH ()
    guiStaticImageLoadImage(shRegister, "shr.png" )
end
 
function Register2SH ()
    guiStaticImageLoadImage(shRegister2, "shr2.png" )
end
 
function GuestSH ()
    guiStaticImageLoadImage(shGuest, "shg.png" )
end
 
 
 
function SErem ()
guiStaticImageLoadImage(shLogin, "login.png" )
guiStaticImageLoadImage(shRegister, "register.png" )
guiStaticImageLoadImage(shGuest, "guest.png" )
guiStaticImageLoadImage(shRegister2, "register2.png" )
 
end
function start_cl_resource()
    open_log_reg_pannel()
end
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),start_cl_resource)
 
 
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
        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 onClickBtnLogin(button,state)
   
    showChat(true)
    showCursor(false)
    guiSetVisible(Image,false)
        guiSetVisible(shGuest, false)
        guiSetVisible(Image, false)
        guiSetVisible(shLogin, false)
       
Link to comment
Bem, acho que o correto seria o jogador primeiro terminar o download para logar e jogar.

Você quer gerar no jogo o jogador que está baixando?

Sim quando o jogador esta em download ele nao spawna como normalmente para jogar ele fica bugado no cel e so consegui sair dando /register mas o mta normalmente nao e assim quando eu tirei a tela de login isso nao aconteceu mas...

Link to comment
Sim quando o jogador esta em download ele nao spawna como normalmente para jogar ele fica bugado no cel e so consegui sair dando /register mas o mta normalmente nao e assim quando eu tirei a tela de login isso nao aconteceu mas...

Use um script que spawne ele²:

x, y, z = 0, 0, 5 
  
addEventHandler ( "onPlayerJoin", root, 
    function ( ) 
        spawnPlayer ( source, x, y, z ) 
        setCameraTarget ( source, source ) 
        fadeCamera ( source, true ) 
    end 
) 

Link to comment
Sim quando o jogador esta em download ele nao spawna como normalmente para jogar ele fica bugado no cel e so consegui sair dando /register mas o mta normalmente nao e assim quando eu tirei a tela de login isso nao aconteceu mas...

Use um script que spawne ele²:

x, y, z = 0, 0, 5 
  
addEventHandler ( "onPlayerJoin", root, 
    function ( ) 
        spawnPlayer ( source, x, y, z ) 
        setCameraTarget ( source, source ) 
        fadeCamera ( source, true ) 
    end 
) 

Da para colocar mas de 1 lugar?

Link to comment

Da para colocar mas de 1 lugar?

Nao sou ele, mais voce pode colocar um Tabela !!

e Adicionar novas coords !!

Exemplo com Tabela:

  
local MySpawns = { 
{0,0,1}, 
{0,0,4}, 
{0,0,5}, 
} 
  
addEventHandler ( "onPlayerJoin", root, 
    function ( ) 
        local number = math.random(table.size(MySpawns)) 
        local x, y, z = MySpawns[number][1],MySpawns[number][2],MySpawns[number][3] 
        spawnPlayer ( source, x, y, z, math.random(0,360), 12, 0, 0) 
        setCameraTarget ( source, source ) 
        fadeCamera ( source, true ) 
    end 
) 
  

-- 12 é a Skin ( Voce pode mudar ) !

Espero que seja disso ta falando :P

:roll::wink::wink:

Link to comment
Nao sou ele, mais voce pode colocar um Tabela !!

e Adicionar novas coords !!

Exemplo com Tabela:

[...]

Seu código não vai funcionar pois a função table.size não está definida, o certo seria usar table.maxn ou #MySpawns

local MySpawns = { 
    { 0, 0, 1 }, 
    { 0, 0, 4 }, 
    { 0, 0, 5 }, 
} 
  
addEventHandler ( "onPlayerJoin", root, 
    function ( ) 
        local number = math.random ( #MySpawns ) 
        local x, y, z = MySpawns[number][1], MySpawns[number][2], MySpawns[number][3] 
        spawnPlayer ( source, x, y, z, math.random ( 0,360 ), 12, 0, 0 ) 
        setCameraTarget ( source, source ) 
        fadeCamera ( source, true ) 
    end 
) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...