Jump to content

Save system to non-XML


Sex*

Recommended Posts

So i have a XML saving system but its very laggy. How to make it non-XML? Im using also savePlayerData and loadPlayerData, i know that these are laggy but im gonna replace them later. Right now i just want to overmake it to non-XML.

function loadPlayerData (player,datatype) 
  local playerIP = getPlayerSerial (player) 
  if (playerIP) then 
    local root = xmlLoadFile ("users.xml") 
    if (root) then 
      local usersNode = xmlFindChild (root,"user",0) 
      if (usersNode) then 
        local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. getPlayerSerial(player),0) 
        if not (playerRootNode == false) then 
          local playerData = xmlNodeGetAttribute (playerRootNode,datatype) 
          if (playerData) then 
            xmlUnloadFile (root) 
            return playerData 
          else 
            xmlNodeSetAttribute (playerRootNode,datatype,0) 
            xmlSaveFile (root) 
            xmlUnloadFile (root) 
            return 0 
          end 
        else 
          local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. getPlayerSerial(player)) 
          xmlNodeSetAttribute (playerRootNode,datatype,0) 
          xmlSaveFile (root) 
          xmlUnloadFile (root) 
          return 0 
        end 
      end 
    end 
  end 
end 
  
function savePlayerData (player,datatype,newvalue) 
  local playerIP = getPlayerSerial (player) 
  if (playerIP) then 
    local root = xmlLoadFile ("users.xml") 
    if (root) then 
      local usersNode = xmlFindChild (root,"user",0) 
      if (usersNode) then 
        local playerRootNode = xmlFindChild (usersNode,"SERIAL_" .. getPlayerSerial(player),0) 
        if not (playerRootNode == false) then 
          local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue) 
          xmlSaveFile (root) 
          xmlUnloadFile (root) 
          return newNodeValue 
        else 
          local playerRootNode = xmlCreateChild (usersNode,"SERIAL_" .. getPlayerSerial(player)) 
          local newNodeValue = xmlNodeSetAttribute (playerRootNode,datatype,newvalue) 
          xmlSaveFile (root) 
          xmlUnloadFile (root) 
          return newNodeValue 
        end 
      end 
    end 
  end 
end 
  

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...