Jump to content

dragonslife

Members
  • Posts

    22
  • Joined

  • Last visited

dragonslife's Achievements

Civilian

Civilian (7/54)

0

Reputation

  1. Look, here's my code client side 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.325 -- define the width and height of the window local Width = 0.35 local Height = 0.35 -- 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.43 guiCreateLabel (X, Y, Width, Height, "password", true, wdwRegister) Y = 0.63 guiCreateLabel (X, Y, Width, Height, "Confirm Password", true, wdwRegister) X = 0.415 Y = 0.205 Width = 0.5 Height = 0.15 edtUser = guiCreateEdit (X, Y, Width, Height, "", true, wdwRegister) Y = 0.40 edtPass = guiCreateEdit (X, Y, Width, Height, "", true, wdwRegister) Y = 0.595 edtPass2 = 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.8 Width = 0.25 Height = 0.2 btnCancel = guiCreateButton(X, Y, Width, Height, "Cancel", true, wdwRegister) X = 0.700 Y = 0.8 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, closeRegisterWindow, 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) -- get the text entered in the 'password' field. local password2 = guiGetText(edtPass2) if button == "left" and state == "up" then triggerServerEvent("registerPlayer",getLocalPlayer(),username,password, password2) end end 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 -- 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) 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 addEvent("registerPlayer",true) addEventHandler("registerPlayer",getRootElement(),registerPlayer) Pressing the cancel button in the register screen will return you to the login window. but when you press the register button, it will create your account but it wont take you back to the login screen as the cancelbutton does. Now the cancelbutton and the function that makes you go back to the loginscreen are both in client side. So I know I'm doing something wrong on server side as in there it tells to use clientside function to close the registerwindow after the account has been created (both by clicking the register button).
  2. 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?
  3. What would be the command to activate a function on the client side from the server side? triggerClientEvent(......) ??
  4. Got it fixed now, changed: under default user to:
  5. 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?
  6. 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?
  7. 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.
  8. It should work with the code i got earlier in this topic... but something in that code is making it stop at the "if".
  9. 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?
  10. Hello People, I'm working in the map editor in MTA. Now I have a place where I wan't to build a mechanics garage only there's a tree and some leaves in the way. Is it possible to remove these? because I can't seem to target them or select them somehow in order to delete them.
  11. 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
  12. 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)
  13. 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)
  14. Yaaaaaaaaaaay! It's working now! thanks alot people!! =D
  15. 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
×
×
  • Create New...