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

[request] Rage API script

Hey guys, I've got a player in my group who is playing a barbarian and I'd like to get a rage script for him so he doesn't have to keep manually changing his stats if one of you code geniuses don't mind throwing something together. The characters name is Mundo, and I'd like a script that works off of "!Rage" When he uses it it would increase the attribute "Str-Mod" by 4, the attribute "Con-Mod" by 4, decreases the attribute "AC" by two and increases the attribute "HP" by (2*@{Mundo|Level}). Similarly I'd appreciate it if there was a command !EndRage that reversed the previous changes. If this is more complex than I'm expecting it to be then by all means don't feel like it will hurt my feelings if you don't donate your time to help my campaign run a bit more smoothly :P But if it is as -relatively- simple as I expect it to be, I'd sure appreciate any help. Thanks
Here's a very crude go at it. It uses the "strong" status icon by default as a toggle. When rage is on, the icon is on, when rage is off, the icon goes away. Simply highlight a single token in the interface, then type !Rage into the chat window. This will toggle the status. You could assign it as a macro button also. var CHOSEN_STATUS = "strong"; var STRATTR = "Str-Mod"; var CONATTR = "Con-Mod"; var HPATTR = "HP"; var ACATTR = "AC"; var LEVATTR = "Level"; on("chat:message", function(msg) { if (msg.type == "api" && msg.content.indexOf("!Rage") !== -1) { _.each(msg.selected, function(objInfo) { var obj = getObj(objInfo._type, objInfo._id); if( obj.get("_type") == "graphic" ){ if( obj.get("_subtype") == "token" ){ var charID = obj.get("represents"); var StrAttr = findObjs({ name: STRATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ConAttr = findObjs({ name: CONATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var HPAttr = findObjs({ name: HPATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ACAttr = findObjs({ name: ACATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var LevAttr = findObjs({ name: LEVATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; if( obj.get("status_"+CHOSEN_STATUS) ){ sendChat("Rage-API", obj.get("name")+" toggling off."); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); obj.set("status_"+CHOSEN_STATUS, false); StrAttr.set("current", parseInt(StrAttr.get("current"))-4); ConAttr.set("current", parseInt(ConAttr.get("current"))-4); HPAttr.set("current", parseInt(HPAttr.get("current"))-(2*parseInt(LevAttr.get("current")))); ACAttr.set("current", parseInt(ACAttr.get("current"))+2); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); } else { sendChat("Rage-API", obj.get("name")+" toggling on."); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); obj.set("status_"+CHOSEN_STATUS, true); StrAttr.set("current", parseInt(StrAttr.get("current"))+4); ConAttr.set("current", parseInt(ConAttr.get("current"))+4); HPAttr.set("current", parseInt(HPAttr.get("current"))+(2*parseInt(LevAttr.get("current")))); ACAttr.set("current", parseInt(ACAttr.get("current"))-2); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); } } } }); } });
1387337367

Edited 1387337414
CAVEATS - that I can think of right now This will not handle multiple tokens selected simultaneously. This does not check to see if the token represents a character This does not verify if the attributes exist on the character
Thanks a ton for this! <3 It's working great!
Hmmm, this is odd. It worked great over on my test campaign, but once I ported the script into my real campaign it only partially works. It still adds the HP and lowers the AC, but it no longer affects the Str-Mod and Con-Mod like it did on the other server. =/
Could be how he's entered it into the attribute panel. I remember seeing a larger and more complete version of this API somewhere which also counted turns enraged and ticked it away from their turns/day, and added in fatigue and exhaustion where appropriate.
1387370283

Edited 1387370321
It's not doing a case insensitive search, so make sure your attributes match up exactly. Nevermind, it is. Didn't look at the right part of the code.
Yeah, its entered the same way. I even copy/pasted from the working one over to the live campaign to be sure. Still nothing.
Strange. I wrote that 100% on a production campaign, I would expect it to work there. Did you double-check to make sure there are no leading or trailing spaces on the attribute names? You can uncomment the 4 log lines to see what it thinks it's doing...
1387458233
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Joe Y, Send me a PM and lets get you coding! This is within your wheelshouse. We can set up a time this weekend and walk through some of this.
Ok! Awesome!
By the way, Lifer, today when I logged in to play with the script a bit more it was working just fine. I'm guessing there was just a bug that fixed itself when I refreshed the site.
Excellent, I'm glad to hear it. Have fun with your campaign!
Hahah, so Stephen S. is doing free Javascript lessons now, right?
i have a question.... is it possible to trigger a script using the icons rather than an api command? because selecting the icon in question is a lot more intuitive and i am trying to eliminate as many commands as possible without losing functionality to my scripts. in this case, could selecting the rage icon trigger the changes in stats and a start a countdown timer that counts up the rounds its been active? If this is possible, I can think of a lot of possibilities for triggering my scripts.
Yes, it'd be an on change:token:status instead of chat:message, but I don't know the exact syntax off hand. It'd change a section of the coding as well.
1387551584

Edited 1387551616
Here's another crude script that uses the toggling of the "strong" status as the trigger. CAVEAT: It only detects a single strong status. Multiple strong status (i.e. strong@3) is considered the same as no strong status icon. var CHOSEN_STATUS = "strong"; var STRATTR = "Str-Mod"; var CONATTR = "Con-Mod"; var HPATTR = "HP"; var ACATTR = "AC"; var LEVATTR = "Level"; on("change:graphic:statusmarkers", function(obj, prev) { // Only counts when a single "strong" status is applied, // "strong@X" is considered not "strong" var isStrong = obj.get("status_"+CHOSEN_STATUS) === true; var wasStrong = prev["statusmarkers"].split(',').indexOf(CHOSEN_STATUS)!=-1; if( isStrong && !wasStrong ) { log("power up!"); var charID = obj.get("represents"); var StrAttr = findObjs({ name: STRATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ConAttr = findObjs({ name: CONATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var HPAttr = findObjs({ name: HPATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ACAttr = findObjs({ name: ACATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var LevAttr = findObjs({ name: LEVATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; sendChat("Rage-API", obj.get("name")+" toggling on."); log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); StrAttr.set("current", parseInt(StrAttr.get("current"))+4); ConAttr.set("current", parseInt(ConAttr.get("current"))+4); HPAttr.set("current", parseInt(HPAttr.get("current"))+(2*parseInt(LevAttr.get("current")))); ACAttr.set("current", parseInt(ACAttr.get("current"))-2); log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); } if( !isStrong && wasStrong ) { log("weakling!"); var charID = obj.get("represents"); var StrAttr = findObjs({ name: STRATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ConAttr = findObjs({ name: CONATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var HPAttr = findObjs({ name: HPATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ACAttr = findObjs({ name: ACATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var LevAttr = findObjs({ name: LEVATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; sendChat("Rage-API", obj.get("name")+" toggling off."); log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); StrAttr.set("current", parseInt(StrAttr.get("current"))-4); ConAttr.set("current", parseInt(ConAttr.get("current"))-4); HPAttr.set("current", parseInt(HPAttr.get("current"))-(2*parseInt(LevAttr.get("current")))); ACAttr.set("current", parseInt(ACAttr.get("current"))+2); log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); } });
unexpected token var error when running above script. can't find the error myself, hope you can fix that.