Jump to content

[HELP] GUI Login Screen Problems


FrankTheTank

Recommended Posts

Dear Scripters,

I'm having some problems don't realy understand i've build an GUI Login Screen and created the code to make it login on the click.

The only thing is that i get this error when loggin in:

  
WARNING: DGC-SS\dgcss_server.lua:16: Bad argument @ 'logIn' 
WARNING: DGC-SS\dgcss_server.lua:18: Bad argument @ 'triggerClientEvent' 
  

So the error seems to be in the server-sided script but i myself can't find it i think i'm looking over something but i'm just an beginner in LUA Scripting so thats why i'm asking it here :)

Here are the servers/client scripts:

Client-Side:

  
-- Begin: DGC Login GUI Handlers 
function resourceStartOpenLoginWindow() 
    createLoginWindow() 
    if ( guiGetVisible ( DGCAccountLogin_Window ) == false ) then 
        guiSetVisible( DGCAccountLogin_Window, true ) 
        showCursor(true) 
        guiSetInputEnabled(true) 
    else 
        outputChatBox("[GUI]: An error has occurred!") 
    end 
end 
  
function clientSubmitLogin(button, state) 
        local username = guiGetText(DGCAccount_UserEdit) 
        local password = guiGetText(DGCAccount_PassEdit) 
        if username and password then 
            triggerServerEvent("submitLogin", getRootElement(), thePlayer, username, password) 
        else 
            outputChatBox("[LOGIN]: Enter username and password!") 
    end 
end 
  
function clientSubmitRegister(button, state) 
    if button == "left" and state == "up" then 
        local username = guiGetText(DGCAccount_UserEdit) 
        local password = guiGetText(DGCAccount_PassEdit) 
        if username and password then 
            triggerServerEvent("submitRegister", getRootElement(), localPlayer, username, password) 
        else 
            outputChatBox("[REGISTER]: Enter username and password.") 
        end 
    end 
end 
  
function hideLoginWindow() 
    guiSetInputEnabled(false) 
    guiSetVisible(DGCAccountLogin_Window, false) 
    showCursor(false) 
end 
  
-- End: DGC Login GUI Handlers 
-- Begin: DGC Login GUI Errors 
  
function unknownError() 
    outputChatBox("[ERROR]: An unknown error occured!") 
end 
  
function loginWrong() 
    outputChatbox("[LOGIN]: Wrong username and/or password!") 
end 
  
function registerTaken() 
    outputChatBox("[REGISTER]: This username is allready taken!") 
end 
  
-- End: DGC Login GUI Errors 
-- Begin: Event Handlers DGC Login GUI 
  
addEvent("hideLoginWindow", true) 
addEvent("unknownError", true) 
addEvent("loginWrong", true) 
addEvent("registerTaken", true) 
addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) 
addEventHandler("unknownError", getRootElement(), unknownError) 
addEventHandler("loginWrong", getRootElement(), loginWrong) 
addEventHandler("registerTaken", getRootElement(), registerTaken) 
addEventHandler("onClientResourceStart", getResourceRootElement( getThisResource( ) ), resourceStartOpenLoginWindow) 
  
-- End: Event Handlers DGC Login GUI 
-- Begin: DGC Login GUI 
  
GUIEditor_Label = {} 
  
DGCAccountLogin_Window = guiCreateWindow(0.3549,0.3344,0.3111,0.29,"DGC Account Services - [LOGIN]",true) 
guiWindowSetMovable(DGCAccountLogin_Window,false) 
guiWindowSetSizable(DGCAccountLogin_Window,false) 
guiSetProperty(DGCAccountLogin_Window,"Visible","true") 
DGCAccount_LoginButton = guiCreateButton(224,218,104,32,"Login",false,DGCAccountLogin_Window) 
guiSetFont(DGCAccount_LoginButton,"default-bold-small") 
guiSetProperty(DGCAccount_LoginButton,"Visible","true") 
DGCAccount_RegisterButton = guiCreateButton(333,218,104,32,"Register",false,DGCAccountLogin_Window) 
guiSetFont(DGCAccount_RegisterButton,"default-bold-small") 
guiSetProperty(DGCAccount_RegisterButton,"Visible","true") 
DGCAccount_UserEdit = guiCreateEdit(56,34,156,24,"",false,DGCAccountLogin_Window) 
guiSetProperty(DGCAccount_UserEdit,"Visible","true") 
DGCAccount_PassEdit = guiCreateEdit(56,61,156,24,"",false,DGCAccountLogin_Window) 
guiSetProperty(DGCAccount_PassEdit,"Visible","true") 
GUIEditor_Label[1] = guiCreateLabel(10,36,51,25,"User:",false,DGCAccountLogin_Window) 
guiLabelSetColor(GUIEditor_Label[1],255,255,255) 
guiLabelSetVerticalAlign(GUIEditor_Label[1],"top") 
guiLabelSetHorizontalAlign(GUIEditor_Label[1],"left",false) 
guiSetProperty(GUIEditor_Label[1],"Visible","true") 
GUIEditor_Label[2] = guiCreateLabel(11,63,52,30,"Pass:",false,DGCAccountLogin_Window) 
guiLabelSetColor(GUIEditor_Label[2],255,255,255) 
guiLabelSetVerticalAlign(GUIEditor_Label[2],"top") 
guiLabelSetHorizontalAlign(GUIEditor_Label[2],"left",false) 
guiSetProperty(GUIEditor_Label[2],"Visible","true") 
GUIEditor_Label[3] = guiCreateLabel(12,238,213,23,"Copyright 2010 @ -DGC-FrankNL",false,DGCAccountLogin_Window) 
guiLabelSetColor(GUIEditor_Label[3],255,255,255) 
guiLabelSetVerticalAlign(GUIEditor_Label[3],"top") 
guiLabelSetHorizontalAlign(GUIEditor_Label[3],"left",false) 
guiSetFont(GUIEditor_Label[3],"default-small") 
guiSetProperty(GUIEditor_Label[3],"Visible","true") 
DGCAccount_AutoLoginBox = guiCreateCheckBox(13,86,208,23,"Auto-Login By Serial (Not Supported Yet!)",false,false,DGCAccountLogin_Window) 
guiSetFont(DGCAccount_AutoLoginBox,"default-small") 
guiSetProperty(DGCAccount_AutoLoginBox,"Visible","true") 
  
GUIEditor_Label[4] = guiCreateLabel(0.7646,0.0011,0.2104,0.0478,"www.dgc-mta.nl",true) 
guiLabelSetColor(GUIEditor_Label[4],255,255,255) 
guiLabelSetVerticalAlign(GUIEditor_Label[4],"top") 
guiLabelSetHorizontalAlign(GUIEditor_Label[4],"left",false) 
guiSetFont(GUIEditor_Label[4],"sa-header") 
  
guiSetVisible( DGCAccountLogin_Window, true ) 
showCursor(true) 
  
addEventHandler("onClientGUIClick", DGCAccount_LoginButton, clientSubmitLogin, false) 
addEventHandler("onClientGUIClick", DGCAccount_RegisterButton, clientSubmitRegister, false) 
  
-- End: DGC Login GUI 
  

Server-side:

  
-- Begin: DGC Join Handler 
  
function joinHandlerDGC ( ) 
    local joinedPlayerName = getPlayerName ( source ) 
    local serverName = getServerName( ) 
    outputChatBox ( "Welcome " .. joinedPlayerName .. " to DGC Gaming, Please Login!" , source, 255, 255, 0 ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), joinHandlerDGC ) 
  
-- End: DGC Join Handler 
-- Begin: DGC Account Services, Login/Register Handler 
  
function loginHandler(player, username, password) 
    local account = getAccount( username, password ) 
    if (account ~= false) then 
        if (logIn ( thePlayer, account, password ) ~= true) then 
            outputChatBox("[DGC]: You are now Logged In, Have Fun!", player) 
            triggerClientEvent (player, "hideLoginWindow", getRootElement()) 
        else 
            triggerClientEvent (player, "unknownError", getRootElement()) 
        end 
        else 
            triggerClientEvent (player, "loginWrong", getRootElement()) 
    end 
end 
  
function registerHandler(player, username, password) 
    local account = getAccount(username, password) 
    if (account ~= false) then 
        triggerClientEvent(player, "registerTaken", getRootElement()) 
    else 
        account = addAccount(username, password) 
        if (logIn(player, account, password) == true) then 
            outputChatBox("[DGC]: You have registered your account and are now logged in!", player) 
            triggerClientEvent(player, "hideLoginWindow", getRootElement()) 
        else 
            triggerClientEvent(player, "unknownError", getRootElement()) 
        end 
    end 
end 
  
addEvent("submitLogin", true) 
addEvent("submitRegister", true) 
addEventHandler("submitLogin", root, loginHandler) 
addEventHandler("submitRegister", root, registerHandler) 
  
-- End: DGC Account Services, Login/Register Handler 
  

Could someone help me and explain what i've done wrong always nice to learn :)

Thanks!

Greatings FrankNL

Link to comment

try Debugging as i said - its much faster than waiting for replies.

example of debugging:

  
function loginHandler(player, username, password) 
  local et = getElementType(player) 
  local name="invalid" 
  if (et=="player") then name = getPlayerName(player) end 
  outputDebugString("player element type is "..et.."("..name.."), the username is "..username.." and the password is "..password") 
  -- rest of actions 
  

in this way you can check if the values are like you excepted them to be, if they are wrong (for example player is not an element or something - get "one step back" in your script to see how it looks before firing the function, if on this step there is still wrong - get back to even previous step (like: to client side, just before triggering event to server) - finally, you will find your error.

Link to comment

Could someone help me and explain what i've done wrong always nice to learn :)

Thanks!

you've used "player" instead of "source" in player-triggered event handler function. funny thing is that you've still used "source" in joinHandlerDGC

function loginHandler(username, password) 
    local account = getAccount(username, password)  
    if account then 
        if logIn(source, account, password) then 
            outputChatBox("[DGC]: You are now Logged In, Have Fun!", source) 
            triggerClientEvent(source, "hideLoginWindow", getRootElement()) 
        else 
            triggerClientEvent(source, "unknownError", getRootElement()) 
        end 
    else 
        triggerClientEvent(source, "loginWrong", getRootElement()) 
    end 
end 

same with registerHandler

update:

ok i've checked your clientside and found some problems. i wont ask why you trigger login event from root element (instead of player element who tries to log in) and send player element as an argument, but:

triggerServerEvent("submitLogin", getRootElement(), thePlayer, username, password) 

thePlayer is undefined.

triggerServerEvent("submitRegister", getRootElement(), localPlayer, username, password) 

localPlayer is (probably) undefined.

ofc this renders my code above not as useful, cause i assumed the event source is player, but turns out it is root and player arguments are simply not defined.

anyway, use getLocalPlayer(), for example:

triggerServerEvent("submitLogin", getLocalPlayer(), username, password) 

in this case event source will be player element.

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...