Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Add/Delete/Sort Items in Player Inventory

Is it possible to add/delete/reorder items from a player's inventory through the API?  It would be enormously useful to my players (who have a tendency to hang onto everything; I even have a player who collects swatches of fur/scales/skin from kills) if items were transferrable or sortable, but the only inventory managers I've been able to find are quite old, and I wasn't able to get them working. Of those things that are more recent, the closest I've seen are the ammo managers and this  equipped-toggling script , but neither of those is actually creating or deleting items, merely updating them.  I should certainly think it would be possible, but I've also had pro status for less than a week, so saying I'm new to this is an understatement.  I've already  expanded the  Cash Master script to do coin transfers between my players, so item transfers and management seemed the next logical step.
1522538182

Edited 1522538367
vÍnce
Pro
Sheet Author
I think you could use&nbsp; ChatsetAttr&nbsp; for this. More info/help:&nbsp; <a href="https://github.com/roll20/roll20-api-scripts/blob/" rel="nofollow">https://github.com/roll20/roll20-api-scripts/blob/</a>...
Vince said: I think you could use&nbsp; ChatsetAttr&nbsp; for this. More info/help:&nbsp; <a href="https://github.com/roll20/roll20-api-scripts/blob/" rel="nofollow">https://github.com/roll20/roll20-api-scripts/blob/</a>... I looked into this as I was looking for the same functionality but gave up when it became clear it would be much too clunky, requiring a look up of the row id or number of a repeating item so the script would know which item was being transferred. Perhaps someone more macro/script savvy than me might figure it out but the time I would have to put in would be much more than the end result. It is convenient enough to either use the compendium or have the players cut and paste the item information manually to/from the chat.
1522616140
vÍnce
Pro
Sheet Author
Hmm.&nbsp; AFAIK, adding items with chatsetattr should automatically create the repeating row the name of the repeating section and any attributes you want to include. Would take a little time to setup a macro, but that's kind of how macros go.&nbsp; Other than deleting known repeating rows, I could see how deleting items could be a pain and I agree that just dragging items from the compendium is VERY convenient.&nbsp; Without a custom compendium option and only a few systems supported with the current compendiums available drag/drop is not an option for everyone.&nbsp; ;-(&nbsp; Now trading items between sheets (pc to pc or pc to npc)...&nbsp; That might be a very cool API script.
1522630314

Edited 1522635749
GM Michael
API Scripter
Well, I've got item transfers partially working, and the only thing I ended up using from ChatSetAttr was the row id generator.&nbsp;&nbsp; <a href="https://gist.github.com/VoltCruelerz/0e4b939c0157" rel="nofollow">https://gist.github.com/VoltCruelerz/0e4b939c0157</a>... !equipPass --targetname|&lt;TARGET_NAME&gt; [--quantity|&lt;QUANTITY&gt;] Known Issues Items that are Resources or have Attacks leave those behind when removed.&nbsp; Now, you can always open your character sheet later and delete them, but you have to do that manually. The line entry in the Equipment list is not actually removed.&nbsp; It's cleared out and can be deleted manually, so it doesn't really hurt &nbsp;anything, but it still looks weird. Weight is not instantly recalculated and the user is compelled to make a change to the equipment list by hand to trigger it. Not exactly ideal, but it does pass items.&nbsp; That said, any help resolving the remaining issues (which I have no clue where to even approach) would be much appreciated.
1522677980

Edited 1522678037
Jakob
Sheet Author
API Scripter
Well, I've got item transfers partially working, and the only thing I ended up using from ChatSetAttr was the row id generator.&nbsp; That one's the same code that Roll20 is using, so you should be good there :). 2. The line entry in the Equipment list is not actually removed. It's cleared out and can be deleted manually, so it doesn't really hurt anything, but it still looks weird. If the row still exists, there are some attributes present in that row that you have not deleted. 3. Weight is not instantly recalculated and the user is compelled to make a change to the equipment list by hand to trigger it. Hard to say what the problem is. Here's a guess: you are creating a new attribute on the target character via createObj(). Unfortunately, this does not trigger sheet workers; you'd have to create it first, then set all the attributes via setWithWorker(). 1. Items that are Resources or have Attacks leave those behind when removed. Now, you can always open your character sheet later and delete them, but you have to do that manually. Look for presence resource or attack ids and delete the corresponding rows as well (where, as for equipment, deleting a row === deleting all attributes within it)?
Is there a comprehensive list of all affiliated attributes for these things somewhere? I couldn't find one.
1522683153

Edited 1522683288
I use this list I compiled from the HTML for the character sheet. I bolded the one I think you are missing. This attribute is simply to say whether the item is in edit mode or display mode. _itemname _itemcount _itemweight _hasattack _itemattackid _itemcontent _equipped _itemmodifiers _itemproperties _itemresourceid _useasresource _inventorysubflag Also, I'm glad you liked my equipment tracker code. Hope you get it working the way you want.
1522683361
Jakob
Sheet Author
API Scripter
Michael G. said: Is there a comprehensive list of all affiliated attributes for these things somewhere? I couldn't find one. Your best bet is probably to just filter all attributes by name, something like this findObjs({ _type: 'attribute', _characterid: charID }) .filter(attr =&gt; attr.get('name').toLowerCase().indexOf(`repeating_${sectionName}_${rowID}`.toLowerCase()) === 0) .forEach(attr =&gt; attr.remove());
1522715437

Edited 1522715559
GM Michael
API Scripter
Kyle G. said: I use this list I compiled from the HTML for the character sheet. I bolded the one I think you are missing. This attribute is simply to say whether the item is in edit mode or display mode. _itemname _itemcount _itemweight _hasattack _itemattackid _itemcontent _equipped _itemmodifiers _itemproperties _itemresourceid _useasresource _inventorysubflag Also, I'm glad you liked my equipment tracker code. Hope you get it working the way you want. Thanks!&nbsp; This was half the problem (the other half being that you have to manually update the quantity to get it to show up as something other than blank when reading from the attribute). Also, yes, it's been very helpful. At this point, I've gotten basic item transfer working.&nbsp; Attached attacks sort-of work.&nbsp; They're not deleted, but some of the data is automagically passed through when you create an attack on the recipient.&nbsp; Similarly, resources aren't deleted or recreated.&nbsp; Yet.&nbsp; That will be the next order of business.
1523046383

Edited 1523046532
GM Michael
API Scripter
I've not had as much time during the week, but i've made a bit more progress.&nbsp; At this point, I'm noticing some other odd behavior, however. If I migrate transfer an item with an attack, the checkbox for the recipient is unchecked, but the attack appears.&nbsp; If the user selects the checkbox, a second attack appears that does not have all the transferred data in it. Resources aren't seeming to get migrated at all.&nbsp; A new resource box is created for the recipient, but it's left empty.&nbsp; Am I missing yet more things?&nbsp; I see that there's resource name left and right, do I need to somehow know which to set manually? Here's the log: "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_inventory_-L9RZFpCOlHHkZOoJNZQ_itemcount\",\"current\":\"11\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_inventory_-L9RZFpCOlHHkZOoJNZQ_itemname\",\"current\":\"Brittany\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_inventory_-L9RZFpCOlHHkZOoJNZQ_itemweight\",\"current\":\"2\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_inventory_-L9RZFpCOlHHkZOoJNZQ_equipped\",\"current\":\"0\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_inventory_-L9RZFpCOlHHkZOoJNZQ_useasaresource\",\"current\":\"0\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_inventory_-L9RZFpCOlHHkZOoJNZQ_hasattack\",\"current\":\"0\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_inventory_-L9RZFpCOlHHkZOoJNZQ_itemproperties\",\"current\":\"\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_inventory_-L9RZFpCOlHHkZOoJNZQ_itemmodifiers\",\"current\":\"\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_inventory_-L9RZFpCOlHHkZOoJNZQ_itemcontent\",\"current\":\"\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_inventory_-L9RZFpCOlHHkZOoJNZQ_inventorysubflag\",\"current\":\"on\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_attack_-L9RZFrw9CZ-aWJeCidC_options-flag\",\"current\":\"0\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_attack_-L9RZFrw9CZ-aWJeCidC_itemid\",\"current\":\"-l9rz-e3anstlvrwbpuh\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_attack_-L9RZFrw9CZ-aWJeCidC_atkname\",\"current\":\"Brittany\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_attack_-L9RZFrw9CZ-aWJeCidC_atkattr_base\",\"current\":\"@{strength_mod}\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_attack_-L9RZFrw9CZ-aWJeCidC_dmgattr\",\"current\":\"@{strength_mod}\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_attack_-L9RZFrw9CZ-aWJeCidC_rollbase_dmg\",\"current\":\"@{wtype}&{template:dmg} {{rname=@{atkname}}} @{atkflag} {{range=@{atkrange}}} @{dmgflag} {{dmg1=[[0 + 2[STR]]]}} {{dmg1type=}} @{dmg2flag} {{dmg2=[[0]]}} {{dmg2type=}} @{saveflag} {{desc=@{atk_desc}}} @{hldmg} {{spelllevel=@{spelllevel}}} {{innate=@{spell_innate}}} @{global_damage_mod} {{globaldamagetype=@{global_damage_type}}} @{charname_output}\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_attack_-L9RZFrw9CZ-aWJeCidC_rollbase_crit\",\"current\":\"@{wtype}&{template:dmg} {{crit=1}} {{rname=@{atkname}}} @{atkflag} {{range=@{atkrange}}} @{dmgflag} {{dmg1=[[0 + 2[STR]]]}} {{dmg1type=}} @{dmg2flag} {{dmg2=[[0]]}} {{dmg2type=}} {{crit1=[[0]]}} {{crit2=[[0]]}} @{saveflag} {{desc=@{atk_desc}}} @{hldmg} {{spelllevel=@{spelllevel}}} {{innate=@{spell_innate}}} @{global_damage_mod} @{global_damage_mod_crit} {{globaldamagetype=@{global_damage_type}}} @{charname_output}\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_attack_-L9RZFrw9CZ-aWJeCidC_atkbonus\",\"current\":\"+4\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_attack_-L9RZFrw9CZ-aWJeCidC_atkdmgtype\",\"current\":\"2 \",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_attack_-L9RZFrw9CZ-aWJeCidC_rollbase\",\"current\":\"@{wtype}&{template:atk} {{mod=@{atkbonus}}} {{rname=[@{atkname}](~repeating_attack_attack_dmg)}} {{rnamec=[@{atkname}](~repeating_attack_attack_crit)}} {{r1=[[@{d20}cs&gt;@{atkcritrange} + 2[STR] + 2[PROF]]]}} @{rtype}cs&gt;@{atkcritrange} + 2[STR] + 2[PROF]]]}} {{range=@{atkrange}}} {{desc=@{atk_desc}}} {{spelllevel=@{spelllevel}}} {{innate=@{spell_innate}}} @{global_attack_mod} ammo=@{ammo} @{charname_output}\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_resource_-L9RZFsTQRESP3q8oEur_itemid\",\"current\":\"-l9rz-e3anstlvrwbpuh\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_resource_-L9RZFsTQRESP3q8oEur_name\",\"current\":\"Brittany\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_resource_-L9RZFsTQRESP3q8oEur\",\"current\":\"11\",\"max\":\"12\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_inventory_-L9RZFpCOlHHkZOoJNZQ_itemattackid\",\"current\":\"-L9RZFrw9CZ-aWJeCidC\",\"max\":\"\"}" "Transferring: {\"characterid\":\"-L91lqQE3r_J20j651fN\",\"name\":\"repeating_inventory_-L9RZFpCOlHHkZOoJNZQ_itemresourceid\",\"current\":\"-L9RZFsTQRESP3q8oEur\",\"max\":\"\"}"