Skip to content

Commit b8dc115

Browse files
committed
initial commit
0 parents  commit b8dc115

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
.idea/*

criticalHitOrFailSoundEffects.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
on('ready',function(){
2+
'use strict';
3+
var excludeGM = true, // this to false if you wish to include GM rolls
4+
playerIds = [],
5+
players = findObjs({_type:'player'}) || [];
6+
7+
8+
_.each(players,function (obj){
9+
if(playerIsGM(obj.get('id')) && !excludeGM || !playerIsGM(obj.get('id'))) {
10+
playerIds.push(obj.get('id'));
11+
}
12+
});
13+
14+
var allsongs = findObjs({
15+
_type: 'jukeboxtrack',
16+
}),
17+
criticalHit = {},
18+
criticalFail = {};
19+
20+
allsongs.forEach(function(song) {
21+
if(song.get('title') === 'Critical Hit') {
22+
criticalHit = song;
23+
} else if (song.get('title') === 'Critical Fail') {
24+
criticalFail = song;
25+
}
26+
});
27+
28+
on("chat:message", function(msg) {
29+
log(playerIds.some(function(playerId){
30+
return(playerId === msg.playerid);
31+
}));
32+
//for Shaped 5e Character Sheet
33+
if (msg.inlinerolls) {
34+
msg.inlinerolls.forEach(function(inlineRoll) {
35+
criticalHitOrFail(inlineRoll.results);
36+
});
37+
}
38+
//for roll chat command
39+
else if (isJson(msg.content)) {
40+
content = JSON.parse(msg.content);
41+
criticalHitOrFail(content);
42+
}
43+
});
44+
45+
function criticalHitOrFail(content) {
46+
content.rolls.forEach(function(roll) {
47+
if (roll.dice === 1 && roll.sides === 20) {
48+
if (roll.results[0].v === 20) {
49+
play(criticalHit);
50+
} else if (roll.results[0].v === 1) {
51+
play(criticalFail);
52+
}
53+
}
54+
});
55+
}
56+
57+
function isJson(str) {
58+
try {
59+
JSON.parse(str);
60+
} catch (e) {
61+
return false;
62+
}
63+
return true;
64+
}
65+
66+
function play (song) {
67+
song.set({'playing': true, 'softstop': false});
68+
}
69+
70+
log('Script loaded: Critical Hit/Failure Sound Effects');
71+
});

0 commit comments

Comments
 (0)