Jump to content

[Ayuda] Guardar cuentas


iSmokee

Recommended Posts

Hola tengo este error y no se por que es: attemp to call global 'loadLoginFromXML' (a nil value)

  
 local username, password = loadLoginFromXML() -- Esta es la linea que me da error y no se por que es como esta todo bien.. 
    
    if not( username == "" or password == "") then 
        guiCheckBoxSetSelected ( recordar, true ) 
        guiSetText ( editUsuario, tostring(username)) 
        guiSetText ( editPassword, tostring(password)) 
    else 
        guiCheckBoxSetSelected ( recordar, false ) 
        guiSetText ( editUsuario, tostring(username)) 
        guiSetText ( editPassword, tostring(password)) 
    end 
     
  
function loadLoginFromXML() --Загрузка логина и пароля из XML 
    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 
  

Link to comment
Perdon por contestar tarde ahora me puse a solucionar ese error bueno lo que me acabas de dar funciono pero cuando te quiere guardar los datos te los guarda pero no los tuyos ejemplo cuando entras al server te dice..

Usuario: nil

Password: ***

Entonces el problema es el guardado, publica el script completo.

Link to comment
  
local sx,sy = guiGetScreenSize()
local px,py = 1360,768
local x,y =  (sx/px), (sy/py)
local sW, sH = guiGetScreenSize()
local argentinaFont = dxCreateFont('fonts/argentinaFont.otf', 32)   
 
 
function guiLoginPanel()
    if isElement(localPlayer) then
        showChat(false)
        dxDrawImage( x*0, y*0, x*1360, y*768, "gfx/fondo.jpg", 0, 0, 0, tocolor ( 255, 255, 255, 255 ), false)
        --  dxDrawText("Bem vindo!", x*990, y*153, x*40, y*40, tocolor(255,255,255,255),1.0,"pricedown",false,false,false,true)
        dxDrawText("Bienvenido a Argentina con Estilo", x*21, y*1, x*1360, y*768, tocolor ( 0, 0, 0, 255 ), 1.0, argentinaFont, "left", "top",  false, false, false, true)
        dxDrawText("#33CAFFBienvenido a #ffffffArgentina #33CAFFcon Estilo", x*20, y*0, x*1360, y*768, tocolor ( 255, 255, 255, 255 ), 1.0, argentinaFont, "left", "top",  false, false, false, true)
        dxDrawRectangle(x*30, y*300, x*395, y*30, tocolor ( 0, 0, 0, 225 ), false )
        dxDrawText ( '#ffffff~|#33CAFFA#ffffffc#33CAFFE#ffffff|~ Panel de Logeo', x*76, y*298, x*0, y*30, tocolor ( 255, 255, 255, 255 ), 2.0, "default-bold","left","top",  false, false, false, true )       
        dxDrawRectangle(x*30, y*330, x*395, y*400, tocolor ( 0, 0, 0, 140 ), false )
        dxDrawImage( x*35, y*366, x*32, y*32, "gfx/user.png", 0, 0, 0, tocolor ( 255, 255, 255, 255 ), false)
        dxDrawImage( x*40, y*448, x*32, y*32, "gfx/lock.png", 0, 0, 0, tocolor ( 255, 255, 255, 255 ), false)
        dxDrawText ( 'Usuario', x*70, y*370, x*0, y*30, tocolor ( 255, 255, 255, 255 ), 2, "default-bold" )        
        dxDrawText ( 'Contraseña', x*80, y*450, x*0, y*30, tocolor ( 255, 255, 255, 255 ), 2, "default-bold" )
    --  for id, hudComponents in ipairs(hudTable) do
    --      showPlayerHudComponent(hudComponents, false)
    --  end 
    end
end
addEventHandler("onClientRender", root, guiLoginPanel)
 
-- dxEditBox Usuario
 
   editUsuario = guiCreateEdit(x*41, y*410, x*372, y*30, "", false)
   guiSetAlpha(editUsuario, 0);
   guiEditSetMaxLength ( editUsuario, 50 )
   showCursor(true)
   
   guiGetVisible(editUsuario, true)
 
function dxEditUsuario()  
    dxText = guiGetText(editUsuario )
    dxDrawRectangle(x*42, y*410, x*372, y*30, tocolor ( 255, 255, 255, 200 ), false);
    dxDrawText(dxText, x*50, y*820, x*400, y*30, tocolor(0, 0, 0, 255), 1.01, "default", "left", "center", false, false, false, false, false)
end
addEventHandler("onClientRender", root, dxEditUsuario)
-- dxEditBox Password
 
   editPassword = guiCreateEdit(x*42, y*490, x*372, y*30, "", false)
   guiSetAlpha(editPassword, 0);
   guiEditSetMaxLength ( editPassword, 50 )
 
   recordar = guiCreateCheckBox(x*225, y*458, x*80, y*15, "(Recordar)", false, false)
   guiSetFont(recordar, "default-bold-small")    
   
   guiGetVisible(editPassword, true)
   guiGetVisible(recordar, true)
 
function dxEditPassword()
    dxText2 = guiGetText(editPassword)
    dxDrawRectangle(x*42, y*490, x*372, y*30, tocolor ( 255, 255, 255, 200 ), false);
    dxDrawText(string.rep ( "*", string.len( dxText2 )), x*50, y*988, x*400, y*30, tocolor(0, 0, 0, 255), 1.01, "default", "left", "center", false, false, false, false, false)
end
addEventHandler("onClientRender", root, dxEditPassword)
 
loginX, loginY, loginW, loginH = 0.030, 0.720, 0.275, 0.080
 
function buttonLogin()
dxDrawRectangle(loginX*sW, loginY*sH, loginW*sW, loginH*sH, color, false)
--dxDrawText ( 'Logearse', x*175, y*570, x*0, y*30, colorTextLogin, 2.0, "default-bold" )
--dxDrawText ( 'Logearse', loginX+175, loginY+568,loginW, loginH, colorTextLogin, 2.0, "default-bold" )
dxDrawText ( 'Logearse', loginX*sW+135, loginY*sH+15,loginW*sW, loginH*sH, colorTextLogin, 2.0, "default-bold" )
    if isCursorShowing() then
    sX, sY, _, _, _ = getCursorPosition()
        if sX >= loginX and sX <= loginX+loginW and sY >= loginY and sY <= loginY+loginH then
            color = tocolor(0, 0, 0, 255)
            colorTextLogin = tocolor(51, 202, 255, 255)
        else
            color = tocolor(0, 0, 0, 180)
            colorTextLogin = tocolor(255, 255, 255, 255)       
        end
    end
end
 
addEventHandler("onClientClick", getRootElement(),
function(button, state, px, py)
    if (button == "left" and state == "down") then
        if (px > loginX*sW and px < (loginX+loginW)*sW and py > loginY*sH and py < (loginY+loginH)*sH) then
            if(isEventHandlerAdded("onClientRender", getRootElement(getThisResource()), buttonLogin)) then
                username = guiGetText(editUsuario)
                password = guiGetText(editPassword)
                triggerServerEvent("onRequestLogin",localPlayer,username,password, checksave)
                if guiCheckBoxGetSelected ( recordar ) == true then
                    checksave = true
                else
                    checksave = false
                end
            end
        end
    end
end)
addEventHandler("onClientRender",root,buttonLogin)
 
function onLogin()
    showChat(true)
    showCursor( false )
    --if isElement(LoginPanel) then
        removeEventHandler("onClientRender",root,guiLoginPanel)
        removeEventHandler("onClientRender",root,buttonLogin)
        removeEventHandler("onClientRender",root,buttonRegister)
        removeEventHandler("onClientRender",root,buttonGuest)
        removeEventHandler("onClientRender",root,dxEditUsuario)
        removeEventHandler("onClientRender",root,dxEditPassword)
        guiSetVisible ( recordar, false )
        guiSetVisible ( editUsuario, false )  
        guiSetVisible ( editPassword, false )
        --setCameraTarget( localPlayer )
        triggerServerEvent("onPlayerLogin", localPlayer)
    --  for id, hudComponents in ipairs(hudTable) do
    --      showPlayerHudComponent(hudComponents, true)
    --  end 
    --removeEventHandler ( "onClientRender", getRootElement(), DXText )
--  end
end
addEvent("onLogin", true)
addEventHandler("onLogin", localPlayer, onLogin)
 
guestX, guestY, guestW, guestH = 0.030, 0.820, 0.132, 0.080
 
function buttonGuest()
dxDrawRectangle(guestX*sW, guestY*sH, guestW*sW, guestH*sH, color2, false)
--dxDrawText ( 'Invitado', x*85, y*645, x*0, y*30, colorTextGuest, 2.0, "default-bold" )
dxDrawText ( 'Invitado',guestX*sW+43, guestY*sH+15, guestW*sW, guestH*sH, colorTextGuest, 2.0, "default-bold" )
    if isCursorShowing() then
    sX, sY, _, _, _ = getCursorPosition()
        if sX >= guestX and sX <= guestX+guestW and sY >= guestY and sY <= guestY+guestH then
            color2 = tocolor(0, 0, 0, 255)
            colorTextGuest = tocolor(51, 202, 255, 255)
        else
            color2 = tocolor(0, 0, 0, 180)
            colorTextGuest = tocolor(255, 255, 255, 255)           
        end
    end
end
 
addEventHandler("onClientClick", getRootElement(),
function(button, state, px, py)
    if (button == "left" and state == "down") then
        if (px > guestX*sW and px < (guestX+guestW)*sW and py > guestY*sH and py < (guestY+guestH)*sH) then
            if(isEventHandlerAdded("onClientRender", getRootElement(getThisResource()), buttonGuest)) then
                removeEventHandler("onClientRender",root,guiLoginPanel)
                removeEventHandler("onClientRender",root,buttonLogin)
                removeEventHandler("onClientRender",root,buttonRegister)
                removeEventHandler("onClientRender",root,buttonGuest)
                removeEventHandler("onClientRender",root,dxEditUsuario)
                removeEventHandler("onClientRender",root,dxEditPassword)
                guiSetVisible ( recordar, false )
                guiSetVisible ( editUsuario, false )  
                guiSetVisible ( editPassword, false )
                triggerServerEvent("onButtonInvitado", localPlayer)
                showCursor( false )
                showChat(true)
            end
        end
    end
end)
addEventHandler("onClientRender",root,buttonGuest)
 
registerX, registerY, registerW, registerH = 0.172, 0.820, 0.132, 0.080
 
function buttonRegister()
dxDrawRectangle(registerX*sW, registerY*sH, registerW*sW, registerH*sH, color3, false)
--dxDrawText ( 'Registrarse', x*253, y*645, x*0, y*30, colorTextRegister, 2.0, "default-bold" )
dxDrawText ( 'Registrarse', registerX*sW+20, registerY*sH+15, registerW*sW, registerH*sH, colorTextRegister, 2.0, "default-bold" )
    if isCursorShowing() then
    sX, sY, _, _, _ = getCursorPosition()
        if sX >= registerX and sX <= registerX+registerW and sY >= registerY and sY <= registerY+registerH then
            color3 = tocolor(0, 0, 0, 255)
            colorTextRegister = tocolor(51, 202, 255, 255)
        else
            color3 = tocolor(0, 0, 0, 180)
            colorTextRegister = tocolor(255, 255, 255, 255) 
        end
    end
end
 
addEventHandler("onClientClick", getRootElement(),
function(button, state, px, py)
    if (button == "left" and state == "down") then
        if (px > registerX*sW and px < (registerX+registerW)*sW and py > registerY*sH and py < (registerY+registerH)*sH) then
            if(isEventHandlerAdded("onClientRender", getRootElement(getThisResource()), buttonRegister)) then
                local registerUsername = guiGetText(editUsuario)
                local registerPassword = guiGetText(editPassword)
                --local passwordConfirm = guiGetText(editConfirmPassword)
                --local registerEmail = guiGetText(editEmail)
                triggerServerEvent("onRequestRegister",localPlayer,registerUsername,registerPassword )
            end
        end
    end
end)
addEventHandler("onClientRender",root,buttonRegister)  
 
 --  local username, password = loadLoginFromXML()
 
addEventHandler("onClientResourceStart", resourceRoot,
function ()
        local username, password = loadLoginFromXML()
end
)
   
    if not( username == "" or password == "") then
        guiCheckBoxSetSelected ( recordar, true )
        guiSetText ( editUsuario, tostring(username))
        guiSetText ( editPassword, tostring(password))
    else
        guiCheckBoxSetSelected ( recordar, false )
        guiSetText ( editUsuario, tostring(username))
        guiSetText ( editPassword, tostring(password))
    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 =
Link to comment

Borra desde la línea 209 a la 217 y reemplaza este código por el que está desde la 203 a la 207

  
addEventHandler("onClientResourceStart", resourceRoot, 
   function () 
       username, password = loadLoginFromXML() 
       if not( username == "" or password == "") then 
          guiCheckBoxSetSelected ( recordar, true ) 
          guiSetText ( editUsuario, tostring(username)) 
          guiSetText ( editPassword, tostring(password)) 
       else 
          guiCheckBoxSetSelected ( recordar, false ) 
          guiSetText ( editUsuario, tostring(username)) 
          guiSetText ( editPassword, tostring(password)) 
       end 
   end 
) 
  

Link to comment
  • 1 month later...
  • Recently Browsing   0 members

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