From Multi Theft Auto: Wiki
Revision as of 14:50, 6 August 2016 by Walid (talk | contribs) (Fix oop syntax)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This function is used to edit an attribute of a node in a configuration file.


bool xmlNodeSetAttribute ( xmlnode node, string name, string/float value )             

OOP Syntax Help! I don't understand this!

Method: xmlnode:setAttribute(...)
Counterpart: xmlNodeGetAttribute

Required Arguments

  • node: The node of which you wish to edit an attribute.
  • name: The name of the attribute.
  • value: The value which you wish to change the attribute to. (Note: nil will delete the attribute)


Returns true if the attribute was set successfully, false if the node and/or attribute do not exist, or if they're faulty.


Click to collapse [-]

In a gamemode, we want a command to change the marker color in the configuration file and remove a deprecated attribute.


    <markers color="255,100,0" foo="deprecated" />

Lua code:

function changeConfigMarkerColor(thePlayer, command, r, g, b)
    local config = xmlLoadFile("config.xml")
    local markernode = xmlFindChild(config, "markers", 0)
    xmlNodeSetAttribute(markernode, "color", r .. "," .. g .. "," .. b)
    xmlNodeSetAttribute(markernode, "foo", nil) -- remove 'foo' attribute
addCommandHandler("markercolor", changeConfigMarkerColor)

See Also