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] Parse dice from !api command...

How can I parse a dice command without sending it to chat and get the result for use in an api script? Fighters in D&D Next have a once per encounter temp hp ability and I would like to be able to script the macro as below so the player only has to click the macro and it will automatically use the !setthp I have working to add temp hp to their selected token. /me uses Second Wind and gains temporary hit points! !setthp 1d6+2
1380362249
Lithl
Pro
Sheet Author
API Scripter
on('chat:message', function(msg) { if(msg.type != 'api') return; var parts = msg.content.toLowerCase().split(' '); var command = parts.shift().substring(1); if(command == 'setthp') { sendChat('', parts[0], function(outs) { // outs[0] is a message object containing the results of the die roll in parts[0] // This sendChat message will NOT appear in the actual chat window }); } });
I cannot figure out how to get this to work...
1380363967

Edited 1380363991
Lithl
Pro
Sheet Author
API Scripter
Using the script above, outs[0] is the same type of object as the msg you're used to using. It contains the message that would have been posted to the chat, but it's sent to the anonymous function instead. I did realize just now that using your example command, you'd need the second parameter in sendChat to be '/r '+parts[0] , so that a roll is actually made.
Ok, so here's what I get when I log(outs); [{"who":"","type":"rollresult","content":"{\"type\":\"V\",\"rolls\":[{\"type\":\"R\",\"dice\":1,\"sides\":6,\"mods\":{},\"results\":[{\"v\":1}]}],\"resultType\":\"sum\",\"total\":1}","playerid":"API","avatar":false,"inlinerolls":{},"origRoll":"1d6"}] How the hell do I get the total out of there?
1380401287

Edited 1380401343
Lithl
Pro
Sheet Author
API Scripter
var rollresult = JSON.parse(outs[0].content); var total = rollresult.total;