Dzsozi (h03) Posted September 7, 2018 Share Posted September 7, 2018 (edited) 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 September 7, 2018 by Dzsozi (h03) Link to comment
Mqtyx Posted September 7, 2018 Share Posted September 7, 2018 (edited) Use triggerClientEvent in order to send the data you want to be sent to client side. triggerClientEvent Edited September 7, 2018 by Mqtyx Link to comment
Dzsozi (h03) Posted September 7, 2018 Author Share Posted September 7, 2018 That doesn't really help me out. Link to comment
Mqtyx Posted September 7, 2018 Share Posted September 7, 2018 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
Dzsozi (h03) Posted September 7, 2018 Author Share Posted September 7, 2018 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
Mqtyx Posted September 7, 2018 Share Posted September 7, 2018 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 1 Link to comment
Dzsozi (h03) Posted September 7, 2018 Author Share Posted September 7, 2018 Got it working and now I understand how it works. Thank you! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now