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

API Status Marker

1418425054
PrincessFairy
Marketplace Creator
/** * Set various token markers based on bar cur/max ratios * * The CONFIG array can have any number of configuration objects. These objects * are processed in order. * * barId - The ID of the bar to look at the values for [1, 2, 3] * barRatio - The ratio of bar value to max value that triggers setting the status marker [0 - 1] * status - The name of the status marker to toggle [redmarker, bluemarker, greenmarker, brownmarker, purplemarker, dead] * whenLow - The state of the marker when the bar value is <= the ratio [true, false] */ var CONFIG = [ {barId: 1, barRatio: .75, status: "pinkmarker", whenLow: true}, {barId: 1, barRatio: .5, status: "half-heart", whenLow: true}, {barId: 1, barRatio: .25, status: "redmarker", whenLow: true}, {barId: 1, barRatio: 0, status: "dead", whenLow: true}]; on("change:token", function(obj) { CONFIG.forEach(function(opts) { var maxValue = parseInt(obj.get("bar" + opts.barId + "_max")); var curValue = parseInt(obj.get("bar" + opts.barId + "_value")); log(opts.barId + ": " + curValue + "/" + maxValue); if (!isNaN(maxValue) && !isNaN(curValue)) { var markerName = "status_" + opts.status; if (curValue <= (maxValue * opts.barRatio)) { obj.set(markerName, opts.whenLow); } else { obj.set(markerName, !opts.whenLow); } } }); }); I am trying to get the configuration to show status marker at 3/4 hp but when I use the code it doesn't work. The code works for everything else, but will not add a marker at 3/4 hp. Could someone help me with the correct code? Also if anyone can offer up suggestions on how to create status marker icons on the bubbles to display what each one represents?
1418429743
The Aaron
Roll20 Production Team
API Scripter
Valid markers are: "red", "blue", "green", "brown", "purple", "pink", "yellow", "dead", "skull", "sleepy", "half-heart", "half-haze", "interdiction", "snail", "lightning-helix", "spanner", "chained-heart", "chemical-bolt", "death-zone", "drink-me", "edge-crack", "ninja-mask", "stopwatch", "fishing-net", "overdrive", "strong", "fist", "padlock", "three-leaves", "fluffy-wing", "pummeled", "tread", "arrowed", "aura", "back-pain", "black-flag", "bleeding-eye", "bolt-shield", "broken-heart", "cobweb", "broken-shield", "flying-flag", "radioactive", "trophy", "broken-skull", "frozen-orb", "rolling-bomb", "white-tower", "grab", "screaming", "grenade", "sentry-gun", "all-for-one", "angel-outfit", "archery-target" pinkmarker should be pink redmarker should be red That will probably fix it. You should probably post this in the API forum, as you will get more focused help there.
1418429782
Lithl
Pro
Sheet Author
API Scripter
Try changing the status from "pinkmarker" and "redmarker" to "pink" and "red". I am running a slightly modified version of this script in my current campaign: var statusManager = statusManager || {}; statusManager.CONFIG = [ {barId: 3, barRatio: .75, status: 'red', whenLow: true}, {barId: 3, barRatio: .25, status: 'purple', whenLow: true}, {barId: 3, barRatio: 5, status: 'black-flag', whenLow: true, exact: true}, {barId: 3, barRatio: 0, status: 'skull', whenLow: true}]; on('change:token', function(obj) { statusManager.CONFIG.forEach(function(opts) { var maxValue = parseInt(obj.get('bar' + opts.barId + '_max')); var curValue = parseInt(obj.get('bar' + opts.barId + '_value')); var markerName = 'status_' + opts.status; if(curValue != NaN) { if(opts.exact) { obj.set(markerName, opts.whenLow && (curValue <= opts.barRatio)); } else if (maxValue != NaN) { obj.set(markerName, opts.whenLow && (curValue <= (maxValue * opts.barRatio))); } } }); }); The biggest change I made was the addition of the "exact" option, as the system I'm playing has wound penalties at 75% and 25%, unconscious at exactly 5 HP (regardless of percentage), and dead at 0 HP.
1418429819
Gauss
Forum Champion
Moved to the API forum.
1418433919
PrincessFairy
Marketplace Creator
Thanks for the help on that, now I figured that out I was trying to add more markers but only 4 are showing up and disable anything with a negative number. var CONFIG = [ {barId: 1, barRatio: .75, status: "pink", whenLow: true}, {barId: 1, barRatio: .5, status: "half-heart", whenLow: true}, {barId: 1, barRatio: .25, status: "red", whenLow: true}, {barId: 1, barRatio: 0, status: "pummeled", whenLow: true}, {barId: 1, barRatio: -1, status: "interdiction", whenLow: true}, {barId: 1, barRatio: -10, status: "dead", whenLow: true}]; on("change:token", function(obj) { CONFIG.forEach(function(opts) { var maxValue = parseInt(obj.get("bar" + opts.barId + "_max")); var curValue = parseInt(obj.get("bar" + opts.barId + "_value")); log(opts.barId + ": " + curValue + "/" + maxValue); if (!isNaN(maxValue) && !isNaN(curValue)) { var markerName = "status_" + opts.status; if (curValue <= (maxValue * opts.barRatio)) { obj.set(markerName, opts.whenLow); } else { obj.set(markerName, !opts.whenLow); } } }); });
1418435115
PrincessFairy
Marketplace Creator
The Dragon said: Thanks for the help on that, now I figured that out I was trying to add more markers but only 4 are showing up and disable anything with a negative number. var CONFIG = [ {barId: 1, barRatio: .75, status: "pink", whenLow: true}, {barId: 1, barRatio: .5, status: "half-heart", whenLow: true}, {barId: 1, barRatio: .25, status: "red", whenLow: true}, {barId: 1, barRatio: 0, status: "pummeled", whenLow: true}, {barId: 1, barRatio: -1, status: "interdiction", whenLow: true}, {barId: 1, barRatio: -10, status: "dead", whenLow: true}]; on("change:token", function(obj) { CONFIG.forEach(function(opts) { var maxValue = parseInt(obj.get("bar" + opts.barId + "_max")); var curValue = parseInt(obj.get("bar" + opts.barId + "_value")); log(opts.barId + ": " + curValue + "/" + maxValue); if (!isNaN(maxValue) && !isNaN(curValue)) { var markerName = "status_" + opts.status; if (curValue <= (maxValue * opts.barRatio)) { obj.set(markerName, opts.whenLow); } else { obj.set(markerName, !opts.whenLow); } } }); }); Apparently it is the - number affecting the status, but I don't know how else to put it in there
1418435564
PrincessFairy
Marketplace Creator
Went around it the long way but got same results var CONFIG = [ {barId: 1, barRatio: .75, status: "pink", whenLow: true}, {barId: 1, barRatio: .5, status: "half-heart", whenLow: true}, {barId: 1, barRatio: .25, status: "red", whenLow: true}, {barId: 1, barRatio: 0, status: "pummeled", whenLow: true}]; on("change:token", function(obj) { CONFIG.forEach(function(opts) { var maxValue = parseInt(obj.get("bar" + opts.barId + "_max")); var curValue = parseInt(obj.get("bar" + opts.barId + "_value")); log(opts.barId + ": " + curValue + "/" + maxValue); if (!isNaN(maxValue) && !isNaN(curValue)) { var markerName = "status_" + opts.status; if (curValue <= (maxValue * opts.barRatio)) { obj.set(markerName, opts.whenLow); } else { obj.set(markerName, !opts.whenLow); } } }); }); on("change:graphic", function(obj) { if(obj.get("bar1_max") === "") return; if(obj.get("bar1_value") <= -1) { obj.set({ status_interdiction: true }); } else { obj.set({ status_interdiction: false }); } if(obj.get("bar1_value") <= -10) { obj.set({ status_dead: true }); } else { obj.set({ status_dead: false }); } });
1418438324
Lithl
Pro
Sheet Author
API Scripter
The final version of your modified script is setting "interdiction" when bar1 <= -1 and "dead" when bar1 <= -10. The previous version of your script (where you first try to add the negative statuses) is setting "interdiction" when bar1 <= -1 * bar1_max (that is, the negative value whose magnitude is equal to the maximum value of bar1) and setting "dead" when bar1 <= -10 * bar1_max (that is, the negative value whose magnitude is ten times the maximum value of bar1). The problem is that for these negative values you appear to be looking to compare the bar to a specific number, while the script is comparing the bar to a percentage. You could use my modification of the script (with the exact: true option) to get the behavior you appear to be looking for with the negative bar values.