here is my login script
Server
function onLogin ( player, user, pass )
local account = getAccount ( user, pass )
if ( account ~= false ) then
if (logIn ( player, account, pass ) == true) then
triggerClientEvent ( "hideLoginWindow", getRootElement())
else
outputChatBox ( "Login error!", player, 255, 255, 0 ) -- Output they got the details wrong.
end
else
outputChatBox ( "Wrong username or password!", player, 255, 255, 0 ) -- Output they got the details wrong.
end
end
addEvent( "onLogin", true )
addEventHandler( "onLogin", getRootElement(), onLogin )
function onRegister ( player, user, pass )
local account = getAccount ( user, pass )
if ( account ~= false ) then
if (logIn ( player, account, pass ) == true) then
triggerClientEvent ( "hideLoginWindow", getRootElement())
else
outputChatBox ( "Login error!", player, 255, 255, 0 ) -- Output they got the details wrong.
end
else
account = addAccount ( user, pass )
if (logIn ( player, account, pass ) == true) then
triggerClientEvent ( "hideLoginWindow", getRootElement())
else
outputChatBox ( "Register/Login error!", player, 255, 255, 0 ) -- Output they got the details wrong.
end
end
end
addEvent( "onRegister", true )
addEventHandler( "onRegister", getRootElement(), onRegister )
Client
GUIEditor_Window = {}
GUIEditor_Button = {}
GUIEditor_Memo = {}
GUIEditor_Label = {}
GUIEditor_Image = {}
GUIEditor_Window[1] = guiCreateWindow(264,152,255,341,"Welcome!",false)
guiSetAlpha(GUIEditor_Window[1],1)
LoginUsername = guiCreateEdit(0.298,0.1701,0.6157,0.1026,"",true,GUIEditor_Window[1])
guiSetAlpha(LoginUsername,1)
LoginPassword = guiCreateEdit(0.298,0.2815,0.6157,0.1026,"",true,GUIEditor_Window[1])
guiSetAlpha(LoginPassword,1)
guiEditSetMasked ( LoginPassword, true )
GUIEditor_Label[2] = guiCreateLabel(0.0431,0.1906,0.2471,0.0616,"Username:",true,GUIEditor_Window[1])
guiSetAlpha(GUIEditor_Label[2],1)
guiLabelSetColor(GUIEditor_Label[2],255,255,255)
guiLabelSetVerticalAlign(GUIEditor_Label[2],"top")
guiLabelSetHorizontalAlign(GUIEditor_Label[2],"left",false)
guiSetFont(GUIEditor_Label[2],"default-bold-small")
GUIEditor_Label[3] = guiCreateLabel(0.0471,0.2962,0.251,0.0704,"Password:",true,GUIEditor_Window[1])
guiSetAlpha(GUIEditor_Label[3],1)
guiLabelSetColor(GUIEditor_Label[3],255,255,255)
guiLabelSetVerticalAlign(GUIEditor_Label[3],"top")
guiLabelSetHorizontalAlign(GUIEditor_Label[3],"left",false)
guiSetFont(GUIEditor_Label[3],"default-bold-small")
GUIEditor_Label[4] = guiCreateLabel(0.0745,0.5279,0.8314,0.0645,"If you are new, please register!",true,GUIEditor_Window[1])
guiSetAlpha(GUIEditor_Label[4],1)
guiLabelSetColor(GUIEditor_Label[4],255,150,255)
guiLabelSetVerticalAlign(GUIEditor_Label[4],"top")
guiLabelSetHorizontalAlign(GUIEditor_Label[4],"left",false)
guiSetFont(GUIEditor_Label[4],"clear-normal")
GUIEditor_Label[5] = guiCreateLabel(0.0784,0.0792,0.8314,0.0645,"Welcome to James Kile's server",true,GUIEditor_Window[1])
guiSetAlpha(GUIEditor_Label[5],1)
guiLabelSetColor(GUIEditor_Label[5],255,150,255)
guiLabelSetVerticalAlign(GUIEditor_Label[5],"top")
guiLabelSetHorizontalAlign(GUIEditor_Label[5],"left",false)
guiSetFont(GUIEditor_Label[5],"clear-normal")
GUIEditor_Button[1] = guiCreateButton(0.5216,0.4164,0.3961,0.0909,"Login!",true,GUIEditor_Window[1])
guiSetAlpha(GUIEditor_Button[1],1)
EditRegisterUsername = guiCreateEdit(0.2902,0.5924,0.6157,0.1026,"",true,GUIEditor_Window[1])
guiSetAlpha(EditRegisterUsername,1)
EditRegisterPassword = guiCreateEdit(0.2902,0.7038,0.6157,0.1026,"",true,GUIEditor_Window[1])
guiEditSetMasked ( EditRegisterPassword, true )
guiSetAlpha(EditRegisterPassword,1)
GUIEditor_Label[6] = guiCreateLabel(0.0392,0.61,0.2471,0.0616,"Username:",true,GUIEditor_Window[1])
guiSetAlpha(GUIEditor_Label[6],1)
guiLabelSetColor(GUIEditor_Label[6],255,255,255)
guiLabelSetVerticalAlign(GUIEditor_Label[6],"top")
guiLabelSetHorizontalAlign(GUIEditor_Label[6],"left",false)
guiSetFont(GUIEditor_Label[6],"default-bold-small")
GUIEditor_Label[7] = guiCreateLabel(0.0392,0.7185,0.251,0.0704,"Password:",true,GUIEditor_Window[1])
guiSetAlpha(GUIEditor_Label[7],1)
guiLabelSetColor(GUIEditor_Label[7],255,255,255)
guiLabelSetVerticalAlign(GUIEditor_Label[7],"top")
guiLabelSetHorizontalAlign(GUIEditor_Label[7],"left",false)
guiSetFont(GUIEditor_Label[7],"default-bold-small")
GUIEditor_Button[2] = guiCreateButton(0.5216,0.8328,0.3961,0.0909,"Register!",true,GUIEditor_Window[1])
guiSetAlpha(GUIEditor_Button[2],1)
GUIEditor_Image[1] = guiCreateStaticImage(0.0549,0.7918,0.349,0.173,"data/mtalogo.png",true,GUIEditor_Window[1])
guiSetAlpha(GUIEditor_Image[1],1)
guiSetVisible ( GUIEditor_Window[1], false )
local localPlayer = getLocalPlayer ( )
function windowHandler( )
local playername = getPlayerName(localPlayer)
guiSetText(LoginUsername, "")
guiSetText(EditRegisterUsername, "")
guiSetText(LoginUsername, playername)
guiSetText(EditRegisterUsername, playername)
guiSetVisible ( GUIEditor_Window[1], true )
guiSetInputEnabled(true)
showCursor ( true )
end
function onClickBtn ( button, state )
if (source == GUIEditor_Button[1]) then
triggerServerEvent ( "onLogin", getRootElement(), localPlayer, guiGetText(LoginUsername), guiGetText(LoginPassword) )
end
end
function onClickBtn2 ( button, state )
if (source == GUIEditor_Button[2]) then
triggerServerEvent ( "onRegister", getRootElement(), localPlayer, guiGetText(EditRegisterUsername), guiGetText(EditRegisterPassword))
end
end
function hideLoginWindow()
guiSetInputEnabled(false)
guiSetVisible ( GUIEditor_Window[1], false )
showCursor ( false )
end
addEvent( "hideLoginWindow", true )
addEventHandler( "hideLoginWindow", getRootElement(), hideLoginWindow )
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), windowHandler )
addEventHandler ( "onClientGUIClick", GUIEditor_Button[1], onClickBtn, false )
addEventHandler ( "onClientGUIClick", GUIEditor_Button[2], onClickBtn2, false