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
m (Changelog)
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{script overview
 
{{script overview
|name=Blood And Honor
+
|name=Blood-and-Honor
 
|author={{user profile|242509|John C.}}
 
|author={{user profile|242509|John C.}}
|version=0.7
+
|version=0.8
 
|lastmodified=2015-01-08}}
 
|lastmodified=2015-01-08}}
  
Blood and Honor is an automatic way to add lightweight blood effects to your campaign, without any animations or commands.
+
'''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. 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 chance for a blood spatter to appear is: <code>(max - current) / max</code>. In other words, the percentage of ''missing'' heath is the chance to water the fields with blood. The larger the amount of damage taken at once, the bigger the spatter will be.
  
: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.
+
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 creates more blood. If a token's bar3 value falls to 0 or below, a large pool of blood graphic appears on the map layer beneath it.
  
'''Spatter'''
+
=== Syntax ===
: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. The larger the amount of damage taken at once, the bigger the spatter will be.
+
{{syntaxbox top|Blood And Honor: Automatic blood spatter, pooling and trail effects}}
 +
{{API command|clearblood}}
 +
{{syntaxbox end}}
  
'''Trails'''
+
If [[Script:IsGM Auth Module|IsGM Auth Module]] is installed and <code>useIsGM</code> is set to <code>true</code>, the <code>!clearblood</code> command will be restricted to GM use only.
: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'''
+
The <code>!clearblood</code> command will move all of the blood splatter graphics to the top left corner of the map so that they can be quickly deleted.
: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.7",
+
gist: "https://gist.github.com/SplenectomY/097dac3e427ec50f32c9",
+
forum: "https://app.roll20.net/forum/post/1477230/",
+
wiki: "https://wiki.roll20.net/Script:Blood_And_Honor:_Automatic_blood_spatter,_pooling_and_trail_effects",
+
/***********************************************/
+
/////////////////////////////////////////////////
+
+
// 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,
+
+
// If you have it installed, this will plug in TheAaron's isGM auth module,
+
// which will make it so only the GM can use the !clearblood command
+
// Change to "true" if you want to check for authorization
+
useIsGM: false,
+
+
// 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",
+
}));
+
},50);
+
},
+
timeout: 0,
+
onTimeout: function theFinalCountdown() {
+
if (BloodAndHonor.timeout > 0) {
+
BloodAndHonor.timeout--;
+
} else {
+
return;
+
}
+
}
+
};
+
 
+
fixedCreateObj = (function () {
+
return function () {
+
var obj = createObj.apply(this, arguments);
+
if (obj && !obj.fbpath) {
+
obj.fbpath = obj.changed._fbpath.replace(/([^\/]*\/){4}/, "/");
+
}
+
return obj;
+
};
+
}());
+
 
+
on("ready", function(obj) {
+
+
setInterval(function(){BloodAndHonor.onTimeout()},1000);
+
 
+
on("change:graphic:bar3_value", function(obj, prev) {
+
if (obj.get("bar3_max") === "" || obj.get("layer") != "objects" || (obj.get("gmnotes")).indexOf("noblood") !== -1) return;
+
// Create spatter near token if "bloodied".
+
// Chance of spatter depends on severity of damage
+
else if (obj.get("bar3_value") <= obj.get("bar3_max") / 2 && prev["bar3_value"] > obj.get("bar3_value") && obj.get("bar3_value") > 0) {
+
if (randomInteger(obj.get("bar3_max")) > obj.get("bar3_value")) {
+
var bloodMult = 1 + ((obj.get("bar3_value") - prev["bar3_value"]) / obj.get("bar3_max"));
+
BloodAndHonor.createBlood(obj.get("_pageid"), obj.get("left"), obj.get("top"), Math.floor(BloodAndHonor.tokenSize * bloodMult), 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 (BloodAndHonor.timeout == 0) {
+
if (obj.get("bar3_value") <= obj.get("bar3_max") / 2 && (obj.get("gmnotes")).indexOf("noblood") == -1) {
+
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")));
+
BloodAndHonor.timeout += 2;
+
}
+
}
+
});
+
}
+
+
on("chat:message", function(msg) {
+
if (msg.type == "api" && msg.content.indexOf("!clearblood") !== -1) {
+
if (isGM(msg.playerid) == false && BloodAndHonor.useIsGM == true) {
+
sendChat(msg.who,"/w " + msg.who + " You are not authorized to use that command!");
+
return;
+
} else {
+
objects = filterObjs(function(obj) {
+
if(obj.get("type") == "graphic" && obj.get("gmnotes") == "blood") return true;
+
else return false;
+
});
+
_.each(objects, function(obj) {
+
obj.set("left",0); obj.set("top",0);
+
});
+
}
+
}
+
});
+
});</pre>
+
  
 
=== Configuration ===
 
=== Configuration ===
 +
Adding the text <code>noblood</code> in any token's GM Notes will cause it to never bleed.
  
'''Stop bleeding'''
+
Add one of the following keywords into the GM Notes of a token if you want the token to bleed a color other than red: <code>bloodcolor_orange</code>, <code>bloodcolor_purple</code>, <code>bloodcolor_blue</code>
 
+
:Putting <code>noblood</code> in any token's GM Notes will cause it to never bleed.
+
 
+
'''Clear the map of blood'''
+
 
+
:Use the <code>!clearblood</code> command in chat and all blood will move to the top left corner of the map for convenient removal.
+
 
+
'''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>
+
  
 
'''NOTE: YOU MUST SET YOUR OWN IMAGE URLS IN THE SCRIPT! You can put as many of either type (spatters or pools) as you wish, and it will choose from them randomly. See [https://wiki.roll20.net/API:Objects#imgsrc_and_avatar_property_restrictions this page] for more details.'''
 
'''NOTE: YOU MUST SET YOUR OWN IMAGE URLS IN THE SCRIPT! You can put as many of either type (spatters or pools) as you wish, and it will choose from them randomly. See [https://wiki.roll20.net/API:Objects#imgsrc_and_avatar_property_restrictions this page] for more details.'''
  
 
=== Changelog ===
 
=== Changelog ===
 
+
{{changelog version|0.8|2015-01-08|* Switched order of GM Auth module checks (thanks Brian)
'''v.0.7 (2015-01-08)'''
+
* [bugfix] ironed out a syntax error}}
* Size of spatters determined by amount of damage received
+
{{changelog version|0.7|2015-01-08|* Size of spatters determined by amount of damage received
* Addressed stability issue (trails) with cooldown timer
+
* Addressed stability issue (trails) with cooldown timer}}
'''v.0.6 (2015-01-07)'''
+
{{changelog version|0.6|2015-01-07|* Added support for TheAaron's GM Auth module}}
* Added support for TheAaron's GM Auth module
+
{{changelog version|0.5|2015-01-06|* Added on "ready" event to keep funny things from happening
'''v.0.5 (2015-01-06)'''
+
* !clearblood command will move all blood to top left corner of map}}
* Added on "ready" event to keep funny things from happening
+
{{changelog version|0.4|2015-01-05|* [bugfix] "noblood" check now properly passes all bleeding types}}
* !clearblood command will move all blood to top left corner of map
+
{{changelog version|0.3|2015-01-05|* [bugfix] blood pools now appear properly
'''v.0.4 (2015-01-05)'''
+
* Adding to bar3_value will no longer cause bleeding if the token is still below half health}}
* [bugfix] "noblood" check now properly passes all bleeding types
+
{{changelog version|0.2|2015-01-05|* Added layer check to make sure nothing bleeds on the non-object layers.
'''v.0.3 (2015-01-05)'''
+
* Fixed tabs and spacing}}
* [bugfix] blood pools now appear properly
+
{{changelog version|0.1|2015-01-05|* Release}}
* Adding to bar3_value will no longer cause bleeding if the token is still below half health
+
'''v.0.2 (2015-01-05)'''
+
* Added layer check to make sure nothing bleeds on the non-object layers.
+
* Fixed tabs and spacing
+
'''v.0.1 (2015-01-05)'''
+
* Release
+
  
 
=== See Also ===
 
=== See Also ===
 
* [https://www.youtube.com/watch?v=b-BhZRLwOZU&feature=youtu.be Explanatory video for this script]
 
* [https://www.youtube.com/watch?v=b-BhZRLwOZU&feature=youtu.be Explanatory video for this script]
* [https://gist.github.com/SplenectomY/1f198a3114903d7a3271 GitHub Gist for this script]
+
* [https://app.roll20.net/forum/post/1477230/script-blood-and-honor-automatic-blood-spatter-pooling-and-trail-effects-lightweight#post-1477230 Forum post]
* [https://app.roll20.net/forum/post/1386741/ Forum post]
+

Revision as of 17:32, 13 January 2015

API ScriptAuthor: John C.
Version: 0.8
Last Modified: 2015-01-08
Code: Blood-and-Honor
Dependencies: None
Conflicts: None

Blood and Honor is an automatic way to add lightweight blood effects to your campaign, without any animations or commands.

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. 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 chance for a blood spatter to appear is: (max - current) / max. In other words, the percentage of missing heath is the chance to water the fields with blood. The larger the amount of damage taken at once, the bigger the spatter will be.

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 creates more blood. If a token's bar3 value falls to 0 or below, a large pool of blood graphic appears on the map layer beneath it.

Contents

Syntax

!clearblood

If IsGM Auth Module is installed and useIsGM is set to true, the !clearblood command will be restricted to GM use only.

The !clearblood command will move all of the blood splatter graphics to the top left corner of the map so that they can be quickly deleted.

Configuration

Adding the text noblood in any token's GM Notes will cause it to never bleed.

Add one of the following keywords into the GM Notes of a token if you want the token to bleed a color other than red: bloodcolor_orange, bloodcolor_purple, bloodcolor_blue

NOTE: YOU MUST SET YOUR OWN IMAGE URLS IN THE SCRIPT! You can put as many of either type (spatters or pools) as you wish, and it will choose from them randomly. See this page for more details.

Changelog

v0.8 (2015-01-08)

  • Switched order of GM Auth module checks (thanks Brian)
  • [bugfix] ironed out a syntax error


v0.7 (2015-01-08)

  • Size of spatters determined by amount of damage received
  • Addressed stability issue (trails) with cooldown timer


v0.6 (2015-01-07)

  • Added support for TheAaron's GM Auth module


v0.5 (2015-01-06)

  • Added on "ready" event to keep funny things from happening
  •  !clearblood command will move all blood to top left corner of map


v0.4 (2015-01-05)

  • [bugfix] "noblood" check now properly passes all bleeding types


v0.3 (2015-01-05)

  • [bugfix] blood pools now appear properly
  • Adding to bar3_value will no longer cause bleeding if the token is still below half health


v0.2 (2015-01-05)

  • Added layer check to make sure nothing bleeds on the non-object layers.
  • Fixed tabs and spacing


v0.1 (2015-01-05)

  • Release


See Also