
sendChat(msg.who, "!powercard making-things-look-like-a-macro");But, again, while dressed up it's lacking because none of the rolls are highlighted or anything. The only way I've been able to think of doing it, is to take the entirety of the Powercard2 script, and create a copy, changing the second one to a function of some sort. Then calling it in my other API on an as needed basis. While this does not sound like a horrible idea, there are a few problems I'm having.
1)I have no idea how to change an entire script into a function, especially something as intricate as Powercard2
2)I'm still working on figuring out the whole "calling functions from one API to work in another API" bit.
3)I wouldn't know what to tack onto the end of my api after all of the "invisible backdoor stuff" happens to give the visual output of Powercard2. (ie. Everything which does not actually have a chat output, but does things like altering attributes on character sheets.)
So here's the script for the healing API I've been working on.
var Healspell = Healspell || {}; /******************************************************* * Typical macro's for different spellcasters * Cleric: !healSpell --type|Spell --spell|[[3d8+@{Level}]] --targetMap|@{target|token_id} --targetName|?{Target?|Name} * Use Magic Item: !healSpell --type|Wand wand|CSW --skill|[[1d20+@{UMD}]] --spell|[[3d8+1]] --targetMap|@{target|token_id} --targetName|?{Target?|Name} * The reason for both targetMap and targetName is if party is on a world map traveling, they can still heal * party members by punching their name into the target field. Otherwise one would always have to either punch in the * name or be on the same page as the target token. */ on("chat:message", function (msg) { if (msg.type != "api") return; //log(msg); var command = msg.content.split(" ", 1); //log(command); if(_.has(msg,'inlinerolls')){ msg.content = _.chain(msg.inlinerolls) .reduce(function(m,v,k){ m['$[['+k+']]']=v.results.total || 0; return m; },{}) .reduce(function(m,v,k){ return m.replace(k,v); },msg.content) .value(); }; var n = msg.content.split(" --"); var a = 1; var chatObj = {}; var mTags = ""; var mContent = ""; while(n[a]) { mTag = n[a].substring(0,n[a].indexOf("|")); mContent = n[a].substring(n[a].indexOf("|") + 1); chatObj[mTag] = mContent; a++; }; //log(chatObj); if (command == "!healSpell") { var HP_bar = 3; var caster = findObjs({ _type: "character", name: msg.who })[0]; //log(caster); //Make sure target is valid. if (chatObj.targetMap == undefined) { sendChat("System", "Please copy and paste this line into your macro. --targetMap|@{target|token_id}"); return; }; if (chatObj.targetName == undefined) { sendChat("System", "Please copy and paste this line into your macro. --targetName|?{Target?}"); return; }; if (chatObj.targetName != "") { var initTarget = chatObj.targetName; } else { var initTarget = findObjs ({ _type: "graphic", _id: chatObj.targetMap })[0].get("name"); }; var target = findObjs ({ _type: "character", name: initTarget })[0]; //log(target); if (target == undefined) { var HP_field = "bar" + HP_bar + "_value"; //assume it is a nameless NPC and check for valid min/max HP bars. var targetHP = findObjs ({ _type: "graphic", _id: chatObj.targetMap })[0]; var HP_cur = parseInt(targetHP.get("bar" + HP_bar + "_value")); var HP_max = parseInt(targetHP.get("bar" + HP_bar + "_max")); if (HP_cur == undefined) { //target does not have a valid HP bar sendChat("System", "Not a valid target, please try again."); return; }; if (HP_max == undefined) { //target does not have a valid HP bar sendChat("System", "Not a valid target, please try again."); return; }; } else { HP_field = "current"; var targetHP = findObjs ({ _type: "attribute", characterid: target.id, _name: "HP" })[0]; if (targetHP == undefined) { sendChat("System", "Target does not have valid HP attribute. Please add one and try again."); return; } var HP_cur = parseInt(targetHP.get("current")); var HP_max = parseInt(targetHP.get("max")); }; //log(HP_cur + " " + HP_max); //Check if Wand or Spell if (chatObj.type.toLowerCase() == "wand") { //Look for attribute containing charges of the wand. if (chatObj.wand == undefined) { sendChat("System", "Please add a field --wand| followed by the name of an attribute containing wand charges. Ex. --wand|Cure Light Wounds"); return; }; var wCharge = findObjs({ _type: "attribute", _characterid: caster.id, name: chatObj.wand })[0]; wCharge.set("current", parseInt(wCharge.get("current"))-1); //skill check //Look for UMD attribute in character sheet. (Use Magic Devce) var skill = findObjs({ _type: "attribute", _characterid: caster.id, _name: "UMD" })[0]; if (skill == undefined) { sendChat("System", "Caster does not have a Use Magic Device attribute (UMD). Please make one and assign it the appropriate skill value."); return; }; var skill = parseInt(skill.get("current")); //log(skill); //Check the skill roll, make sure it is not a 1 or below 20. if (chatObj.skill == undefined) { sendChat("System", "Please add a skill check to your macro. --skill|1d20+UMD"); return; }; var skillRoll = parseInt(chatObj.skill); //log(skillRoll); if (skillRoll-skill == 1) { sendChat("System", msg.who + " has rolled a 1. The spell fizzles."); }; if (skillRoll < 20){ sendChat("System", msg.who + " has rolled a " + skillRoll + " the spell fizzles."); return; }; } else if (chatObj.type.toLowerCase() != "spell") { sendChat("System", "Cast type not defined. Please define either Wand or Spell. --type|(Wand/Spell)"); return; }; //Perform healing math var HP_new = HP_cur + parseInt(chatObj.spell); if (HP_new > HP_max) { var HP_new = HP_max; }; targetHP.set(HP_field, HP_new); sendChat(msg.who, "Heals " + initTarget + " for " + chatObj.spell + " points of damage. Putting them at " + HP_new + "/" + HP_max + ". "); }; });I know it's crap, but I'm actually quite proud of this one.
So, essentially I would like I way to take that final line and just push (a version of) it and the inline rolls from msg into Powercards 2, then finally have PC2 spit its fancy goodness all over my chat. But I can't think of how to do that, without PC2 re-rolling all of the inline rolls for it's own use.