dragonslife Posted March 20, 2012 Share Posted March 20, 2012 Hello people, I'm totally new to scripting and thougt of doing some basic tutorials for it to make my own MTA server. So I've been working trough the wiki pages with some basic scripting. These are the wiki pages i've been trough so far. https://wiki.multitheftauto.com/wiki/Scr ... troduction https://wiki.multitheftauto.com/wiki/Int ... ng_the_GUI Now that i've finished those 2 pages I tried to login to my server and as a result got a black screen. I've been trying quite some stuff myself to be able to find out what's not right in my code, but couldn't find the solution. So I hope some of you guys can help me with it. Here's my code so far. script.lua -- create our loginHandler function, with username and password parameters (passed from the client GUI). function loginHandler(username,password) -- check that the username and password are correct. if username == "user" and password =="apple" then -- the player has succesfully logged in, so spawn them. if (client) then spawnPlayer (client, 1959.55, -1714.46, 10) faceCamera(client, true) setCameraTarget(client, client) outputChatBox("Enjoy your time!", client) end else -- if the username or password are not correct, output a message to the player. outputChatBox("invalid username and password. Please re-connect and try again.", client) end end -- define our costom event, and allow it to be triggered from the client ('true'). addEvent("submitLogin",true) -- add an event handler so that when submitLogin is triggered, the function loginHandler is called. addEventHandler("submitLogin",root, loginHandler) and my gui.lua function createLoginWindow() -- define the X and Y positions of the window local X = 0.375 local Y = 0.375 -- define the width and height of the window local Width = 0.25 local Height = 0.25 -- create the window and save it's element value into the variable "wdwLogin" -- click on the function's name to read its documentation. wdwLogin = guiCreateWindow(x, y, Width, Height, "Please login with your username and password", true) -- define new X and Y positions for the first label. X = 0.0825 y = 0.2 -- define new Width and Height values for the first label. Width = 0.25 Height = 0.25 -- create the first label, note the final argument passed is 'wdwLogin' meaning the window -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window). guiCreateLabel (X, Y, Width, Height, "Username", true, wdwLogin) -- alter the Y value so the second label is slightly below the first. 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) -- set the maximum character length for the username and password fields to 50. 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) -- now add our onClientGUIClick event to the button we just created. addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) -- make the window invisible guiSetVisible(wdwLogin, false) -- create the function and define the 'button' and 'state' parameters. -- (these are passed automatically by onClientGUIClick) function clientSubmitLogin(button,state) -- if our login button was clicked with the left mouse button, and the state of the mousebutton is up: if button == "left" and state == "up" then -- get the text entered in the 'username' field. local username = guiGetText(edtUser) -- get the text entered in the 'password' field. local password = guiGetText(edtPass) -- if the username and password both exist: if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it. triggerServerEvent("submitLogin", getRootElement(), username, password) -- move the input focus back on the game (allowing players to move arround, open the chatbox, etc) guiSetInputEnabled(false) -- hide the window and all the components. guiSetVisible(wdwLogin, false) -- hide the mouse cursor. showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui. outputChatBox("please enter a username and password.") end end end -- attach the event handler to the root element of the resource. -- this means it will only trigger when it's own resource is started. addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () -- create the log in window and it's components. createLoginWindow() -- output a brief welcome message to the player outputChatBox("Welcome to BlackDeath's Alpha Server, Please log in with the login information provided to you") -- if the GUI was successfully created, then show the GUI to the player. if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else -- if the GUI hasn't been properly been created, tell the player. outputChatBox("An unexpected error has occurred and the login GUI has not been created.") end -- enable the players cursor (so that they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening. guiSetInputEnabled(true) end ) -- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) Link to comment
drk Posted March 20, 2012 Share Posted March 20, 2012 Because your script is totally copied from Wiki. Your code verify if username is user and password apple. You need delete this and use getAccount to verify if account exists, if exists login, else output error. You must start learn: https://wiki.multitheftauto.com/ http://lua-users.org/wiki/TutorialDirectory Link to comment
Absence2 Posted March 20, 2012 Share Posted March 20, 2012 use /debugscript 3, syntax errors. gui.lua function createLoginWindow() -- define the X and Y positions of the window local X = 0.375 local Y = 0.375 -- define the width and height of the window local Width = 0.25 local Height = 0.25 -- create the window and save it's element value into the variable "wdwLogin" -- click on the function's name to read its documentation. wdwLogin = guiCreateWindow(x, y, Width, Height, "Please login with your username and password", true) -- define new X and Y positions for the first label. X = 0.0825 y = 0.2 -- define new Width and Height values for the first label. Width = 0.25 Height = 0.25 -- create the first label, note the final argument passed is 'wdwLogin' meaning the window -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window). guiCreateLabel (X, Y, Width, Height, "Username", true, wdwLogin) -- alter the Y value so the second label is slightly below the first. 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) -- set the maximum character length for the username and password fields to 50. 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) -- now add our onClientGUIClick event to the button we just created. addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) -- make the window invisible guiSetVisible(wdwLogin, false) -- create the function and define the 'button' and 'state' parameters. -- (these are passed automatically by onClientGUIClick) function clientSubmitLogin(button,state) -- if our login button was clicked with the left mouse button, and the state of the mousebutton is up: if button == "left" and state == "up" then -- get the text entered in the 'username' field. local username = guiGetText(edtUser) -- get the text entered in the 'password' field. local password = guiGetText(edtPass) -- if the username and password both exist: if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it. triggerServerEvent("submitLogin", getRootElement(), username, password) -- move the input focus back on the game (allowing players to move arround, open the chatbox, etc) guiSetInputEnabled(false) -- hide the window and all the components. guiSetVisible(wdwLogin, false) -- hide the mouse cursor. showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui. outputChatBox("please enter a username and password.") end end end end -- attach the event handler to the root element of the resource. -- this means it will only trigger when it's own resource is started. addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () -- create the log in window and it's components. createLoginWindow() -- output a brief welcome message to the player outputChatBox("Welcome to BlackDeath's Alpha Server, Please log in with the login information provided to you") -- if the GUI was successfully created, then show the GUI to the player. if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else -- if the GUI hasn't been properly been created, tell the player. outputChatBox("An unexpected error has occurred and the login GUI has not been created.") end -- enable the players cursor (so that they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening. guiSetInputEnabled(true) end ) -- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) And like Draken said, this script wont work. Link to comment
dragonslife Posted March 20, 2012 Author Share Posted March 20, 2012 Because your script is totally copied from Wiki. Your code verify if username is user and password apple.You need delete this and use getAccount to verify if account exists, if exists login, else output error. You must start learn: https://wiki.multitheftauto.com/ http://lua-users.org/wiki/TutorialDirectory How exactly should i use the getAccount ? can you explain? use /debugscript 3, syntax errors.gui.lua function createLoginWindow() -- define the X and Y positions of the window local X = 0.375 local Y = 0.375 -- define the width and height of the window local Width = 0.25 local Height = 0.25 -- create the window and save it's element value into the variable "wdwLogin" -- click on the function's name to read its documentation. wdwLogin = guiCreateWindow(x, y, Width, Height, "Please login with your username and password", true) -- define new X and Y positions for the first label. X = 0.0825 y = 0.2 -- define new Width and Height values for the first label. Width = 0.25 Height = 0.25 -- create the first label, note the final argument passed is 'wdwLogin' meaning the window -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window). guiCreateLabel (X, Y, Width, Height, "Username", true, wdwLogin) -- alter the Y value so the second label is slightly below the first. 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) -- set the maximum character length for the username and password fields to 50. 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) -- now add our onClientGUIClick event to the button we just created. addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) -- make the window invisible guiSetVisible(wdwLogin, false) -- create the function and define the 'button' and 'state' parameters. -- (these are passed automatically by onClientGUIClick) function clientSubmitLogin(button,state) -- if our login button was clicked with the left mouse button, and the state of the mousebutton is up: if button == "left" and state == "up" then -- get the text entered in the 'username' field. local username = guiGetText(edtUser) -- get the text entered in the 'password' field. local password = guiGetText(edtPass) -- if the username and password both exist: if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it. triggerServerEvent("submitLogin", getRootElement(), username, password) -- move the input focus back on the game (allowing players to move arround, open the chatbox, etc) guiSetInputEnabled(false) -- hide the window and all the components. guiSetVisible(wdwLogin, false) -- hide the mouse cursor. showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui. outputChatBox("please enter a username and password.") end end end end -- attach the event handler to the root element of the resource. -- this means it will only trigger when it's own resource is started. addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () -- create the log in window and it's components. createLoginWindow() -- output a brief welcome message to the player outputChatBox("Welcome to BlackDeath's Alpha Server, Please log in with the login information provided to you") -- if the GUI was successfully created, then show the GUI to the player. if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else -- if the GUI hasn't been properly been created, tell the player. outputChatBox("An unexpected error has occurred and the login GUI has not been created.") end -- enable the players cursor (so that they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening. guiSetInputEnabled(true) end ) -- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) And like Draken said, this script wont work. Did you change something in the code or? Link to comment
drk Posted March 20, 2012 Share Posted March 20, 2012 local acc = getAccount ( username, password ) if ( acc ) then -- Your code here else outputChatBox ( "Account not found!" ) end end Link to comment
dragonslife Posted March 20, 2012 Author Share Posted March 20, 2012 So, like this? function loginHandler(username,password) -- check that the username and password are correct. local acc = getAccount(username, password) -- the player has succesfully logged in, so spawn them. if (acc) then spawnPlayer (client, 1959.55, -1714.46, 10) faceCamera(client, true) setCameraTarget(client, client) outputChatBox("Enjoy your time!", client) end else -- if the username or password are not correct, output a message to the player. outputChatBox("invalid username and password. Please re-connect and try again.", client) end end Link to comment
drk Posted March 20, 2012 Share Posted March 20, 2012 Client-side: function createLoginWindow() -- define the X and Y positions of the window local X = 0.375 local Y = 0.375 -- define the width and height of the window local Width = 0.25 local Height = 0.25 -- create the window and save it's element value into the variable "wdwLogin" -- click on the function's name to read its documentation. wdwLogin = guiCreateWindow(x, y, Width, Height, "Please login with your username and password", true) -- define new X and Y positions for the first label. X = 0.0825 y = 0.2 -- define new Width and Height values for the first label. Width = 0.25 Height = 0.25 -- create the first label, note the final argument passed is 'wdwLogin' meaning the window -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window). guiCreateLabel (X, Y, Width, Height, "Username", true, wdwLogin) -- alter the Y value so the second label is slightly below the first. 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) -- set the maximum character length for the username and password fields to 50. 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) -- now add our onClientGUIClick event to the button we just created. addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) -- make the window invisible guiSetVisible(wdwLogin, false) -- create the function and define the 'button' and 'state' parameters. -- (these are passed automatically by onClientGUIClick) function clientSubmitLogin(button,state) -- if our login button was clicked with the left mouse button, and the state of the mousebutton is up: if button == "left" and state == "up" then -- get the text entered in the 'username' field. local username = guiGetText(edtUser) -- get the text entered in the 'password' field. local password = guiGetText(edtPass) -- if the username and password both exist: if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it. triggerServerEvent("submitLogin", getRootElement(), localPlayer, username, password) -- move the input focus back on the game (allowing players to move arround, open the chatbox, etc) guiSetInputEnabled(false) -- hide the window and all the components. guiSetVisible(wdwLogin, false) -- hide the mouse cursor. showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui. outputChatBox("please enter a username and password.") end end end end -- attach the event handler to the root element of the resource. -- this means it will only trigger when it's own resource is started. addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () -- create the log in window and it's components. createLoginWindow() -- output a brief welcome message to the player outputChatBox("Welcome to BlackDeath's Alpha Server, Please log in with the login information provided to you") -- if the GUI was successfully created, then show the GUI to the player. if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else -- if the GUI hasn't been properly been created, tell the player. outputChatBox("An unexpected error has occurred and the login GUI has not been created.") end -- enable the players cursor (so that they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening. guiSetInputEnabled(true) end ) -- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) Server-side: function loginHandler(client,username,password) -- check that the username and password are correct. local acc = getAccount(username, password) -- the player has succesfully logged in, so spawn them. if (acc) then spawnPlayer (client, 1959.55, -1714.46, 10) faceCamera(client, true) setCameraTarget(client, client) outputChatBox("Enjoy your time!", client) else -- if the username or password are not correct, output a message to the player. outputChatBox("invalid username and password. Please re-connect and try again.", client) end end addEvent('submitLogin',true) addEventHandler('submitLogin',root,loginHandler) Link to comment
Castillo Posted March 20, 2012 Share Posted March 20, 2012 function loginHandler(client,username,password) -- check that the username and password are correct. local acc = getAccount(username, password) -- the player has succesfully logged in, so spawn them. if (acc) then spawnPlayer (client, 1959.55, -1714.46, 10) fadeCamera(client, true) -- It's 'fadeCamera', not 'faceCamera'. setCameraTarget(client) outputChatBox("Enjoy your time!", client) else -- if the username or password are not correct, output a message to the player. outputChatBox("invalid username and password. Please re-connect and try again.", client) end end addEvent('submitLogin',true) addEventHandler('submitLogin',root,loginHandler) Link to comment
dragonslife Posted March 20, 2012 Author Share Posted March 20, 2012 Ok I fixed all things you guys told my and my script now looks like this: script.lua -- create our loginHandler function, with username and password parameters (passed from the client GUI). function loginHandler(client,username,password) -- check that the username and password are correct. local acc = getAccount(username, password) -- the player has succesfully logged in, so spawn them. if (acc) then spawnPlayer (client, 1959.55, -1714.46, 10) fadeCamera(client, true) setCameraTarget(client) outputChatBox("Enjoy your time!", client) else -- if the username or password are not correct, output a message to the player. outputChatBox("invalid username and password. Please re-connect and try again.", client) end end -- define our costom event, and allow it to be triggered from the client ('true'). addEvent("submitLogin",true) -- add an event handler so that when submitLogin is triggered, the function loginHandler is called. addEventHandler("submitLogin",root, loginHandler) gui.lua function createLoginWindow() -- define the X and Y positions of the window local X = 0.375 local Y = 0.375 -- define the width and height of the window local Width = 0.25 local Height = 0.25 -- create the window and save it's element value into the variable "wdwLogin" -- click on the function's name to read its documentation. wdwLogin = guiCreateWindow(x, y, Width, Height, "Please login with your username and password", true) -- define new X and Y positions for the first label. X = 0.0825 y = 0.2 -- define new Width and Height values for the first label. Width = 0.25 Height = 0.25 -- create the first label, note the final argument passed is 'wdwLogin' meaning the window -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window). guiCreateLabel (X, Y, Width, Height, "Username", true, wdwLogin) -- alter the Y value so the second label is slightly below the first. 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) -- set the maximum character length for the username and password fields to 50. 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) -- now add our onClientGUIClick event to the button we just created. addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) -- make the window invisible guiSetVisible(wdwLogin, false) -- create the function and define the 'button' and 'state' parameters. -- (these are passed automatically by onClientGUIClick) function clientSubmitLogin(button,state) -- if our login button was clicked with the left mouse button, and the state of the mousebutton is up: if button == "left" and state == "up" then -- get the text entered in the 'username' field. local username = guiGetText(edtUser) -- get the text entered in the 'password' field. local password = guiGetText(edtPass) -- if the username and password both exist: if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it. triggerServerEvent("submitLogin", getRootElement(), username, password) -- move the input focus back on the game (allowing players to move arround, open the chatbox, etc) guiSetInputEnabled(false) -- hide the window and all the components. guiSetVisible(wdwLogin, false) -- hide the mouse cursor. showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui. outputChatBox("please enter a username and password.") end end end -- attach the event handler to the root element of the resource. -- this means it will only trigger when it's own resource is started. addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () -- create the log in window and it's components. createLoginWindow() -- output a brief welcome message to the player outputChatBox("Welcome to BlackDeath's Alpha Server, Please log in with the login information provided to you") -- if the GUI was successfully created, then show the GUI to the player. if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else -- if the GUI hasn't been properly been created, tell the player. outputChatBox("An unexpected error has occurred and the login GUI has not been created.") end -- enable the players cursor (so that they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening. guiSetInputEnabled(true) end ) -- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) But the black screen on login still remains, anyone knows why? Link to comment
drk Posted March 20, 2012 Share Posted March 20, 2012 Because you fade camera but don't put normal again. Link to comment
dragonslife Posted March 20, 2012 Author Share Posted March 20, 2012 Because you fade camera but don't put normal again. So I need to put back fadecamera on false again afterwards? That would be weird cause when I use an script like this: local spawnX, spawnY, spawnZ = 1959.55, -1714.46, 10 function joinHandler() spawnPlayer(source, spawnX, spawnY, spawnZ) fadeCamera(source, true) setCameraTarget(source, source) outputChatBox("Welcome to My Server", source) end addEventHandler("onPlayerJoin", getRootElement(), joinHandler) the screen isn't black, while fadecamera is also on true in that script and does not go false afterwards. Link to comment
dragonslife Posted March 20, 2012 Author Share Posted March 20, 2012 Maybe I should state that this black screen is even before the login window. As soon as I connect to the server my screen goes and stays black. Talking in the chat is possible. The loginscreen as in the gui.lua doesn't show. Link to comment
drk Posted March 20, 2012 Share Posted March 20, 2012 https://wiki.multitheftauto.com/wiki/fadeCamera Example: setTimer ( fadeCamera, 5000, 1, source, true, 0.5 ) Link to comment
drk Posted March 20, 2012 Share Posted March 20, 2012 You forgot a end to end function. function createLoginWindow() -- define the X and Y positions of the window local X = 0.375 local Y = 0.375 -- define the width and height of the window local Width = 0.25 local Height = 0.25 -- create the window and save it's element value into the variable "wdwLogin" -- click on the function's name to read its documentation. wdwLogin = guiCreateWindow(x, y, Width, Height, "Please login with your username and password", true) -- define new X and Y positions for the first label. X = 0.0825 y = 0.2 -- define new Width and Height values for the first label. Width = 0.25 Height = 0.25 -- create the first label, note the final argument passed is 'wdwLogin' meaning the window -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window). guiCreateLabel (X, Y, Width, Height, "Username", true, wdwLogin) -- alter the Y value so the second label is slightly below the first. 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) -- set the maximum character length for the username and password fields to 50. 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) -- now add our onClientGUIClick event to the button we just created. addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) -- make the window invisible guiSetVisible(wdwLogin, false) end -- create the function and define the 'button' and 'state' parameters. -- (these are passed automatically by onClientGUIClick) function clientSubmitLogin(button,state) -- if our login button was clicked with the left mouse button, and the state of the mousebutton is up: if button == "left" and state == "up" then -- get the text entered in the 'username' field. local username = guiGetText(edtUser) -- get the text entered in the 'password' field. local password = guiGetText(edtPass) -- if the username and password both exist: if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it. triggerServerEvent("submitLogin", getRootElement(), username, password) -- move the input focus back on the game (allowing players to move arround, open the chatbox, etc) guiSetInputEnabled(false) -- hide the window and all the components. guiSetVisible(wdwLogin, false) -- hide the mouse cursor. showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui. outputChatBox("please enter a username and password.") end end end -- attach the event handler to the root element of the resource. -- this means it will only trigger when it's own resource is started. addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function () -- create the log in window and it's components. createLoginWindow() -- output a brief welcome message to the player outputChatBox("Welcome to BlackDeath's Alpha Server, Please log in with the login information provided to you") -- if the GUI was successfully created, then show the GUI to the player. if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else -- if the GUI hasn't been properly been created, tell the player. outputChatBox("An unexpected error has occurred and the login GUI has not been created.") end -- enable the players cursor (so that they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening. guiSetInputEnabled(true) end ) -- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) Link to comment
dragonslife Posted March 20, 2012 Author Share Posted March 20, 2012 local acc = getAccount(username, password) -- the player has succesfully logged in, so spawn them. if (acc) then spawnPlayer (client, 1959.55, -1714.46, 10) setTimer ( fadeCamera, 5000, 1, source, true, 0.5 ) setCameraTarget(client) outputChatBox("Enjoy your time!", client) else -- if the username or password are not correct, output a message to the player. outputChatBox("invalid username and password. Please re-connect and try again.", client) end So like this? Link to comment
Castillo Posted March 20, 2012 Share Posted March 20, 2012 1: Did your script ever worked? because I got many errors in the client side. 2: You we're using 'client' argument, but you never triggered it. 3: You forgot about logIn function to login the player. -- client side: function createLoginWindow() -- define the X and Y positions of the window local X = 0.375 local Y = 0.375 -- define the width and height of the window local Width = 0.25 local Height = 0.25 -- create the window and save it's element value into the variable "wdwLogin" -- click on the function's name to read its documentation. wdwLogin = guiCreateWindow(X, Y, Width, Height, "Please login with your username and password", true) -- define new X and Y positions for the first label. X = 0.0825 y = 0.2 -- define new Width and Height values for the first label. Width = 0.25 Height = 0.25 -- create the first label, note the final argument passed is 'wdwLogin' meaning the window -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window). guiCreateLabel (X, Y, Width, Height, "Username", true, wdwLogin) -- alter the Y value so the second label is slightly below the first. 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) -- set the maximum character length for the username and password fields to 50. 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) -- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) -- make the window invisible guiSetVisible(wdwLogin, false) -- create the function and define the 'button' and 'state' parameters. -- (these are passed automatically by onClientGUIClick) end function clientSubmitLogin(button,state) -- if our login button was clicked with the left mouse button, and the state of the mousebutton is up: if button == "left" and state == "up" then -- get the text entered in the 'username' field. local username = guiGetText(edtUser) -- get the text entered in the 'password' field. local password = guiGetText(edtPass) -- if the username and password both exist: if ( username and password ) then -- trigger the server event 'submitLogin' and pass the username and password to it. triggerServerEvent("submitLogin", localPlayer, username, password) -- move the input focus back on the game (allowing players to move arround, open the chatbox, etc) guiSetInputEnabled(false) -- hide the window and all the components. guiSetVisible(wdwLogin, false) -- hide the mouse cursor. showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui. outputChatBox("please enter a username and password.") end end end -- attach the event handler to the root element of the resource. -- this means it will only trigger when it's own resource is started. addEventHandler("onClientResourceStart", resourceRoot, function () -- create the log in window and it's components. createLoginWindow() -- output a brief welcome message to the player outputChatBox("Welcome to BlackDeath's Alpha Server, Please log in with the login information provided to you") -- if the GUI was successfully created, then show the GUI to the player. if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else -- if the GUI hasn't been properly been created, tell the player. outputChatBox("An unexpected error has occurred and the login GUI has not been created.") end -- enable the players cursor (so that they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening. guiSetInputEnabled(true) end ) -- server side: -- create our loginHandler function, with username and password parameters (passed from the client GUI). function loginHandler(username,password) -- check that the username and password are correct. local acc = getAccount(username, password) -- the player has succesfully logged in, so spawn them. if (acc) then logIn ( source, acc, password ) spawnPlayer (source, 1959.55, -1714.46, 10) fadeCamera(source, true) setCameraTarget(source) outputChatBox("Enjoy your time!", source) else -- if the username or password are not correct, output a message to the player. outputChatBox("invalid username and password. Please re-connect and try again.", source) end end -- define our costom event, and allow it to be triggered from the client ('true'). addEvent("submitLogin",true) -- add an event handler so that when submitLogin is triggered, the function loginHandler is called. addEventHandler("submitLogin",root, loginHandler) Link to comment
dragonslife Posted March 20, 2012 Author Share Posted March 20, 2012 I editted my code again, it's like this now script.lua -- create our loginHandler function, with username and password parameters (passed from the client GUI). function loginHandler(username,password) -- check that the username and password are correct. local acc = getAccount(username, password) -- the player has succesfully logged in, so spawn them. if (acc) then logIn (source, acc, password) spawnPlayer (source, 1959.55, -1714.46, 10) fadeCamera(source, true) setCameraTarget(source) outputChatBox("Enjoy your time!", source) else -- if the username or password are not correct, output a message to the player. outputChatBox("invalid username and password. Please re-connect and try again.", source) end end -- define our costom event, and allow it to be triggered from the client ('true'). addEvent("submitLogin",true) -- add an event handler so that when submitLogin is triggered, the function loginHandler is called. addEventHandler("submitLogin",root, loginHandler) gui.lua function createLoginWindow() -- define the X and Y positions of the window local X = 0.375 local Y = 0.375 -- define the width and height of the window local Width = 0.25 local Height = 0.25 -- create the window and save it's element value into the variable "wdwLogin" -- click on the function's name to read its documentation. wdwLogin = guiCreateWindow(x, y, Width, Height, "Please login with your username and password", true) -- define new X and Y positions for the first label. X = 0.0825 y = 0.2 -- define new Width and Height values for the first label. Width = 0.25 Height = 0.25 -- create the first label, note the final argument passed is 'wdwLogin' meaning the window -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window). guiCreateLabel (X, Y, Width, Height, "Username", true, wdwLogin) -- alter the Y value so the second label is slightly below the first. 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) -- set the maximum character length for the username and password fields to 50. 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) -- now add our onClientGUIClick event to the button we just created. addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) -- make the window invisible guiSetVisible(wdwLogin, false) end -- create the function and define the 'button' and 'state' parameters. -- (these are passed automatically by onClientGUIClick) function clientSubmitLogin(button,state) -- if our login button was clicked with the left mouse button, and the state of the mousebutton is up: if button == "left" and state == "up" then -- get the text entered in the 'username' field. local username = guiGetText(edtUser) -- get the text entered in the 'password' field. local password = guiGetText(edtPass) -- if the username and password both exist: if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it. triggerServerEvent("submitLogin", getRootElement(), username, password) -- move the input focus back on the game (allowing players to move arround, open the chatbox, etc) guiSetInputEnabled(false) -- hide the window and all the components. guiSetVisible(wdwLogin, false) -- hide the mouse cursor. showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui. outputChatBox("please enter a username and password.") end end end -- attach the event handler to the root element of the resource. -- this means it will only trigger when it's own resource is started. addEventHandler("onClientResourceStart", resourceRoot, function () -- create the log in window and it's components. createLoginWindow() -- output a brief welcome message to the player outputChatBox("Welcome to BlackDeath's Alpha Server, Please log in with the login information provided to you") -- if the GUI was successfully created, then show the GUI to the player. if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else -- if the GUI hasn't been properly been created, tell the player. outputChatBox("An unexpected error has occurred and the login GUI has not been created.") end -- enable the players cursor (so that they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening. guiSetInputEnabled(true) end ) -- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) Problem of a black screen on connect still remains Link to comment
Castillo Posted March 20, 2012 Share Posted March 20, 2012 Use the code I posted, I've fixed a few bugs in the client side. Link to comment
Absence2 Posted March 20, 2012 Share Posted March 20, 2012 I editted my code again, it's like this nowscript.lua -- create our loginHandler function, with username and password parameters (passed from the client GUI). function loginHandler(username,password) -- check that the username and password are correct. local acc = getAccount(username, password) -- the player has succesfully logged in, so spawn them. if (acc) then logIn (source, acc, password) spawnPlayer (source, 1959.55, -1714.46, 10) fadeCamera(source, true) setCameraTarget(source) outputChatBox("Enjoy your time!", source) else -- if the username or password are not correct, output a message to the player. outputChatBox("invalid username and password. Please re-connect and try again.", source) end end -- define our costom event, and allow it to be triggered from the client ('true'). addEvent("submitLogin",true) -- add an event handler so that when submitLogin is triggered, the function loginHandler is called. addEventHandler("submitLogin",root, loginHandler) gui.lua function createLoginWindow() -- define the X and Y positions of the window local X = 0.375 local Y = 0.375 -- define the width and height of the window local Width = 0.25 local Height = 0.25 -- create the window and save it's element value into the variable "wdwLogin" -- click on the function's name to read its documentation. wdwLogin = guiCreateWindow(x, y, Width, Height, "Please login with your username and password", true) -- define new X and Y positions for the first label. X = 0.0825 y = 0.2 -- define new Width and Height values for the first label. Width = 0.25 Height = 0.25 -- create the first label, note the final argument passed is 'wdwLogin' meaning the window -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window). guiCreateLabel (X, Y, Width, Height, "Username", true, wdwLogin) -- alter the Y value so the second label is slightly below the first. 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) -- set the maximum character length for the username and password fields to 50. 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) -- now add our onClientGUIClick event to the button we just created. addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) -- make the window invisible guiSetVisible(wdwLogin, false) end -- create the function and define the 'button' and 'state' parameters. -- (these are passed automatically by onClientGUIClick) function clientSubmitLogin(button,state) -- if our login button was clicked with the left mouse button, and the state of the mousebutton is up: if button == "left" and state == "up" then -- get the text entered in the 'username' field. local username = guiGetText(edtUser) -- get the text entered in the 'password' field. local password = guiGetText(edtPass) -- if the username and password both exist: if username and password then -- trigger the server event 'submitLogin' and pass the username and password to it. triggerServerEvent("submitLogin", getRootElement(), username, password) -- move the input focus back on the game (allowing players to move arround, open the chatbox, etc) guiSetInputEnabled(false) -- hide the window and all the components. guiSetVisible(wdwLogin, false) -- hide the mouse cursor. showCursor(false) else -- otherwise, output a message to the player, do not trigger the server -- and do not hide the gui. outputChatBox("please enter a username and password.") end end end -- attach the event handler to the root element of the resource. -- this means it will only trigger when it's own resource is started. addEventHandler("onClientResourceStart", resourceRoot, function () -- create the log in window and it's components. createLoginWindow() -- output a brief welcome message to the player outputChatBox("Welcome to BlackDeath's Alpha Server, Please log in with the login information provided to you") -- if the GUI was successfully created, then show the GUI to the player. if (wdwLogin ~= nil) then guiSetVisible(wdwLogin, true) else -- if the GUI hasn't been properly been created, tell the player. outputChatBox("An unexpected error has occurred and the login GUI has not been created.") end -- enable the players cursor (so that they can select and click on the components) showCursor(true) -- set the input focus onto the GUI, allowing players (for example) to press 'T' without the chatbox opening. guiSetInputEnabled(true) end ) -- attach the event onClientGUIClick to btnLogin and set it to trigger the 'clientSubmitLogin' function. addEventHandler("onClientGUIClick", btnLogin, clientSumbitLogin, false) Problem of a black screen on connect still remains I posted clientside on page #1 btnLogin = guiCreateButton(X, Y, Width, Height, "Log In" true, wdwLogin) line 39, missed comma, 'end' on line 76 Link to comment
dragonslife Posted March 20, 2012 Author Share Posted March 20, 2012 Yaaaaaaaaaaay! It's working now! thanks alot people!! =D Link to comment
iFoReX Posted March 20, 2012 Share Posted March 20, 2012 solid what are the functions or events for a GUI register ? Link to comment
Castillo Posted March 20, 2012 Share Posted March 20, 2012 You mean the function to add an account? if so: addAccount Link to comment
dragonslife Posted March 20, 2012 Author Share Posted March 20, 2012 Ok been messing arround a bit... my login screen looks like this now Now i tried movind the username and password text up.. but no matter where to i change the x and y amounts, it wont move. it does respond to the y amount between username and password tough. My code is like this: X = 0.0825 y = 0.2 -- define new Width and Height values for the first label. Width = 0.50 Height = 0.50 -- create the first label, note the final argument passed is 'wdwLogin' meaning the window -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window). guiCreateLabel (X, Y, Width, Height, "Username", true, wdwLogin) -- alter the Y value so the second label is slightly below the first. Y = 0.7 guiCreateLabel (X, Y, Width, Height, "password", true, wdwLogin) Link to comment
Castillo Posted March 20, 2012 Share Posted March 20, 2012 X = 0.0825 Y = 0.2 -- Lua is case sensitive. -- define new Width and Height values for the first label. Width = 0.50 Height = 0.50 -- create the first label, note the final argument passed is 'wdwLogin' meaning the window -- we created above is the parent of this label (so all the position and size values are now relative to the position of that window). guiCreateLabel (X, Y, Width, Height, "Username", true, wdwLogin) -- alter the Y value so the second label is slightly below the first. Y = 0.7 guiCreateLabel (X, Y, Width, Height, "password", true, wdwLogin) 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