Jump to content

[help]logingui


Wisin

Recommended Posts

hi community, i come here to ask help with my logingui i will post here my code if someone can help i will give so much thanks :D

client-side

local localPlayer = getLocalPlayer()

local localPlayerName = getPlayerName(localPlayer)

local localRootElement = getRootElement()

local newUser

local passwordAttempts = 0

function CreateLoginWindow()

wdwLogin = guiCreateWindow(226,146,372,233,"[LOGIN/REGISTER SYSTEM]",false)

guiWindowSetMovable(wdwLogin,false)

guiWindowSetSizable(wdwLogin,false)

tabpanel = guiCreateTabPanel(0.0242,0.0858,0.9489,0.8755,true,wdwLogin)

tab1 = guiCreateTab("Login",tabpanel)

login = guiCreateButton(0.3711,0.8611,0.2436,0.1167,"Login",true,tab1)

username = guiCreateLabel(0.0113,0.1167,0.3768,0.15,"UserName:",true,tab1)

guiLabelSetColor(username,255,255,255)

guiLabelSetVerticalAlign(username,"top")

guiLabelSetHorizontalAlign(username,"left",false)

guiSetFont(username,"default-bold-small")

password = guiCreateLabel(0.0113,0.2889,0.3768,0.15,"Password:",true,tab1)

guiLabelSetColor(password,255,255,255)

guiLabelSetVerticalAlign(password,"top")

guiLabelSetHorizontalAlign(password,"left",false)

guiSetFont(password,"default-bold-small")

username = guiCreateEdit(0.2266,0.1,0.3598,0.1389,localPlayerName,true,tab1)

password = guiCreateEdit(0.2266,0.2611,0.3598,0.1389,"",true,tab1)

guiEditSetMasked(password,true)

tab2 = guiCreateTab("Register",tabpanel)

user = guiCreateLabel(0.0085,0.0889,0.3824,0.1611,"UserName:",true,tab2)

guiLabelSetColor(user,255,255,255)

guiLabelSetVerticalAlign(user,"top")

guiLabelSetHorizontalAlign(user,"left",false)

guiSetFont(user,"clear-normal")

pass = guiCreateLabel(0.0113,0.2722,0.3824,0.1611,"Password:",true,tab2)

guiEditSetMasked(pass,true)

guiLabelSetColor(pass,255,255,255)

guiLabelSetVerticalAlign(pass,"top")

guiLabelSetHorizontalAlign(pass,"left",false)

guiSetFont(pass,"clear-normal")

register = guiCreateButton(0.3909,0.8667,0.2125,0.1222,"Register",true,tab2)

userr = guiCreateEdit(0.255,0.0833,0.3484,0.1444,localPlayerName,true,tab2)

passs = guiCreateEdit(0.255,0.25,0.3484,0.1444,"",true,tab2)

guiSetVisible(wdwLogin,false)

end

addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()),

function()

CreateLoginWindow()

lblDisplayArea = guiCreateLabel(0.100,0.800,0.800,0.100,"",true)

guiLabelSetHorizontalAlign(lblDisplayArea,"center",true)

addEventHandler("onClientGUIClick",login,clientSubmitLogin,false)

addEventHandler("onClientGUIClick",register,clientSubmitCreate,false)

addEventHandler("onClientGUIAccepted",password,clientEnterLogin,false)

triggerServerEvent ("checkValidAct",localPlayer,localPlayerName)

end

)

function clientNewUserHandler() --Called when no account exists for this players name...

newUser = true

guiSetText(lblDisplayArea,"No account exists for your username. Please create a password.")

if(tab2) then

guiSetVisible(wdwLogin,true)

guiBringToFront(edtPass) --Puts the cursor into the password box for typing...

end

showCursor(true)

guiSetInputEnabled(true)

end

addEvent("clientNewUser",true)

addEventHandler("clientNewUser",localRootElement,clientNewUserHandler)

function clientReturningUserHandler() --Called when there is an existing account for this player's name...

newUser = false

guiSetText(lblDisplayArea,"You are using a registered nickname - please enter your password.")

if(wdwLogin) then

guiSetVisible(wdwLogin,true)

guiBringToFront(edtPass) --Puts the cursor into the password box for typing...

end

showCursor(true)

guiSetInputEnabled(true)

end

addEvent("clientReturningUser",true)

addEventHandler("clientReturningUser",localRootElement,clientReturningUserHandler)

function clientEnterLogin()

if(newUser) then

triggerServerEvent("SubmitCreate",localRootElement,guiGetText(edtUser),guiGetText(edtPass))

else

triggerServerEvent("SubmitLogin",localRootElement,guiGetText(edtUser),guiGetText(edtPass))

end

end

function clientSubmitLogin(button)

if(button == "left") then

if(newUser) then

triggerServerEvent("SubmitCreate",localRootElement,guiGetText(edtUser),guiGetText(edtPass))

else

triggerServerEvent("SubmitLogin",localRootElement,guiGetText(edtUser),guiGetText(edtPass))

end

end

end

function clientDisplayAreaHandler(theMessage)

guiSetText(lblDisplayArea,theMessage)

end

addEvent("clientDisplayArea",true)

addEventHandler("clientDisplayArea",localRootElement,clientDisplayAreaHandler)

function clientWrongPasswordHandler(theMessage)

passwordAttempts = passwordAttempts + 1

if(passwordAttempts > 3) then

guiSetText(lblDisplayArea,"Too many incorrect password attempts. Please disconnect.")

destroyElement(wdwLogin)

triggerServerEvent("removePlayer",localPlayer)

end

end

addEvent("clientWrongPassword",true)

addEventHandler("clientWrongPassword",localRootElement,clientWrongPasswordHandler)

function clientLoginSuccessHandler()

guiSetInputEnabled(false)

destroyElement(wdwLogin)

destroyElement(lblDisplayArea)

wdwLogin = nil

newUser = nil

lblDisplayArea = nil

passwordAttempts = nil

localPlayer = nil

localPlayerName = nil

localRootElement = nil

showCursor(false)

end

addEvent("clientLoginSuccess",true)

addEventHandler("clientLoginSuccess",localRootElement,clientLoginSuccessHandler)

server-side

--Default spawn location, if you wish to use one...

--local spawnX = 1959

--local spawnY = -1714

--local spawnZ = 17

--Default welcome messages...

local welcomeMessageNewUser = "Welcome to our server!"

local welcomeMessageReturningUser = "Welcome back to the server!"

function clientAttemptLogin(username,password)

local userAccount = getAccount(username)

local tryToLog

if (client) then

tryToLog = logIn(client,userAccount,password)

if (tryToLog) then

spawnPlayer(client,spawnX,spawnY,spawnZ)

fadeCamera(client,true)

outputChatBox(welcomeMessageReturningUser,client)

triggerClientEvent(source,"clientLoginSuccess",getRootElement())

else

triggerClientEvent(source,"clientDisplayArea",getRootElement(),"Incorrect password, please try again.")

triggerClientEvent(source,"clientWrongPassword",getRootElement())

end

end

end

addEvent("SubmitLogin",true)

addEventHandler("SubmitLogin",getRootElement(),clientAttemptLogin)

function clientAttemptCreate(userr,passs)

if (password ~= nil and password ~= "") then

addAccount(userr,pass)

local userAccount = getAccount(userr)

local tryToLog

if (client and userAccount ~= false and userAccount ~= nil) then

tryToLog = logIn(client,userAccount,password)

if (tryToLog) then

--spawnPlayer(client,spawnX,spawnY,spawnZ)

fadeCamera(client,true)

outputChatBox(welcomeMessageNewUser,client)

triggerClientEvent(source,"clientLoginSuccess",getRootElement())

else

triggerClientEvent(source,"clientDisplayArea",getRootElement(),"Unable to log in to new account, try again.")

end

else

triggerClientEvent(source,"clientDisplayArea",getRootElement(),"Unable to create new account, try again.")

end

else

triggerClientEvent(source,"clientDisplayArea",getRootElement(),"Please create a password for your new account.")

end

end

addEvent("SubmitCreate",true)

addEventHandler("SubmitCreate",getRootElement(),clientAttemptCreate)

function checkValidActHandler(thePlayer)

local theAccount = getAccount(thePlayer)

if (theAccount) then

triggerClientEvent(source,"clientReturningUser",getRootElement())

else

triggerClientEvent(source,"clientNewUser",getRootElement())

end

end

addEvent("checkValidAct",true)

addEventHandler("checkValidAct",getRootElement(),checkValidActHandler)

function removePlayerHandler()

kickPlayer(source)

end

addEvent("removePlayer",true)

addEventHandler("removePlayer",getRootElement(),removePlayerHandler)

Link to comment

Well, I recommend you scrap logingui and make your own from scratch. I find logingui is written a bit wierd. And if you look at the snippet of code below; there is no such function as "clientSubmitCreate" in your code.

addEventHandler("onClientGUIClick",register,clientSubmitCreate,false)

Link to comment

If your having trouble with gui maybe rather than jumping in at the deep end, just get accustomed to the functions and events of gui in more simple ways, e.g a welcome message when you join the server with a close button. Thats how i started any way :fadein:

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...