Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[SCRIPT] Blood and Honor - Reversed Calculations

1438780303

Edited 1438869228
DK Heinrich
Marketplace Creator
Sheet Author
Due to my system comparing an adjustable DAMAGE total to a mostly constant HEALTH score, where the damage number goes up until it equals or exceeds the health score (compared to HP going down until reaching zero) I needed to alter the existing script... and it works. Thanks to those that tossed in ideas in previous threads and to those who gave me ideas about how to correct my errors. It is not a huge change, but its the 1st time I have really changed a scripts actual function so... here it is. If you have a system that works this way. btw - this is off of version 0.6 as I wanted to use the github copy as opposed the the version 0.8 that I could only find cut and pasted into messages (I had an illegal character and wanted to make sure I was clean). I do not know what changed in v.7 and v.8 - but so far this works as I think it is intended. ///////////////////////////////////////////////// /***********************************************/ var BloodAndHonor = { author: { name: "John C." || "Echo" || "SplenectomY", company: "Team Asshat" || "The Alehounds", contact: "<a href="mailto:echo@TeamAsshat.com" rel="nofollow">echo@TeamAsshat.com</a>", }, version: "0.6", gist: "<a href="https://gist.github.com/SplenectomY/097dac3e427ec50f32c9" rel="nofollow">https://gist.github.com/SplenectomY/097dac3e427ec50f32c9</a>", forum: "<a href="https://app.roll20.net/forum/post/1477230/" rel="nofollow">https://app.roll20.net/forum/post/1477230/</a>", /***********************************************/ ///////////////////////////////////////////////// // 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: // <a href="https://wiki.roll20.net/API:Objects#imgsrc_and_avatar_property_restrictions" rel="nofollow">https://wiki.roll20.net/API:Objects#imgsrc_and_avatar_property_restrictions</a> // You can add as many as you'd like to either category. // Spatters are also used for blood trails. spatters: [ "<a href="https://s3.amazonaws.com/files.d20.io/images/11286771/xRLL9raFNt_TQ8SgqslqAg/thumb.jpg?1438705742" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11286771/xRLL9raFNt_TQ8SgqslqAg/thumb.jpg?1438705742</a>", "<a href="https://s3.amazonaws.com/files.d20.io/images/11286727/6x7XPEuQAGcxNcCqNMQ0Ng/thumb.png?1438705560" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11286727/6x7XPEuQAGcxNcCqNMQ0Ng/thumb.png?1438705560</a>", "<a href="https://s3.amazonaws.com/files.d20.io/images/11286716/IqrtE9CArI4Ir8Xrhuztpw/thumb.png?1438705510" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11286716/IqrtE9CArI4Ir8Xrhuztpw/thumb.png?1438705510</a>", "<a href="https://s3.amazonaws.com/files.d20.io/images/11286704/n-l3XDjVM10rHAaxBh9YdQ/thumb.png?1438705444" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11286704/n-l3XDjVM10rHAaxBh9YdQ/thumb.png?1438705444</a>", "<a href="https://s3.amazonaws.com/files.d20.io/images/11286697/8LVFOJ8m8MkD0R2evQ2crw/thumb.png?1438705411" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11286697/8LVFOJ8m8MkD0R2evQ2crw/thumb.png?1438705411</a>", "<a href="https://s3.amazonaws.com/files.d20.io/images/11286685/wmdeoTlHH6oyz5mI8KVjOQ/thumb.png?1438705329" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11286685/wmdeoTlHH6oyz5mI8KVjOQ/thumb.png?1438705329</a>", ], pools: [ "<a href="https://s3.amazonaws.com/files.d20.io/images/11286841/FCh9qOHYJPOeX3dsLfvmEA/thumb.jpg?1438705968" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11286841/FCh9qOHYJPOeX3dsLfvmEA/thumb.jpg?1438705968</a>", ], 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); }, }; 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) { 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") &gt;= obj.get("bar3_max") / 2 && prev["bar3_value"] &lt; obj.get("bar3_value") && obj.get("bar3_value") &lt; obj.get("bar3_max")) { if (randomInteger(obj.get("bar3_max")) &lt; obj.get("bar3_value")) { 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") &gt;= obj.get("bar3_max")) { 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") &gt;= obj.get("bar3_max") / 2 && (obj.get("gmnotes")).indexOf("noblood") == -1) { if (randomInteger(obj.get("bar3_max")) &lt; 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"))); } } }); 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); }); } } }); });
1438787612

Edited 1438868032
DK Heinrich
Marketplace Creator
Sheet Author
above had an issue - it crashed when I did damage to a token that was larger than 1 square. So I got the v0.8 copy hoping that it would take that into account possibly and did same changes as above... and I broke it... getting Unexpected Identifier error. Here is the v0.8 script - if anyone can scan it to see if anything jumps out at them as to what would cause it. Thanks! EDIT: used code box - Thanks (learn something new every day...) ///////////////////////////////////////////////// /***********************************************/ var BloodAndHonor = { &nbsp; &nbsp; author: { name: "John C." || "Echo" || "SplenectomY", company: "Team Asshat" || "The Alehounds", contact: "<a href="mailto:echo@TeamAsshat.com" rel="nofollow">echo@TeamAsshat.com</a>", modifited by: "DK Heinrich", }, version: "0.8", gist: "<a href="https://gist.github.com/SplenectomY/097dac3e427ec50f32c9" rel="nofollow">https://gist.github.com/SplenectomY/097dac3e427ec50f32c9</a>", forum: "<a href="https://app.roll20.net/forum/post/1477230/" rel="nofollow">https://app.roll20.net/forum/post/1477230/</a>", wiki: "<a href="https://wiki.roll20.net/Script:Blood_And_Honor:_Automatic_blood_spatter,_pooling_and_trail_effects" rel="nofollow">https://wiki.roll20.net/Script:Blood_And_Honor:_Automatic_blood_spatter,_pooling_and_trail_effects</a>", /***********************************************/ ///////////////////////////////////////////////// // 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: // &nbsp;<a href="https://wiki.roll20.net/API:Objects#imgsrc_and_av" rel="nofollow">https://wiki.roll20.net/API:Objects#imgsrc_and_av</a>... // You can add as many as you'd like to either category. // Spatters are also used for blood trails. spatters: [ &nbsp; &nbsp; &nbsp; &nbsp; "<a href="https://s3.amazonaws.com/files.d20.io/images/11308495/wgpCBVKLA9xkZBPLZs2Jfw/thumb.png?1438782756" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11308495/wgpCBVKLA9xkZBPLZs2Jfw/thumb.png?1438782756</a>", &nbsp; &nbsp; &nbsp; &nbsp; "<a href="https://s3.amazonaws.com/files.d20.io/images/11308515/JPJbvubaL7Fbj7jCmMLRdw/thumb.png?1438782875" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11308515/JPJbvubaL7Fbj7jCmMLRdw/thumb.png?1438782875</a>", &nbsp; &nbsp; &nbsp; &nbsp; "<a href="https://s3.amazonaws.com/files.d20.io/images/11308554/wO9ME0h45T74xq29GpTlxw/thumb.png?1438783132" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11308554/wO9ME0h45T74xq29GpTlxw/thumb.png?1438783132</a>", &nbsp; &nbsp; &nbsp; &nbsp; "<a href="https://s3.amazonaws.com/files.d20.io/images/11308568/YV9GDW2btgqpGf9LbCi8Og/thumb.png?1438783190" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11308568/YV9GDW2btgqpGf9LbCi8Og/thumb.png?1438783190</a>", &nbsp; &nbsp; &nbsp; &nbsp; "<a href="https://s3.amazonaws.com/files.d20.io/images/11308599/07Znimavzx-DqON9R2NtrA/thumb.png?1438783373" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11308599/07Znimavzx-DqON9R2NtrA/thumb.png?1438783373</a>", &nbsp; &nbsp; &nbsp; &nbsp; "<a href="https://s3.amazonaws.com/files.d20.io/images/11308621/IRkRSt7rxYUzu9df2XSBVw/thumb.png?1438783490" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11308621/IRkRSt7rxYUzu9df2XSBVw/thumb.png?1438783490</a>", &nbsp; &nbsp; &nbsp; &nbsp; "<a href="https://s3.amazonaws.com/files.d20.io/images/11308629/pMR0S8SbA7rzKDnw12FOgg/thumb.png?1438783545" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11308629/pMR0S8SbA7rzKDnw12FOgg/thumb.png?1438783545</a>", &nbsp; &nbsp; &nbsp; &nbsp; "<a href="https://s3.amazonaws.com/files.d20.io/images/11308636/jWVMPfRh_eFiEy75AZ27Ng/thumb.png?1438783602" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11308636/jWVMPfRh_eFiEy75AZ27Ng/thumb.png?1438783602</a>", &nbsp; &nbsp; &nbsp; &nbsp; "<a href="https://s3.amazonaws.com/files.d20.io/images/11308646/5rvvjhNrq2f-yDpOP4QvhQ/thumb.png?1438783656" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11308646/5rvvjhNrq2f-yDpOP4QvhQ/thumb.png?1438783656</a>", &nbsp; &nbsp; &nbsp; &nbsp; "<a href="https://s3.amazonaws.com/files.d20.io/images/11308660/y29gFvkPhkbzqmXQTZiHfg/thumb.png?1438783726" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11308660/y29gFvkPhkbzqmXQTZiHfg/thumb.png?1438783726</a>", ], pools: [ &nbsp; &nbsp; &nbsp; &nbsp; "<a href="https://s3.amazonaws.com/files.d20.io/images/11308586/mVAuc41Amb78bnO5iTMSPg/thumb.png?1438783301" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11308586/mVAuc41Amb78bnO5iTMSPg/thumb.png?1438783301</a>", &nbsp; &nbsp; &nbsp; &nbsp; "<a href="https://s3.amazonaws.com/files.d20.io/images/11308609/G8y5VJNFrMZzwer_Gth8QA/thumb.png?1438783421" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/11308609/G8y5VJNFrMZzwer_Gth8QA/thumb.png?1438783421</a>", &nbsp; &nbsp; ], 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 &gt; 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") &gt;= obj.get("bar3_max") / 2 && prev["bar3_value"] &lt; obj.get("bar3_value") && obj.get("bar3_value") &lt; obj.get("bar3_max")) { if (randomInteger(obj.get("bar3_max")) &lt; 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") &gt;= 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") &gt;= obj.get("bar3_max") / 2 && (obj.get("gmnotes")).indexOf("noblood") == -1) { if (randomInteger(obj.get("bar3_max")) &lt; 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 (BloodAndHonor.useIsGM && !isGM(msg.playerid)) { 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); }); } } }); });
1438803418
Kryx
Pro
Sheet Author
API Scripter
I'd suggest you use the code feature so that it has proper indentation. Click the paragraph looking thing in the post text editor and click code - paste the data in that block.
1438804664

Edited 1438804982
DK Heinrich
Marketplace Creator
Sheet Author
was just told how to do that a few minutes ago - it has now been edited. EDIT - and I am seeing some lines of the added .png files that are not indented properly, but they look like they are in the API... trying to tweak that to see if it helps.
1438868100

Edited 1438869289
DK Heinrich
Marketplace Creator
Sheet Author
was able to get rid of 2 rogue blank spaces in and around the image files - but still tossing the&nbsp; Unexpected Identifier error. Anyone else find an error? EDIT - I edited previous post with most current version of script that is tossing the error. EDIT - tried adding in a 'tab' in indent the image files (like they are in the v0.6) and it still tossed the error.
1438973306
DK Heinrich
Marketplace Creator
Sheet Author
Just bump looking for help still - thanks! :)