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

[Script] Roll comparisons

May 09 (11 years ago)

Edited September 24 (11 years ago)

I saw a thread ( https://app.roll20.net/forum/post/149507/request-slash-suggestion-roll-total-vs-target-number#post-149664 ). I don't play GURPS, but I was curious if it would be possible to do some more advanced comparisons. I put together this script to allow you to compare an arbitrary expression with attribute value substitution to the result of a die roll.

So the API doesn't have a direct interface into the dice roller, and I didn't want to try to recreate all the advanced features, so I came up with this syntax:

/r [dice expression here] [comment here] |<| @DEX

/r 3d6 Dex Check! |<| @DEX

The idea being that the dice roller would complete the roll as normal, in this case 3d6. The API script checks every roll to see if it has an operator in a pipe, and if so it compares the total from the die roll to whatever expression is to the right of the operator, substituting attributes from whoever you are sending the roll chat as. It is doing very basic attribute substitution, so there could be some bugs. 

https://gist.github.com/rlittlefield/5545693?1=7

Note: This is super easy to break if you put the wrong syntax in there, as I didn't put much error handling and this is just splitting on pipes and running "eval" on stuff, not actually parsing anything.
Edit: forgot to mention that this will say "Success (-3)", "Success (2)" or "Failure", depending on the truthiness of the expression. Edit 2: If you don't like the number in the success parenthesis (currently the difference between the roll total and the expression total) being a negative number when you do your less-than comparison, the code could be adjusted to get an absolute value of the difference.
Update (2013-09-22): I've added GManator's request to have this work with /gmroll. It will whisper the results to both the GM and the player doing the roll. It does this using player names, which could get complicated if everyone has the same first name, so don't treat this as completely secure. If it can't figure out what a players name is, it will complain to the GM through a whisper.
May 09 (11 years ago)
GManator
KS Backer

Wow, thank's Ryan L. Can you put modifiers on the attribute / target number on the right side of the |<| (such as /r 3D6 Dex Check! |<| @DEX +2)? Also, once the script is installed can it be included in macros (sorry haven't really done anything with the API yet)?

May 09 (11 years ago)

You could do "/r 3d6 |<| @DEX+@STR+1" and it would make sure that what you rolled was less than your dex plus strength plus one. You can do addition, subtraction, multiplication, division, and you can use parenthesis to specify the order of operations.

I assume you could use it in a macro just fine, but I haven't tried.

May 09 (11 years ago)
GManator
KS Backer

AWESOME!! you are the man. I'll try this out as soon as I can.

May 09 (11 years ago)
GManator
KS Backer

Ok, I loaded the API up on the Dev server version of my campaign and I am not seeing the output of the Success (2), Failure, etc. All I see is the roll total.


May 10 (11 years ago)

Did you install the script from my link? Once you have it installed, you can see if there are any errors on the page in which you install. The script just reads the dice rolls and adds an extra message based on what you type after the main roll command.

May 10 (11 years ago)
GManator
KS Backer

I see an error when I go to the script page but it seems fine when I resave the script. This is the error I am getting:

Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again. More info...

For reference, the error message generated was: TypeError: Cannot read property 'length' of null at evalmachine.<anonymous>:34:26 at eval (

. Also your code on github has 87 lines but when I past it into the API script window it only has 74 which could be part of the problem I imagine.

May 10 (11 years ago)

I think this is happening when there is no character selected. I've upgraded the code at ( https://gist.github.com/rlittlefield/5545693 ) to not care about this anymore (but keep in mind that you probably only want to use attributes if you have a character you are speaking/rolling as in the chat area).

May 10 (11 years ago)
GManator
KS Backer

Ok, SUCCESS!! Thank you very much for this. Could I request a some tweaks? This is what I rolled and the output I got:  /r 3D6 |<| 12 -> (1 + 5 + 4) = 10 -> RollSystem: Success (-2) 3D6 |<| 12

1. Could "RollSystem" be changed to "RollResult"?

2. As GURPS rolls under 3D6, is it possible to remove the negative in front of the number of successes in parenthesis?

3. It is showing the roll formula after the number of successes (in bold above). Can this be removed??

4. Showing the amount failed by would also be useful.

5. Could the results be changed to "Success By" and "Failed By".

May 10 (11 years ago)
GManator
KS Backer

With a little tinkering I've been able to modify the script to do all of the above except #2. Also I've noticed that rolling a 12 vs a target number of 12 outputs a failure when it should be a success.

May 10 (11 years ago)
Alex L.
Pro
Sheet Author

GManator said:

With a little tinkering I've been able to modify the script to do all of the above except #2. Also I've noticed that rolling a 12 vs a target number of 12 outputs a failure when it should be a success.

this line
sendChat('RollSystem', 'Success ('+difference+') '+msg.origRoll);
should be
sendChat('RollSystem', 'Success '+msg.origRoll);
If you dont want the dif in the brakets


May 10 (11 years ago)
GManator
KS Backer

+Alex L. I've already figured those issues out. I just need to figure how to always express the Success and Failure results as positive numbers and register target number ties as Successes instead of Failures.

May 11 (11 years ago)

Because this uses normal javascript expression syntax, it is actually correct. What you want to do is say: /r 20d1 |<=| 20

The "<=" means less than or equal to, which should turn that failure into a success.

I've just updated the script to give the absolute value instead of the negatives as well, so feel free to grab the new version.

Edit: Oh, and the new version does not output the expression again. That was mainly for keeping track of which roll it came from, which shouldn't be a problem most of the time based on how fast the API has been at responding.

May 12 (11 years ago)
GManator
KS Backer

It works perfectly now. Thanks for all the work Ryan. Me, my players and I'm sure many other GURPS / CHAMPIONS groups appreciate it.

May 13 (11 years ago)
Riley D.
Roll20 Team

Someone be sure to add a link to this to a GURPS page on the Wiki...

May 13 (11 years ago)
GManator
KS Backer

Already done ;)

July 11 (11 years ago)
Axel Castilla
KS Backer

Great work Ryan L! 

Some time ago I was suggesting / requesting this very functionality, so I'm glad to see it coming via the API! 

Thank you very much for sharing the script.

September 01 (11 years ago)

Just added this to my Eclipse Phase Campaign. :)

September 04 (11 years ago)
GManator
KS Backer

Hey Ryan, I just discovered that this script doesn't work for /gmroll instead of the standard /r or /roll commands. Any chance of adding that to the script?

September 21 (11 years ago)
GManator
KS Backer

So the original author of this script doesn't seem to be around. Does anyone know how to modify this script so that it applies to /gmroll as well as /roll?

September 22 (11 years ago)

GManator: I've added support for /gmroll as per my edit above. It is a little tricky on the messaging, but it works. It also looks like Riley has added some fantastic chat callbacks, so potentially we could replace /roll and /gmroll with !roll and !gmroll and avoid running this through the chat system altogether. For now, I've just made the changes to the existing script.

September 23 (11 years ago)

Edited September 23 (11 years ago)

@Ryan L: hey good to see you back. Yea, the api commands are damned useful. If you could update it to use those it would be awesome - I tried and failed, (Just couldn't follow your script for some reason - might have been the medication though ) 

FYI - This really has been the most useful script I have available at the moment. Its good for so many reasons.

September 23 (11 years ago)
GManator
KS Backer

WoooHOOO!! Glad you're back Ryan!! I thought I was going to have beg and plead to have someone edit the code. I can't thank you enough!

September 23 (11 years ago)
GManator
KS Backer

hmmm, I noticed that it now says "From RollResult" instead of "RollResult".

September 23 (11 years ago)
GManator
KS Backer

Ok, so I've done some quick testing below is an image of a regular roll (/roll) and a gm roll (/gmroll):

As you can see the gmroll shows as (From RollResult): instead of just RollResult:. I'm not sure if that is something that can be changed. Also, the result shows up twice for some reason when you use a gmroll.

September 23 (11 years ago)

                if (result) {
                    sendChat('RollResult', '/w gm Success by '+difference+'');
                    sendChat('RollResult', '/w ' + who + ' Success by '+difference+'');
                } else {
                    sendChat('RollResult', '/w gm Failure by '+difference+'');
                    sendChat('RollResult', '/w ' + who + ' Failure by '+difference+'');
                }
the double posting should be because of this because who=gm. Just add an additional if who != GM, and it'll prevent that. as far as the From RollResult, that's just because of how the whisper system works. It will always say "From" unless if the /w GM command is comming from the GM himself in the server.

September 23 (11 years ago)
GManator
KS Backer

Sorry Emile, I didn't really follow that first part. My programming skill are less than basic to say the least. As for the From RollResult the whispher is coming coming from the GM (me).

September 23 (11 years ago)

The only time the roll result will come to you twice is when you're on the one sending it.... if your players type it, which I'm sure is 99% of the times you want this to work, it'll only post once in yours and theirs. Otherwise, you can make check if who = indexOf("GM") to prevent it from double posting.

September 23 (11 years ago)
GManator
KS Backer

Actually no. I'm using it when I roll for NPC's (hiding their roll results from the players).

September 23 (11 years ago)

Yes, the reason it has "From RollResult" and does it twice is that it uses the /w whisper message, once to each. I don't really know of another way to privately announce the result to both the user and the GM. It would technically be possible to do it without the "From" but only if we publicly announce the result. Emile's changes would prevent it from happening twice.

Michael: I am considering the possibilities of using the new chat callbacks to make a fancier version of this script. With some API adjustments, I could control the exact message output or do better whispers directly to a playerid instead of hoping the whisper to their first name will be enough.

September 23 (11 years ago)

Thanks Ryan. If I understood your code at all, I would have a go at it, but for now I have changed the output of the default roll to be a whispered gm roll with a public chatmsg from the character that called the roll stating only the degree of success or failure. It allows for a little bit of secrecy on my part as the DM, and lets players have a bit of mystery to their characters too (as only they and I actually see the target level they were shooting for)

September 23 (11 years ago)
GManator
KS Backer

ah, ok now I understand. I hadn't thought of a player whispering a roll TO the gm (mainly because I don't think I've ever seen that done in a tabletop game). I can live with the double output if that is how it is intended to work. Any chance you could outline exactly what I would have to change to remove the second rollresult if I decide to? As a code ignorant person I can't really follow where or what Emile has suggested I change.

September 24 (11 years ago)

Michael: Ah, yes I could see that being useful. Switching to an API command instead of a roll observer would let us do something cool, such as a success/failure indicator based on monster stats or GM input (through those fancy roll queries), without someone even knowing their roll total or target number.

GManator: To be honest, it didn't occur to me at the time that the gm might gmroll to themselves, but I do imagine that would be a common use case. I've made that adjustment in the above code, and I think it works. Please give it a try and see that you think.

September 24 (11 years ago)

Edited September 24 (11 years ago)

With API commands available now, I would recommend having at least three different ways of printing the results.

my question is would be easier to use one api command to activate the roll (perhaps '!compare' or something similar??) and use a different following symbol to dictate who receives the rolls result? I would suggest using variations of the |<=| symbol.

for example, |<=| could be simply the generic roll command, printing the roll result to the player and the GM directly as whispers, while |<-| could mean a roll that only prints out the result to the GM, and |<+| could be a roll result that prints out to general chat for everyone to read.

also, the output, whether in whisper or open format, should work something like this:

  • player clicks the skill check macro - it's set up to take the values like this: !compare 3d6 |<=| ?{Modified skill level?} and inputs 11 as his modified skill level.
  • the API takes the input, rolls the values using the API die roller (saving on space in the game and preventing the players from being spammed four lines, and getting a result of 1, 3, and 1 again.)
  • a whisper is sent to the people indicated by the symbol (in this case the GM and the player who rolled the check)  like this:
    • (from system): [character] rolled a 5 ( 1 + 3 + 1 ) vs 11.
  • the output that everyone can see (because the symbol used was |<=|, the symbol for sharing the roll results only with the public chat,) prints like this: 
    • [character]: success by 6! 
of course, if it is a GM only roll, |<-|, then ONLY the GM get both of those outputs, as private whispers, and the no-one else gets to see the results at all, while if it is a public roll, |<+|, then it would print out both outputs to general chat, with no whispers so everyone can see what happened and how. (some people prefer to have the game 'in the open' like that)


September 24 (11 years ago)
GManator
KS Backer

I cannot thank the Dev Team enough for releasing the Roll20 API. Also, the fact that the community has coders like Ryan L. who are willing to put in the time and work to help those of us out who do not have the required skills to take advantage of the API is just awesome.

October 26 (11 years ago)

Edited October 26 (11 years ago)
GManator
KS Backer
Is there anyway to get this to work with the selected token variable? It doesn't seem to currently.