G-Stefan Posted June 30, 2016 Share Posted June 30, 2016 The client script is: GUIEditor = { button = {}, window = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(0, 0, 312, 206, "Welcome to ...", false) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.button[1] = guiCreateButton(31, 31, 239, 51, "Login", false, GUIEditor.window[1]) guiSetFont(GUIEditor.button[1], "sa-header") guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FF1BFB03") GUIEditor.button[2] = guiCreateButton(31, 110, 239, 51, "Register", false, GUIEditor.window[1]) guiSetFont(GUIEditor.button[2], "sa-header") guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FFFDE801") addEventHandler("onClientGUIClick", GUIEditor.button[2], openRegisterPanel, false) end ) function openRegisterPanel(button,state) if button == "left" and state == "up" then guiSetVisible(GUIEditor.window[1],false) registerWindow = guiCreateWindow(0, 0, 239, 328, "Register if you dont have an account", false) guiWindowSetSizable(registerWindow, false) userLabel = guiCreateLabel(10, 27, 88, 45, "User", false, registerWindow) guiSetFont(userLabel, "sa-header") guiLabelSetColor(userLabel, 253, 232, 1) editUser = guiCreateEdit(105, 37, 124, 26, "", false, registerWindow) passLabel = guiCreateLabel(10, 82, 88, 45, "Pass", false, registerWindow) guiSetFont(passLabel, "sa-header") guiLabelSetColor(passLabel, 253, 232, 1) editPass = guiCreateEdit(105, 91, 124, 26, "", false, registerWindow) registerButton = guiCreateButton(21, 148, 198, 57, "Register", false, registerWindow) guiSetFont(registerButton, "sa-header") guiSetProperty(registerButton, "NormalTextColour", "FF36FC01") backButton = guiCreateButton(20, 235, 198, 57, "Back", false, registerWindow) guiSetFont(backButton, "sa-header") guiSetProperty(backButton, "NormalTextColour", "FFFD0000") addEventHandler("onClientGUIClick",registerButton,accountsDataBase, false) end end function accountsDataBase(button,state) if button == "left" and state == "up" then newUser = tostring(guiGetText(editUser)) newPass = tostring(guiGetText(editPass)) if newUser and newPass then triggerServerEvent("saveAccountInDatabase",resourceRoot) else outputChatBox("Please insert an username/password") end end end addCommandHandler("test",accountsDataBase) The server script: auxVar = 0 addEvent("saveAccountInDatabase",true) function xmlAccountsDataBase() accountsXML = xmlLoadFile("accounts.xml") if accountsXML then outputChatBox("accounts.xml loaded") accountsTable = xmlNodeGetChildren(accountsXML) for i,v in ipairs (accountsTable) do if newUser == tostring(v) then auxVar = 1 end end if auxVar == 0 then accountUsername = xmlCreateChild(accountsXML,newUser) xmlNodeSetAttribute(accountUsername,"password",newPass) xmlNodeSetAttribute(accountUsername,"money",0) end xmlSaveFile(accountsXML) else outputChatBox("creating accounts.xml") xmlCreateFile("accounts.xml","accounts") accountUsername = xmlCreateChild(accountsXML,newUser) xmlNodeSetAttribute(accountUsername,"password",newPass) xmlNodeSetAttribute(accountUsername,"money",0) xmlSaveFile(accountsXML) end end addEventHandler("saveAccountInDatabase",root,xmlAccountsDataBase) It gives me errors at al xml functions (request node at argument 1) Link to comment
Noki Posted July 2, 2016 Share Posted July 2, 2016 You never defined accountsXML in your else statement. So it's trying to open a nil value instead of a file handler. Simply define accountsXML and it should work. else outputChatBox("creating accounts.xml") accountsXML = xmlCreateFile("accounts.xml","accounts") accountUsername = xmlCreateChild(accountsXML,newUser) xmlNodeSetAttribute(accountUsername,"password",newPass) xmlNodeSetAttribute(accountUsername,"money",0) xmlSaveFile(accountsXML) end 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