Advertisement
Extreemhost

XML System

Jun 25th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. -- XML SYSTEM
  2. -- Be Extreemhost
  3. local XML = {
  4.     file = 'GameXML.xml',
  5.     xmlFile = false,
  6. }
  7. function XMLClientStart()
  8.     XML.xmlFile = checkForXMLFile()
  9. end
  10.  
  11. function XMLClientStop()
  12.     if xmlData.xmlFile then
  13.         XML:xmlUnloadFile(XML.xmlFile)
  14.     end
  15. end
  16.  
  17. function checkForXMLFile()
  18.     if not XML.xmlFile then
  19.         local xmlFile = XML:xmlLoadFile(XML.file, 'xmlData')
  20.         if xmlFile then
  21.             return xmlFile
  22.         else
  23.             xmlFile = XML:xmlCreateFile(XML.file, 'xmlData')
  24.             XML:xmlSaveFile(xmlFile)
  25.             return xmlFile
  26.         end
  27.     else
  28.         return XML.xmlFile
  29.     end
  30. end
  31.  
  32. -- XML LOAD
  33. function loadXML(xmlNode, defaultValues)
  34.     if XML.xmlFile then
  35.         if xmlNode then
  36.             local dataNode = XML:xmlFindChild(XML.xmlFile, xmlNode, 0)
  37.             if not dataNode then
  38.                 dataNode = XML:xmlCreateChild(XML.xmlFile, xmlNode)
  39.                 XML:xmlNodeSetValue(dataNode, defaultValues)
  40.                 XML:xmlSaveFile(XML.xmlFile)
  41.                 return defaultValues
  42.             end
  43.             if dataNode then
  44.                 local returnData = XML:xmlNodeGetValue(dataNode)
  45.                 if returnData then
  46.                     return returnData
  47.                 else
  48.                     return defaultValues
  49.                 end
  50.             end
  51.         else
  52.             return false
  53.         end
  54.     end
  55. end
  56.  
  57. -- XML SAVE
  58. function saveXML(xmlNode, valueToSave)
  59.     if XML.xmlFile then
  60.         if xmlNode then
  61.             local dataNode = XML:xmlFindChild(XML.xmlFile, xmlNode, 0)
  62.             if not dataNode then
  63.                 dataNode = XML:xmlCreateChild(XML.xmlFile, xmlNode)
  64.             end
  65.             if dataNode then
  66.                 XML:xmlNodeSetValue(dataNode, valueToSave)
  67.                 XML:xmlSaveFile(XML.xmlFile)
  68.                 return true
  69.             end
  70.             return false
  71.         else
  72.             return false
  73.         end
  74.     end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement