Jump to content

Send a return string data from server to client


Dzsozi (h03)

Recommended Posts

Hello!

I would like to get the current account state variable on client side, so I can adjust my login interface based on that (if the player already has an account disable the register button, etc.).

My problem is I don't know how to do that, could somebody help me out? I need to call the function on client side, so I can't use element datas (as far as I know). Here's my server side script:

function getPlayerAccountState(playerSource)
	if (playerSource) then
		local accountState = "canCreate"
		local selectQuery = dbPoll(dbQuery(connection, "SELECT * FROM accounts"), -1)
		if (selectQuery) then
			for k, v in ipairs(selectQuery) do
				if (tostring(v["username"]):upper() == tostring(playerUsername):upper()) then
					accountState = "haveUsername"
					break
				end

				if not (getServerOwners(playerSerial)) then
					if (tostring(v["serial"]):upper() == tostring(playerSerial):upper()) then
						accountState = "haveAccount"
						break
					end		
				end
			end
		end
		
		return accountState
	end
end

 

Edited by Dzsozi (h03)
Link to comment

An example of what I mean might help you out:

 

Server side:

function whateverEventYouAreUsing() -- The event that initializes login panel server side
  triggerClientEvent(source, "theClientSideEventThatInitializesLoginPanel", resourceRoot, getPlayerAccountState(source))
end

Client side:

function theClientSideEventThatInitializesLoginPanel(accountState)
  if (accountState == "haveAccount") then
	-- Do whatever you want when the player has an account
  else
	-- Do whatever you want when the player doesn't have an account
  end
end
addEvent("theClientSideEventThatInitializesLoginPanel", true)
addEventHandler("theClientSideEventThatInitializesLoginPanel", resourceRoot, theClientSideEventThatInitializesLoginPanel)

 

Link to comment

But on client side I need to use the function like on server side, so I need to call the function and then return the value given on server side, I want to use it inside a render function so like accountState = getPlayerAccountState(localPlayer), and then based on that I can disable or enable the register button, change it's color, add tooltip, whatever.

Link to comment

That'd be really inefficient calling this function over and over yet, that ain't possible I guess. A really efficient way that just come in my mind is that you initialize the account state when the player joins the server and store it in a global variable client side.

An example:

accountState = nil

function theClientSideEventThatInitializesLoginPanel(accState)
  accountState = accState
end
addEvent("theClientSideEventThatInitializesLoginPanel", true)
addEventHandler("theClientSideEventThatInitializesLoginPanel", resourceRoot, theClientSideEventThatInitializesLoginPanel)

function render() -- Your rendering function
  -- Here you can use the accountState variable however you like.
end

 

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