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] Bloodied and Dead Status Markers - Extended

1395349674

Edited 1395427996
Version: 1.1 I have made a few changes to the Bloodied and Dead Status Markers script from <a href="https://wiki.roll20.net/API:Cookboox" rel="nofollow">https://wiki.roll20.net/API:Cookboox</a> . You do have now the following settings: var lifeBarNumber = 3; // 3:red; 2:blue; 1:green var percentForRedmark = 50; // Write for example 50 for 50% var totalKillThreshold = -10; // As soon as a tokens life goes bellow this value it gets an additional (killed) symbol. That means, that you can select which bare you would like to use as your life bar. It allows you to select the %-level after which a token is seen as wounded. It gives you the ability to select an ending level. Which means, after this amount of negative hit points a target counts as completely dead (no reanimation). Additional to that, you get a symbol if a token has been reanimated (his life points have been below 1 and now are again higher than 0). This symbol disappears once the token reaches again max heal. If you do find any bugs let me know. on("change:graphic", function(obj) { // Settings: var lifeBarNumber = 3; // 3:red; 2:blue; 1:green var percentForRedmark = 50; // Write for example 50 for 50% var totalKillThreshold = -10; // As soon as a tokens life goes bellow this value // it gets an additional (killed) symbol. // Is life bar set at all? // If not simply escape the function. if(obj.get("bar" + lifeBarNumber + "_max") === "") return; // Back from the dead? if((obj.get("status_dead") == true || obj.status_skull == true) && obj.get("bar" + lifeBarNumber + "_value") &gt; 0){ SetStatuSymbolById(obj,3,1); } // Total-kill if(obj.get("bar" + lifeBarNumber + "_value") &lt;= totalKillThreshold){ SetStatuSymbolById(obj,0,0); SetStatuSymbolById(obj,1,1); SetStatuSymbolById(obj,2,1); SetStatuSymbolById(obj,3,0); } // Dead else if(obj.get("bar" + lifeBarNumber + "_value") &lt;= 0){ SetStatuSymbolById(obj,0,0); SetStatuSymbolById(obj,1,1); SetStatuSymbolById(obj,2,0); SetStatuSymbolById(obj,3,0); } // Bellow x% life else if(obj.get("bar" + lifeBarNumber + "_value") &lt;= obj.get("bar" + lifeBarNumber + "_max") / 100 * percentForRedmark) { SetStatuSymbolById(obj,0,1); SetStatuSymbolById(obj,1,0); SetStatuSymbolById(obj,2,0); } else{ ResetDeathSymbols(obj); // Back from the dead but now again with full (or beyond that) health? // TODO: &gt;= not working..? if(obj.get("bar" + lifeBarNumber + "_value") == obj.get("bar" + lifeBarNumber + "_max")){ SetStatuSymbolById(obj,3,0); } } }); /* Reset the following symboles redmarker, dead & skull */ function ResetDeathSymbols(obj){ SetStatuSymbolById(obj,0,0); SetStatuSymbolById(obj,1,0); SetStatuSymbolById(obj,2,0); } /* Sets the value of a given tokens symbol by the symbols id symbolid: 0:redmarker 1:dead 2:skull 3:death-zone x:y value: true/1 or false/0 */ function SetStatuSymbolById(obj, symbolid, value) { switch(symbolid){ case 0: SetStatusSymbolByName(obj, "redmarker", value); break; case 1: SetStatusSymbolByName(obj, "dead", value); break; case 2: SetStatusSymbolByName(obj, "skull", value); break; case 3: SetStatusSymbolByName(obj, "death-zone", value); break; default: // Something is wrong so log it and exit. log("Error: SetStatuSymbolById - There was no usable number for symbolid given!"); log(" Object name: " + obj.get("name") + "; symbolid: " + symbolid + "; value: " + value); return; } } /* Sets the value of a given tokens symbol by the symbols name value: true/1 or false/0 */ function SetStatusSymbolByName(obj, symbolname, value){ value = CheckForTrueOrFalse(value); // Set the symbols value. obj.set("status_" + symbolname, value); } /* Checks if a given value is true or false. value: 0:false 1:true default:false */ function CheckForTrueOrFalse(value){ if (value === 0){value = false;} else if (value === 1){value = true;} else if (value === true || value === false){ // Nothing to do, these are valid values. } // The input for value is not known, therefore we set it to false. else{ value = false; log("Error: CheckForTrueOrFalse - An unhandled value has been used!"); log(" value has been set to de default value " + value); } return value; } /* Debug function Place where ever you would like to see the actual values. */ function DebugMe(obj,msg){ log("--- DEBUG: " + msg + "---"); log("obj name: " + obj.get("name")); log("status values:"); log("redmarker: " + obj.get("status_redmarker")); log("dead: " + obj.get("status_dead")); log("skull: " + obj.get("status_skull")); log("death: " + obj.get("status_death")); } By the way: does any one of you know why this is not working or how I could get it to work? // Sets the value of a given tokens symbol by the symbols name // value: true/1 or false/0 // // Actuall not in use, due to parsing problems... function SetSymbolByName(obj, symbolname, value){ if (value == 0){value = false;} else if (value == 1){value = true;} else if (value == true || value = false){ // Nothing to do, these are valid values. } else{value = true;} // Set the symbols value. //obj.set({ symbolname: value }); obj[symbolname] = value; //log(obj.get("name") + " " + symbolname + " " + value); }
What are you trying to do with the second part that isn't working?
1395350332

Edited 1395427814
Do not use this! It is a non-working example! I have the idea to put it like this: // Sets the value of a given tokens symbol by the symbols id // // 0:status_redmarker // 1:status_dead // 2:status_skull // 3:status_death-zone // x:y // // value: true/1 or false/0 function SetSymbolById(obj, symbolid, value) { switch(symbolid){ case 0: SetSymbolByName(obj, "status_redmarker", value); break; case 1: SetSymbolByName(obj, "status_dead", value); break; case 2: SetSymbolByName(obj, "status_skull", value); break; case 3: SetSymbolByName(obj, "status_death-zone", value); break; default: // Something is wrong so log it and exit. log("Error: SetSymbolById has been called, however ther was no usable number for symbolid given!"); } } // Sets the value of a given tokens symbol by the symbols name // value: true/1 or false/0 function SetSymbolByName(obj, symbolname, value){ if (value == 0){value = false;} else if (value == 1){value = true;} else if (value == true || value = false){ // Nothing to do, these are valid values. } else{value = true;} // Set the symbols value. obj[symbolname] = value; //log(obj.get("name") + " " + symbolname + " " + value); } It does not bring any additional functionality, it’s just for my and for understanding... ;)
I meant tell me what you're wanting it to do. Tell me in plain english.
1395364481
Lithl
Pro
Sheet Author
API Scripter
Cuerpo said: By the way: does any one of you know why this is not working or how I could get it to work? // Sets the value of a given tokens symbol by the symbols name // value: true/1 or false/0 // // Actuall not in use, due to parsing problems... function SetSymbolByName(obj, symbolname, value){ if (value == 0){value = false;} else if (value == 1){value = true;} else if (value == true || value = false){ // Nothing to do, these are valid values. } else{value = true;} // Set the symbols value. //obj.set({ symbolname: value }); obj[symbolname] = value; //log(obj.get("name") + " " + symbolname + " " + value); } First: It would be faster to set value with value = !!value; instead of the series of conditional blocks. This is the standard method for coercing a JavaScript value into a boolean. (How it works: !value checks the truthiness of value , and negates it; things like 0, false, NaN, and undefined are all falsey values. After negating the original truthiness and making it a boolean, that boolean is negated again, giving you a boolean with a T/F value equal to the original truthiness. This method will work for anything you can put into a variable.) Second: To set a specific statusmarker to on or off, use obj.set(symbolname, value); (assuming that symbolname starts with "status_"; if that's not the case, use "status_"+symbolname instead).
1395382795
Alex L.
Pro
Sheet Author
Brian said: Cuerpo said: By the way: does any one of you know why this is not working or how I could get it to work? // Sets the value of a given tokens symbol by the symbols name // value: true/1 or false/0 // // Actuall not in use, due to parsing problems... function SetSymbolByName(obj, symbolname, value){ if (value == 0){value = false;} else if (value == 1){value = true;} else if (value == true || value = false){ // Nothing to do, these are valid values. } else{value = true;} // Set the symbols value. //obj.set({ symbolname: value }); obj[symbolname] = value; //log(obj.get("name") + " " + symbolname + " " + value); } First: It would be faster to set value with value = !!value; instead of the series of conditional blocks. This is the standard method for coercing a JavaScript value into a boolean. (How it works: !value checks the truthiness of value , and negates it; things like 0, false, NaN, and undefined are all falsey values. After negating the original truthiness and making it a boolean, that boolean is negated again, giving you a boolean with a T/F value equal to the original truthiness. This method will work for anything you can put into a variable.) Although this is true and is common practice it is not best practice, where ever possible you should always attempt to know what a particular variable is expected to be and check that is the case then throw an error if it is not (or handle it in some way). The funny part about that script is because he is using == and not === "value == true" this will never get used as 1 == true.
Thank you all for your feed back. I'll try to step up my skills by using them. ;)