FrankTheTank Posted October 26, 2010 Share Posted October 26, 2010 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
dzek (varez) Posted October 26, 2010 Share Posted October 26, 2010 function loginHandler([b][color=#FF0000]player[/color][/b], username, password) local account = getAccount( username, password ) if (account ~= false) then if (logIn ( [b][color=#FF0000]thePlayer[/color][/b], account, password ) ~= true) then Link to comment
FrankTheTank Posted October 26, 2010 Author Share Posted October 26, 2010 Srry about that but when they are both player it still doesn't work... Link to comment
dzek (varez) Posted October 26, 2010 Share Posted October 26, 2010 I'm bit busy right know, but when computer is doing something I'm checking the forums - anyway, i dont have a time to debug it, try it by yourself, you will need in many times: https://wiki.multitheftauto.com/wiki/Debugging Link to comment
FrankTheTank Posted October 26, 2010 Author Share Posted October 26, 2010 Someone else may have a suggestion? thanks for your reactions varez. I've tried everything i know at the moment because i'm just an beginner Link to comment
dzek (varez) Posted October 26, 2010 Share Posted October 26, 2010 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
Aibo Posted October 30, 2010 Share Posted October 30, 2010 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now