489
edits
Script 10k (talk | contribs) |
Script 10k (talk | contribs) (→Example: adding the example) |
||
Line 668: | Line 668: | ||
===Example=== | ===Example=== | ||
Let's say your want to add one additional ammo and cell to all characters that are from TCTF team. | |||
'''XmlTools patch command:''' | |||
@CUSTOM_CODE Files "BINACJBOCharacter.xml" | |||
<nowiki><code></nowiki> | |||
var myBuilder = new JSXMLBuilder(); | |||
myBuilder.load($xmlData); | |||
var elements = myBuilder.elements[0]; | |||
var charactersNode = elements.childElement("Objects"); | |||
var currAmmoElement, currCellsElement; | |||
<span style="color:green">// Loop over all characters</span> | |||
for (var i=0; i<(charactersNode.childElement(i)); i++){ <span style="color:green">// the condition checks if the ith element exists (!= undefined)</span> | |||
var currChar=charactersNode.childElement(i); | |||
<span style="color:green">// Check if it is TCTF</span> | |||
if(currChar.childElement("OSD").childElement("Team").text=="TCTF"){ | |||
<span style="color:green">// Get current amount</span> | |||
currAmmoElement=currChar.childElement("OSD").childElement("Inventory").childElement("Ammo").childElement("Use"); | |||
currCellsElement=currChar.childElement("OSD").childElement("Inventory").childElement("EnergyCell").childElement("Use"); | |||
<span style="color:green">// Add +1 to the current ammount of ammo and cells to use</span> | |||
currAmmoElement.text=parseInt(currAmmoElement.text)+1; | |||
currCellsElement.text=parseInt(currCellsElement.text)+1; | |||
} | |||
} | |||
$xmlData=myBuilder.generateXML(); <span style="color:green">// update the global variable with the new XML</span> | |||
<nowiki></code></nowiki> | |||
{| style="margin: 1em auto 1em auto;" <!-- Centers table --> | |||
! style="width: 50%;" | XML Original | |||
! style="width: 50%;" | XML After Command | |||
|- | |||
| | |||
<Oni> | |||
<Objects> | |||
... | |||
<CHAR Id="3926"> | |||
... | |||
<OSD> | |||
... | |||
<Name>A_L18</Name> | |||
<Weapon>w8_mbo</Weapon> | |||
<Inventory> | |||
<Ammo> | |||
<Use><span style="color:blue">'''0'''</span></Use> | |||
... | |||
</Ammo> | |||
<EnergyCell> | |||
<Use><span style="color:blue">'''0'''</span></Use> | |||
... | |||
</EnergyCell> | |||
</Inventory> | |||
<Team>TCTF</Team> | |||
... | |||
</OSD> | |||
</CHAR> | |||
<CHAR Id="7684"> | |||
... | |||
<OSD> | |||
... | |||
<Name>D_Sbo93</Name> | |||
<Weapon>w1_tap</Weapon> | |||
<Inventory> | |||
<Ammo> | |||
<Use><span style="color:blue">'''3'''</span></Use> | |||
... | |||
</Ammo> | |||
<EnergyCell> | |||
<Use><span style="color:blue">'''1'''</span></Use> | |||
... | |||
</EnergyCell> | |||
</Inventory> | |||
<Team>TCTF</Team> | |||
... | |||
</OSD> | |||
</CHAR> | |||
<CHAR Id="7606"> | |||
... | |||
<OSD> | |||
... | |||
<Name>D_N76</Name> | |||
<Weapon /> | |||
<Inventory> | |||
<Ammo> | |||
<Use>'''0'''</Use> | |||
... | |||
</Ammo> | |||
<EnergyCell> | |||
<Use>'''0'''</Use> | |||
... | |||
</EnergyCell> | |||
</Inventory> | |||
<Team>Neutral</Team> | |||
... | |||
</OSD> | |||
</CHAR> | |||
... | |||
... | |||
</Objects> | |||
</Oni> | |||
| | |||
<Oni> | |||
<Objects> | |||
... | |||
<CHAR Id="3926"> | |||
... | |||
<OSD> | |||
... | |||
<Name>A_L18</Name> | |||
<Weapon>w8_mbo</Weapon> | |||
<Inventory> | |||
<Ammo> | |||
<Use><span style="color:red">'''1'''</span></Use> | |||
... | |||
</Ammo> | |||
<EnergyCell> | |||
<Use><span style="color:red">'''1'''</span></Use> | |||
... | |||
</EnergyCell> | |||
</Inventory> | |||
<Team>TCTF</Team> | |||
... | |||
</OSD> | |||
</CHAR> | |||
<CHAR Id="7684"> | |||
... | |||
<OSD> | |||
... | |||
<Name>D_Sbo93</Name> | |||
<Weapon>w1_tap</Weapon> | |||
<Inventory> | |||
<Ammo> | |||
<Use><span style="color:red">'''4'''</span></Use> | |||
... | |||
</Ammo> | |||
<EnergyCell> | |||
<Use><span style="color:red">'''2'''</span></Use> | |||
... | |||
</EnergyCell> | |||
</Inventory> | |||
<Team>TCTF</Team> | |||
... | |||
</OSD> | |||
</CHAR> | |||
<CHAR Id="7606"> | |||
... | |||
<OSD> | |||
... | |||
<Name>D_N76</Name> | |||
<Weapon /> | |||
<Inventory> | |||
<Ammo> | |||
<Use>'''0'''</Use> | |||
... | |||
</Ammo> | |||
<EnergyCell> | |||
<Use>'''0'''</Use> | |||
... | |||
</EnergyCell> | |||
</Inventory> | |||
<Team>Neutral</Team> | |||
... | |||
</OSD> | |||
</CHAR> | |||
... | |||
... | |||
</Objects> | |||
</Oni> | |||
|} |
edits