PDA

View Full Version : Understanding Item Types and Dynamic Field Creation



LordEntrails
July 5th, 2022, 06:08
In my ruleset I would like different types of items to have different attributes. This is similar to how in the D&D 5E ruleset Weapons, Armor, and Arcane Focus items have additional fields like AC, Damage, Bonus, etc that those types of items can have.

I believe I have worked out in 5E this is handled in the file "item_main.lua". That part that confuses me is here:

local bID = LibraryData.getIDState("item", nodeRecord);
wand
local bWeapon, sTypeLower, sSubtypeLower = ItemManager2.isWeapon(nodeRecord);
local bArmor = ItemManager2.isArmor(nodeRecord);
local bArcaneFocus = (sTypeLower == "rod") or (sTypeLower == "staff") or (sTypeLower == "wand");


First, what the heck is that second line "wand" doing? It that some remnant or typo?

To the important stuff: I understand how bArcaneFocus gets set, i.e. if the sTypeLower field equals rod, staff, wand then bArcaneFcus is true. And though I don't quite understand why the bWeapon and bArmor functins have a bunch of other stuff in them, I do see how they get set to True, but I don't understand why they are evaluated in manager_item2.lua.

Now my question; why would I want to use the bWeapon approach over the bArcaneFocus approach?

And, if I want some of my types to have sub-types with unique attributes, does that impact the approach above? i.e weapons that are ranged to have other attributes.

superteddy57
July 5th, 2022, 06:32
That is all down to what you would like to do honestly. Both have their merits. The bWeapon line and bArmor line have built in functions to verify the item is a weapon or a piece of armor. In some cases in 5e, the subtype would also contain weapon for it to be used as such mechanically throughout the ruleset. The bArcaneFocus line is a more deliberate approach looking for those types without any additional checks needed. I would check out TEST soon for some changes to this approach and may give you a better way of approaching this process and help organize data fields better.

LordEntrails
July 5th, 2022, 15:27
Ok, thanks. So bWeapon and bArmor are also checking for subtypes that may make the item a weapon or armor. Makes sense now. I don't see that I will need that. Will check out test as well to see about the change you mention.

Still curious about the "wand" line though :)

superteddy57
July 5th, 2022, 16:50
As I mentioned, the bArcaneFocus line is more deliberate query. It will return true if the sTypeLower is one of those three item types.

Example:
If I create a blank item in 5e, and go and type in Wand into the Type field, it will then change what is visible on the frame. A new bonus field should now be available. If I remove it, it removes the bonus field.

Trenloe
July 5th, 2022, 17:07
Still curious about the "wand" line though :)
I don't see that the live 5E ruleset item_main.lua on my install.

LordEntrails
July 5th, 2022, 19:00
I don't see that the live 5E ruleset item_main.lua on my install.
Hmm, not there when I refresh. I must have corrupted/changed the file myself when experimenting. Probably meant to by typing in FG and actually types in NPP. Thanks for checking :)