Sign in to follow this  
Master_11

Something to get Account from the account Name.

Recommended Posts

Hello,

Currently, I am working on a script of Player's Email. Its work is to retrieve the player's Email from his/her account name using "getAccountData"

 

Client: 

function getMailFromAccount(accName)
	local accName = guiGetText(acceditbox)
	triggerServerEvent("getMail", resourceRoot, localPlayer, accName)
end

function getMailID()
	if (eMail) then
	guiSetText(resultmail, "Result: "..eMail..".")
end
addEvent("setMailOnLable", true)
addEventHandler("setMailOnLable", localPlayer, getMailID)
end

 

Server:

function getMailFromAccount(accName, eMail)
	if (accName) then
		local account = getAccountFromName(accName)
	end
	if (account) then
		local eMail = getAccountData(account, "accounts.email")
		triggerClientEvent(client, "setMailOnLable", client, eMail)
	end
end
addEvent("getMail", true)
addEventHandler("getMail", getRootElement(), getMailFromAccount)

 

However, this code isn't working and I cannot find any other way to make it work. Any Ideas?

Also, I keep getting this errors: 

[20:10:08] WARNING: NTsGetMailID\server.lua:19: Bad argument @ 'getAccount' [Expected string at argument 1, got player]

Share this post


Link to post

We are going to need the full code in order to give you a proper answer.

1 hour ago, Master_11 said:

[20:10:08] WARNING: NTsGetMailID\server.lua:19: Bad argument @ 'getAccount' [Expected string at argument 1, got player] 

I don't see 'getAccount' nowhere.

Share this post


Link to post

@Peti

function getAccountFromName(name)
	return getAccount(name) or false
end

function getMailFromAccount(accName, eMail)
	if (accName) then
		local account = getAccountFromName(accName)
	end
	if (account) then
		local eMail = getAccountData(account, "accounts.email")
		triggerClientEvent(client, "setMailOnLable", client, eMail)
	end
end
addEvent("getMail", true)
addEventHandler("getMail", getRootElement(), getMailFromAccount)

 

Before using the first function, the value from "getAccountFromName" was (nil)

 

Aslo, Do you need the full client code too?

Edited by Master_11

Share this post


Link to post
37 minutes ago, Master_11 said:

Aslo, Do you need the full client code too? 

No, It's ok.

Have you tried debugging your 'getAccountFromName'? Maybe put an outputChatBox and see if the function returns an acc.

function getMailFromAccount(accName)
	local accName = guiGetText(acceditbox)
  	outputChatBox(accName)
	triggerServerEvent("getMail", resourceRoot, localPlayer, accName)
end

Something like this. It is for testing purposes.

 

If you don't get any account, check if the account exists.

 

EDIT:

If I'm correct, here you are passing a parameter to the function:

triggerClientEvent(client, "setMailOnLable", client, eMail)

but here you haven't defined anything:

function getMailID(eMail) -- here
	if (eMail) then
		guiSetText(resultmail, "Result: "..eMail..".")
	end
	addEvent("setMailOnLable", true)
	addEventHandler("setMailOnLable", localPlayer, getMailID)
end

 

Also, try this:
function getMailID(eMail) -- here
	if (eMail) then
		guiSetText(resultmail, "Result: "..eMail..".")
	end
end
addEvent("setMailOnLable", true)
addEventHandler("setMailOnLable", localPlayer, getMailID)

 

Edited by Peti
  • Thanks 1

Share this post


Link to post

@Peti

Sorry, I was very busy with some other work, so couldn't make a reply.

On 04/02/2019 at 00:30, Peti said:

EDIT:

If I'm correct, here you are passing a parameter to the function:


triggerClientEvent(client, "setMailOnLable", client, eMail)

but here you haven't defined anything:

 

Yes, I missed defining the parameter on the client side. Thanks for that.

However, about the main issue, the problem was with this

triggerServerEvent

As I forgot to change the extra element "localPlayer" which was passing the player data to the server-side function. Also, "getAccountFromName" was not really useful in the whole function so I replaced it with "getAccount(accName)" which works perfectly fine as expected. Also, there were a few typing mistakes in the code too, I've fixed them. I don't know what happened that day maybe I was just way too tired to check the code carefully. Thanks anyways.

 

Pasting the fixed code for anyone who needs a reference in future.

Client:

function getMailFromAccount(accName)
	local accName = guiGetText(acceditbox)
	triggerServerEvent("getMail", resourceRoot, accName)
end
addEventHandler("onClientGUIClick", searchButton, getMailFromAccount, false)

function getMailID(mailID)
	local eMail = mailID
	if (mailID) then
		guiSetText(mailoutput, mailID)
	end
end
addEvent("setMailOnLable", true)
addEventHandler("setMailOnLable", resourceRoot, getMailID)

function invalidAcc()
	guiSetText(mailoutput, "Invalid Account.")
end
addEvent("mailAccInvalid", true)
addEventHandler("mailAccInvalid", resourceRoot, invalidAcc)

Server:

function getMailFromAccount(accName)
	local account = getAccount(accName)
	if (not account) then
		triggerClientEvent(client, "mailAccInvalid", resourceRoot)
		return false
	end
	local eMail = getAccountData(account, "accounts.email")
	triggerClientEvent(client, "setMailOnLable", resourceRoot, eMail)
end
addEvent("getMail", true)
addEventHandler("getMail", resourceRoot, getMailFromAccount)

 

This topic can be locked now.

Edited by Master_11
Typing Mistake.
  • Like 1

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.