Here
-- Login/Register
local newUser
local localPlayer = getLocalPlayer()
local localPlayerName = getPlayerName(localPlayer)
local localRootElement = getRootElement()
local passwordAttempts = 0
GUIEditor_Window = {}
GUIEditor_Button = {}
GUIEditor_Edit = {}
function CreateLoginWindow()
GUIEditor_Window[1] = guiCreateWindow(230,160,336,265,"J Login",false)
guiSetAlpha(GUIEditor_Window[1],1)
guiWindowSetMovable(GUIEditor_Window[1],false)
guiWindowSetSizable(GUIEditor_Window[1],false)
-- Buttons
GUIEditor_Button[1] = guiCreateButton(22,184,143,40,"Login",false,GUIEditor_Window[1])
GUIEditor_Button[2] = guiCreateButton(201,184,123,44,"Register",false,GUIEditor_Window[1])
-- Labels
guiCreateLabel(35,48,87,21,"Username:",false,GUIEditor_Window[1])
guiCreateLabel(37,90,53,17,"Password:",false,GUIEditor_Window[1])
-- Type in...
GUIEditor_Edit[1] = guiCreateEdit(133,45,171,27,"",false,GUIEditor_Window[1])
guiEditSetMaxLength(GUIEditor_Edit[1],23)
GUIEditor_Edit[2] = guiCreateEdit(128,95,186,28,"",false,GUIEditor_Window[1])
guiEditSetMasked(GUIEditor_Edit[2],true)
guiEditSetMaxLength(GUIEditor_Edit[2],13)
end
GUIEditor_Window = {}
GUIEditor_Button = {}
GUIEditor_Edit = {}
function CreateRegisterWindow()
GUIEditor_Window[1] = guiCreateWindow(197,122,369,330,"Register",false)
guiSetAlpha(GUIEditor_Window[1],1)
guiWindowSetMovable(GUIEditor_Window[1],false)
guiWindowSetSizable(GUIEditor_Window[1],false)
guiCreateLabel(39,48,64,15,"Username:",false,GUIEditor_Window[1])
guiCreateLabel(43,119,66,15,"Password:",false,GUIEditor_Window[1])
-- Type in...
GUIEditor_Edit[1] = guiCreateEdit(122,49,205,26,"",false,GUIEditor_Window[1])
guiEditSetMaxLength(GUIEditor_Edit[1],23)
GUIEditor_Edit[2] = guiCreateEdit(121,114,205,29,"",false,GUIEditor_Window[1])
guiEditSetMasked(GUIEditor_Edit[2],true)
guiEditSetMaxLength(GUIEditor_Edit[2],13)
-- Image
guiCreateStaticImage(19,168,117,114,"images/mtalogo.png",false,GUIEditor_Window[1])
-- Buton
GUIEditor_Button[1] = guiCreateButton(154,270,111,45,"Login",false,GUIEditor_Window[1])
end
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),
function()
CreateLoginWindow()
-- if the GUI was successfully created, then show the GUI to the player
if (GUIEditor_Window[1] ~= nil) then
guiSetVisible(GUIEditor_Window[1], true)
else
-- if the GUI hasnt been properly created, tell the player
outputChatBox("An unexpected error has occurred and the log in GUI has not been created.")
end
-- enable the players cursor (so 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)
-- now add our onClientGUIClick event to the button we just created
addEventHandler("onClientGUIClick",GUIEditor_Button[1], clientSubmitLogin, false)
addEventHandler("onClientGUIClick",GUIEditor_Button[2], clientClickReg,false)
end
)
-- create the function and define the 'button' and 'state' parameters
-- (these are passed automatically by onClientGUIClick)
function clientSubmitLogin(button,state)
if button == "left" and state == "up" then
-- get the text entered in the 'username' field
local username = guiGetText(GUIEditor_Edit[1])
-- get the text entered in the 'password' field
local password = guiGetText(GUIEditor_Edit[2])
-- 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)
-- hide the gui, hide the cursor and return control to the player
guiSetInputEnabled(false)
guiSetVisible(GUIEditor_Window[1], false)
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
function clientClickReg()
guiSetVisible(CreateRegisterWindow(),true)
if (GUIEditor_Window[1] ~= nil) then
guiSetVisible(GUIEditor_Window[1], true)
else
-- if the GUI hasnt been properly created, tell the player
outputChatBox("An unexpected error has occurred and the log in GUI has not been created.")
end
-- enable the players cursor (so 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)
-- now add our onClientGUIClick event to the button we just created
addEventHandler("onClientGUIClick",GUIEditor_Button[1], clientSubmitRegister, false)
end
-- create the function and define the 'button' and 'state' parameters
-- (these are passed automatically by onClientGUIClick)
function clientSubmitRegister(button,state)
if button == "left" and state == "up" then
-- get the text entered in the 'username' field
local username = guiGetText(GUIEditor_Edit[1])
-- get the text entered in the 'password' field
local password = guiGetText(GUIEditor_Edit[2])
-- 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("submitRegister", getRootElement(), username, password)
-- hide the gui, hide the cursor and return control to the player
guiSetInputEnabled(false)
guiSetVisible(GUIEditor_Window[1], false)
showCursor(false)
end
end
end