Log in

View Full Version : How to copy an item, but put it under a different node.



eldarune
November 13th, 2023, 10:57
In the AFF ruleset we have custom buttons to add armour and weapons, as they are saved under the <armour /> and <weapon /> XML nodes in db.xml. I've added GM buttons as can be seen in the attachment.

In the example of an armour item, the database will look like this:



<root version="4.4" dataversion="20230911" release="23.11|CoreRPG:6">
<armour>
<id-00001>
<damage_mod type="number">0</damage_mod>
<itemtype type="string">armour</itemtype>
<level type="number">0</level>
<name type="string">Some Armour</name>
<roll1 type="number">0</roll1>
<roll2 type="number">0</roll2>
<roll3 type="number">0</roll3>
<roll4 type="number">0</roll4>
<roll5 type="number">0</roll5>
<roll6 type="number">0</roll6>
<roll7 type="number">0</roll7>
<text type="formattedtext">
<p />
</text>
</id-00001>
</armour>


Dragging said and dropping it back into the list correctly creates a copy, but under the <item> node.



<item>
<id-00001>
<action1_value type="number">0</action1_value>
<consumable type="number">0</consumable>
<name type="string">An Item</name>
<notes type="formattedtext">
<p />
</notes>
<weight type="number">0</weight>
</id-00001>
<id-00003>
<action1_value type="number">0</action1_value>
<consumable type="number">0</consumable>
<count type="number">1</count>
<damage_mod type="number">0</damage_mod>
<itemtype type="string">armour</itemtype>
<level type="number">0</level>
<locked type="number">1</locked>
<name type="string">Some Armour (Copy)</name>
<notes type="formattedtext">
<p />
</notes>
<roll1 type="number">0</roll1>
<roll2 type="number">0</roll2>
<roll3 type="number">0</roll3>
<roll4 type="number">0</roll4>
<roll5 type="number">0</roll5>
<roll6 type="number">0</roll6>
<roll7 type="number">0</roll7>
<text type="formattedtext">
<p />
</text>
<weight type="number">0</weight>
</id-00003>
</item>


How do I tell FGU that I want the new item, one where
itemtype = "armour", that I want it copied into the
<armour />. Also, some item properties (weight, etc) are being merged as well.

I know in hindsight I should have made these sub-item types but I believe I followed one of Damned's tutorials and this is where we are :)

Thanks in advance for any insight.

Oh, and I worked out the hard way the order of strings in the aDataMap variable is important. Make sure item is first.

Moon Wizard
November 13th, 2023, 19:11
It is not recommended to store multiple item types in separate locations in the database, as all the core item management features (party sheet, item transfers, etc.) are designed to be used with a single source of data. For every other ruleset out there, all the items are stored in the same location, and the type/subtype fields are used to differentiate armor and weapons. Then, special record views are used to be able to display these (which you can see in 5E/PFRPG rulesets and more). I highly recommend migrating to using a single item record type approach.

If you want to create a new item with some fields pre-filled, you would need to create the child node, get a reference to that node, and preset the data field (i.e. type/subtype). Or you can just allow them to type into type/subtype field; or provide a drop-down.

Regards,
JPG

eldarune
November 14th, 2023, 03:00
Thanks JPG. I might have to just bite the bullet and refactor.

superteddy57
November 14th, 2023, 03:58
You can crack open 5E and see how the type field operates in displaying different fields based on the item type. It's a bit of staple for most rulesets I've built.