Character Vault
Any Concept / Any System
Compendium
Your System Come To Life
Roll20 for Android
Streamlined for your Tablet
Roll20 for iPad
Streamlined for your Tablet

Personal tools

Difference between revisions of "Script:Blood And Honor: Automatic blood spatter, pooling and trail effects"

From Roll20 Wiki

Jump to: navigation, search
(switch place on page/redirect)
 
(19 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{script overview
+
#REDIRECT [[Script:Blood and Honor]]
|name=Blood And Honor
+
|author=242509
+
|version=0.2
+
|lastmodified=2015-01-05}}
+
<img src="https://s3.amazonaws.com/files.d20.io/images/7000553/V1ay9Ot3LVGPprW8KWBKRA/med.jpg?1420449414">
+
Blood and Honor is an automatic way to add lightweight blood effects to your campaign, without any animations or commands.
+
 
+
'''How it works:'''
+
 
+
:Any token in the object layer that has a bar3 (health) value less than or equal to its max has a chance to bleed. The chance goes up depending on how severe the damage is.
+
 
+
'''Spatter'''
+
:Any time a token's health bar is changed so that it's total value is half or less of its maximum, a randomly selected, offset and rotated blood graphic will be placed on the map layer beneath it. The exact formula is as such - the system rolls a dice with as many sides as the max health value. If that roll exceeds the current health value, a blood spatter appears.
+
 
+
'''Trails'''
+
:If a token moves while at or below half health, a smaller blood graphic will appear where it moves to based on the chances described above. Less health = more blood.
+
 
+
'''Pool'''
+
:If a token's bar3 value falls 0 or below, a large pool of blood graphic appears on the map layer beneath it.
+
 
+
=== Code ===
+
<pre data-language="javascript">/////////////////////////////////////////////////
+
/***********************************************/
+
var BloodAndHonor = {
+
author: {
+
name: "John C." || "Echo" || "SplenectomY",
+
company: "Team Asshat" || "The Alehounds",
+
contact: "echo@TeamAsshat.com",
+
},
+
version: "0.2",
+
gist: "https://gist.github.com/SplenectomY/1f198a3114903d7a3271",
+
forum: "https://app.roll20.net/forum/post/1386741/",
+
/***********************************************/
+
/////////////////////////////////////////////////
+
+
// This value should match the size of a standard grid in your campaign
+
// Default is 70 px x 70 px square, Roll20's default.
+
tokenSize: 70,
+
 
+
// YOU MUST ADD YOUR OWN SPATTERS AND POOLS TO YOUR LIBRARY
+
// AND GET THE IMAGE LINK VIA YOUR WEB BROWSER.
+
// FOLLOW THE INSTRUCTIONS HERE:
+
// https://wiki.roll20.net/API:Objects#imgsrc_and_avatar_property_restrictions
+
// You can add as many as you'd like to either category.
+
// Spatters are also used for blood trails.
+
spatters: [
+
//"https://s3.amazonaws.com/files.d20.io/images/6993500/mAA-8agYIwkhEciVVSCFmg/thumb.png?1420411542",
+
],
+
pools: [
+
//"https://s3.amazonaws.com/files.d20.io/images/6993478/77YowTZze57mGAHfSaxwYg/thumb.png?1420411480",
+
],
+
chooseBlood: function chooseBlood(type) {
+
if (type == "spatter") return BloodAndHonor.spatters[randomInteger(BloodAndHonor.spatters.length) - 1]
+
if (type == "pool") return BloodAndHonor.pools[randomInteger(BloodAndHonor.pools.length) - 1]
+
},
+
getOffset: function getOffset() {
+
if (randomInteger(2) == 1) return 1
+
else return -1
+
},
+
bloodColor: function bloodColor(gmnotes) {
+
if (gmnotes.indexOf("bloodcolor_purple") !== -1) return "#0000ff"
+
if (gmnotes.indexOf("bloodcolor_blue") !== -1) return "#00ffff"
+
if (gmnotes.indexOf("bloodcolor_orange") !== -1) return "#ffff00"
+
else return "transparent"
+
},
+
createBlood: function createBlood(gPage_id,gLeft,gTop,gWidth,gType,gColor) {
+
gLeft = gLeft + (randomInteger(Math.floor(gWidth / 2)) * BloodAndHonor.getOffset())
+
gTop = gTop + (randomInteger(Math.floor(gWidth / 2)) * BloodAndHonor.getOffset())
+
setTimeout(function(){
+
toFront(fixedCreateObj("graphic",{
+
imgsrc: gType,
+
gmnotes: "blood",
+
pageid: gPage_id,
+
left: gLeft,
+
tint_color: gColor,
+
top: gTop,
+
rotation: randomInteger(360) - 1,
+
width: gWidth,
+
height: gWidth,
+
layer: "map",
+
}));
+
},5);
+
},
+
};
+
 
+
fixedCreateObj = (function () {
+
return function () {
+
var obj = createObj.apply(this, arguments);
+
if (obj && !obj.fbpath) {
+
obj.fbpath = obj.changed._fbpath.replace(/([^\/]*\/){4}/, "/");
+
}
+
return obj;
+
};
+
}());
+
 
+
on("change:graphic:bar3_value", function(obj) {
+
if(obj.get("bar3_max") === "" || obj.get("layer") != "objects") return;
+
// Create spatter near token if "bloodied".
+
// Chance of spatter depends on severity of damage
+
if(obj.get("bar3_value") <= obj.get("bar3_max") / 2) {
+
if (randomInteger(obj.get("bar3_max")) > obj.get("bar3_value") && (obj.get("gmnotes")).indexOf("noblood") == -1) {
+
BloodAndHonor.createBlood(obj.get("_pageid"), obj.get("left"), obj.get("top"), BloodAndHonor.tokenSize, BloodAndHonor.chooseBlood("spatter"), BloodAndHonor.bloodColor(obj.get("gmnotes")));
+
}
+
}
+
// Create pool near token if health drops below 1.
+
else if(obj.get("bar3_value") <= 0) {
+
BloodAndHonor.createBlood(obj.get("_pageid"), obj.get("left"), obj.get("top"), Math.floor(BloodAndHonor.tokenSize * 1.5), BloodAndHonor.chooseBlood("pool"), BloodAndHonor.bloodColor(obj.get("gmnotes")));
+
}
+
});
+
 
+
//Make blood trails, chance goes up depending on how injured a token is
+
on("change:graphic:lastmove", function(obj) {
+
if(obj.get("bar3_value") <= obj.get("bar3_max") / 2) {
+
if (randomInteger(obj.get("bar3_max")) > obj.get("bar3_value")) {
+
BloodAndHonor.createBlood(obj.get("_pageid"), obj.get("left"), obj.get("top"), Math.floor(BloodAndHonor.tokenSize / 2), BloodAndHonor.chooseBlood("spatter"), BloodAndHonor.bloodColor(obj.get("gmnotes")));
+
}
+
}
+
});</pre>
+
 
+
=== Configuration ===
+
 
+
'''Stop bleeding'''
+
 
+
:Putting <code>noblood</code> in any token's GM Notes will cause it to never bleed.
+
 
+
'''Change color'''
+
 
+
:There are currently three custom colors, but you can easily add your own in the script. Put one of the following into the GM Notes if you want the token to bleed a color other than red:
+
 
+
<code>bloodcolor_orange</code>, <code>bloodcolor_purple</code>, <code>bloodcolor_blue</code>
+
 
+
 
+
=== See Also ===
+
 
+
* [https://gist.github.com/SplenectomY/1f198a3114903d7a3271 GitHub Gist for this script]
+
* [https://app.roll20.net/forum/post/1386741/ Forum post]
+

Latest revision as of 11:52, 21 May 2021

  1. REDIRECT Script:Blood and Honor