Jump to content

Confusing Problem (XML)


Recommended Posts

Hey,

I'm working on buymap script and want to do this with xml.

So i created this script:

addEvent("onMapStarting")
addEventHandler('onMapStarting', getRootElement(),
function()
    local mapName = getMapName()
	 if mapName and mapName ~= "None" then
	  saveMapData ("MapName",getMapName())
	 end 
end
)
 
function loadMapData (player,datatype)
 local mapName = getMapName()
 if mapName and mapName ~= "None" then
   local root = xmlLoadFile ("maps.xml")
   if (root) then
     local MapsNode = xmlFindChild (root,"map",0)
     if (MapsNode) then
       local MapRootNode = xmlFindChild (MapNode,"MAP_" .. getMapName() .. "||",0)
       if not (MapRootNode == false) then
         local MapData = xmlNodeGetAttribute (MapRootNode,datatype)
         if (MapData) then
           xmlUnloadFile (root)
           return MapData
         else
           xmlNodeSetAttribute (MapRootNode,datatype,0)
           xmlSaveFile (root)
           xmlUnloadFile (root)
           return 0
         end
       else
         local MapRootNode = xmlCreateChild (MapNode,"MAP_" .. getMapName().. "||")
         xmlNodeSetAttribute (MapRootNode,datatype,0)
         xmlSaveFile (root)
         xmlUnloadFile (root)
         return 0
       end
     end
   end
 end
end
 
function saveMapData (datatype,newvalue)
 local mapName = getMapName()
  if mapName and mapName ~= "None" then
   local root = xmlLoadFile ("maps.xml")
   if (root) then
     local MapNode = xmlFindChild (root,"map",0)
         if (MapNode) then
            local MapRootNode = xmlFindChild (MapNode,"MAP_" .. getMapName().. "||",0)
            if not (MapRootNode == false) then
               local newNodeValue = xmlNodeSetAttribute (MapRootNode,datatype,newvalue)
               xmlSaveFile (root)
               xmlUnloadFile (root)
               return newNodeValue
            else
               local MapRootNode = xmlCreateChild (MapNode,"MAP_" .. getMapName().. "||")
               local newNodeValue = xmlNodeSetAttribute (MapRootNode,datatype,newvalue)
               xmlSaveFile (root)
               xmlUnloadFile (root)
               return newNodeValue
            end
         end
   end
 end
end

I don't get any error but it doesn't save the map everytime.

That means, when i have the empty xml and start the script and a map, it saves it in the xml.

But when i change the map, it doesn't save it...

Can someone help me?

Greetings

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...