jkub Posted August 25, 2012 Share Posted August 25, 2012 I am trying to make a house system for my new server, I do understand that there are several house systems uploaded to the community but please do understand I am trying to make my own with a couple of unique features. I have been coding for quiet a long time now and what would a coder do with his relative scripting knowledge if he just downloaded what he wanted from the community? I have tried troubleshooting this problem several times myself but I just can't figure it out. This was working fine when I first started out but now nothing is saving to the xml file. Basically is supposed to happen is the information input into the building gui (in the text fields) is saved into an xml file as a "property node". The file is saved and the script later reopens the file and loads all houses (property nodes) from the file and creates the houses. xmlSaveFile doesn't seem to work, even though it returns true to the chatbox. Here is some code function checkData() propertyData = {} for i, guiElement in pairs ( buildingGUI ) do if i == "field" then for k, field in pairs ( guiElement ) do propertyData["entMarkerX"] = guiGetText ( buildingGUI["field"].entMarkerX ) propertyData["entMarkerY"] = guiGetText ( buildingGUI["field"].entMarkerY ) propertyData["entMarkerZ"] = guiGetText ( buildingGUI["field"].entMarkerZ ) propertyData["entMarkerInt"] = guiGetText ( buildingGUI["field"].entMarkerInt ) propertyData["entMarkerDim"] = guiGetText ( buildingGUI["field"].entMarkerDim ) propertyData["exitMarkerX"] = guiGetText ( buildingGUI["field"].exitMarkerX ) propertyData["exitMarkerY"] = guiGetText ( buildingGUI["field"].exitMarkerY ) propertyData["exitMarkerZ"] = guiGetText ( buildingGUI["field"].exitMarkerZ ) propertyData["exitMarkerInt"] = guiGetText ( buildingGUI["field"].exitMarkerInt ) propertyData["exitMarkerDim"] = guiGetText ( buildingGUI["field"].exitMarkerDim ) propertyData["entTeleX"] = guiGetText ( buildingGUI["field"].entTeleX ) propertyData["entTeleY"] = guiGetText ( buildingGUI["field"].entTeleY ) propertyData["entTeleZ"] = guiGetText ( buildingGUI["field"].entTeleZ ) propertyData["entTeleRot"] = guiGetText ( buildingGUI["field"].entTeleRot ) propertyData["entTeleInt"] = guiGetText ( buildingGUI["field"].entTeleInt ) propertyData["entTeleDim"] = guiGetText ( buildingGUI["field"].entTeleDim ) propertyData["exitTeleX"] = guiGetText ( buildingGUI["field"].exitTeleX ) propertyData["exitTeleY"] = guiGetText ( buildingGUI["field"].exitTeleY ) propertyData["exitTeleZ"] = guiGetText ( buildingGUI["field"].exitTeleZ ) propertyData["exitTeleRot"] = guiGetText ( buildingGUI["field"].exitTeleRot ) propertyData["exitTeleInt"] = guiGetText ( buildingGUI["field"].exitTeleInt ) propertyData["exitTeleDim"] = guiGetText ( buildingGUI["field"].exitTeleDim ) propertyData["drivewayX"] = guiGetText ( buildingGUI["field"].drivewayX ) propertyData["drivewayY"] = guiGetText ( buildingGUI["field"].drivewayY ) propertyData["drivewayZ"] = guiGetText ( buildingGUI["field"].drivewayZ ) propertyData["drivewayRot"] = guiGetText ( buildingGUI["field"].drivewayRot ) propertyData["cacheX"] = guiGetText ( buildingGUI["field"].cacheX ) propertyData["cacheY"] = guiGetText ( buildingGUI["field"].cacheY ) propertyData["cacheZ"] = guiGetText ( buildingGUI["field"].cacheZ ) propertyData["cacheInt"] = guiGetText ( buildingGUI["field"].cacheInt ) propertyData["cacheDim"] = guiGetText ( buildingGUI["field"].cacheDim ) propertyData["propertyName"] = guiGetText ( buildingGUI["field"].propertyName ) propertyData["propertyPrice"] = guiGetText ( buildingGUI["field"].propertyPrice ) if guiGetText ( field ) == "" then ready = false break else ready = true end end end end if ready == true then action_Create_Property ( propertyData ) else call ( getResourceFromName ( "prompt" ), "outputPromptBoxClient", "ERROR: There appears to be required information missing from one or more fields, please make sure all information is given", getLocalPlayer() ) end end function action_Create_Property ( propertyDataTable ) propertyDatabase = xmlLoadFile ( "data/client/properties.xml" ) propertyMasterNode = xmlCreateChild ( propertyDatabase, "property" ) xmlNodeSetAttribute ( propertyMasterNode, "name", propertyData["propertyName"] ) xmlNodeSetAttribute ( propertyMasterNode, "price", propertyData["propertyPrice"] ) xmlNodeSetAttribute ( propertyMasterNode, "owner", "" ) propertyLocationMasterNode = xmlCreateChild ( propertyMasterNode, "location" ) entMarkerMasterNode = xmlCreateChild ( propertyLocationMasterNode, "entrance_marker" ) exitMarkerMasterNode = xmlCreateChild ( propertyLocationMasterNode, "exit_marker" ) entTeleMasterNode = xmlCreateChild ( propertyLocationMasterNode, "entrance_teleport" ) exitTeleMasterNode = xmlCreateChild ( propertyLocationMasterNode, "exit_teleport" ) drivewayMasterNode = xmlCreateChild ( propertyLocationMasterNode, "driveway" ) cacheMasterNode = xmlCreateChild ( propertyLocationMasterNode, "cache" ) xmlNodeSetAttribute ( entMarkerMasterNode, "x", propertyData["entMarkerX"] ) xmlNodeSetAttribute ( entMarkerMasterNode, "y", propertyData["entMarkerY"] ) xmlNodeSetAttribute ( entMarkerMasterNode, "z", propertyData["entMarkerZ"] ) xmlNodeSetAttribute ( entMarkerMasterNode, "int", propertyData["entMarkerInt"] ) xmlNodeSetAttribute ( entMarkerMasterNode, "dim", propertyData["entMarkerDim"] ) xmlNodeSetAttribute ( exitMarkerMasterNode, "x", propertyData["exitMarkerX"] ) xmlNodeSetAttribute ( exitMarkerMasterNode, "y", propertyData["exitMarkerY"] ) xmlNodeSetAttribute ( exitMarkerMasterNode, "z", propertyData["exitMarkerZ"] ) xmlNodeSetAttribute ( exitMarkerMasterNode, "int", propertyData["exitMarkerInt"] ) xmlNodeSetAttribute ( exitMarkerMasterNode, "dim", propertyData["exitMarkerDim"] ) xmlNodeSetAttribute ( entTeleMasterNode, "x", propertyData["entTeleX"] ) xmlNodeSetAttribute ( entTeleMasterNode, "y", propertyData["entTeleY"] ) xmlNodeSetAttribute ( entTeleMasterNode, "z", propertyData["entTeleZ"] ) xmlNodeSetAttribute ( entTeleMasterNode, "rot", propertyData["entTeleRot"] ) xmlNodeSetAttribute ( entTeleMasterNode, "int", propertyData["entTeleInt"] ) xmlNodeSetAttribute ( entTeleMasterNode, "dim", propertyData["entTeleDim"] ) xmlNodeSetAttribute ( exitTeleMasterNode, "x", propertyData["exitTeleX"] ) xmlNodeSetAttribute ( exitTeleMasterNode, "y", propertyData["exitTeleY"] ) xmlNodeSetAttribute ( exitTeleMasterNode, "z", propertyData["exitTeleZ"] ) xmlNodeSetAttribute ( exitTeleMasterNode, "rot", propertyData["exitTeleRot"] ) xmlNodeSetAttribute ( exitTeleMasterNode, "int", propertyData["exitTeleInt"] ) xmlNodeSetAttribute ( exitTeleMasterNode, "dim", propertyData["exitTeleDim"] ) xmlNodeSetAttribute ( drivewayMasterNode, "x", propertyData["drivewayX"] ) xmlNodeSetAttribute ( drivewayMasterNode, "y", propertyData["drivewayY"] ) xmlNodeSetAttribute ( drivewayMasterNode, "z", propertyData["drivewayZ"] ) xmlNodeSetAttribute ( drivewayMasterNode, "rot", propertyData["drivewayRot"] ) xmlNodeSetAttribute ( cacheMasterNode, "x", propertyData["cacheX"] ) xmlNodeSetAttribute ( cacheMasterNode, "y", propertyData["cacheY"] ) xmlNodeSetAttribute ( cacheMasterNode, "z", propertyData["cacheZ"] ) xmlNodeSetAttribute ( cacheMasterNode, "int", propertyData["cacheInt"] ) xmlNodeSetAttribute ( cacheMasterNode, "dim", propertyData["cacheDim"] ) xmlSaveFile ( propertyDatabase ) xmlUnloadFile ( propertyDatabase ) loadPropertiesFromFile() for i, field in pairs ( buildingGUI["field"] ) do guiSetText ( field, "" ) end call ( getResourceFromName ( "prompt" ), "outputPromptBoxClient", "Success: Property has been successfully added to the server", getLocalPlayer() ) end Link to comment
Jaysds1 Posted August 25, 2012 Share Posted August 25, 2012 try this: function checkData() propertyData = {} for i, guiElement in pairs ( buildingGUI ) do if i == "field" then for _, field in ipairs ( guiElement ) do propertyData["entMarkerX"] = guiGetText ( buildingGUI["field"].entMarkerX ) propertyData["entMarkerY"] = guiGetText ( buildingGUI["field"].entMarkerY ) propertyData["entMarkerZ"] = guiGetText ( buildingGUI["field"].entMarkerZ ) propertyData["entMarkerInt"] = guiGetText ( buildingGUI["field"].entMarkerInt ) propertyData["entMarkerDim"] = guiGetText ( buildingGUI["field"].entMarkerDim ) propertyData["exitMarkerX"] = guiGetText ( buildingGUI["field"].exitMarkerX ) propertyData["exitMarkerY"] = guiGetText ( buildingGUI["field"].exitMarkerY ) propertyData["exitMarkerZ"] = guiGetText ( buildingGUI["field"].exitMarkerZ ) propertyData["exitMarkerInt"] = guiGetText ( buildingGUI["field"].exitMarkerInt ) propertyData["exitMarkerDim"] = guiGetText ( buildingGUI["field"].exitMarkerDim ) propertyData["entTeleX"] = guiGetText ( buildingGUI["field"].entTeleX ) propertyData["entTeleY"] = guiGetText ( buildingGUI["field"].entTeleY ) propertyData["entTeleZ"] = guiGetText ( buildingGUI["field"].entTeleZ ) propertyData["entTeleRot"] = guiGetText ( buildingGUI["field"].entTeleRot ) propertyData["entTeleInt"] = guiGetText ( buildingGUI["field"].entTeleInt ) propertyData["entTeleDim"] = guiGetText ( buildingGUI["field"].entTeleDim ) propertyData["exitTeleX"] = guiGetText ( buildingGUI["field"].exitTeleX ) propertyData["exitTeleY"] = guiGetText ( buildingGUI["field"].exitTeleY ) propertyData["exitTeleZ"] = guiGetText ( buildingGUI["field"].exitTeleZ ) propertyData["exitTeleRot"] = guiGetText ( buildingGUI["field"].exitTeleRot ) propertyData["exitTeleInt"] = guiGetText ( buildingGUI["field"].exitTeleInt ) propertyData["exitTeleDim"] = guiGetText ( buildingGUI["field"].exitTeleDim ) propertyData["drivewayX"] = guiGetText ( buildingGUI["field"].drivewayX ) propertyData["drivewayY"] = guiGetText ( buildingGUI["field"].drivewayY ) propertyData["drivewayZ"] = guiGetText ( buildingGUI["field"].drivewayZ ) propertyData["drivewayRot"] = guiGetText ( buildingGUI["field"].drivewayRot ) propertyData["cacheX"] = guiGetText ( buildingGUI["field"].cacheX ) propertyData["cacheY"] = guiGetText ( buildingGUI["field"].cacheY ) propertyData["cacheZ"] = guiGetText ( buildingGUI["field"].cacheZ ) propertyData["cacheInt"] = guiGetText ( buildingGUI["field"].cacheInt ) propertyData["cacheDim"] = guiGetText ( buildingGUI["field"].cacheDim ) propertyData["propertyName"] = guiGetText ( buildingGUI["field"].propertyName ) propertyData["propertyPrice"] = guiGetText ( buildingGUI["field"].propertyPrice ) if guiGetText ( field ) == "" then ready = false break; else ready = true end end end end if ready == true then action_Create_Property ( propertyData ) else call ( getResourceFromName ( "prompt" ), "outputPromptBoxClient", "ERROR: There appears to be required information missing from one or more fields, please make sure all information is given", getLocalPlayer() ) end end function action_Create_Property ( propertyDataTable ) local propertyDatabase = xmlLoadFile ( "data/client/properties.xml" ) local propertyMasterNode = xmlCreateChild ( propertyDatabase, "property" ) xmlNodeSetAttribute ( propertyMasterNode, "name", propertyDataTable["propertyName"] ) xmlNodeSetAttribute ( propertyMasterNode, "price", propertyDataTable["propertyPrice"] ) xmlNodeSetAttribute ( propertyMasterNode, "owner", "" ) local propertyLocationMasterNode = xmlCreateChild ( propertyMasterNode, "location" ) entMarkerMasterNode = xmlCreateChild ( propertyLocationMasterNode, "entrance_marker" ) exitMarkerMasterNode = xmlCreateChild ( propertyLocationMasterNode, "exit_marker" ) entTeleMasterNode = xmlCreateChild ( propertyLocationMasterNode, "entrance_teleport" ) exitTeleMasterNode = xmlCreateChild ( propertyLocationMasterNode, "exit_teleport" ) drivewayMasterNode = xmlCreateChild ( propertyLocationMasterNode, "driveway" ) cacheMasterNode = xmlCreateChild ( propertyLocationMasterNode, "cache" ) xmlNodeSetAttribute ( entMarkerMasterNode, "x", propertyDataTable["entMarkerX"] ) xmlNodeSetAttribute ( entMarkerMasterNode, "y", propertyDataTable["entMarkerY"] ) xmlNodeSetAttribute ( entMarkerMasterNode, "z", propertyDataTable["entMarkerZ"] ) xmlNodeSetAttribute ( entMarkerMasterNode, "int", propertyDataTable["entMarkerInt"] ) xmlNodeSetAttribute ( entMarkerMasterNode, "dim", propertyDataTable["entMarkerDim"] ) xmlNodeSetAttribute ( exitMarkerMasterNode, "x", propertyDataTable["exitMarkerX"] ) xmlNodeSetAttribute ( exitMarkerMasterNode, "y", propertyDataTable["exitMarkerY"] ) xmlNodeSetAttribute ( exitMarkerMasterNode, "z", propertyDataTable["exitMarkerZ"] ) xmlNodeSetAttribute ( exitMarkerMasterNode, "int", propertyDataTable["exitMarkerInt"] ) xmlNodeSetAttribute ( exitMarkerMasterNode, "dim", propertyDataTable["exitMarkerDim"] ) xmlNodeSetAttribute ( entTeleMasterNode, "x", propertyDataTable["entTeleX"] ) xmlNodeSetAttribute ( entTeleMasterNode, "y", propertyDataTable["entTeleY"] ) xmlNodeSetAttribute ( entTeleMasterNode, "z", propertyDataTable["entTeleZ"] ) xmlNodeSetAttribute ( entTeleMasterNode, "rot", propertyDataTable["entTeleRot"] ) xmlNodeSetAttribute ( entTeleMasterNode, "int", propertyDataTable["entTeleInt"] ) xmlNodeSetAttribute ( entTeleMasterNode, "dim", propertyDataTable["entTeleDim"] ) xmlNodeSetAttribute ( exitTeleMasterNode, "x", propertyDataTable["exitTeleX"] ) xmlNodeSetAttribute ( exitTeleMasterNode, "y", propertyDataTable["exitTeleY"] ) xmlNodeSetAttribute ( exitTeleMasterNode, "z", propertyDataTable["exitTeleZ"] ) xmlNodeSetAttribute ( exitTeleMasterNode, "rot", propertyDataTable["exitTeleRot"] ) xmlNodeSetAttribute ( exitTeleMasterNode, "int", propertyDataTable["exitTeleInt"] ) xmlNodeSetAttribute ( exitTeleMasterNode, "dim", propertyDataTable["exitTeleDim"] ) xmlNodeSetAttribute ( drivewayMasterNode, "x", propertyDataTable["drivewayX"] ) xmlNodeSetAttribute ( drivewayMasterNode, "y", propertyDataTable["drivewayY"] ) xmlNodeSetAttribute ( drivewayMasterNode, "z", propertyDataTable["drivewayZ"] ) xmlNodeSetAttribute ( drivewayMasterNode, "rot", propertyDataTable["drivewayRot"] ) xmlNodeSetAttribute ( cacheMasterNode, "x", propertyDataTable["cacheX"] ) xmlNodeSetAttribute ( cacheMasterNode, "y", propertyDataTable["cacheY"] ) xmlNodeSetAttribute ( cacheMasterNode, "z", propertyDataTable["cacheZ"] ) xmlNodeSetAttribute ( cacheMasterNode, "int", propertyDataTable["cacheInt"] ) xmlNodeSetAttribute ( cacheMasterNode, "dim", propertyDataTable["cacheDim"] ) xmlSaveFile ( propertyDatabase ) loadPropertiesFromFile() for _, field in ipairs ( buildingGUI["field"] ) do guiSetText ( field, "" ) end call ( getResourceFromName ( "prompt" ), "outputPromptBoxClient", "Success: Property has been successfully added to the server", getLocalPlayer() ) end Link to comment
Anderl Posted August 25, 2012 Share Posted August 25, 2012 I recommend you to use MySQL. Link to comment
Jaysds1 Posted August 25, 2012 Share Posted August 25, 2012 well, anything can be used, "MySQL,SQLite,XML" probably even the file functions: fileClose fileCreate fileDelete fileExists fileFlush fileGetPos fileGetSize fileIsEOF fileOpen fileRead fileRename fileSetPos fileWrite Link to comment
Anderl Posted August 25, 2012 Share Posted August 25, 2012 But using files you'll have to download them. More houses = bigger download. Link to comment
Jaysds1 Posted August 25, 2012 Share Posted August 25, 2012 I know, but i was saying that he could even store it in a file. Link to comment
jkub Posted August 27, 2012 Author Share Posted August 27, 2012 Thank you, Jaysds for the suggestion. I will try this here in a little bit when I start my test server back up for the night. I will get back on that when I have the results. @Anderl, I'd love to use MySQL instead but my lack of MySQL knowledge will prevent me from saving the houses this way. I've tried to learn it before but I didn't pick up on it. Link to comment
Anderl Posted August 27, 2012 Share Posted August 27, 2012 Thank you, Jaysds for the suggestion. I will try this here in a little bit when I start my test server back up for the night. I will get back on that when I have the results.@Anderl, I'd love to use MySQL instead but my lack of MySQL knowledge will prevent me from saving the houses this way. I've tried to learn it before but I didn't pick up on it. You can request help here or if you want, PM me. Link to comment
Jaysds1 Posted August 27, 2012 Share Posted August 27, 2012 damn didn't work... was there any errors in the debug? Link to comment
jkub Posted August 28, 2012 Author Share Posted August 28, 2012 Nevermind, I rewrote it a bit differently and it works now. Thanks anyways. 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