Strike27208 Posted November 2, 2016 Share Posted November 2, 2016 (edited) Hey , this is my code , He don't create the XML file and i tried this : ( Only Client ) function createXML() if source == vehPanel.button[1] then settings = xmlCreateFile("savedsettings.xml","settings") if guiCheckBoxGetSelected(vehPanel.checkbox[1]) then xmlNodeSetAttribute(settings, "car", "true") else xmlNodeSetAttribute(settings, "car", "false") end end addEventHandler("onClientGUIClick", getRootElement(), createXML) And this : function createXML() settings = xmlCreateFile("savedsettings.xml","settings") if guiCheckBoxGetSelected(vehPanel.checkbox[1]) then xmlNodeSetAttribute(settings, "car", "true") else xmlNodeSetAttribute(settings, "car", "false") end end addEventHandler("onClientResourceStart", getRootElement(), createXML) And this : function createXML() local exists = fileExists ( "savedsettings.xml" ) if not exists then settings = xmlCreateFile("savedsettings.xml","settings") if guiCheckBoxGetSelected(vehPanel.checkbox[1]) then xmlNodeSetAttribute(settings, "car", "true") else xmlNodeSetAttribute(settings, "car", "false") end end addEventHandler("onClientResourceStart", getRootElement(), createXML) And no one create xml , i need some help please , this is the end code : function load() local currentFile = xmlLoadFile ("savedsettings.xml") if xmlNodeGetAttribute(currentFile, "car") == "true" then guiCheckBoxSetSelected(vehPanel.checkbox[1], true) veh1() end end load() Edited November 2, 2016 by Strike27208 Link to comment
Dealman Posted November 2, 2016 Share Posted November 2, 2016 (edited) You might wanna save the file first. Use xmlSaveFile. Also, you're not properly closing an if statement in example 1 and 3. Edited November 2, 2016 by Dealman Link to comment
Strike27208 Posted November 2, 2016 Author Share Posted November 2, 2016 26 minutes ago, Dealman said: You might wanna save the file first. Use xmlSaveFile. Also, you're not properly closing an if statement in example 1 and 3. Thanks i used with this : function createXML() local exists = fileExists ( "savedsettings.xml" ) if not exists then settings = xmlCreateFile("savedsettings.xml","settings") if guiCheckBoxGetSelected(vehPanel.checkbox[1]) then xmlNodeSetAttribute(settings, "car", "true") else xmlNodeSetAttribute(settings, "car", "false") end end addEventHandler("onClientPlayerJoin", getRootElement(), createXML) And this work but i find i have a big problem with xml , if you know how to work with xml please help me , http://imgur.com/WVVhsb9 Line : if guiCheckBoxGetSelected( vehPanel.checkbox[1] ) == true then xmlNodeSetAttribute(settings, "bandito", "true") --------My Stuff end Why i get that error ? this part is in another function , i don't know if matter or not . Link to comment
Dealman Posted November 2, 2016 Share Posted November 2, 2016 Mind posting all the code? Link to comment
Strike27208 Posted November 2, 2016 Author Share Posted November 2, 2016 It's start like this : function createXML() local exists = fileExists ( "savedsettings.xml" ) if not exists then settings = xmlCreateFile("savedsettings.xml","settings") if guiCheckBoxGetSelected(vehPanel.checkbox[1]) then xmlNodeSetAttribute(settings, "car", "true") else xmlNodeSetAttribute(settings, "car", "false") end end addEventHandler("onClientPlayerJoin", getRootElement(), createXML) ----Gui vehPanel.checkbox[1] = guiCreateCheckBox(0.03, 0.02, 0.05, 0.07, "", false, true, vehPanel.tab[1]) vehPanel.button[1] = guiCreateButton(0.71, 0.80, 0.24, 0.15, "Save", true, vehPanel.tab[1]) ---Here save my checkbox addEventHandler ( "onClientGUIClick", getRootElement(), function() if source == vehPanel.button[1] then xmlSaveFile(settings) xmlUnloadFile(settings) guiSetVisible( vehPanel.window[1], false ) end end ) ----------Function function veh1(file, success) local exists = fileExists ( "vehicles/car.txd" and "vehicles/car.dff" ) if not exists then exports.notification:outputTopBar("[ERROR] You don't have this car .", 255, 0, 0) guiCheckBoxSetSelected(vehPanel.checkbox[1],false) currentTrack = playSound ( "error.wav" ) end if guiCheckBoxGetSelected( vehPanel.checkbox[1] ) == true then xmlNodeSetAttribute(settings, "car", "true") local exists = fileExists ( "vehicles/car.txd" and "vehicles/car.dff" ) if exists then exports.notification:outputTopBar("Car mod enabled", 0, 255, 0) local changeTXD = engineLoadTXD ("vehicles/car.txd") local changeDFF = engineLoadDFF ("vehicles/car.dff") engineImportTXD ( changeTXD, 568 ) engineReplaceModel (changeDFF, 568) guiLabelSetColor ( vehPanel.label[1], 0, 255, 0 ) end else xmlNodeSetAttribute(settings, "car", "false") local exists = fileExists ( "vehicles/bandito.txd" and "vehicles/bandito.dff" ) if exists then exports.notification:outputTopBar("Car mod disabled", 255, 0, 0) engineRestoreModel ( 568 ) guiLabelSetColor ( vehPanel.label[1], 219, 219, 219 ) end end end addEventHandler ( "onClientGUIClick", vehPanel.checkbox[1], veh1, false) ---------End function load() local currentFile = xmlLoadFile ("savedsettings.xml") if xmlNodeGetAttribute(currentFile, "car") == "true" then guiCheckBoxSetSelected(vehPanel.checkbox[1], true) veh1() end end load() This is it. Link to comment
MIKI785 Posted November 3, 2016 Share Posted November 3, 2016 You should mark the lines with the warnings for us, since the numbers are different here. Anyway, on lines 37 and 48 settings is nil. I guess it's nil because you used xmlUnloadFile previously and didn't load it again. Also, local exists = fileExists ( "vehicles/bandito.txd" and "vehicles/bandito.dff" ) is wrong. That will only check for the second file, that is the dff. You have to use it like this: local exists = fileExists("vehicles/bandito.txd") and fileExists("vehicles/bandito.dff") Link to comment
Strike27208 Posted November 3, 2016 Author Share Posted November 3, 2016 Thanks MIKI785 , now if i get nil from xml , that mean he dont find that shortcut , i have this : xmlNodeSetAttribute(settings, "car", "true") -- nil argunment 1 , argument 1 is "settings" . He don't find xml , i tried to put local currentFile = xmlLoadFile ("savedsettings.xml") No more warrnings but he don't change in savedsettings.xml nothing , all are false . , 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