on("chat:message", function(msg) {
if(msg.type == "api" && msg.content.indexOf("!dogman") !== -1) {
var selected = msg.selected;
if(selected) {
for(var i = 0; i < selected.length; i++) {
var token = getObj("graphic", selected[i]._id);
if(token) {
var characterId = token.get("represents");
var character = getObj("character", characterId);
if(character) {
// Append the subrace to the "race" attribute
var raceAttribute = findObjs({ type: 'attribute', characterid: characterId, name: 'race' })[0];
var currentRace = raceAttribute ? raceAttribute.get("current") : "";
if(raceAttribute) {
raceAttribute.set({ current: "Dogman" });
} else {
// If the race attribute does not exist, create it with the subrace appended
createObj("attribute", {
name: "race",
current: "Dogman",
characterid: characterId
});
}
// Increase Constitution by 2
var constitutionAttribute = findObjs({ type: 'attribute', characterid: characterId, name: 'constitution' })[0];
if (constitutionAttribute) {
var currentConstitution = parseInt(constitutionAttribute.get("current")) || 0;
constitutionAttribute.set({ current: currentConstitution + 2 });
} else {
createObj("attribute", {
name: "constitution",
current: "2", // Assumes no base constitution score; adjust as necessary
characterid: characterId
});
}
// Calculate the increase in hit points
var levelAttribute = findObjs({ type: 'attribute', characterid: characterId, name: 'level' })[0];
var currentHPAttribute = findObjs({ type: 'attribute', characterid: characterId, name: 'hp' })[0]; // Adjust 'hp' if needed
var maxHPAttribute = findObjs({ type: 'attribute', characterid: characterId, name: 'hp_max' })[0]; // Adjust 'hp_max' as per your sheet
if (levelAttribute && currentHPAttribute && maxHPAttribute) {
var level = parseInt(levelAttribute.get("current")) || 0;
var currentHP = parseInt(currentHPAttribute.get("current")) || 0;
var maxHP = parseInt(maxHPAttribute.get("current")) || 0;
var hpIncrease = level; // Increase HP by 1 for each level
currentHPAttribute.set({ current: currentHP + hpIncrease });
maxHPAttribute.set({ current: maxHP + hpIncrease });
// Send a confirmation message
sendChat("API", "/w gm Updated hit points for " + character.get("name") + " due to increased Constitution modifier.");
}
// Increase Dexterity by 1
var dexterityAttribute = findObjs({ type: 'attribute', characterid: characterId, name: 'dexterity' })[0];
if (dexterityAttribute) {
var currentDexterity = parseInt(dexterityAttribute.get("current")) || 0;
dexterityAttribute.set({ current: currentDexterity + 1 });
} else {
createObj("attribute", {
name: "dexterity",
current: "1", // Assumes no base dex score; adjust as necessary
characterid: characterId
});
}
// Send a confirmation message
sendChat("API", "/w gm Added homebrew race to " + character.get("name"));
}
}
}
} else {
sendChat("API", "/w gm No tokens selected.");
}
}
});
Basically, I am trying to make a custom race that has a +2 con and +1 dex (using the standard DnD 5e sheet). Everything works except the max hp doesn't increase when the con modifier changes. The part that is coming back undefined but appears correct according to the character sheet, is this: var maxHPAttribute = findObjs({ type: 'attribute', characterid: characterId, name: 'hp_max' })[0];