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

Gestalt character proficiency API... Help

Hello all you lovely people of the internet. I'm trying to make my life easier in the future by making it complicated in the moment. I'm trying to make a "Gestalt rules" API for a DnD game where I can just have my players level up their characters as if they're multiclassing without ruining things. Specifically at the moment I'm trying to use TokenMod and ChatSetAttr to automatically fix the proficiency bonus to the correct level. Since roll20 thinks they're multiclassing, it's miscalculating it. Here's the code I currently have. on('ready', function() { on('change:attribute:level', function(obj) { const level = obj.get('current'); const characterId = obj.get('_characterid'); const proficiencyBonus = Math.floor((level - 1) / 8) + 2; // Use ChatSetAttr to update the proficiency bonus const command = `!setattr --charid ${characterId} --proficiency_bonus|${proficiencyBonus}`; sendChat('API', command); }); }); I've no idea if I'm even in the right ballpark here... any help would be appreciated.
1722259570
The Aaron
Pro
API Scripter
I missed this message originally, but the above should work with: on('ready', function() { on('change:attribute', function(obj) { if('level' === obj.get('name')){ const level = obj.get('current'); const characterId = obj.get('characterid'); const proficiencyBonus = Math.floor((level - 1) / 8) + 2; let PBAttr = findObj({name:'proficiency_bonus',characterid:characterId})[0]; if(PBAttr){ PBAttr.setWithWorker({ current: proficiencyBonus }); } } }); }); You have to watch for any attribute to change, then filter based on the name of the changing attribute.  Also, since you are in the API already, it's faster to just get the Proficiency Bonus attribute and set it directly.
The Aaron said: I missed this message originally, but the above should work with: on('ready', function() { on('change:attribute', function(obj) { if('level' === obj.get('name')){ const level = obj.get('current'); const characterId = obj.get('characterid'); const proficiencyBonus = Math.floor((level - 1) / 8) + 2; let PBAttr = findObj({name:'proficiency_bonus',characterid:characterId})[0]; if(PBAttr){ PBAttr.setWithWorker({ current: proficiencyBonus }); } } }); }); You have to watch for any attribute to change, then filter based on the name of the changing attribute.  Also, since you are in the API already, it's faster to just get the Proficiency Bonus attribute and set it directly. Does this work with the 5E Shaped sheet or is it just for the base roll20 one? I gave it a try and got the following error: ReferenceError: findObj is not defined ReferenceError: findObj is not defined at apiscript.js:4885:20 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:169:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:169:1), <anonymous>:70:8) at TrackedObj.set (/home/node/d20-api-server/api.js:1108:14) at updateLocalCache (/home/node/d20-api-server/api.js:1443:18) at /home/node/d20-api-server/api.js:1629:11 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546) at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489)
1722535960

Edited 1722535995
timmaugh
Pro
API Scripter
Change that to be "findObjs" (with an 's'), and it will work. Aaron probably just air-coded that... while simultaneously coding 13 other scripts. =D
You're all amazing! I'll give it a try when get the chance!
MJ Cooper said: You're all amazing! I'll give it a try when get the chance! Let me know if you have any luck, I have been having some trouble getting it to work and I don't know if it's something I have done on my end.
1724463779

Edited 1724507822
Hey, coming back to this I managed to get it working by working off what Aaron posted on('ready', function() { on('change:attribute', function(obj) { if('level' === obj.get('name')){ const level = obj.get('current'); const characterId = obj.get('characterid'); // Defining attributes const proficiencyBonus = Math.floor((level - 1) / 8) + 2; const levelUp = Math.floor(level / 2); const displayShow = Math.floor(proficiencyBonus); // Setting the attributes const command = `!setattr --charid ${characterId} --level|${levelUp} --pb|${proficiencyBonus} --pb_display|${displayShow}`; sendChat('API', command ); } log('--Applying Changes--') }); log('-=> Gestalt Leveling For ChatSetAttr <=-') }); One thing I haven't managed to get working is the sheet updating when the changes are made, I need to deselect proficiencies and weapons and then reselect for the sheet to acknowledge the change  Editing for a cleaned up version of the code.
1724516917
The Aaron
Roll20 Production Team
API Scripter
Great!  Sorry for the typo. =D   Glad you got it sorted out.