iFoReX Posted March 20, 2012 Share Posted March 20, 2012 dragonslife a tip, use GuieDitor I use this and view my Guis = is exelent for news in this of GUI Link to comment
dragonslife Posted March 20, 2012 Author Share Posted March 20, 2012 Ok so I've been messing arround a bit more.. I added a register button to my login screen. When you press the register button it's supposed to hide the login window and create a new window for the register window. Except when I press my register button nothing happens, the login button does work tough. I've been looking over my code quite a few times and couldn't find out why it wouldn't respond when the register button is clicked. Here's my code so far: function createLoginWindow() -- define the X and Y positions of the window local X = 0.335 local Y = 0.375 -- define the width and height of the window local Width = 0.35 local Height = 0.25 -- create the window and save it's element value into the variable "wdwLogin" 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.230 -- 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.53 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) X = 0.700 Y = 0.7 Width = 0.25 Height = 0.2 btnRegister = guiCreateButton(X, Y, Width, Height, "Register", true, wdwLogin) -- now add our onClientGUIClick event to the buttons we just created. addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) addEventHandler("onClientGUIClick", btnRegister, createRegisterWindow, false) -- make the login 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", 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 --------------------------------------------------------------------------------------------------------- -- create the function and define the 'button' and 'state' parameters. -- (these are passed automatically by onClientGUIClick) function createRegisterWindow1(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 function createRegisterWindow() -- define the X and Y positions of the window local X = 0.335 local Y = 0.375 -- define the width and height of the window local Width = 0.35 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. wdwRegister = guiCreateWindow(X, Y, Width, Height, "Please register with an username and password", true) -- define new X and Y positions for the first label. X = 0.0825 Y = 0.230 -- 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, wdwRegister) -- alter the Y value so the second label is slightly below the first. Y = 0.53 guiCreateLabel (X, Y, Width, Height, "password", true, wdwRegister) X = 0.415 Y = 0.2 Width = 0.5 Height = 0.15 edtUser = guiCreateEdit (X, Y, Width, Height, "", true, wdwRegister) Y = 0.5 edtPass = guiCreateEdit (X, Y, Width, Height, "", true, wdwRegister) -- 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 btnCancel = guiCreateButton(X, Y, Width, Height, "Cancel", true, wdwRegister) X = 0.700 Y = 0.7 Width = 0.25 Height = 0.2 btnRegister = guiCreateButton(X, Y, Width, Height, "Register", true, wdwRegister) -- now add our onClientGUIClick event to the button we just created. addEventHandler("onClientGUIClick", btnLogin, registerWindowCancel, false) addEventHandler("onClientGUIClick", btnRegister, clientRegister, false) -- make the window invisible guiSetVisible(wdwRegister, false) -- make the window visible guiSetVisible(wdwLogin, true) 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) addEventHandler("onClientGUIClick", btnRegister, createRegisterWindow, false) Link to comment
Absence2 Posted March 20, 2012 Share Posted March 20, 2012 guiGetVisible guiSetVisible Link to comment
Castillo Posted March 20, 2012 Share Posted March 20, 2012 -- 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) function registerPlayer ( username, password ) if ( password ~= "" and password ~= nil and username ~= "" and username ~= nil ) then if ( not getAccount ( username ) ) then local accountAdded = addAccount ( username, password ) if ( accountAdded ) then outputChatBox ( "Thank you " .. getPlayerName ( source ) .. ", Ya estas Registrado ahora loggeate", source ) else outputChatBox ( "Error creating account, contact the server admin.", source ) end else outputChatBox ( "This account already exists..", source ) end else outputChatBox ( "Porfavor Pon tus datos Correctos.", source ) end end function createLoginWindow() -- define the X and Y positions of the window local X = 0.335 local Y = 0.375 -- define the width and height of the window local Width = 0.35 local Height = 0.25 -- create the window and save it's element value into the variable "wdwLogin" 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.230 -- 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.53 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) X = 0.700 Y = 0.7 Width = 0.25 Height = 0.2 btnRegister = guiCreateButton(X, Y, Width, Height, "Register", true, wdwLogin) -- now add our onClientGUIClick event to the buttons we just created. addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) addEventHandler("onClientGUIClick", btnRegister, createRegisterWindow1, false) -- make the login 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", 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 --------------------------------------------------------------------------------------------------------- -- create the function and define the 'button' and 'state' parameters. -- (these are passed automatically by onClientGUIClick) function createRegisterWindow1(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 createRegisterWindow() end end function createRegisterWindow() -- define the X and Y positions of the window local X = 0.335 local Y = 0.375 -- define the width and height of the window local Width = 0.35 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. wdwRegister = guiCreateWindow(X, Y, Width, Height, "Please register with an username and password", true) -- define new X and Y positions for the first label. X = 0.0825 Y = 0.230 -- 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, wdwRegister) -- alter the Y value so the second label is slightly below the first. Y = 0.53 guiCreateLabel (X, Y, Width, Height, "password", true, wdwRegister) X = 0.415 Y = 0.2 Width = 0.5 Height = 0.15 edtUser = guiCreateEdit (X, Y, Width, Height, "", true, wdwRegister) Y = 0.5 edtPass = guiCreateEdit (X, Y, Width, Height, "", true, wdwRegister) -- 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 btnCancel = guiCreateButton(X, Y, Width, Height, "Cancel", true, wdwRegister) X = 0.700 Y = 0.7 Width = 0.25 Height = 0.2 btnRegister = guiCreateButton(X, Y, Width, Height, "Register", true, wdwRegister) -- now add our onClientGUIClick event to the button we just created. addEventHandler("onClientGUIClick", btnCancel, registerWindowCancel, false) addEventHandler("onClientGUIClick", btnRegister, clientRegister, false) -- make the window visible guiSetVisible(wdwRegister, true) -- make the window invisible guiSetVisible(wdwLogin, false) 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 ) Link to comment
dragonslife Posted March 20, 2012 Author Share Posted March 20, 2012 somehow with this code i keep getting the message that I should fill in a username and password, which I did. While the code clearly says, if something is filled in, check if it excists, if not create account... right? function registerPlayer ( username, password ) if ( password ~= "" and password ~= nil and username ~= "" and username ~= nil ) then if ( not getAccount ( username ) ) then local accountAdded = addAccount ( username, password ) if ( accountAdded ) then outputChatBox ( "Thank you " .. getPlayerName ( source ) .. ", You can now login with your account.", source ) else outputChatBox ( "Error creating account, contact the server admin.", source ) end else outputChatBox ( "This account already exists..", source ) end else outputChatBox ( "Please fill in a username and password.", source ) end end Link to comment
dragonslife Posted March 21, 2012 Author Share Posted March 21, 2012 Ok so, I now have the following code: function createRegisterWindow() -- define the X and Y positions of the window local X = 0.335 local Y = 0.375 -- define the width and height of the window local Width = 0.35 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. wdwRegister = guiCreateWindow(X, Y, Width, Height, "Please register with an username and password", true) -- define new X and Y positions for the first label. X = 0.0825 Y = 0.230 -- 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, wdwRegister) -- alter the Y value so the second label is slightly below the first. Y = 0.53 guiCreateLabel (X, Y, Width, Height, "password", true, wdwRegister) X = 0.415 Y = 0.2 Width = 0.5 Height = 0.15 edtUser = guiCreateEdit (X, Y, Width, Height, "", true, wdwRegister) Y = 0.5 edtPass = guiCreateEdit (X, Y, Width, Height, "", true, wdwRegister) -- 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 btnCancel = guiCreateButton(X, Y, Width, Height, "Cancel", true, wdwRegister) X = 0.700 Y = 0.7 Width = 0.25 Height = 0.2 btnRegister = guiCreateButton(X, Y, Width, Height, "Register", true, wdwRegister) -- now add our onClientGUIClick event to the button we just created. addEventHandler("onClientGUIClick", btnCancel, registerWindowCancel, false) addEventHandler("onClientGUIClick", btnRegister, registerPlayer1, false) -- make the window visible guiSetVisible(wdwRegister, true) -- 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 registerPlayer1(button,state) -- if our login button was clicked with the left mouse button, and the state of the mousebutton is up: -- 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 button == "left" and state == "up" then registerPlayer( username, password ) end end function registerPlayer(username, password) outputChatBox( "Username:"..username.." Password: "..password, source ) if ( (password ~= "" and password ~= nil) and (username ~= "" and username ~= nil) ) then if ( not getAccount ( username ) ) then local accountAdded = addAccount ( username, password ) if ( accountAdded ) then outputChatBox ( "Thank you " .. getPlayerName ( source ) .. ", Ya estas Registrado ahora loggeate", source ) else outputChatBox ( "Error creating account, contact the server admin.", source ) end else outputChatBox ( "This account already exists..", source ) end else outputChatBox ( "Please enter a username and password.", source ) end end when the register button is clicked the information is recieved at the registerplayer function, except it proves that it stops doing anything at "if ( not getAccount ( username ) ) then......." anyone knows why? Link to comment
TwiX! Posted March 21, 2012 Share Posted March 21, 2012 (edited) function registerPlayer1(button,state) -- if our login button was clicked with the left mouse button, and the state of the mousebutton is up: -- 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 button == "left" and state == "up" then registerPlayer( username, password ) end end u check state not check btn Because u just made a button, nothing more function registerPlayer1(button,state) if(button == "left" and state == "up") then if (source == btnRegister) then local username = guiGetText(edtUser) local password = guiGetText(edtPass) registerPlayer( username, password ) end end end or i'm not understand you if ( not getAccount ( username ) ) then add account SERVER ONLY FUNCTIONS u can Client: function registerPlayer1(button,state)--make function if(button == "left" and state == "up") then -- check button if (source == btnRegister) then -- if player pressed on this button local username = guiGetText(edtUser)--Get text from edtUser local password = guiGetText(edtPass) --get text from edtPass triggerServerEvent("regmePls",getLocalPlayer(),username,password) -- call server-side function (first name trigger,getLocalPlayer() - its you (we not want register all), username(with out text),password(with our text) end -- close btnRegister end -- Close check end -- Close function Server: addEvent("regmePls",true)--Made event for client function canRegister(username,password) -- Made function for server (our username/password[From client]) if not (username == "") then -- if player not write username if not (password == "") then -- if player not write password local account = getAccount (username,password) -- get account if (account == false) then -- if player not have account , we add him local accountAdded = addAccount(tostring(username),tostring(password)) -- added with username and pass from client if (accountAdded) then -- if account added write message outputChatBox ( "Thank you " .. getPlayerName ( source ) .. ", Ya estas Registrado ahora loggeate", source ) else -- if not -//- outputChatBox ( "Error creating account, contact the server admin.", source ) end else outputChatBox ( "This account already exists..", source end else outputChatBox ( "Please enter a password", source ) end else outputChatBox ( "Please enter a username", source ) end end addEventHandler("regmePls",getRootElement(),canRegister) -- add handler for 'source' and for function with our event name Edited March 21, 2012 by Guest Link to comment
dragonslife Posted March 21, 2012 Author Share Posted March 21, 2012 It should work with the code i got earlier in this topic... but something in that code is making it stop at the "if". Link to comment
TwiX! Posted March 21, 2012 Share Posted March 21, 2012 It should work with the code i got earlier in this topic... but something in that code is making it stop at the "if". dude your function function registerPlayer(username, password) is server-side, you put it in client-side, check up my code.. Link to comment
Absence2 Posted March 21, 2012 Share Posted March 21, 2012 client: -- 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) function createLoginWindow() -- define the X and Y positions of the window local X = 0.335 local Y = 0.375 -- define the width and height of the window local Width = 0.35 local Height = 0.25 -- create the window and save it's element value into the variable "wdwLogin" 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.230 -- 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.53 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) X = 0.700 Y = 0.7 Width = 0.25 Height = 0.2 btnRegister = guiCreateButton(X, Y, Width, Height, "Register", true, wdwLogin) -- now add our onClientGUIClick event to the buttons we just created. addEventHandler("onClientGUIClick", btnLogin, clientSubmitLogin, false) addEventHandler("onClientGUIClick", btnRegister, createRegisterWindow1, false) -- make the login 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", 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 --------------------------------------------------------------------------------------------------------- -- create the function and define the 'button' and 'state' parameters. -- (these are passed automatically by onClientGUIClick) function createRegisterWindow1(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 createRegisterWindow() end end function createRegisterWindow() -- define the X and Y positions of the window local X = 0.335 local Y = 0.375 -- define the width and height of the window local Width = 0.35 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. wdwRegister = guiCreateWindow(X, Y, Width, Height, "Please register with an username and password", true) -- define new X and Y positions for the first label. X = 0.0825 Y = 0.230 -- 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, wdwRegister) -- alter the Y value so the second label is slightly below the first. Y = 0.53 guiCreateLabel (X, Y, Width, Height, "password", true, wdwRegister) X = 0.415 Y = 0.2 Width = 0.5 Height = 0.15 edtUser = guiCreateEdit (X, Y, Width, Height, "", true, wdwRegister) Y = 0.5 edtPass = guiCreateEdit (X, Y, Width, Height, "", true, wdwRegister) -- 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 btnCancel = guiCreateButton(X, Y, Width, Height, "Cancel", true, wdwRegister) X = 0.700 Y = 0.7 Width = 0.25 Height = 0.2 btnRegister = guiCreateButton(X, Y, Width, Height, "Register", true, wdwRegister) -- now add our onClientGUIClick event to the button we just created. addEventHandler("onClientGUIClick", btnCancel, registerWindowCancel, false) addEventHandler("onClientGUIClick", btnRegister, registerPlayer1, false) -- make the window visible guiSetVisible(wdwRegister, true) -- 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 registerWindowCancel(button,state) if(button == "left" and state == "up") then if (source == btnCancel) then guiSetVisible(wdwRegister, false) guiSetVisible(wdwLogin, true) end end end function registerPlayer1(button,state) if(button == "left" and state == "up") then if (source == btnRegister) then local username = guiGetText(edtUser) local password = guiGetText(edtPass) triggerServerEvent("regmePls",getLocalPlayer(),username,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: -- 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) addEvent("regmePls",true) function canRegister(username,password) if not (username == "") then if not (password == "") then local account = getAccount (username,password) if ( not getAccount ( username ) ) then if (account == false) then local accountAdded = addAccount(tostring(username),tostring(password)) if (accountAdded) then outputChatBox ( "Thank you " .. getPlayerName ( source ) .. ", Ya estas Registrado ahora loggeate", source ) else outputChatBox ( "Error creating account, contact the server admin.", source ) end end else outputChatBox ( "This account already exists..", source ) end else outputChatBox ( "Please enter a password", source ) end else outputChatBox ( "Please enter a username", source ) end end addEventHandler("regmePls",getRootElement(),canRegister) replace all yours with this Link to comment
TwiX! Posted March 21, 2012 Share Posted March 21, 2012 update my code and added descriptions what problem now? Link to comment
dragonslife Posted March 21, 2012 Author Share Posted March 21, 2012 (edited) Ok so I now got this. script.lua function registerPlayer(username,password) outputChatBox( "Username:"..username.." Password: "..password, source ) if not (username == "") then -- if player not write username if not (password == "") then -- if player not write password local account = getAccount (username,password) -- get account if ( not getAccount ( username ) ) then local accountAdded = addAccount(username, password) -- added with username and pass from client if (accountAdded) then -- if account added write message outputChatBox ( "Thank you " .. getPlayerName ( source ) .. ", Ya estas Registrado ahora loggeate", source ) else -- if not -//- outputChatBox ( "Error creating account, contact the server admin.", source ) end else outputChatBox ( "This account already exists..", source ) end else outputChatBox ( "Please enter a password", source ) end else outputChatBox ( "Please enter a username", source ) end end addEvent("registerPlayer",true) addEventHandler("registerPlayer",getRootElement(),registerPlayer) gui.lua -- create the function and define the 'button' and 'state' parameters. -- (these are passed automatically by onClientGUIClick) function registerPlayer1(button,state) -- if our login button was clicked with the left mouse button, and the state of the mousebutton is up: -- 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 button == "left" and state == "up" then triggerServerEvent("registerPlayer",getLocalPlayer(),username,password) end end So now it is recognizing when an account already excists, but if it's not... it fails to create the account and gives me the "contact an admin" message. Edited March 21, 2012 by Guest Link to comment
Absence2 Posted March 21, 2012 Share Posted March 21, 2012 I don't get it.. it works, but it doesn't? Anyways, I tested the script I posted, it works, all of it, use it instead. Replace everything you have with it, server & client. Link to comment
dragonslife Posted March 21, 2012 Author Share Posted March 21, 2012 When I try to create an account, I frist try to leave the field empty, then it reports that I left the fields empty, which is good. Next I'm filling in an excisting accountname, then it tells me the account name already excists, which is good also. But when I enter a non-excisting account name and press account, it's saying it couldn't create an account and that I should contact an admin.. But I don't understand why it's not able to create the account? Link to comment
dragonslife Posted March 21, 2012 Author Share Posted March 21, 2012 Found the problem, the server reported this: [2012-03-21 14:16:09] WARNING: myserver\script.lua:31: Access denied @ 'addAccount' But anyone has an idea why it got acces denied? and where/how I can change that? Link to comment
Absence2 Posted March 21, 2012 Share Posted March 21, 2012 (edited) you have to add access in acl.xml Server have to be offline Edited March 21, 2012 by Guest Link to comment
dragonslife Posted March 21, 2012 Author Share Posted March 21, 2012 Got it fixed now, changed: under default user to: Link to comment
dragonslife Posted March 21, 2012 Author Share Posted March 21, 2012 What would be the command to activate a function on the client side from the server side? triggerClientEvent(......) ?? Link to comment
Absence2 Posted March 21, 2012 Share Posted March 21, 2012 https://wiki.multitheftauto.com/wiki/TriggerClientEvent Link to comment
X-SHADOW Posted March 21, 2012 Share Posted March 21, 2012 yes its triggerClientEvent Link to comment
dragonslife Posted March 21, 2012 Author Share Posted March 21, 2012 Ok so, I got this code now server side: function registerPlayer(username,password, password2) outputChatBox( "Username:"..username.." Password: "..password.."password confirm"..password2, source ) -- if player not write username. if not (username == "") then -- if player not write password. if not (password == "") then -- verify that both passwords are the same. if (password == password2) then local account = getAccount (username,password) -- get account if ( not getAccount ( username ) ) then local accountAdded = addAccount(username, password) -- added with username and pass from client if (accountAdded) then -- if account added write message outputChatBox ( "Thank you " ..username.. ", You can now login with your username and password.", source ) -- upon succesfull creation of the account this function will be called to set the the register screen to invisible and the login screen to visible. triggerClientEvent ( "closeRegister", getRootElement()) else -- if not -//- outputChatBox ( "Error creating account, contact the server admin.", source ) end else outputChatBox ( "This account already exists..", source ) end else outputChatBox ("The passwords do not match, please re-enter.") end else outputChatBox ( "Please enter a password", source ) end else outputChatBox ( "Please enter a username", source ) end end client side addEvent( "closeRegister", true ) addEventHandler( "closeRegister", getRootElement(), closeRegisterWindow ) function closeRegisterWindow() -- make the Register window invisible. guiSetVisible(wdwRegister, false) -- make the login window visible again. guiSetVisible(wdwLogin, true) end But when pressing the register button it aint activating "closeRegisterWindow". In the client side it is correctly scripted, as the cancel button is also scripted in the client side and also uses "closeRegisterWindow" to go back to the login screen. So what am I doing wrong on serverside? Link to comment
TwiX! Posted March 21, 2012 Share Posted March 21, 2012 pls write here part of script, erros, or errors in /debugscript 3 and tell me what u want when register complited close window? if cansel close too? Link to comment
Absence2 Posted March 21, 2012 Share Posted March 21, 2012 I added this without telling you, that might be the problem function registerWindowCancel(button,state) if(button == "left" and state == "up") then if (source == btnCancel) then guiSetVisible(wdwRegister, false) guiSetVisible(wdwLogin, true) end end end It will show loginwindow after pressing Cancel just delete the wdwLogin part if you don't want the login window to show if you press Cancel NOTE: this part exists in the clientside I posted before, mess around with it there Link to comment
TwiX! Posted March 21, 2012 Share Posted March 21, 2012 i not see the problem, code will work or i still do not understand you Link to comment
Absence2 Posted March 21, 2012 Share Posted March 21, 2012 I thought that was the problem, the loginwindow shows after pressing Cancel then hides register. I suppose he wanted to hide both 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