Jump to content

Help with writing information to a .xml file?


Bean

Recommended Posts

So pretty much what I'm trying to do, is make an in-game command, that would edit part of the configuration .xml for the zDay script. I think this can be pretty useful, and am wondering if I could get some help with it? I looked through the wiki, and found several XML commands, can someone point out where I went wrong?

config = xmlLoadFile("C:\Users\MTAServer\Desktop\server\mods\deathmatch\resources\zombies\meta.xml") 
  
function changeMaxZombies(thePlayer, commandName, zombiemax) 
            if not (zombiemax) then 
            outputChatBox("SYNTAX: /" .. commandName .. " [max numbers of zombies to spawn]", thePlayer, 255, 194, 14) 
            else 
            local markernode = xmlFindChild(config, "setting", 0) 
            xmlNodeSetAttribute(markernode, "name="*MaxZombies" value="[" .. zombiemax .. "]"") 
            xmlSaveFile(config) 
            outputChatBox("Done.", thePlayer, 255, 194, 14) 
            end 
        end 
    end 
addCommandHandler("setzombienumber", changeMaxZombies) 

And this is the line of XML I am trying to replace:

"*MaxZombies" value="[20]" /> 

I'm trying to replace the integer where 20 is, with the integer of my choice, or zombiemax.

So pretty much where it's stuck is, when I type the command with an incorrect syntax, it will give me the syntax to type it in, but when I give it the correct syntax, "Done." does not get outputted, so my problem lies within the XML parts.

I'd appreciate any help on this. :)

Link to comment
config = xmlLoadFile("C:\Users\MTAServer\Desktop\server\mods\deathmatch\resources\zombies\meta.xml") 

why are you trying to change "meta.xml" in resource "zombies" ? Make a new one in resource "zombies" because i think you are trying to change how much people have "maximum zombies"

Link to comment

The reason I have it like that, is because I'd like to be able to change the value of "MaxZombies" even when the 'zombie' resource isn't running, hence I have the script listed above in a resource called 'c-zombies', as in the configuration of it. The reason it's like this is because, if I can only set the value while the resource is running, then people will be flooded with zombies the entire time, I'd like to be able to just set it while the resource 'zombies' isn't running.

Link to comment

Dude, you got a lot of useless coding here, I'd recommend you look at the function set(). It helps a lot.

function changeMaxZombies(thePlayer, commandName, zombiemax) 
    if not zombiemax then 
        outputChatBox("SYNTAX: /" .. commandName .. " [max numbers of zombies to spawn]", thePlayer, 255, 194, 14) 
    else 
        set("zombies.MaxZombies", zombiemax) 
        restartResource(getResourceFromName("zombies")) 
        outputChatBox("Done.", thePlayer, 255, 194, 14) 
    end 
end 
addCommandHandler("setzombienumber", changeMaxZombies) 

If it doesnt work, change

set("zombies.MaxZombies", zombiemax)

to

set("zombies.MaxZombies", tonumber(zombiemax))

I've added restart resource to apply the effects, it will require admin rights.

Link to comment

I'm trying to write an integer, in a meta.xml file. I'm trying to make a command that will overwrite the bolded text.

The command would be like /setzombienumber the integer, and that integer would replace the value which is 20. I can't seem to figure out how to overwrite an xml file with the set function like you said. :?

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