Skip to content

Instantly share code, notes, and snippets.

@Bastlifa
Last active March 3, 2022 21:47
Show Gist options
  • Save Bastlifa/291d456123179b335b408827a7fe24d4 to your computer and use it in GitHub Desktop.
Save Bastlifa/291d456123179b335b408827a7fe24d4 to your computer and use it in GitHub Desktop.
Threat and Momentum Report and Adjustment for Star Trek Adventures on Roll20. Simplified by Aaron.
/************************************************************************************************************
You will need to create a character named TMChar. Leave him empty, but in the attributes and abilities tab,
add two attributes: PoolThreat, and PoolMomentum. Set appropriate caps. Momentum caps at 6, I believe.
I chose 20 for a threat cap, but I'm not sure there is one. You can edit to remove the cap on threat,
or just set it very high on the sheet.
You will then need to make 5 macros, with the following bodies:
!TMReport
!TMThreatInc
!TMThreatDec
!TMMomentumInc
!TMMomentumDec
I would share all of these with all players, except for threat decrease.
As you can tell from my horrid code, I have no clue about Javascript. I hope this is useful for someone.
*************************************************************************************************************/
on("ready", function() {
on("chat:message", function (msg) {
if (msg.type === "api"){
var TMChar = findObjs({ type: 'character', name: 'TMChar' })[0];
var Threat = findObjs({name: "PoolThreat",_type: "attribute",_characterid: TMChar.id}, {caseInsensitive: true})[0];
var Momentum = findObjs({ type: "attribute", name: "PoolMomentum", _characterid: TMChar.id})[0];
if (msg.content === "!TMReport") {
Report(msg, Threat, Momentum, msg.content.replace(/^!TM/,''));
};
if (msg.content === "!TMThreatInc") {
if (Threat.get("current") < Threat.get("max")){
Threat.set("current", parseInt(Threat.get("current")) + 1);
Report(msg, Threat, Momentum, msg.content.replace(/^!TM/,''));
}
else{
sendChat(msg.who, "Threat is capped");
}
};
if (msg.content === "!TMThreatDec") {
if (Threat.get("current") > 0){
Threat.set("current", parseInt(Threat.get("current")) - 1);
Report(msg, Threat, Momentum, msg.content.replace(/^!TM/,''));
}
else{
sendChat(msg.who, "An Empty Threat (pool)");
}
};
if (msg.content === "!TMMomentumInc") {
if (Momentum.get("current") < Momentum.get("max")){
Momentum.set("current", parseInt(Momentum.get("current")) + 1);
Report(msg, Threat, Momentum, msg.content.replace(/^!TM/,''));
}
else{
sendChat(msg.who, "Momentum is capped");
}
};
if (msg.content === "!TMMomentumDec") {
if (Momentum.get("current") > 0){
Momentum.set("current", parseInt(Momentum.get("current")) - 1);
Report(msg, Threat, Momentum, msg.content.replace(/^!TM/,''));
}
else{
sendChat(msg.who, "The Moment(um) has passed");
}
};
};
});
});
function Report(msg, Threat, Momentum, format) {
let title='';
switch(format){
case 'ThreatInc':
title = 'Threat Increased';
break;
case 'ThreatDec':
title = 'Threat Decreased';
break;
case 'MomentumInc':
title = 'Momentum Increased';
break;
case 'MomentumDec':
title = 'Momentum Decreased';
break;
default:
title = 'Momentum and Threat Report';
break;
}
sendChat(msg.who,
'<div class="sheet-rolltemplate-lcars">' +
'<table>' +
'<tbody><tr><th>'+ title +'</th></tr>' +
'<tr><td>' +
'Threat: ' + Threat.get("current") +
'</td></tr>' +
'<tr><td>' +
'Momentum: ' + Momentum.get("current") +
'</td></tr>' +
'</tbody></table>' +
'</div>');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment