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

[Help] API for Macro to alter attribute

Alright, I know this has been asked a million times over, but I've spent the past week or so looking for a few hours a day and can only find result older than 6 months. So either it was figured out and I just can't find the solution, or it's been given up on. So, long story short, I would love to track down a hunk of API script that lets a macro write to an attribute on activation. It sounds simple. I think. Current Macro is simple. Vs AC:[[1d20r<1+@{Bab}+@{Dex}+2]] DMG:[[1d8+2+1d6[Fire]]] I just want one little piece of API to go @{Arrow}-1 The in macro equivalent of clicking on a bubble (the red/green/blue ones over a token) and going "-1" Bam. Done. Yes, I know there should be a "!" in there. Somewhere. But that's a problem for after I find an API for it. What I'm not looking for is what half of the people are looking for. Subtracting from health with rolls automatically. Don't need it. But, not having to manage ammo would be fantastic. I would just like to bow and scrape on my hands and knees for a moment while I request this of the people smarter than I who actually know their way around code. Thank you.
1406206206
The Aaron
Roll20 Production Team
API Scripter
Ok, I can probably help with that. =D So, lets nail down what you want. Would something like this be acceptable? Vs AC:[[1d20r<1+@{Bab}+@{Dex}+2]] DMG:[[1d8+2+1d6[Fire]]] !ammo @{selected|token_id} attr_arrows -1 Where attr_arrows is the name of the attribute, -1 is the adjustment to apply to it, and @{selected|token_id} identifies which character's attribute to subtract from? Probably you'd want to know if there wasn't any ammo to begin with, so error conditions might be: attr_arrows is currently 0 attr_arrows < the abs( adjustment ), if say they are doing a special maneuver requiring multiple arrows but only have 1 adjustment is 0 In which cases, I'd suggest sending a chat message to reflect that.
1406206918
Sam M.
Pro
Sheet Author
I currently use this script I created for this purpose. You're welcome to try it out. <a href="https://gist.github.com/Thequietcroc/c2fd1dcc46238" rel="nofollow">https://gist.github.com/Thequietcroc/c2fd1dcc46238</a>... To decrement, just use !decattr @{selected|token_id} attribute_name
You, Sam, my friend are the best. Worked like a charm. I actually did a happy dance. I've been holding out for something like that for ages. Its beautiful. Now I'm sure this'll start off some massive wave of me just pouring API into my campaign. But for now, you may sleep well knowing you've made one lazy mans job just a little bit simpler.
1406216056

Edited 1406217441
The Aaron
Roll20 Production Team
API Scripter
Ah... Sam beat me. =D Oh well.. I built one too, that's a bit more special purpose for ammunition: Some sample output (to chat for players, whispered to GMs): Bounds checking is not enforced for the GM: Also has a command to lookup character ids from tokens, so you can use them directly instead of relying on the token_id or @{selected|token_id}: Edit: Updated to ensure that the player controls the character they are attempting to adjust: With notification to the GM that they tried. Dependencies : This script uses my isGM script, see it for install instructions. GIST: <a href="https://gist.github.com/shdwjk/79a60b8d2ee58e87604" rel="nofollow">https://gist.github.com/shdwjk/79a60b8d2ee58e87604</a>...
Ah, much appreciated! Only catch is I'm also using the Power Cards API now that I got his installed. I just tied the player's ammo attribute to the green bar, so whenever they click on their token they can see how many shots they have left. And it looks like yours is much more specialized for a gun/modern style of play like 40K. Don't think I've ever heard of anyone needing 23 arrows for a single attack in 3.5. But it is quite relieving to see another API out there for altering attributes. (Way more code than my half-assed lua codes for minecraft)
1406218023
The Aaron
Roll20 Production Team
API Scripter
I try to build them to suit multiple genres. You can use -1 or 1 as much as you like, I just used the larger one to test the bounds. !ammo @{selected|token} arrows -1 will work just fine. With the Power Cards, is there something that isn't working?
Hey Aaron, I'm using yours and it works awesome, but is there a way to make it so that the player gets a message when he's out of ammo? And block him from doing the command? This I doubt since I'm using the API as part of a macro but yeah. Thought I'd ask :P
You're gonna hate me soon because so many questions. Is there also a way to input maximum value as a value when using !ammo ? Example some dude has 1/5 ammo, he wants to reload. As part of a macro maybe like !ammo {selected|token_id} Ammo1 [max or something]... I can't just add +5 in the macro because like in the previous example he'd reach 6/5 :/
1407868219
The Aaron
Roll20 Production Team
API Scripter
I'm not sure if this is what you mean, but if the attribute has a max, it won't let players adjust above that max currently. I'm assembling a list of changes for my ammo script here: <a href="https://app.roll20.net/forum/post/1034829/script-ammo-automated-ammunition-management-in-a-character-attribute#post-1067117" rel="nofollow">https://app.roll20.net/forum/post/1034829/script-ammo-automated-ammunition-management-in-a-character-attribute#post-1067117</a>
Oh I see! I haven't tested it yet extensively since as a GM it ignores warning. Thanks for the thread, too. Following it :)
1407869480

Edited 1407869495
The Aaron
Roll20 Production Team
API Scripter
Cheers. =D If you want to have the limits enforced for the GM as well, you can change line 35 to this: if( valid ) {
I am using Sam's script found here . And was wondering is there a way to pass the value of a roll instead of the dice of the roll? !setattr @{selected|token_id} Misfire 3df sets the value of Misfire to "3df" as expected :) !setattr @{selected|token_id} Misfire [[3df]] sets the value of Misfire to "$[0]" is there some way to evaluate the roll and just send that number that I'm missing? Sorry to hijack the thread.
1407986258
The Aaron
Roll20 Production Team
API Scripter
@Fear the Alpaca, are you asking if it's possible to mod Sam's script to take dice expressions? In the API, when you pass a dice expression, it replaces the whole expression with a marker it the text like $[[0]] . The msg parameter then has an extra object which contains tons of info about the roll, including the result value. It shouldn't be too bad to add something that checks for the presence of that object ( _.has(msg,'inlinerolls') ) and then substitutes the result for the $[[0]] markers.
I was asking if there was a way to format them so that I wouldn't have to mod it, or if there was a quick and dirty universal thing that I could do. But alas I am learning the hard way that there is a lot to adjust for when moving from Maptools to Roll20. PROGRESS! So now I guess I need to tear into said script and see if I can kludge in a way to have it check for inline rolls and convert them or what not. *sigh* another long night :)
1407988671

Edited 1407989983
The Aaron
Roll20 Production Team
API Scripter
Long night!!! Don't do that!! Insert this at line 90: 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(); }
1407990739

Edited 1407990877
Thank you for all your help, Aaron. Okay, I did that, and the API spits out "msgTxt: !setattr -JRIbaS7aIXujmkSJe4S Misfire -3" but the Misfire attribute in the character sheet still says $[[0]] any ideas? (for refrence this is what i did:) var args = msg.content.split(" "); var command = args.shift(); // Arron's code to catch inline rolls. if(_.has(msg,'inlinerolls')){ msg.content = _.chain(msg.inlinerolls) .reduce(function(m,v,k){ m['$[['+k+']]']=v.results.total; return m; },{}) .reduce(function(m,v,k){ return m.replace(k,v); },msg.content) .value(); } // end of Arron's code.
1407991976
The Aaron
Roll20 Production Team
API Scripter
aAron. :) My code needs to be before the "var args = "... Line.
1407992006
The Aaron
Roll20 Production Team
API Scripter
It's possible my copy of the code is slightly off in the line numbers.
1407992474
The Aaron
Roll20 Production Team
API Scripter
Hope that works. Going to bed. Will check in the morning!
Works beautifully!! I could kiss you!
1408014557
The Aaron
Roll20 Production Team
API Scripter
I thought Alpaca's spit? =D Glad it's working for you!
We only spit when threatened or angry :)