AGENT_STEELMEAT Posted January 8, 2011 Share Posted January 8, 2011 I've been following the GUI tutorial, and am trying to script a very basic login system. I have been trying to link it to the actual accounts system in MTA (like the one /login uses) and am having a lot of issues. So far, I have the login GUI passing the credentials to the server, and the server is able to check if they are valid or not (but not log them in). The big issue is getting it to pass that user along to the joinHandler function, so they can spawn. I can't seem to figure it out, and every solution I've tried has failed miserably. any help is appreciated. core.lua (server) function spawnHandler() local x = 2028 local y = 1545 local z = 11 local r = 270 local s = 167 spawnPlayer(source, x, y, z, r, s) fadeCamera(source, true) setCameraTarget(source, source) end function joinHandler() spawnHandler() newPlayer = getPlayerName(source) outputChatBox("Welcome to John's Test Server, " ..newPlayer.. "!", source, 0, 255, 0, true) outputChatBox( newPlayer.. " has joined the server.", getRootElement(), 255, 0, 0, true) end function quitHandler(quitType) local quittingPlayerName = getPlayerName(source) outputChatBox(quittingPlayerName .. " has left the server [" .. quitType .. "]" ) end addEventHandler("onPlayerQuit", getRootElement(), quitHandler) --addEventHandler("onPlayerJoin", getRootElement(), joinHandler) function loginHandler(username, password) --This is the area where the trouble begins local account = getAccount(username, password) if ( account ~= false ) then outputChatBox("good pass") else outputChatBox ("bad pass") end end addEvent("submitLogin",true) addEventHandler("submitLogin",root,loginHandler) and here is login.lua (clientside) function createLoginWindow() local X = 0.375 local Y = 0.375 local Width = 0.25 local Height = 0.25 wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) X = 0.0825 Y = 0.2 Width = 0.25 Height = 0.25 guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) Y = 0.5 guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) X = 0.415 Y = 0.2 Width = 0.5 Height = 0.15 edtUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin) Y = 0.5 edtPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin) guiEditSetMaxLength(edtUser, 50) guiEditSetMaxLength(edtPass, 50) X = 0.415 Y = 0.7 Width = 0.25 Height = 0.2 btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) guiSetVisible(wdwLogin, false) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () createLoginWindow() if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end showCursor(true) guiSetInputEnabled(true) end ) function clientSubmitLogin(button,state) if button == "left" and state == "up" then local username = guiGetText(edtUser) local password = guiGetText(edtPass) if username and password then triggerServerEvent("submitLogin", getRootElement(), username, password, logger) guiSetInputEnabled(false) guiSetVisible(wdwLogin, false) showCursor(false) else outputChatBox("Please enter a username and password.") end end end Link to comment
Castillo Posted January 8, 2011 Share Posted January 8, 2011 server side: function spawnHandler(player) local x = 2028 local y = 1545 local z = 11 local r = 270 local s = 167 spawnPlayer(player, x, y, z, r, s) fadeCamera(player, true) setCameraTarget(player, player) end function joinHandler() spawnHandler(source) newPlayer = getPlayerName(source) outputChatBox("Welcome to John's Test Server, " ..newPlayer.. "!", source, 0, 255, 0, true) outputChatBox( newPlayer.. " has joined the server.", getRootElement(), 255, 0, 0, true) end function quitHandler(quitType) local quittingPlayerName = getPlayerName(source) outputChatBox(quittingPlayerName .. " has left the server [" .. quitType .. "]" ) end addEventHandler("onPlayerQuit", getRootElement(), quitHandler) --addEventHandler("onPlayerJoin", getRootElement(), joinHandler) function loginHandler(username, password) --This is the area where the trouble begins local account = getAccount(username, password) if ( account ~= false ) then outputChatBox("good pass",source,0,255,0) joinHandler() else outputChatBox ("bad pass",source,255,0,0) end end addEvent("submitLogin",true) addEventHandler("submitLogin",root,loginHandler) client side: function createLoginWindow() local X = 0.375 local Y = 0.375 local Width = 0.25 local Height = 0.25 wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please Log In", true) X = 0.0825 Y = 0.2 Width = 0.25 Height = 0.25 guiCreateLabel(X, Y, Width, Height, "Username", true, wdwLogin) Y = 0.5 guiCreateLabel(X, Y, Width, Height, "Password", true, wdwLogin) X = 0.415 Y = 0.2 Width = 0.5 Height = 0.15 edtUser = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin) Y = 0.5 edtPass = guiCreateEdit(X, Y, Width, Height, "", true, wdwLogin) guiEditSetMaxLength(edtUser, 50) guiEditSetMaxLength(edtPass, 50) X = 0.415 Y = 0.7 Width = 0.25 Height = 0.2 btnLogin = guiCreateButton(X, Y, Width, Height, "Log In", true, wdwLogin) addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) guiSetVisible(wdwLogin, false) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () createLoginWindow() if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else outputChatBox("An unexpected error has occurred and the log in GUI has not been created.") end showCursor(true) guiSetInputEnabled(true) end ) function clientSubmitLogin(button,state) if button == "left" and state == "up" then local username = guiGetText(edtUser) local password = guiGetText(edtPass) if username and password then triggerServerEvent("submitLogin", getLocalPlayer(), username, password) guiSetInputEnabled(false) guiSetVisible(wdwLogin, false) showCursor(false) else outputChatBox("Please enter a username and password.") end end end Link to comment
AGENT_STEELMEAT Posted January 8, 2011 Author Share Posted January 8, 2011 Wow, that was quick. I can sorta see how that worked, but could you maybe explain what was wrong / what it needed? Thanks! Link to comment
Castillo Posted January 8, 2011 Share Posted January 8, 2011 well, at client side you had an error in triggerServerEvent which was giving bad argument, your error was: you was triggering some argument called "logger" which didn't exist in the script so i changed it to getLocalPlayer() and got fixed. in server side you was trying to call a function but your player element wasn't defined so i added some arguments as you can see and thats all. Link to comment
AGENT_STEELMEAT Posted January 8, 2011 Author Share Posted January 8, 2011 Well that makes perfect sense, now I fell a little stupid. Thanks again! 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