-- Client Side
wdwLogin = guiCreateWindow(0.375, 0.375, 0.70, 0.70, "Vitaj", true)
guiCreateLabel(0.0825, 0.1, 0.25, 0.25, "Meno", true, wdwLogin)
guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Heslo", true, wdwLogin)
guiCreateLabel(0.0825, 0.6, 0.25, 0.25, "Info", true, wdwLogin)
wdwRegister = guiCreateWindow(0.375, 0.375, 0.40, 0.40, "Registracia", true)
guiCreateLabel(0.0825, 0.2, 0.25, 0.25, "Meno", true, wdwRegister)
guiCreateLabel(0.0825, 0.4, 0.25, 0.25, "Heslo", true, wdwRegister)
guiSetProperty(wdwRegister, "AlwaysOnTop", "true")
edtUser = guiCreateEdit(0.160, 0.1, 0.3, 0.06, "", true, wdwLogin)
edtPass = guiCreateEdit(0.160, 0.2, 0.3, 0.06, "", true, wdwLogin)
guiCreateMemo( 118, 200, 850, 280, "", false, wdwLogin )
guiEditSetMaxLength(edtUser, 50)
guiEditSetMaxLength(edtPass, 50)
edtUserS = guiCreateEdit(0.160, 0.2, 0.4, 0.06, "", true, wdwRegister)
edtPassS = guiCreateEdit(0.160, 0.4, 0.5, 0.06, "", true, wdwRegister)
guiEditSetMaxLength(edtUserS, 50)
guiEditSetMaxLength(edtPassS, 50)
guiEditSetMasked ( edtPassS, true )
guiEditSetMasked ( edtPass, true )
btnLogin = guiCreateButton(0.500, 0.1, 0.25, 0.2, "Prihlasit", true, wdwLogin)
btnRegister = guiCreateButton(0.750, 0.1, 0.25, 0.2, "Registracia", true, wdwLogin)
btnRegisterS = guiCreateButton(0.750, 0.1, 0.25, 0.2, "Registrovat", true, wdwRegister)
guiSetVisible(wdwRegister,false)
showCursor(true)
guiSetInputEnabled(true)
addEventHandler('onClientGUIClick',root,
function()
if source == btnLogin then
local user = guiGetText(edtUser)
local pass = guiGetText(edtPass)
if user ~= "" and pass ~= "" then
triggerServerEvent('submitLogin',localPlayer,user,pass)
else
outputChatBox("Prosim napis svoje meno a heslo.")
end
elseif source == btnRegisterS then
local user = guiGetText(edtUserS)
local pass = guiGetText(edtPassS)
triggerServerEvent('submitRegister',localPlayer,user,pass)
end
end
)
addEvent("HideGui",true)
addEventHandler("HideGui",root,
function()
guiSetInputEnabled(false)
showCursor(false)
guiSetVisible(wdwLogin,false)
guiSetVisible(wdwRegister,false)
end)
addEventHandler('onClientGUIClick', root,
function()
if source == btnRegister then
guiSetVisible(wdwRegister,true)
end
end)
-- Server Side --
addEvent( "submitLogin", true)
addEvent("submitRegister", true)
function loginHandler(username,password)
local account = getAccount (username, password)
if account then
logIn(source, account, password)
triggerClientEvent(source,"HideGui",source)
else
outputChatBox("Zle zadane Meno alebo Heslo, skus znova prosim.",source)
end
end
addEventHandler("submitLogin",root,loginHandler)
function registerHandler(username, password)
local account = getAccount(username)
if (account) then
outputChatBox("Account with this name already exists!", source, 255, 255, 255) return end
account = addAccount(username, password)
if (logIn(source, account, password) == true) then
triggerClientEvent(source, "HideGui", source)
end
end
addEventHandler("submitRegister", root, registerHandler)