
case '!short-rest':
if(!playerIsGM(msg.playerid)) {
sendChat('','/w "'+who+'" '+
'<div style="border: 1px solid black; background-color: white; padding: 3px 3px;">'+
'<span style="font-weight:bold;color:#990000;">Error:</span> '+
'Only the GM can initiate a short rest.'+
'</div>'
);
} else {
_.chain(state.UsePower.usedPowers.encounter)
.uniq()
.map(function(id){
return getObj('ability',id);
})
.reject(_.isUndefined)
.each(function(a){
a.set({
istokenaction: true
});
});
state.UsePower.usedPowers.encounter=[];
}
break; I am trying to add portions that include an argument !short-rest --Monday !short-rest --Tuesday etc..assuming characters have an attribute named GroupMonday or GroupTuesday with a 1 or a 0 or a yes no inside the value then, only sheets that have that attribute will have the final command to restore encounter powers. I have messed around with various methods, but I am stuck. Here is an example of what I tried to do; case '!short-rest':
if (!playerIsGM(msg.playerid)) {
sendChat('','/w "'+who+'" '+
'<div style="border: 1px solid black; background-color: white; padding: 3px 3px;">'+
'<span style="font-weight:bold;color:#990000;">Error:</span> '+
'Only the GM can initiate a short rest.'+
'</div>'
);
} else {
// Check if the group flag is included
var groupFlag = msg.content.match(/--(Tuesday|Wednesday|Saturday)/); // Look for any of the three groups
if (!groupFlag) {
sendChat('', '/w "' + who + '" ' +
'<div style="border: 1px solid black; background-color: white; padding: 3px 3px;">'+
'<span style="font-weight:bold;color:#990000;">Error:</span> ' +
'Invalid group selected. Please choose either --Tuesday, --Wednesday, or --Saturday.' +
'</div>'
);
return; // Stop the function if no valid group is specified
}
var groupChoice = groupFlag[0].substring(2); // Extract group name (Tuesday, Wednesday, or Saturday)
var groupAttrName = 'Group' + groupChoice; // The exact attribute name: GroupTuesday, GroupWednesday, GroupSaturday
// Find all tokens and check if they belong to the selected group
var selectedTokens = findObjs({
_type: 'graphic',
_subtype: 'token'
});
var encounteredPowersApplied = false; // Track if any powers were applied
var noValidTokens = true; // Flag to track if we find any valid tokens
_.each(selectedTokens, function(token) {
var character = getObj('character', token.get('represents'));
if (character) {
// Check if the character has the group attribute and if it matches the selected group
var groupAttr = getAttrByName(character.id, groupAttrName); // Get the Group attribute based on the groupChoice
// Debugging: output group attribute value
sendChat('', '/w "' + who + '" Group Attribute: ' + groupAttr + ' (for token ' + token.get('name') + ')');
if (groupAttr && groupAttr.toLowerCase() === 'yes') {
// If the token belongs to the selected group, apply short rest
_.chain(state.UsePower.usedPowers.encounter)
.uniq()
.map(function(id) {
return getObj('ability', id);
})
.reject(_.isUndefined)
.each(function(a) {
// Set the powers to be token actions
a.set({
istokenaction: true
});
encounteredPowersApplied = true;
});
noValidTokens = false; // Mark that we found at least one valid token
}
}
});
if (noValidTokens) {
sendChat('', '/w "' + who + '" ' +
'<div style="border: 1px solid black; background-color: white; padding: 3px 3px;">'+
'<span style="font-weight:bold;color:#990000;">Error:</span> ' +
'No valid characters in the selected group to apply the short rest.' +
'</div>'
);
} else if (encounteredPowersApplied) {
sendChat('', '/w "' + who + '" ' +
'The short rest has been applied to the selected group (' + groupChoice + ').'
);
}
state.UsePower.usedPowers.encounter = [];
}
break; I know I am probably way off here, but if someone could help me out with this part, I think I can handle the rest of the code in the main body that I am wishing to do similar. IE !long-rest. It seems like the basic idea is doable?