Jump to content

[SOLUCIONADO] loginPanel no responde a los botones


UserToDelete

Recommended Posts

Tengo un problema con un panel de loggeo, mas bien dos

  • Los botones de "login" y "resgister" no funcionan
    La GUI se abre extrañamente dos veces, y con el tiempo se vuelve a abrir, e y si esta abierta parece que se abre otra vez

Client.lua

localPlayer = getLocalPlayer() 
addEventHandler("onClientResourceStart", root,  
function () 
    local screenW, screenH = guiGetScreenSize() 
        ventana = guiCreateWindow((screenW - 780) / 2, (screenH - 580) / 2, 780, 580, "== Panel de Login - TrosNos RolePlay ==", false) 
        guiWindowSetMovable(ventana, false) 
        guiWindowSetSizable(ventana, false) 
        guiSetAlpha(ventana, 0.75) 
        guiSetProperty(ventana, "CaptionColour", "FF00FF3C") 
  
        edit_username = guiCreateEdit(10, 65, 331, 35, "", false, ventana) 
        guiEditSetMaxLength (edit_username, 12) 
        label_username = guiCreateLabel(20, 40, 130, 15, "Nombre de usuario", false, ventana) 
        guiSetFont(label_username, "default-bold-small") 
        label_password = guiCreateLabel(20, 110, 130, 15, "Contraseña", false, ventana) 
        guiSetFont(label_password, "default-bold-small") 
        edit_password = guiCreateEdit(10, 135, 331, 35, "", false, ventana) 
        guiEditSetMasked(edit_password, true) 
        guiEditSetMaxLength (edit_password, 12) 
        button_login = guiCreateButton(10, 180, 160, 42, "Login", false, ventana) 
        guiSetProperty(button_login, "NormalTextColour", "FFFFFFFF") 
        button_register = guiCreateButton(180, 180, 160, 42, "Registrarse", false, ventana) 
        guiSetProperty(button_register, "NormalTextColour", "FFFFFFFF") 
        tabPanel = guiCreateTabPanel(11, 238, 759, 332, false, ventana) 
         
         
        button_close = guiCreateButton(10, 220, 160, 42, "CERRAR", false, ventana) 
         
         
        tab_info = guiCreateTab("Informacion del servidor", tabPanel)     
        showCursor (true) 
        addEventHandler("onClientGUIClick", button_close, closeGUI, false) 
        addEventHandler("onClientGUIClick", button_login, loginb, false) 
        addEventHandler("onClientGUIClick", button_register, loginr, false) 
    end ) 
function openGUI_ () 
    guiSetVisible(ventana, true) 
    showCursor(true) 
end 
addEvent("openGUI",true) 
addEventHandler("openGUI",localPlayer, openGUI_) 
function closeGUI () 
    guiSetVisible(ventana, false) 
end 
  
function loginb () 
    triggerServerEvent("loginPanel", localPlayer, edit_username, edit_password) 
    guiSetVisible(ventana, false) 
    showCursor (false) 
end 
  
function loginr () 
    triggerServerEvent("registerPanel", localPlayer, edit_username, edit_password) 
    guiSetVisible(ventana, false) 
    showCursor (false) 
end 

Server.lua

function onPlayerRegister_ (source, account, password) 
    logged = logIn(source, account, password) 
    if logged == false then 
    triggerClientEvent("openGUI", source) 
    end 
end 
addEvent("loginPanel", true) 
addEventHandler("loginPanel", root, onPlayerRegister_) 
  
function onRegister_ (source, username, password) 
    addAccount(username, password) 
    onPlayerRegister_(source, username, password) 
end 
addEvent("registerPanel", true) 
addEventHandler("registerPanel", root, onRegister_) 

Edited by Guest
Link to comment

No es necesario definir la función 'localPlayer' está pre-definida.

  
addEventHandler("onClientResourceStart", resourceRoot, 
function () 
    local screenW, screenH = guiGetScreenSize() 
        ventana = guiCreateWindow((screenW - 780) / 2, (screenH - 580) / 2, 780, 580, "== Panel de Login - TrosNos RolePlay ==", false) 
        guiWindowSetMovable(ventana, false) 
        guiWindowSetSizable(ventana, false) 
        guiSetAlpha(ventana, 0.75) 
        guiSetProperty(ventana, "CaptionColour", "FF00FF3C") 
  
        edit_username = guiCreateEdit(10, 65, 331, 35, "", false, ventana) 
        guiEditSetMaxLength (edit_username, 12) 
        label_username = guiCreateLabel(20, 40, 130, 15, "Nombre de usuario", false, ventana) 
        guiSetFont(label_username, "default-bold-small") 
        label_password = guiCreateLabel(20, 110, 130, 15, "Contraseña", false, ventana) 
        guiSetFont(label_password, "default-bold-small") 
        edit_password = guiCreateEdit(10, 135, 331, 35, "", false, ventana) 
        guiEditSetMasked(edit_password, true) 
        guiEditSetMaxLength (edit_password, 12) 
        button_login = guiCreateButton(10, 180, 160, 42, "Login", false, ventana) 
        guiSetProperty(button_login, "NormalTextColour", "FFFFFFFF") 
        button_register = guiCreateButton(180, 180, 160, 42, "Registrarse", false, ventana) 
        guiSetProperty(button_register, "NormalTextColour", "FFFFFFFF") 
        tabPanel = guiCreateTabPanel(11, 238, 759, 332, false, ventana) 
        
        
        button_close = guiCreateButton(10, 220, 160, 42, "CERRAR", false, ventana) 
        
        
        tab_info = guiCreateTab("Informacion del servidor", tabPanel)     
        showCursor (true) 
        addEventHandler("onClientGUIClick", button_close, closeGUI, false) 
        addEventHandler("onClientGUIClick", button_login, loginb, false) 
        addEventHandler("onClientGUIClick", button_register, loginr, false) 
    end ) 
function openGUI_ () 
    guiSetVisible(ventana, true) 
    showCursor(true) 
end 
addEvent("openGUI",true) 
addEventHandler("openGUI",localPlayer, openGUI_) 
function closeGUI () 
    guiSetVisible(ventana, false) 
end 
  
function loginb () 
    triggerServerEvent("loginPanel", localPlayer, guiGetText(edit_username), guiGetText(edit_password)) 
    guiSetVisible(ventana, false) 
    showCursor (false) 
end 
  
function loginr () 
    triggerServerEvent("registerPanel", localPlayer, guiGetText(edit_username), guiGetText(edit_password)) 
    guiSetVisible(ventana, false) 
    showCursor (false) 
end 
  

Link to comment

Aun asi, el script sigue sin loggear

Nuevo script

Server

function onPlayerRegister_ (source, account, password) 
    logged = logIn(source, account, password) 
    outputDebugString( 
    if logged == true then 
        outputChatBox("Te has logeado en el servidor", source, 0, 255, 0, true) 
        triggerClientEvent("closeGUI") 
    end 
    if logged == false then 
        outputChatBox("No te has podido loggear en el servidor",source) 
    end 
end 
addEvent("loginPanel", true) 
addEventHandler("loginPanel", resourceRoot, onPlayerRegister_) 
  
function onRegister_ (source, username, password) 
    addAccount(username, password) 
    onPlayerRegister_(source, username, password) 
end 
addEvent("registerPanel", true) 
addEventHandler("registerPanel", resourceRoot, onRegister_) 

Client

addEventHandler("onClientResourceStart", resourceRoot, 
function () 
    local screenW, screenH = guiGetScreenSize() 
        ventana = guiCreateWindow((screenW - 780) / 2, (screenH - 580) / 2, 780, 580, "== Panel de Login - TrosNos RolePlay ==", false) 
        guiWindowSetMovable(ventana, false) 
        guiWindowSetSizable(ventana, false) 
        guiSetAlpha(ventana, 0.75) 
        guiSetProperty(ventana, "CaptionColour", "FF00FF3C") 
  
        edit_username = guiCreateEdit(10, 65, 331, 35, "", false, ventana) 
        guiEditSetMaxLength (edit_username, 12) 
        label_username = guiCreateLabel(20, 40, 130, 15, "Nombre de usuario", false, ventana) 
        guiSetFont(label_username, "default-bold-small") 
        label_password = guiCreateLabel(20, 110, 130, 15, "Contraseña", false, ventana) 
        guiSetFont(label_password, "default-bold-small") 
        edit_password = guiCreateEdit(10, 135, 331, 35, "", false, ventana) 
        guiEditSetMasked(edit_password, true) 
        guiEditSetMaxLength (edit_password, 12) 
        button_login = guiCreateButton(10, 180, 160, 42, "Login", false, ventana) 
        guiSetProperty(button_login, "NormalTextColour", "FFFFFFFF") 
        button_register = guiCreateButton(180, 180, 160, 42, "Registrarse", false, ventana) 
        guiSetProperty(button_register, "NormalTextColour", "FFFFFFFF") 
        tabPanel = guiCreateTabPanel(11, 238, 759, 332, false, ventana) 
        
        
        button_close = guiCreateButton(10, 220, 160, 42, "CERRAR", false, ventana) 
        
        
        tab_info = guiCreateTab("Informacion del servidor", tabPanel)     
        showCursor (true) 
        addEventHandler("onClientGUIClick", button_close, closeGUI, false) 
        addEventHandler("onClientGUIClick", button_login, loginb, false) 
        addEventHandler("onClientGUIClick", button_register, loginr, false) 
    end ) 
function openGUI_ () 
    guiSetVisible(ventana, true) 
    showCursor(true) 
end 
addEvent("openGUI",true) 
addEventHandler("openGUI",localPlayer, openGUI_) 
function closeGUI () 
    guiSetVisible(ventana, false) 
end 
  
function loginb () 
    triggerServerEvent("loginPanel", localPlayer, guiGetText(edit_username), guiGetText(edit_password)) 
end 
  
function loginr () 
    triggerServerEvent("registerPanel", localPlayer, guiGetText(edit_username), guiGetText(edit_password)) 
end 
  
function openGUI_ () 
    guiSetVisible(ventana, true) 
    showCursor(true) 
end 
addEvent("openGUI", true) 
addEventHandler("openGUI", resourceRoot, openGUI_) 
  
function closeGUI_ () 
    guiSetVisible(ventana, false) 
    showCursor(false) 
end 
addEvent("closeGUI", true) 
addEventHandler("closeGUI", resourceRoot, closeGUI_) 
  

Link to comment

No había visto esto, lol.

  
addEventHandler("onClientResourceStart", resourceRoot, 
function () 
    local screenW, screenH = guiGetScreenSize() 
        ventana = guiCreateWindow((screenW - 780) / 2, (screenH - 580) / 2, 780, 580, "== Panel de Login - TrosNos RolePlay ==", false) 
        guiWindowSetMovable(ventana, false) 
        guiWindowSetSizable(ventana, false) 
        guiSetAlpha(ventana, 0.75) 
        guiSetProperty(ventana, "CaptionColour", "FF00FF3C") 
  
        edit_username = guiCreateEdit(10, 65, 331, 35, "", false, ventana) 
        guiEditSetMaxLength (edit_username, 12) 
        label_username = guiCreateLabel(20, 40, 130, 15, "Nombre de usuario", false, ventana) 
        guiSetFont(label_username, "default-bold-small") 
        label_password = guiCreateLabel(20, 110, 130, 15, "Contraseña", false, ventana) 
        guiSetFont(label_password, "default-bold-small") 
        edit_password = guiCreateEdit(10, 135, 331, 35, "", false, ventana) 
        guiEditSetMasked(edit_password, true) 
        guiEditSetMaxLength (edit_password, 12) 
        button_login = guiCreateButton(10, 180, 160, 42, "Login", false, ventana) 
        guiSetProperty(button_login, "NormalTextColour", "FFFFFFFF") 
        button_register = guiCreateButton(180, 180, 160, 42, "Registrarse", false, ventana) 
        guiSetProperty(button_register, "NormalTextColour", "FFFFFFFF") 
        tabPanel = guiCreateTabPanel(11, 238, 759, 332, false, ventana) 
        
        
        button_close = guiCreateButton(10, 220, 160, 42, "CERRAR", false, ventana) 
        
        
        tab_info = guiCreateTab("Informacion del servidor", tabPanel)     
        showCursor (true) 
        addEventHandler("onClientGUIClick", button_close, closeGUI, false) 
        addEventHandler("onClientGUIClick", button_login, loginb, false) 
        addEventHandler("onClientGUIClick", button_register, loginr, false) 
    end ) 
function openGUI_ () 
    guiSetVisible(ventana, true) 
    showCursor(true) 
end 
addEvent("openGUI",true) 
addEventHandler("openGUI",localPlayer, openGUI_) 
function closeGUI () 
    guiSetVisible(ventana, false) 
end 
  
function loginb () 
    triggerServerEvent("loginPanel", localPlayer, guiGetText(edit_username), guiGetText(edit_password)) 
end 
  
function loginr () 
    triggerServerEvent("registerPanel", localPlayer, localPlayer,guiGetText(edit_username), guiGetText(edit_password)) 
end 
  
function openGUI_ () 
    guiSetVisible(ventana, true) 
    showCursor(true) 
end 
addEvent("openGUI", true) 
addEventHandler("openGUI", resourceRoot, openGUI_) 
  
function closeGUI_ () 
    guiSetVisible(ventana, false) 
    showCursor(false) 
end 
addEvent("closeGUI", true) 
addEventHandler("closeGUI", resourceRoot, closeGUI_) 
  
  

No te recomiendo pasar el 'localPlayer' por un trigger porque no puede ser seguro, puedes usar 'client' desde el serverside.

Link to comment

Ahora el problema es que la GUI se cierra para todos los jugadores que la tienen abierta :/

Server | Creo que aqui es donde esta el problema

function onPlayerRegister_ (account, password) 
    account2 = getAccount(account) 
    logged = logIn(source, account2, password) 
    outputChatBox(tostring(account2)..""..tostring(password), source, 0, 255, 0, true) 
    if logged == true then 
        outputChatBox("Te has logeado en el servidor", client, 0, 255, 0, true) 
        state = false 
        triggerClientEvent("closeGUI", source, state) 
    end 
    if logged == false then 
        outputChatBox("No te has podido loggear en el servidor",client) 
    end 
end 
addEvent("loginPanel", true) 
addEventHandler("loginPanel", root, onPlayerRegister_) 

Client

function closeGUI_ (state) 
    destroyElement(ventana) 
    showCursor(state) 
    --local guiSetInputMode("allow_binds") 
end 
addEvent("closeGUI", true) 
addEventHandler("closeGUI", root, closeGUI_) 

Edito:

Si esto

addEventHandler("closeGUI", root, closeGUI_) 

Lo cambio por

addEventHandler("closeGUI", resourceRoot, closeGUI_) 

Deja de funcionar

Link to comment
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...