Jump to content

getAccount not working


Recommended Posts

Hello there, I'm making my own login system. So far, it goes great, but code stucks at getAccount, which does not progress any further. It does no output since line getAccount. just nothing. Like if it's stuck at that line. 

			username = guiGetText(GUIEditor.edit[1])
			password2 = guiGetText(GUIEditor.edit[2])
			if getAccount(username,password2) then
				outputConsole("passed")
				logIn ( thePlayer, username, password2 )
			else
				outputConsole("false")
			end

Basically it's that simple, but it won't work. And I have no clue why. Username and password2 are set.

Link to comment
  • Moderators

Serverside scripting should run on serverside. ORANGE > getAccount, logIn

Clientside scripting should run on clientside. RED > guiGetText

Shared, can be used on both sides. BLUE > outputConsole

 

Clientside > every client/player

The GUI is an user interface which only exists for the clients/players.

Serverside > mta server

The account database doesn't exist on a player his computer. It only exist on the server, which means you can't login clientside.

 

A tutorial on how to transfer data between both sides:

 

Link to comment
14 minutes ago, IIYAMA said:

Serverside scripting should run on serverside. ORANGE > getAccount, logIn

Clientside scripting should run on clientside. RED > guiGetText

Shared, can be used on both sides. BLUE > outputConsole

 

Clientside > every client/player

The GUI is an user interface which only exists for the clients/players.

Serverside > mta server

The account database doesn't exist on a player his computer. It only exist on the server, which means you can't login clientside.

 

A tutorial on how to transfer data between both sides:

Well, co i made this..


SERVER
function getAcc(username,password2)
	local account = getAccount(username,password2)
	return account
end

CLIENT
account = getAcc(username,password2)
outputConsole("lel3")
if account then
	outputConsole("lel3")
	logIn ( thePlayer, username, password2 )
else
	outputConsole("lel2")
end

Still, no results.

Nevermind, I forgot to do it thru events.

 

SOLUTION

addEvent ( "Account", true )
function getAcc(username,password2)
	local account = getAccount(username,password2)
	return account
end
addEventHandler ( "Account", getRootElement(), getAcc )

account = triggerServerEvent ( "Account", getRootElement(),username, password2 )

 

Edited by Logann
solved
Link to comment
  • Moderators

the logIn function is also serverside. Accounts can't be passed to the other side, since they are serverside references only.

You will have to pass the username and password to serverside and login there.

Edited by IIYAMA
Link to comment
22 minutes ago, IIYAMA said:

the logIn function is also serverside. Accounts can't be passed to the other side, since they are serverside references only.

You will have to pass the username and password to serverside and login there.

I see, the problem is, that getAccount returns true no matter whatever it is.

 

FINAL SOLUTION

 

client

function login()
        --if an element was clicked on screen
			username = guiGetText(GUIEditor.edit[1])
			password2 = guiGetText(GUIEditor.edit[2])
			account = triggerServerEvent ( "Account", getRootElement(),username)
			if (account == true) then
				local tf = triggerServerEvent ( "logInn", getRootElement(),localPlayer,username,password2)
				if (tf == true) then
					outputConsole("success")
					isLoggedIn = true
					showCursor(false)
				else
					outputConsole("wrn")
				end	
			else
				outputConsole("lel2")
			end
end

server

addEvent ( "Account", true )
function getAcc(username)
	local account = isGuestAccount(username)
	if (account == true) then
		return false
	else
		return true
	end
end
addEventHandler ( "Account", getRootElement(), getAcc )

addEvent ( "logInn", true )
function logInn(thePlayer,username,password2)
	local noole = logIn(thePlayer,getAccount(username),password2)
	return noole
end
addEventHandler ( "logInn", getRootElement(), logInn )

 

Edited by Logann
Fixed
Link to comment
  • Moderators

 

 

Wiki: https://wiki.multitheftauto.com/wiki/GetAccount

Returns an account or false if an account matching the username specified (and password, if specified) could not be found.

 

Why true?

https://wiki.multitheftauto.com/wiki/TriggerServerEvent

triggerServerEvent does indeed return true, when the message has been send. And false if not for some reason.

 

Ping

Let me remind you that something called ping exist. This is the delay between the server and the client.

Which means that triggerServerEvent can't give you the result directly back, because the code doesn't wait for this delay.

 

Todo

- You will have to use triggerServerEvent to send the username and password.

- When the user has been logged in, you have to send back (with triggerClientEvent) the message that user has been logged in.

 

 

 

 

 

Link to comment
2 minutes ago, IIYAMA said:

 

 

Wiki: https://wiki.multitheftauto.com/wiki/GetAccount

Returns an account or false if an account matching the username specified (and password, if specified) could not be found.

 

Why true?

https://wiki.multitheftauto.com/wiki/TriggerServerEvent

triggerServerEvent does indeed return true, when the message has been send. And false if not for some reason.

 

Ping

Let me remind you that something called ping exist. This is the delay between the server and the client.

Which means that triggerServerEvent can't give you the result directly back, because the code doesn't wait for this delay.

 

Todo

- You will have to use triggerServerEvent to send the username and password.

- When the user has been logged in, you have to send back (with triggerClientEvent) the message that user has been logged in.

 

 

 

 

 

I solved it. Thanks for help :D.

  • 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...