Ok, so I have been working on this script and used it in a game this past weekend and I was pretty happy with it. I have added a check upon running to make sure the condition macros are created, and if not create them with description text for the condition. I would enjoy some critique. Oh and one thing, as a Windows programmer (from C on up) I HATE javascript curly braces as I can't ever line them up in my head (30 years of looking at braces not on the same line) so I am NOT using that style LOL. Oh and there are probably too many log() calls right now, but hey, nothing like old school print statements to debug. Oh there is one question also. Creating a macro requires a player id, so I assumed that the first player found when the script is installed (when it should create the macros) will be the GM. Is that a safe assumtion? var globalMacros = [
{
"action": "You are Blinded.\rA blinded creature can't see and automatically fails any ability check that requires sight.\rAttack rolls against the creature have advantage, and the creature's attack rolls have disadvantage.",
"istokenaction": false,
"name": "Condition-Blinded",
"visibleto": "all",
"_playerid":""
},
{
"action": "You are Charmed.\rA charmed creature can't attack the charmer or target the charmer with harmful abilities or magical effects.\rThe charmer has advantage on any ability check to interact socially with the creature.",
"istokenaction": false,
"name": "Condition-Charmed",
"visibleto": "all",
"_playerid":""
},
{
"action": "You are Deafened.\rA deafened creature can't hear and automatically fails any ability check that requires hearing.",
"istokenaction": false,
"name": "Condition-Deafened",
"visibleto": "all",
"_playerid":""
},
{
"action": "You are Frightened.\rA frightened creature has disadvantage on ability checks and attack rolls while the source of its fear is within line of sight.\rThe creature can't willingly move closer to the source of its fear.",
"istokenaction": false,
"name": "Condition-Frightened",
"visibleto": "all",
"_playerid":""
},
{
"action": "You are Grappled.\rA grappled creature's speed becomes 0, and it can't benefit from any bonus to its speed.\rThe condition ends if the grappler is incapacitated (see the condition).\rThe condition also ends if an effect removes the grappled creature from the reach of the grappler or grappling effect, such as when a creature is hurled away by the thunderwave spell.",
"istokenaction": false,
"name": "Condition-Grappled",
"visibleto": "all",
"_playerid":""
},
{
"action": "You are Incapacitated.\rAn incapacitated creature can't take actions or reactions",
"istokenaction": false,
"name": "Condition-Incapacitated",
"visibleto": "all",
"_playerid":""
},
{
"action": "You are Invisible.\rAn invisible creature is impossible to see without the aid of magic or a special sense. For the purpose of hiding, the creature is heavily obscured. The creature's location can be detected by any noise it makes or any tracks it leaves.\rAttack rolls against the creature have disadvantage, and the creature's attack rolls have advantage.",
"istokenaction": false,
"name": "Condition-Invisible",
"visibleto": "all",
"_playerid":""
},
{
"action": "You are Paralyzed.\rA paralyzed creature is incapacitated (see the condition) and can't move or speak.\rThe creature automatically fails Strength and Dexterity saving throws.\rAttack rolls against the creature have advantage.\rAny attack that hits the creature is a critical hit if the attacker is within 5 feet of the creature.",
"istokenaction": false,
"name": "Condition-Paralyzed",
"visibleto": "all",
"_playerid":""
},
{
"action": "You are Petrified.\rA petrified creature is transformed, along with any nonmagical object it is wearing or carrying, into a solid inanimate substance (usually stone). Its weight increases by a factor of ten, and it ceases aging.\rThe creature is incapacitated (see the condition), can't move or speak, and is unaware of its surroundings.\rAttack rolls against the creature have advantage.\rThe creature automatically fails Strength and Dexterity saving throws.\rThe creature has resistance to all damage.\rThe creature is immune to poison and disease, although a poison or disease already in its system is suspended, not neutralized.",
"istokenaction": false,
"name": "Condition-Petrified",
"visibleto": "all",
"_playerid":""
},
{
"action": "You are Poisoned.\rA poisoned creature has disadvantage on attack rolls and ability checks.",
"istokenaction": false,
"name": "Condition-Poisoned",
"visibleto": "all",
"_playerid":""
},
{
"action": "You are Prone.\rA prone creature's only movement option is to crawl, unless it stands up and thereby ends the condition.\rThe creature has disadvantage on attack rolls.\rAn attack roll against the creature has advantage if the attacker is within 5 feet of the creature. Otherwise, the attack roll has disadvantage.",
"istokenaction": false,
"name": "Condition-Prone",
"visibleto": "all",
"_playerid":""
},
{
"action": "You are Restrained.\rA restrained creature's speed becomes 0, and it can't benefit from any bonus to its speed.\rAttack rolls against the creature have advantage, and the creature's attack rolls have disadvantage.\rThe creature has disadvantage on Dexterity saving throws.",
"istokenaction": false,
"name": "Condition-Restrained",
"visibleto": "all",
"_playerid":""
},
{
"action": "You are Stunned.\rA stunned creature is incapacitated (see the condition), can't move, and can speak only falteringly.\rThe creature automatically fails Strength and Dexterity saving throws.\rAttack rolls against the creature have advantage.",
"istokenaction": false,
"name": "Condition-Stunned",
"visibleto": "all",
"_playerid":""
},
{
"action": "You are Exhausted.\rSome special abilities and environmental hazards, such as starvation and the long-term effects of freezing or scorching temperatures, can lead to a special condition called exhaustion. Exhaustion is measured in six levels. An effect can give a creature one or more levels of exhaustion, as specified in the effect's description.",
"istokenaction": false,
"name": "Condition-Exhausted",
"visibleto": "all",
"_playerid":""
},
{
"action": "You are Unconscious.\rAn unconscious creature is incapacitated, can't move or speak, and is unaware of its surroundings.\rThe creature drops whatever it's holding and falls prone.\rThe creature automatically fails Strength and Dexterity saving throws.\rAttack rolls against the creature have advantage.\rAny attack that hits the creature is a critical hit if the attacker is within 5 feet of the creature.",
"istokenaction": false,
"name": "Condition-Unconscious",
"visibleto": "all",
"_playerid":""
}
]
function checkInstall()
{
log("Condition Response Check Install")
//log("GM Id: " + gmId)
var macros = findObjs({ type: 'macro'});
log("Macros Found: " + macros.length);
if (macros.length > 0)
log(macros[0].playerid);
var conditionMacros = macros.filter((obj) => {return obj.get("name").indexOf("Condition") === 0})
log("conditionMacros Found: " + conditionMacros.length);
if (conditionMacros.length !== globalMacros.length)
{
//var macroName = macro.get('name');
//var macroId = macro.get('_id');
//_.each(conditionMacros, function(macro) {macro.remove()});
createConditionMacros();
}
}
function createConditionMacros()
{
var macro
log("Creating Condition Macros")
log(`Macro: ${macro}`)
let allPlayers = findObjs({_type: 'player'});
let player = allPlayers[0];
let playerId = player.get('_id');
log("Player: " + playerId)
let isGM = playerIsGM(playerId)
log("IsGM: ", isGM)
log(player.get('_d20userid'))
log(player.get('_displayname'))
for (var index = 0; index < globalMacros.length; ++index)
{
log(`Find Macro: ${globalMacros[index].name}`)
let macro = findObjs
(
{
_type: 'macro',
//_playerid: playerId,
name: `${globalMacros[index].name}`
}
)[0];
log(`Macro: ${macro}`)
if(!macro)
{
globalMacros[index]._playerid = playerId;
log("Create Macro: " + globalMacros[index].name)
createObj('macro', globalMacros[index]);
}
else
{
log("Not Creating " + globalMacros[index].name)
}
}
}
// Handle Condition
on('ready', function()
{
checkInstall();
on('chat:message', function(msg)
{
if (msg.type === "emote")
{
log('--------------------------------------------------------')
log(msg.type)
log(msg.content);
var post = ''
var index = 0
var charname = msg.who;
if (msg.content.indexOf("is: ") !== -1)
{
var conditions = msg.content.split(':')[1];
conditions = conditions.trim();
log('All Conditions:' + conditions)
var condition = conditions.split(',')
log('Split Condition:' + condition)
log(condition.length)
log(charname + ' ' + msg.content);
log("Get the Character");
var c = findObjs({ type: 'character', name: charname})[0];
log(condition[0]);
if(c)
{
log("Found " + charname)
post = '&{template:desc} {{desc=**' + charname + ' is ' + conditions + '**'
for(index = 0; index < condition.length; ++index)
(
post = post + '\r\n\r\nYou have become [' + condition[index].trim() + '](!&#13;#Condition-' + condition[index].trim() + ').'
)
post = post + '\r\n\r\nPlease select your token and click the link to assign yourself the condition. If there is more than one, only apply the new ones to your character.\r\n}}'
}
}
else if (msg.content.indexOf == ("has no active conditions") !== -1)
{
post = '&{template:desc} {{desc=**' + charname + ' ' + msg.content + '** \r\n\r\nYou are free from conditions. \r\n\r\nPlease select your token and remove all your condition icons\r\n}}'
}
log(post)
if (post.length> 0) sendChat('GM', post)
};
});
});