EDIT: If you're looking for v2, check a few posts down . Read this first though, so you know what I'm talking about there :) So, I finally decided to upgrade to Mentor and check this API thing out. Yikes, this is fun! We've been playing Dragon Age RPG lately, and since I've heard that the battles are exaggerately bloody in the video game, I decided to make a blood splatter script (and attach it to damage dealing macros). It worked out pretty swell, and it was surprisingly quick to hack together. The hardest part was finding good blood splatter images. I figured someone else might find this fun, and maybe even help me improve it someway. So, enjoy: Here it is in action Usage: !splatter @{target|token_id} Script: // See: <a href="https://app.roll20.net/forum/post/733277/api-fire" rel="nofollow">https://app.roll20.net/forum/post/733277/api-fire</a>...
(function () {
var oldCreateObj = createObj;
createObj = function () {
var obj = oldCreateObj.apply(this, arguments);
if (obj && !obj.fbpath) {
obj.fbpath = obj.changed._fbpath.replace(/([^\/]*\/){4}/, "/");
}
return obj;
};
}());
// TODO: This script pretty much assumes square-ish/round tokens. Width is the desicive factor in many places.
// helper functions
function toDegrees(angle) { return angle * (180 / Math.PI); }
function toRadians(angle) { return angle * (Math.PI / 180); }
// Global constants
var bloodUrls = [
"any amount of urls to assets UPLOADED to your gallery (see Wiki for imgsrc usage). Recommended is square-ish image that is partly transparent to make several blood splatters on top of each other intensified."
];
// Splat functions
// Splatter's location is [top,left], and moved to random direction r pixels
function createSplat(pageId, top, left, r) {
var randomDirection = randomInteger(360) - 1,
createResult = createObj("graphic", {
_subtype: "token",
_pageid: pageId,
imgsrc: bloodUrls[randomInteger(bloodUrls.length) - 1],
top: top + Math.sin(toRadians(randomDirection)) * r,
left: left + Math.cos(toRadians(randomDirection)) * r,
width: 70,
height: 70,
rotation: randomInteger(360) - 1,
layer: "map",
flipv: randomInteger(2) === 2 ? true : false,
fliph: randomInteger(2) === 2 ? true : false,
controlledby: ""
}),
splatterEnlargeFunction = function (splatterDrawing, targetWidth, increment) {
var sx = splatterDrawing.get("width"),
sy = splatterDrawing.get("height");
if (sx < targetWidth) {
splatterDrawing.set({width: sx + increment, height: sy + increment});
setTimeout(function () {splatterEnlargeFunction(splatterDrawing, targetWidth, increment); }, 60);
}
};
setTimeout(function () {
splatterEnlargeFunction(createResult, 120 + randomInteger(40), 9);
}, 100);
}
// Script to add a splat of blood to a token
on("chat:message", function (msg) {
var cmdName = "!splatter ",
msgTxt = msg.content,
targetTokenId,
target;
if (msg.type === "api" && msgTxt.indexOf(cmdName) !== -1) {
targetTokenId = msgTxt.slice(cmdName.length);
if (_.isString(targetTokenId) && targetTokenId.length > 0) {
target = getObj("graphic", targetTokenId);
createSplat(target.get("_pageid"), target.get("top"), target.get("left"), target.get("width") / 2);
}
}
});
/* TODO: Listen to "lastmove" for a bloodtrail for "wounded tokens */
Edit 1 Notice that you must setup the bloodUrls variable yourself. I used the ones from this marketplace item (there's two blood splatters in there, they work pretty well), and because it's not free I didn't retain the urls to the images in my library (I don't even know if someone else's campaign could use resources in my library...).