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

Question how best to implement LotFP class-specific ability modifiers?

In LotFP a couple of the demi-human classes (Dwarfs and Halflings) have an additional +1 to the ability modifier (not the stat itself), what would be the best way to implement this with the existing ability modifier code from the LotFP character sheet? There is an attr_class variable that indicates what the class is. // Ability modifiers ['Cha', 'Con', 'Dex', 'Int', 'Str', 'Wis'].forEach(ability => { on(`sheet:opened change:${ability.toLowerCase()}`, () => { getAttrs([ability.toLowerCase()], v => { const value = parseInt(v[ability.toLowerCase()]) || 10, setting = {}; if (value <= 1) setting[`${ability}Mod`] = -4; else if (value <= 3) setting[`${ability}Mod`] = -3; else if (value <= 5) setting[`${ability}Mod`] = -2; else if (value <= 8) setting[`${ability}Mod`] = -1; else if (value <= 12) setting[`${ability}Mod`] = 0; else if (value <= 15) setting[`${ability}Mod`] = 1; else if (value <= 17) setting[`${ability}Mod`] = 2; else if (value <= 19) setting[`${ability}Mod`] = 3; else setting[`${ability}Mod`] = 4; setAttrs(setting); }); }); });
1571793305
GiGs
Pro
Sheet Author
API Scripter
The specifics would help - which stat bonuses get modified by which race? Having a quick look at the character sheet, I would strong recommend changing the attr_class input to a select, because otherwise players might not type the race name in correctly, and the bonus wouldnt work. But I'll sidestep that for now. Here's a quick-and-dirty conversion of the above macro to include those specific cases. I assume halfling gets a dex bonus, and dwarf gets a con bonus - theng the relevant line if that's not the case: ['Cha', 'Con', 'Dex', 'Int', 'Str', 'Wis'].forEach(ability => {     on(`sheet:opened change:class change:${ability.toLowerCase()}`, () => {         getAttrs([ability.toLowerCase(), 'class'], v => {             const value = parseInt(v[ability.toLowerCase()]) || 10,                 race = v.class.trim(),                 mod = 0,                 setting = {};             // check if race matches             if ((ability === 'Con' && race.toLowerCase() === 'dwarven') || (ability === 'Dex' && race.toLowerCase() === 'halfling')) mod = 1;             if (value <= 1) setting[`${ability}Mod`] = -4 + mod;             else if (value <= 3) setting[`${ability}Mod`] = -3 + mod;             else if (value <= 5) setting[`${ability}Mod`] = -2 + mod;             else if (value <= 8) setting[`${ability}Mod`] = -1 + mod;             else if (value <= 12) setting[`${ability}Mod`] = 0 + mod;             else if (value <= 15) setting[`${ability}Mod`] = 1 + mod;             else if (value <= 17) setting[`${ability}Mod`] = 2 + mod;             else if (value <= 19) setting[`${ability}Mod`] = 3 + mod;             else setting[`${ability}Mod`] = 4 + mod;             setAttrs(setting);         });     }); }); But do note that the races have to be spelled correctly.
1571795335
GiGs
Pro
Sheet Author
API Scripter
Here's an alternate way to do the sheet worker, reducing the if statement, and allowing you to add different race/class modifiers (assuming each has only one stat that always gives a +1 bonus). Just add to the classMods line. // Ability modifiers const classMods = {dwarven: "Con", halfling: "Dex"}; ['Cha', 'Con', 'Dex', 'Int', 'Str', 'Wis'].forEach(ability => {     on(`sheet:opened change:class change:${ability.toLowerCase()}`, () => {         getAttrs([ability.toLowerCase(), 'class'], v => {             const score = parseInt(v[ability.toLowerCase()]) || 10;             const race = v.class.trim();             const setting = {};             const statrank = [1,3,5,8,12,15,17,19].findIndex(rank => score <= rank);             setting[`${ability}Mod`] = (statrank === -1 ? 4 : statrank -4) + ((classMods[race] || '') === ability ? 1 : 0);             setAttrs(setting);         });     }); });
Halflings get a +1 to their DexMod and Dwarfs get a +1 to their ConMod.
1571797651

Edited 1571797660
GiGs
Pro
Sheet Author
API Scripter
I guessed right then, the code above assumes those.
Yep, and thanks! That 2nd bit of code works very nicely!
1571799585
GiGs
Pro
Sheet Author
API Scripter
I'm glad to hear it :)