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

[Question] Modifying the dice roll after it is rolled but before it's displayed

I would like to be able to use a script based on the sendChat callback example that changes the result of the roll in some way. I'm not clear on what the optional 3rd parameter callback function should return in order to keep things moving. Can someone provide an example of a sort of pass-thru callback function that just logs the roll result to the JS log and then outputs the dice roll as normal? That would be all that I'd need, I think, to figure it out. 
My API script for roll formatting does what you want. The problem with it is that it does work on ordinary chat. So, if your players use inline rolling or /r commands, it does not catch them first, you would get both results. But if you are trying to do something specific, my code may help you get there.
Is there any way to pass the roll/result structure on through to the chat window as normal, without having to do the chat window formatting myself? Your script is great, but I'm afraid it's doing much more than I need to do. I just want to interrupt the roll result before it lands on the chat window for everyone to see.
you can, but it has to be sent through the API interface. You can just have your players type !r instead of /r and replace the message with sendChat(theirtext+"your modifier")
OK. Let me come at this another way. Is there any exposed functionality of the API that allows me to say something like showDiceResult() where I can pass in the number/type of dice, their modifiers, and their values? What if I want to be able to rig the dice rolls? That's what I'm getting at here. What if I want, from time to time for dramatic effect (or to avoid a TPK), to have a bad guy roll a natural 1 (or roll just low enough not to hit)? And what if I want to make it LOOK like he really rolled that, so that the players were none the wiser? If I could insert myself into the roll result and change the value before it made it to the chat window, my problem would be solved. Yes, I could just make a local roll and tell the players he fumbled, but it's more dramatic if the players saw the dice and believed them.
That's a lot tougher, I don't think there's a way because the /r command and [[d]] commands are built into roll20 as their own function. The only way you could intercept a number at that point would be to insert lines of code directly into the function, and I'm pretty sure that it isn't possible at this time. Please correct me if I'm wrong!
Little flash of insight, maybe intercepting is the wrong way of doing it. Perhaps just having a command (i.e. !fakeroll) that takes xdy+z, adds x+z, and outputs it using the HTML elements the game naturally uses? I'm a little wrapped up right now and don't have time to test it, but if you get started, I'd be happy to collaborate.
Yes, that's what I want to do. How do I use "the HTML elements the game naturally uses"? How do I know exactly what those are? That's why I was wondering about a showDiceResult() function that might duplicate that output. There surely must be a function that does that already that takes into account all the user preferences and setting about output. I would ideally like to be able to just tap into that function and call it myself.
<div class="formula" style="margin-bottom: 3px;">          rolling xdy+z </div> <div class="clear"></div> <div class="formula formattedformula"> <div class="dicegrouping ui-sortable" data-groupindex="0"> "(" <div data origindex="0" class="diceroll dy critfail "> <div class="dicon"> <div class="didroll">1</div> <div class="backing"></div> </div> </div> "+z" <div class="clear"></div> </div> <div class="clear"></div> <strong> = </strong> <div class="rolled ui-draggable"> 1+z </div> </div> had to hand type this hastily, so if I typo'd don't fault me for it lol.
oh, and easiest way to find them is to use chrome, right click, and choose "Inspect Element"
OK. That mostly works, but it still doesn't look right. This script does what you suggest, and the dice "roll" as they've been told. But I think I'm not getting some style information or something, because the final output doesn't match the norm. I've attached a screenshot below to illustrate what "normal" looks like and how this deviates from normal. The last roll was accomplished using "!fudge 20:+1:8". &lt;script src="<a href="https://gist.github.com/anonymous/59ada4691a8f67737b86.js&quot;&gt;&lt;/script" rel="nofollow">https://gist.github.com/anonymous/59ada4691a8f67737b86.js"&gt;&lt;/script</a>&gt;
No luck so far, whenever you try to format anything it changes it to &lt;div class="userscript *whatever*&gt;. I asked in another thread if the roll format was released, otherwise, we can build the formatting and boxes by hand.
Well, this is the best I've been able to do. There seems to be no way to change the background color to the normal blue because that is happening further up the chain than the script has access to. Also, I can't see why the picture of the 20-sided die is gone now that I've added the styles. I also don't know how to make it draggable/sortable. All in all, I think this is likely not possible without support in the API for showing the result of a die roll. Unless, of course, you modify the other script that customizes ALL die rolls, in which case you should be able to make it look just like that. But if you want to stay with the normal rolls, I don't think it's possible. Script is embedded, along with a screenshot (fake on top, real on bottom). &lt;script src="<a href="https://gist.github.com/anonymous/5c76acada11dc4cd92b8.js&quot;&gt;&lt;/script" rel="nofollow">https://gist.github.com/anonymous/5c76acada11dc4cd92b8.js"&gt;&lt;/script</a>&gt;
Fixes: 1:) Main dice font 2:) Dice picture 3:) Font color for "natural" 1's and max's 4:) Strange little line that apears above = result 5:) = and result are now on the same line 6:) result is now in a white column as well EDIT: The modifier is in the correct spot now. Cheat on my GM friends! <a href="https://gist.github.com/anonymous/6118756" rel="nofollow">https://gist.github.com/anonymous/6118756</a>
Well done, Emile. It looks great. I really wish there was a way to modify the background color to be the normal blue, rather than the pale blue. I don't think that's possible, since the API messages are scrubbed and reformatted before they're displayed. Once again, though, it looks really good.
The problem is that blue is only for your messages. Your messages turn grey when other players see them so it'd stand out hell a bad
P.S. found another 5 minutes to finish the script, it now looks EXACTLY like a natural roll, oh, and My edited post above has 2 gists for some reason, the &nbsp;top one DOES NOT function, please use the bottom.
Excellent! And I didn't know that about it only being blue for me. I assumed blue meant GM, since that's the only role I've ever had in roll20.
naw, but I'm updating it to allow for non-modified rolls... a.k.a. a 20::8 would just be a d20 with a result of 8
When you're done with all of the tweaking, are you going to post the final version in its own new post? I don't know what the protocol is for that on this forum.
eh, you can. You'd probably want to delete this thread and post a newer, cleaner one.