Skip to content

Instantly share code, notes, and snippets.

on("chat:message", function (msg) {
// Exit if not an api command
if (msg.type != "api") return;
var command = msg.content.split(" ")[0];
if (command == "!replace") {
var selected_id = msg.content.split(" ")[1];
var selected = getObj("graphic", selected_id);
var name = msg.content.substr(msg.content.indexOf(selected_id) + selected_id.length).trim();
@mfajer
mfajer / temp_hp.js
Last active August 29, 2015 14:05
Roll20 API Script for handling temp HP, death status, maximum HP and bloodied status (DnD 4e)
/**
* Automatically removes temp HP if they exist.
*
* When a token has its HP reduced the script checks to see if there are any
* temp HP available. If it does those are removed first and the real HP is
* updated to reflect the temp HP absorbing the hit.
*
* TEMP_BAR_ID - The bar used to track temp HP [1, 2, 3]
* HP_BAR_ID - The bar used top track real HP [1, 2, 3]
*/
@mfajer
mfajer / npcs.js
Last active August 29, 2015 14:05
Roll20 API Script for setting NPC health values on tokens when they are added to the table
var HP_BAR_ID = 3;
on("ready", function() {
on("add:graphic", function(obj) {
//Will only be called for new objects that get added, since existing objects have already been loaded before the ready event fires.
log("DEBUG: " + obj.get("represents") + " : " + obj.get("bar" + HP_BAR_ID + "-link"));
if (obj.get("represents") && obj.get("bar" + HP_BAR_ID + "-link") === undefined) {
var character = getObj("character", obj.get("represents"));
obj.set("bar" + HP_BAR_ID + "_value", getAttrByName(character.get("_id"), "hp", "max"));
obj.set("bar" + HP_BAR_ID + "_max", getAttrByName(character.get("_id"), "hp", "max"));
@mfajer
mfajer / language.js
Last active August 29, 2015 14:05
Roll20 API script adding a "!speak [language] [message]" command that garbles the message if a character does not know it
// The attribute where languages are stored on the character using a comma-separated list
var LANG_ATTRIBUTE = 'lang';
// Global PC array so we can use getObj instead of findObjs
var PCS = [];
var separators = /[()\-\s,]+/;
on("add:graphic", function(obj) {
if (obj.get("represents")) {