PDA

View Full Version : Monitoring items in the inventory list



peterb
June 19th, 2023, 11:37
I'm writing an extension for BRP that will calculate the encumbrance penalty, and I'm not only interested in the total weight being carried but also if an item is carried or equipped. I'm specifically interest in monitoring when an items "carried" flag changes. So, how do add a handler to the items of a list? I guess that is what I have to do.

damned
June 19th, 2023, 12:00
I think the code that calculates total weight should show you how.
See manager_char_encumbrance.lua
CharEncumbranceManager.calcDefaultInventoryEncumbr ance

peterb
June 19th, 2023, 13:32
Thanks! Yes, I found that one. I need to trigger something similar when an item in the inventory is updated. Searching the code in CoreRPG, I found this function in scripts/manager_char_inventory.lua. I'll try and add a similar handler to my encumbrance penalty calculator.


function enableInventoryUpdates(sList)
if not sList then
sList = "inventorylist";
end
if not _tInvLists[sList] then
_tInvLists[sList] = true;
DB.addHandler("charsheet.*." .. sList .. ".*.*", "onUpdate", CharInventoryManager.onFieldUpdate);
end
end

Moon Wizard
June 19th, 2023, 16:16
Here are a couple examples:
5E - Calculates encumbrance limit updates for character sheets
MGT2 - Calculates custom encumbrance (due to custom weight field name), calculates encumbrance limits, and sets an encumbrance state

Regards,
JPG

peterb
June 20th, 2023, 16:56
Thanks for the pointers, that helped.