Skip to content

Commit 5b2f657

Browse files
author
SteveKoontz
committed
adding Feng Shui init script
1 parent 7ede6f3 commit 5b2f657

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// !init <# of steps> <token name>
2+
// !init 3 Jackie Chan
3+
// If no step value is set, the standard 3 steps are removed. If no token name is specified steps are removed from the top initiative in the tracker. If neither are specified 3 steps are removed from the top initiative.
4+
5+
on('chat:message', function(msg) {
6+
if (msg.type == 'api' && msg.content.indexOf('!init') !== -1) {
7+
var char;
8+
var steps = 3;
9+
var pieces = msg.content.split(" ");
10+
if (pieces.length > 2) {
11+
var char = pieces.slice(2, pieces.length).join(" ");
12+
// char = findObjs({_type: "character", name: char_name}, {caseInsensitive: true});
13+
}
14+
if (pieces.length > 1) {
15+
steps = pieces[1] && !isNaN(parseInt(pieces[1],10)) ? parseInt(pieces[1],10) : 3;
16+
}
17+
do_steps(steps, char);
18+
};
19+
});
20+
21+
var do_steps = function(steps, char) {
22+
// GET TURN ORDER
23+
var currentTurnOrder = Campaign().get("turnorder") === "" || Campaign().get("turnorder") === "[]" ? currentTurnOrder = [] : JSON.parse(Campaign().get("turnorder"));
24+
25+
// CHANGE STEPS
26+
if (!char) {
27+
currentTurnOrder[0]["pr"] = currentTurnOrder[0]["pr"] - steps > 0 ? currentTurnOrder[0]["pr"] - steps : 0;
28+
}
29+
else {
30+
_.each(currentTurnOrder, function(turn) {
31+
var graphic = getObj("graphic", turn.id);
32+
if(graphic && graphic.get("name") && graphic.get("name").toLowerCase() === char.toLowerCase()) {
33+
turn.pr = turn.pr - steps > 0 ? turn.pr - steps : 0;
34+
}
35+
});
36+
}
37+
38+
// SORT TURN ORDER
39+
currentTurnOrder = _.sortBy(currentTurnOrder, function(turnitem) {
40+
if (typeof turnitem.pr === "string") {
41+
return -(parseInt(turnitem.pr, 10));
42+
}
43+
else {
44+
return -(turnitem.pr);
45+
}
46+
});
47+
48+
// SAVE TURN ORDER
49+
Campaign().set({
50+
turnorder: JSON.stringify(currentTurnOrder)
51+
});
52+
};

Feng Shui Initiative/script.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "Feng Shui Initiative",
3+
"script": "Feng Shui Initiative.js",
4+
"version": "1.0",
5+
"previousversions": [],
6+
"description": "Allows GM and players to automatically deduct and resort steps from the initiative tracker to speed up play for Fung Shui 2 action scenes.\r\r**API Commands:**\r**!init** <# of steps> <token name in tracker>\rExample: !init 3 Jackie Chan\r\rIf no step value is set, the standard 3 steps are removed. If no token name is specified steps are removed from the top initiative in the tracker. If neither are specified 3 steps are removed from the top initiative.\r\r**Recomended Macros**\rQuick Attack: !init\rUnusual Attack: !init ?{Steps?|3}\rPlayer Quick Attack: !init 3 <name>\rPlayer Unusual Actions: !init ?{Steps?|3} <name>",
7+
"authors": "Steve K.",
8+
"roll20userid": "5047",
9+
"useroptions": [],
10+
"dependencies": [],
11+
"modifies": {},
12+
"conflicts": []
13+
}

0 commit comments

Comments
 (0)