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

Looking for help

Hello everyone, I just started to be a pro-subscriber because I wanted to use some of the API-Scripts and make one myself. Since I'm new to Java I couold use a little help with how to write the script I'd love to use... So the function I'd like to have is the following: check if the rolled d6 from the makro have multiples, add those together and show the highest value. For example: 5d6= 1,2,2,5,3= 1 3 4 5 = output should be 5 4d6= 2,3,3,1= 1 2 6 = output should be 6 3d6= 4,6,4= 6 8 = output should be 8 5d6= 6,3,3,4,3= 4 6 9 = output should be 9 So is it possible to let the API-Script read the output from the diceroll-makro and compare thos numbers to output the highest value? Or do I have to use a script for the whole thing? And how do I do it? Especially since the players have to define how many dice they roll? ( The dice roll works like the following: 2d6 + Xd6 - Yd6 and the Makro looks like the following: /me tries to ?{Name of Query|ability-check,do stuff|ini-roll}! /roll (?{Bonus Dice|0}+2)d6sdkh1 ) I'm sorry for the trouble and appreciate every help you can offer!
1458672508
The Aaron
Pro
API Scripter
I do some of these operations in a couple of different scripts, but look at CthulhuTechDice for the closest match.  In my case, I do them based on an inline roll, but you could do them based on a regular dice roll, or if a particular message contains an inline dice roll.  To get started understanding the way chat messages work, I suggest loading this script and watching the log output while you try various things in the chat: on('ready',function(){ on('chat:message',function(msg){ log(msg); }); });
1458672657
The Aaron
Pro
API Scripter
See:&nbsp; <a href="https://wiki.roll20.net/API:Chat#Chat_Events" rel="nofollow">https://wiki.roll20.net/API:Chat#Chat_Events</a> also for more info.
Ok...I now played around while having the chat-log-script active and I think I understand what it does...but after looking at the code for the CthulhuTechDice I'm confused. ^^' This code looks more complex than what I thought would be needed for my roll-function.
1458734602
The Aaron
Pro
API Scripter
It is a bit complex, but you probably are only interested in the function getDiceCounts() on line 23: &nbsp; &nbsp; var getDiceCounts = function(msg,idx) { &nbsp; &nbsp; &nbsp; &nbsp; var rolls = {}; &nbsp; &nbsp; &nbsp; &nbsp; if( msg.inlinerolls &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; && msg.inlinerolls[idx] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; && msg.inlinerolls[idx].results &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; && msg.inlinerolls[idx].results.rolls[0] &nbsp; &nbsp; &nbsp; &nbsp; ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each(msg.inlinerolls[idx].results.rolls,function(res){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rolls=_.reduce(_.map(res.results,function(r){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return r.v; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }).sort() &nbsp;|| [], function(m,r){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m[r]=(m[r]||0)+1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return m; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },rolls); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; return rolls; &nbsp; &nbsp; }; Given a message object and the index of a roll, it will return an object that maps the result to the number of times it occurs, so assuming a message from this command: !something [[7d6]] with rolls of: &nbsp;5,2,3,5,1,3,5 Then calling: var counts = getDiceCounts(msg,0); will give you this object: { '1': 1, '2': 1, '3': 2, '5': 3 } You can then turn that into the counts numbers you want with a map: var values=_.map(counts,function(num,face){ return parseInt(face,10)*num; }); yielding: [1,2,6,15] and take the max value: var maxval = values.max(); You could also use a modified version of the original function and cut out the intermediate _.map() call if you have no need of the actual counts: &nbsp; &nbsp; var getDiceCounts = function(msg,idx) { &nbsp; &nbsp; &nbsp; &nbsp; var rolls = {}; &nbsp; &nbsp; &nbsp; &nbsp; if( msg.inlinerolls &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; && msg.inlinerolls[idx] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; && msg.inlinerolls[idx].results &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; && msg.inlinerolls[idx].results.rolls[0] &nbsp; &nbsp; &nbsp; &nbsp; ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each(msg.inlinerolls[idx].results.rolls,function(res){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rolls=_.reduce(_.map(res.results,function(r){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return r.v; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }).sort() &nbsp;|| [], function(m,r){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m[r]=(m[r]||0)+r; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return m; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },rolls); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; return rolls; &nbsp; &nbsp; }; Hope that helps!
Sort of... ^^' but it also makes me feel like a total noob or rather that I should take the time to learn Javascript...and I don't really have the time. -.- The campaign starts next week and I still have some NPCs and stuff to prepare too... So the inlineroll-part means that it takes the roll which was made through the chat? So I'd write a script so that if someone types !something 7d6 (to stick with your example) in the chat the script would activate and show the highest value in the chat? Can I use a template to design this somehow?
1458764349
The Aaron
Pro
API Scripter
See if this does what you want: on('ready',function(){ &nbsp; &nbsp; "use strict"; &nbsp; &nbsp; var getDiceSums = function(results) { &nbsp; &nbsp; &nbsp; &nbsp; var rolls = {}; &nbsp; &nbsp; &nbsp; &nbsp; if( results) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each(results,function(res){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rolls=_.reduce(_.map(res.results,function(r){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return r.v; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }).sort() &nbsp;|| [], function(m,r){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m[r]=(m[r]||0)+r; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return m; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },rolls); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; return rolls; &nbsp; &nbsp; }; &nbsp; &nbsp; on('chat:message',function(msg){ &nbsp; &nbsp; &nbsp; &nbsp; var rollData,res,output,who; &nbsp; &nbsp; &nbsp; &nbsp; if('API'===msg.playerid || 'api' === msg.type){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; switch(msg.type){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 'gmrollresult': &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 'rollresult': &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rollData = JSON.parse(msg.content); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( rollData &&&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rollData.rolls && &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rollData.rolls &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rollData=rollData.rolls; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(!msg.inlinerolls){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rollData=msg.inlinerolls[0]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( rollData &&&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rollData.results && &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rollData.results.rolls &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rollData = rollData.results.rolls; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; res = _.last(_.toArray(_.sortBy(getDiceSums(rollData),_.identity))); &nbsp; &nbsp; &nbsp; &nbsp; output = '&lt;div style="font-size: .8em; background-color:#eeeeff; border: 1px solid #999; border-radius: .2em; padding: .1em .5em;"&gt;Highest Value: &lt;b&gt;'+res+'&lt;/b&gt;&lt;/div&gt;'; &nbsp; &nbsp; &nbsp; &nbsp; switch(msg.type){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 'whisper': &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 'gmrollresult': &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('HighestValue','/w "'+(msg.target_name||'gm')+'" '+output); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(msg.target && !('gm' === msg.target && playerIsGM(msg.playerid))){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; who =getObj('player',msg.playerid).get('displayname'); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('HighestValue','/w "'+who+'" '+output); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('HighestValue', output); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }); }); It will do your Highest Value calculation on the first inline roll for any of /desc, /w, /em and regular chat, as well as doing the roll in /roll or /gmroll. &nbsp;In the case of /w and /gmroll, it will whisper the results to the involved parties.
You are great! Thank you.
1459000411
The Aaron
Pro
API Scripter
No problem! &nbsp;=D
Yeah, I was hesitant to buy Roll20 as the last time I had a computer language course was in 1983. &nbsp;So I bought it, watched the video tutorials, here and the 5 others by others on youtube....Yeah - not sure what I was thinking as everything is DnD and I want to create a Super Hero RPG. &nbsp;I could just use dice stream on Google Hangouts and skip fancy maps and scripts. &nbsp;No scripting needed.
1459050846
Gold
Forum Champion
Robert S. said: Yeah, I was hesitant to buy Roll20 as the last time I had a computer language course was in 1983. &nbsp;So I bought it, watched the video tutorials, here and the 5 others by others on youtube....Yeah - not sure what I was thinking as everything is DnD and I want to create a Super Hero RPG. &nbsp;I could just use dice stream on Google Hangouts and skip fancy maps and scripts. &nbsp;No scripting needed. Hi Robert . You can create and play Super Hero RPG's on Roll20. Many of us do! This particular thread is Nicole's help thread in a specialized section of the forum for people who want to do advanced scripting. It is not &nbsp;at all necessary to use scripts, or to write any code for Super Hero games on Roll20, and you also do not need to use fancy maps unless you want to. &nbsp;Also you don't even need to have the Pro subscription for making a Super Hero game, unless you want some of the special features for Pro subscribers. Lots of people play & GM super hero games on the Free account status. Look into the General forum, and the Specific Use Questions forum. Here is a link to a helpful introductory post from Roll20's community manager that will help demonstrate the many basic accessible features of Roll20, <a href="https://app.roll20.net/forum/post/1693101/new-to-r" rel="nofollow">https://app.roll20.net/forum/post/1693101/new-to-r</a>...
Thanks Gold. &nbsp;I ran all the crash course tutorials, watched youtuber vids, searched the forums for Marvel Heroic threads - sadly 3 years old. &nbsp;One that peaked interest was someone was trying to make a script for its unique dice roll system. &nbsp;I found a group running the old old 1980s FASERIP Marvel. &nbsp;Buts it really MHRP I want to do. &nbsp;Thanks again Gold, will keep exploring.
Well, thanks, Gold. Robert your posting doesn't help me in any way. In case someone is interested: I use OVA- The Anime Roleplayinggame, so it is sort of an comicish thing I'm gonna GM. Someone wrote a Charactersheet for this system, which is really awesome. I bought the pro-subsicription because I'd love to use some features I can't use as a free user, like this API-Script Aaron wrote and helped me to adapt. Of course we don't really need a "fancy script" to now how high the roll is and if the character succeeded it's task, but it makes rolling dice faster, therefore we have more time for actual roleplaying. And why shouldn't I use some scripts to help with the dice, if those scripts may help us having more fun while playing?