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

New API user- REALLY new API user

1456208760

Edited 1456208888
Hey, folks I'm new to API. Incredibly new. I can follow basic instructions, but I don't know java and I can't really make an API of my own. I'm hoping to at least get someone to tell me how much I have to learn. I'm running a homebrew system with a number of varied abilities for a bunch of different classes, but ultimately I'm trying to get one thing out of the API, and that's targeted HP loss (or gain, if it's a healing ability) based on the result of a roll. I was pretty sure this would be a common theme, but I can't seem to find a thread that explains what I need, so let me try and clarify my particular problem. All I want is an API command I can plug into the multiple macros I have for character abilities. These abilities are affected by, at most, a single stat on a character sheet with only 6 stats. I want the Macro to then roll the damage for that attack, and subtract the result of the roll from the target enemy's attribute, 'Total Health', or add health if it's a healing ability. I've seen target-damage macros before, but I understand they have to be tailored if you want roll expression to be involved. A few questions relating to what I need: Are there any macros existing that do what I need? I've browsed the extensive list, but found a lot that seem to require vastly more complex character sheets to work properly. If I want an attack to hit multiple targets, can I make a script that gives that option? If I can make an attack hit multiple targets, but the player only wants to hit one of, let's say, 3, how would the request for targets 2 and 3 need to be handled by the player to make the macro work? How simple would it be to make a script that takes the result of a roll and applies that damage to a target? Could I do it? If not, is it work-intensive enough that getting a scripter to help would warrant payment? Let's say that more than an hour of work would require payment- I'd feel terrible having someone work for more than an hour without giving them some form of compensation. Thanks, guys- And if there's a thread that answers these questions already on the forums that I missed, I'd love to take a look.
1456238683
The Aaron
Pro
API Scripter
Hi Thorrson! I'll hit your questions first, then come back for some commentary: 1) &nbsp;If the HP is stored in one of the token's bars, you can use TokenMod to do this, something like this for damage: !token-mod --set bar1_value|[[ {(@{target|1|bar1}-[[2d6]]),0}kh1 ]] --ids @{target|1|token_id} 2) This is a bit more complicated, certainly, you could use the above to do it, otherwise you'd likely need to write a script to handle it. &nbsp;Making a script is certainly an option. 3) The way I handle targeting a maximum of X targets but allowing fewer is by doubling up on the tokens selected. &nbsp;Lets assume you were going to put the blue status marker on up to 4 targets with token mod: !token-mod --set statusmarkers|blue --ids @{target|1|token_id} @{target|2|token_id} @{target|3|token_id} @{target|4|token_id} If you only wanted to put it on 2 instead, you'd just click the second one 3 times, so your command to the API might look like: !token-mod --set statusmarkers|blue --ids -JASDFAS123as12 -JQWdfawe32445 -JQWdfawe32445 -JQWdfawe32445 In TokenMod, I _.uniq() the supplied IDs, so only 2 tokens are affected. 4) You could do it! &nbsp;It could be as simple as you want, or as complicated as you want to make it. &nbsp;Here's a simplistic version: // set this up when the API is fully spun up on('ready',function(){ &nbsp; &nbsp; "use strict"; &nbsp; &nbsp; // from the cookbook: &nbsp; <a href="https://wiki.roll20.net/API:Cookbook#processInlin" rel="nofollow">https://wiki.roll20.net/API:Cookbook#processInlin</a>... &nbsp; &nbsp; var processInlinerolls = function(msg) { &nbsp; &nbsp; &nbsp; &nbsp; if (_.has(msg, 'inlinerolls')) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return _.chain(msg.inlinerolls) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .reduce(function(previous, current, index) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; previous['$[[' + index + ']]'] = current.results.total || 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return previous; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },{}) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .reduce(function(previous, current, index) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return previous.replace(index, current); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }, msg.content) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .value(); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; return msg.content; &nbsp; &nbsp; }; &nbsp; &nbsp; // respond to chat messages &nbsp; &nbsp; on('chat:message',function(msg){ &nbsp; &nbsp; &nbsp; &nbsp; var content,token,damage; &nbsp; &nbsp; &nbsp; &nbsp; // make sure this is an API command and matches our !hit command &nbsp; &nbsp; &nbsp; &nbsp; if('api' === msg.type && msg.content.match(/^!hit/) ){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // swap out inline rolls for the result, and split on spaces &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; content=processInlinerolls(msg).split(/\s+/); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // get the token for the supplied id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; token=getObj('graphic',content[1]); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // get the damage as an integer or use 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; damage=parseInt(content[2],10)||0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // if we found the token &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(token){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // set it's bar1 to the current value - the damage &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; token.set('bar1_value',(parseInt(token.get('bar1_value'),10)||0)-damage); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // send a message to chat with the details &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('','Token: '+token.get('name')+' took '+damage+' damage.'); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }); }); You might call it like this: !hit @{target|token_id} [[2d6]] I'd say, get that working (I didn't test it...) and see if you understand what it's doing (don't worry so much about processInlinerolls), then see about expanding it. The API is written in JavaSCRIPT, btw, so if you go digging, look for Javascript, not Java. &nbsp;(The history of why the two names are similar is not important, we're just left with the legacy of annoyance from the decision. =D) Also, be sure to ask any questions you have. &nbsp;You can post them in the forum or feel free to PM me if you'd rather for any reason. &nbsp;We're all happy to help!
Alright, I'll be giving this a try soon. Thanks!
Hmm. My API doesn't seem to want to function. It didn't work for this Token script or any others!
I think I got it working. If I need any more help I'll drop by. Thanks!