Jump to content

[Help]Canceling server event on clientside


UnchiuDawg

Recommended Posts

Hi, I'm new to lua and scripting itself.

I'm trying to make a simple login panel. Almost everything works right, except this one thing:

serverside:

function loginHandler ( usernamelogin, passwordlogin )
	local accountlogin = getAccount ( usernamelogin, passwordlogin )
	if ( accountlogin ~= false ) then
		logIn ( client, accountlogin, passwordlogin )
		fadeCamera(client, false, 1.5)
		setTimer(fadeCameraDelay,1500,1,client)
	else
		outputChatBox ( "Wrong username or password!", client, 255, 255, 0 ) -- the login failed
	end
end

addEvent("submitLogin",true)
addEventHandler("submitLogin",root,loginHandler)

clientside:

function clientSubmitLogin(button,state)
	if button == "left" and state == "up" then
		local usernamelogin = guiGetText(UserLogin)
		local passwordlogin = guiGetText(PassLogin)
		triggerServerEvent("submitLogin", getRootElement(), usernamelogin, passwordlogin)
		guiSetInputEnabled(false) -- should not happen if login failed
		guiSetVisible(LoginPanel, false) -- should not happen if login failed
		showCursor(false) -- should not happen if login failed
		stopSound(loginpanelsong) -- should not happen if login failed
	end
end

This is for the login button, but I don't know how to make some of the functions (the ones I put comments on) not happen when the login fails.

I tried working around it but still couldn't figure it out and I kept looking on the wiki but couldn't find a way to do it.

Any help is appreciated :D

Edited by UnchiuDawg
Link to comment

Server side

function loginHandler ( usernamelogin, passwordlogin )
	local accountlogin = getAccount ( usernamelogin, passwordlogin )
	if ( accountlogin ~= false ) then
		logIn ( client, accountlogin, passwordlogin )
		fadeCamera(client, false, 1.5)
		setTimer(fadeCameraDelay,1500,1,client)
		triggerClientEvent(client, "hideLogin", getRootElement())
	else
		outputChatBox ( "Wrong username or password!", client, 255, 255, 0 ) -- the login failed
	end
end

addEvent("submitLogin",true)
addEventHandler("submitLogin",root,loginHandler)

Client side

function clientSubmitLogin(button,state)
	if button == "left" and state == "up" then
		local usernamelogin = guiGetText(UserLogin)
		local passwordlogin = guiGetText(PassLogin)
		triggerServerEvent("submitLogin", getRootElement(), usernamelogin, passwordlogin)
	end
end

addEvent("hideLogin", true)
addEventHandler("hideLogin", getRootElement(), function()
	guiSetInputEnabled(false)
	guiSetVisible(LoginPanel, false)
	showCursor(false)
	stopSound(loginpanelsong)
end

Should work mate.

Edited by NeXuS™
  • Like 1
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...