maky55 Posted March 31, 2015 Share Posted March 31, 2015 Hey again . The newbie scripter here. Well this may seem real stupid thing to say, but I don't know how to add a register button to my login gui :\. I've looked all over for a register function on the wiki, and i have found: account addAccount ( string name, string pass ) I know it's a server side function, and i've tried messing about with the script to get it to register an account, but no luck here. Any help with this would be appreciated! Server: local posX, posY, posZ = 2584.9523925781, -2209.318359375, 1.9927320480347 local thePlayer = source function loginHandler(username, password) local account = getAccount(username, password) if ( account ) then local loggin = logIn(source, account, password) if ( loggin ) then spawnPlayer(source, posX, posY, posZ) fadeCamera(source, true) setCameraTarget(source, source) outputChatBox("Wow, you actually made it on", source) triggerClientEvent(source, "hideLoginWindow", source) end else outputChatBox("Invalid username or password!",source) end end addEvent("submitLogin", true) addEventHandler("submitLogin", getRootElement(), loginHandler) function deathHandler() spawnPlayer(source, posX, posY, posZ) fadeCamera(source, true) setCameraTarget(source, source) end addEventHandler("onPlayerWasted", getRootElement(), deathHandler) Client: local playerName = getPlayerName(localPlayer) local guiElements = { } function clientSubmitLogin() local username = guiGetText(guiElements["edit_user"]) local password = guiGetText(guiElements["edit_pass"]) if ( username ~= "" and password ~= "" ) then triggerServerEvent("submitLogin", localPlayer, username, password) else outputChatBox("Please enter a username and password.") end end function createLoginWindow() guiElements["login_window"] = guiCreateWindow(0.375, 0.375, 0.25, 0.25, "Please enter your Username and Password", true) guiCreateLabel(0.0825, 0.225, 0.25, 0.25, "Username", true, guiElements["login_window"]) guiCreateLabel(0.0825, 0.425, 0.25, 0.25, "Password", true, guiElements["login_window"]) guiElements["edit_user"] = guiCreateEdit(0.415, 0.2, 0.5, 0.15, "", true, guiElements["login_window"]) guiElements["edit_pass"] = guiCreateEdit(0.415, 0.4, 0.5, 0.15, "", true, guiElements["login_window"]) guiEditSetMaxLength(guiElements["edit_user"], 20) guiEditSetMaxLength(guiElements["edit_pass"], 20) guiElements["login_button"] = guiCreateButton(0.415, 0.7, 0.25, 0.20, "Log In", true, guiElements["login_window"]) addEventHandler("onClientGUIClick", guiElements["login_button"], clientSubmitLogin, false) end addEventHandler("onClientResourceStart", resourceRoot, function () createLoginWindow() outputChatBox("Welcome to My MTA:SA Server, please log in.") showCursor(true) guiSetInputEnabled(true) end ) function hideLoginWindow() guiSetInputEnabled(false) showCursor(false) if ( isElement ( guiElements["login_window"] ) ) then destroyElement ( guiElements["login_window"] ) end end addEvent("hideLoginWindow", true) addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) Meta: <meta> <info author="Tiger" version="1.0" type="gamemode" name="Server" description="a simple spawn script" /> <script src="Server\Server_Script.lua" /> <script src="Client\gui.lua" type="client" /> </meta> Just for fun, here is what I tried to edit it too , atleast I tried : Server: local posX, posY, posZ = 2584.9523925781, -2209.318359375, 1.9927320480347 local thePlayer = source function registerHandler(username, password) local account = getAccount(username, password) if ( account ) then local register = addAccount(username, password) if ( register ) then outputChatbox("You have registered your account", source) end end end addEvent("submitRegister", true) addEventHandler("submitRegister", getRootElement(), registerHandler) function loginHandler(username, password) local account = getAccount(username, password) if ( account ) then local loggin = logIn(source, account, password) if ( loggin ) then spawnPlayer(source, posX, posY, posZ) fadeCamera(source, true) setCameraTarget(source, source) outputChatBox("Wow, you actually made it on", source) triggerClientEvent(source, "hideLoginWindow", source) end else outputChatBox("Invalid username or password!",source) end end addEvent("submitLogin", true) addEventHandler("submitLogin", getRootElement(), loginHandler) function deathHandler() spawnPlayer(source, posX, posY, posZ) fadeCamera(source, true) setCameraTarget(source, source) end addEventHandler("onPlayerWasted", getRootElement(), deathHandler) Client: local playerName = getPlayerName(localPlayer) local guiElements = { } function clientSubmitLogin() local username = guiGetText(guiElements["edit_user"]) local password = guiGetText(guiElements["edit_pass"]) if ( username ~= "" and password ~= "" ) then triggerServerEvent("submitLogin", localPlayer, username, password) else outputChatBox("Please enter a username and password.") end end function clientSubmitPassword() local username = guiGetText(guiElements["edit_user"]) local password = guiGetText(guiElements["edit_pass"]) if ( username ~= "" and password ~= "" ) then triggerServerEvent("submitRegister", localPlayer, username, password) else outputChatBox("Please enter a username and password to create an account.") end end function createLoginWindow() guiElements["login_window"] = guiCreateWindow(0.375, 0.375, 0.25, 0.25, "Please enter your Username and Password", true) guiCreateLabel(0.0825, 0.225, 0.25, 0.25, "Username", true, guiElements["login_window"]) guiCreateLabel(0.0825, 0.425, 0.25, 0.25, "Password", true, guiElements["login_window"]) guiElements["edit_user"] = guiCreateEdit(0.415, 0.2, 0.5, 0.15, "", true, guiElements["login_window"]) guiElements["edit_pass"] = guiCreateEdit(0.415, 0.4, 0.5, 0.15, "", true, guiElements["login_window"]) guiEditSetMaxLength(guiElements["edit_user"], 20) guiEditSetMaxLength(guiElements["edit_pass"], 20) guiElements["register_button"] = guiCreateButton(0.315, 0.7, 0.25, 0.20, "Register", true, guiElements["login_window"]) guiElements["login_button"] = guiCreateButton(0.415, 0.7, 0.25, 0.20, "Log In", true, guiElements["login_window"]) addEventHandler("onClientGUIClick", guiElements["login_button"], clientSubmitLogin, false) end addEventHandler("onClientResourceStart", resourceRoot, function () createLoginWindow() outputChatBox("Welcome to My MTA:SA Server, please log in.") showCursor(true) guiSetInputEnabled(true) end ) function hideLoginWindow() guiSetInputEnabled(false) showCursor(false) if ( isElement ( guiElements["login_window"] ) ) then destroyElement ( guiElements["login_window"] ) end end addEvent("hideLoginWindow", true) addEventHandler("hideLoginWindow", getRootElement(), hideLoginWindow) thanks, Tiger. Link to comment
Castillo Posted March 31, 2015 Share Posted March 31, 2015 outputChatbox That's wrong, the function name is outputChatBox Link to comment
maky55 Posted March 31, 2015 Author Share Posted March 31, 2015 (edited) outputChatbox That's wrong, the function name is outputChatBox Thanks for pointing that out for me , but that bit doesn't matter too much, cause it's the script that didn't work. I just need to know how to add a register button. Thanks anyway. Edited March 31, 2015 by Guest Link to comment
Castillo Posted March 31, 2015 Share Posted March 31, 2015 An error such as that can stop parts of the script from working. Anyway, what is the problem? and, did you add the resource to the ACL group "Admin"? since addAccount requires ACL rights. Link to comment
maky55 Posted March 31, 2015 Author Share Posted March 31, 2015 Well, the button came up with the word 'Register' on it, but it didn't register. What I added was probably wrong anyway. And the script was already ACL. And I'm getting no errors in debugscript 3 Link to comment
Castillo Posted March 31, 2015 Share Posted March 31, 2015 local account = getAccount(username, password) if ( account ) then Here is your problem, you are checking if the account already exists, then you add it, which makes no sense. Change these two lines to: local account = getAccount ( username ) if ( not account ) then Link to comment
maky55 Posted March 31, 2015 Author Share Posted March 31, 2015 (edited) local account = getAccount(username, password) if ( account ) then Here is your problem, you are checking if the account already exists, then you add it, which makes no sense. Change these two lines to: local account = getAccount ( username ) if ( not account ) then Thank you at first, it didn't work, but I did some editing and got it to work!: At first, I did this: guiElements["register_button"] = guiCreateButton(0.715, 0.7, 0.25, 0.20, "Register", true, guiElements["login_window"]) guiElements["login_button"] = guiCreateButton(0.415, 0.7, 0.25, 0.20, "Log In", true, guiElements["login_window"]) addEventHandler("onClientGUIClick", guiElements["login_button"], clientSubmitLogin, false) addEventHandler("onClientGUIClick", guiElements["login_button"], clientSubmitRegister, false) then I realised I didn't change: guiElements["login_button"] But I changed it to guiElements["register_button"] and it worked . Thank you so much, you've helped alot! But, how do I delete accounts? I made like 20 testing the script? Edited March 31, 2015 by Guest Link to comment
maky55 Posted March 31, 2015 Author Share Posted March 31, 2015 You're welcome. Can I ask how you can delete accounts from the server? I created many when testing the script. Link to comment
Castillo Posted March 31, 2015 Share Posted March 31, 2015 removeAccount And if you want to remove every account, you can use this function: getAccounts which returns a table, loop it and use removeAccount function. 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