Visual die rolls

Discussion concerning lmarkus' campaign framework for D&D3.x and Pathfinder.

Moderators: dorpond, trevor, Azhrei, giliath, Gamerdude, jay, Mr.Ice, lmarkus001

Forum rules
Discussion regarding lmarkus001's framework only. Other posts deleted without notice! :)
User avatar
Lifer4700
Cave Troll
Posts: 48
Joined: Thu Aug 25, 2011 3:17 pm

Visual die rolls

Post by Lifer4700 »

I'm using the MT1.3.86_DnD35Pathfinder framework, and I've gotten to the point where I'm nearly ready to start my first ever MapTool gaming session with players that have never seen the MapTool software either.

I have learned many things about this framework, normally by going about something "the hard way", then asking for help on the forums, only to find out there was already an "easy way" all along.

So this time, I'm going to ask first.

I want to have die rolls show visually. There are some die pictures included with MapTool, and I know I can create tables for each die type, and apply the pictures to the results, and I've seen the Dice Box add-on, but I would like to see those visual die pictures with the rolls made by the framework.


Is this even possible without changing LibAttack@Lib:libDnD35Pathfinder? (and charSkillCheck, charStatCheck, charSavingThrow, subBullRush, subCharge, etc.)
I should change my profile name to Freddy because JSON and I don't quite get along yet.

User avatar
Lifer4700
Cave Troll
Posts: 48
Joined: Thu Aug 25, 2011 3:17 pm

Re: Visual die rolls

Post by Lifer4700 »

As a test, I first created a table for a D20 roll, called "die-20", and assigned the pictures to the results. As expected, a double-click of the table produces the die roll result image in the chat window.

Next, I figured out that in order to get the picture to show when I typed into the chat window I had to enter the following:

Code: Select all

<image src='[r:tableImage("die-20")]'></image>
Finally, I took that information to add one line, and modify another in the charSkillCheck@Lib:libDnD35Pathfinder campaign macro.

BEFORE

Code: Select all

[H: droll = 1d20]
[H: dieroll = if(take > 0, take * 10, droll)]

[H: sCheck = dieroll + classMod + skR + skRM + skSyn + skFeat + skEq + skMisc + tStatB + tACP + SkillMisc + skSize + skSpd + tempBonus]
[H: sTip = '
<table border=0 cellspacing=0 cellpadding=0>
    <tr>
        <td align=left valign=top>Die Roll (1d20):</td>
        <td align=right>' + dieroll + '</td>
    </tr>
AFTER

Code: Select all

[H: droll = 1d20]
[H: dieroll = if(take > 0, take * 10, droll)]
[H: visDie = tableImage("die-20", dieroll)]

[H: sCheck = dieroll + classMod + skR + skRM + skSyn + skFeat + skEq + skMisc + tStatB + tACP + SkillMisc + skSize + skSpd + tempBonus]
[H: sTip = '
<table border=0 cellspacing=0 cellpadding=0>
    <tr>
        <td align=left valign=top>Die Roll (1d20):</td>
        <td align=right><image src=' + visDie + '></image></td>
    </tr>

Now, when skill checks are made, the regular numbers still show up, but in the 'hover' popup, the picture of the rolled value shows at the top, above all the modifiers.

It looks really good, actually.
I should change my profile name to Freddy because JSON and I don't quite get along yet.

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Visual die rolls

Post by aliasmask »

CiF has a nifty little visual die roller.

User avatar
lmarkus001
Great Wyrm
Posts: 1867
Joined: Sat Mar 29, 2008 12:30 am
Location: Layfayette Hill, PA

Re: Visual die rolls

Post by lmarkus001 »

You are correct, there is no single quick place to change from a text number to a die image.

User avatar
Lifer4700
Cave Troll
Posts: 48
Joined: Thu Aug 25, 2011 3:17 pm

Re: Visual die rolls

Post by Lifer4700 »

@aliasmask - I saw that one as well, but it doesn't seem that any of them integrate with the existing framework/macros. (seemingly confirmed by Imarkus001)


I'm pretty happy with the results I was able to achieve last night, so now it's just a question of finding and modifying ALL the campaign macros that roll dice. :wink:

Thanks again for the prompt and informative replies.
Great community!
I should change my profile name to Freddy because JSON and I don't quite get along yet.

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Visual die rolls

Post by CoveredInFish »

Searching for the generated output and fixing it by hand is probably the better solution. BUT ...
lmarkus001 wrote:there is no single quick place to change from a text number to a die image.
... I just had an idea. This works, but I havent tested it inside of any framework yet. So this could cause sideeffects or errors.

There is ONE single place, the roll-function. We can redefine that.

Just giving back images would break all macros, since we cannot calculate with images. But we can use the broadcast-function. So whenever a roll is made (i just have tried roll() what is the same as xDy, other roll types remain unchanged) it returns the number but broadcasts directly into chat images of the rolled dices.
This COULD break complex output, but generally should happen before any other output of the macro.

All you have to do is
a) add dice image tables.

Menu->Help->Add default tables works fine. The macro as written expects the name to be D4, D6, etc...
The macro as written doesnt check if the tables exists (because right out of my head i dont know how) but checks if the faces number is a standard one (the defaullt tables provide images for only d4,d6,d8,d10,d12,d20 - any other faced roll will generate text output)


b)add this macro "rollWithImages" to a Lib:token

Code: Select all

[h: sides = json.get(macro.args, 0)]
[h: faces = json.get(macro.args, 1)]
[h: singleRolls = ""]
[h: total = 0]
[h, count(sides), code: {
    [h: thisRoll = oldFunction(1, faces)]
    [h: singleRolls = listAppend(singleRolls, thisRoll)]
    [h: total = total + thisRoll]
}]
[h: output = ""]
[h, if(listContains("4,6,8,10,12,20", faces)), code: {
    [h: tblName = strformat("D%s", faces)]
    [h, foreach(item, singleRolls): output=strformat("%s<img src='%s'></img>", output, tblImage(tblName, item))]
};{
    [h, foreach(item, singleRolls): output=strformat("%s%s<sub>%s</sub> ", output, item, faces)]
}]
[r: total]
[h, if(output!=""): broadcast(output)]
 
c) add to the onCampaignLoad-Macro on this Lib:token this line
This redefines the standard roll function with the roll-macro above.

Code: Select all

[h: defineFunction("roll", "rollWithImages@this")]
 
Use at your own risk. And report how it works :)
Last edited by CoveredInFish on Tue Sep 06, 2011 2:38 pm, edited 1 time in total.

User avatar
Lifer4700
Cave Troll
Posts: 48
Joined: Thu Aug 25, 2011 3:17 pm

Re: Visual die rolls

Post by Lifer4700 »

I will try that in my test campaign when I get home from work tonight, thanks!
I should change my profile name to Freddy because JSON and I don't quite get along yet.

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Visual die rolls

Post by CoveredInFish »

I tested this in a framework of mine and it worked fine. This is no promise that it will work in lindsays

One curiosity though: if you click onCampaignLoad more than once it chains the new function definitions. I had it clicked twice and wondered why all rolls were doubled. A reload of the campaign fixed this.

User avatar
Lifer4700
Cave Troll
Posts: 48
Joined: Thu Aug 25, 2011 3:17 pm

Re: Visual die rolls

Post by Lifer4700 »

Menu->Help->Add default tables
WOW! That's a time saver!

Thanks
I should change my profile name to Freddy because JSON and I don't quite get along yet.

User avatar
Lifer4700
Cave Troll
Posts: 48
Joined: Thu Aug 25, 2011 3:17 pm

Re: Visual die rolls

Post by Lifer4700 »

Oh, does anyone know where I can get sets of pictures of dice?

I'd hate to set up a camera/lighting rig just to take pics of my own...
I should change my profile name to Freddy because JSON and I don't quite get along yet.

User avatar
Lifer4700
Cave Troll
Posts: 48
Joined: Thu Aug 25, 2011 3:17 pm

Re: Visual die rolls

Post by Lifer4700 »

This does what I'm looking for. It requires that the default tables have been generated, or at least one named D20 with pictures...


I inserted this section of code just before the line that writes the output.

Code: Select all

[H: vAtkRolls = ""]
[H, C(numAtk, ""), CODE:
{	[H: dieRoll = eval("result1" + roll.count)]
	[H: rollPic = ""]
	[H: rollPic = tableImage("D20", dieRoll)]
	[H: diePic = ""]
	[H: diepic = '<img src="' + rollPic + '">']
	[H: vAtkRolls = vAtkRolls + diePic]
}]
Then I inserted the vAtkRolls into the tip. The final code section looks like this.

Code: Select all

[H: vAtkRolls = ""]
[H, C(numAtk, ""), CODE:
{	[H: dieRoll = eval("result1" + roll.count)]
	[H: rollPic = ""]
	[H: rollPic = tableImage("D20", dieRoll)]
	[H: diePic = ""]
	[H: diepic = '<img src="' + rollPic + '">']
	[H: vAtkRolls = vAtkRolls + diePic]
}]

[H: output = if( Primary != 0, targString + AtkString1, "" ) ]
[H: outputwTip = "<span title='<html>" + targ1Image +  targ2Image +  if(  target1ID != "" || target2ID != "" , "<br> ", " " ) + + vAtkRolls + "<br>"  + atkList + " " + dmgList + " </html>'>" + output + "</span>"]

Next, I'm going to try to tackle the damage dice! :?
I should change my profile name to Freddy because JSON and I don't quite get along yet.

User avatar
Lifer4700
Cave Troll
Posts: 48
Joined: Thu Aug 25, 2011 3:17 pm

Re: Visual die rolls

Post by Lifer4700 »

Yeah, ok....

So visual damage dice are not going to happen without an almost complete re-write of the libAttack macro, since the damage is rolled on-the-fly during output, and I would need to 'figure out' how many and which kind of dice are being rolled.

At first glance, here are the things I would need to do:
1) parse the Damage variable to get qty and type of dice (might be 2d6, 1d8, 2d4+3, etc)
2) perform the individual roll(s)
3) fetch the individual die picture(s), build the <img> tag string for eventual output
4) add up the rolls to get a total dmg for further calculations
5) modify temp3, temp4, temp5 to accept the pre-rolled totals
6) modify atkList & criList to accept the pre-rolled totals
7) modify outputwTip to display the die images


I think that's it... O_o
I should change my profile name to Freddy because JSON and I don't quite get along yet.

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Visual die rolls

Post by CoveredInFish »

Have you tried rewriting the roll()-function? (as I show above)

I totally!! admit this will be nowhere as good an output as a complete rewrite could do (for example I have no idea how to "name" a die roll without similar heavy rewriting) but it would be done in some minutes.

If you fear cluttering the chat - the diceimages could be shown in a frame (if every player should be able to see see this it would take some more coding, but its possible)

User avatar
Lifer4700
Cave Troll
Posts: 48
Joined: Thu Aug 25, 2011 3:17 pm

Re: Visual die rolls

Post by Lifer4700 »

No, I have not tried it yet. I was on a roll deciphering/disecting the existing libAttack to see how it works.

I see no reason to modify any of the logic, as it is all very sound, so I will just be modifying the rest of it. For instance, the initial attack rolls are stored, and I was able to squeeze in the images with little difficulty, but all the damage rolls are calculated on the fly and only the total is displayed, they are not really stored as individual die results.

I think that I might try your method tonight (I know I said that before) and see how it looks. I'm already thinking that I will prefer a formatted output, especially since, at higher levels, with two-weapon fighting, haste, multi-shot, critical confirmations, et. al., there will be LOTS of dice flying!

In the Ultimate Test Attack Scenario that I'm using, there are a total of 8 attack rolls: 5 Primary (haste), 3 Off-Hand.

For the Ultimate Test Damage Scenario, I envision a Longsword with Lead Blades cast upon it, Vital Strike (all three), critical + flaming burst, power attack, high strength, using two hands... and it crits.

That should come out to... lemmee see... 10d6 slash + 1d6 fire + 1d10 fire + gobs of additional damage.

Now granted, Vital Strike and the Full Attack option don't play well together, but even so, there's potentially lots of dice.
I should change my profile name to Freddy because JSON and I don't quite get along yet.

User avatar
Lifer4700
Cave Troll
Posts: 48
Joined: Thu Aug 25, 2011 3:17 pm

Re: Visual die rolls

Post by Lifer4700 »

@CoveredInFish

I have created the rollWithImages macro, and the added the defineFunction line to the existing onCampaignLoad macro on the existing campaign Lib:libDnD35Pathfinder token.

1) As expected, it works as you said, broadcasting each die roll picture to the chat as it happens.

2) As hoped, it does not interfere with the ultimate output.

However
3) There is a deluge of die pictures - even more than I thought possible - the existing macro rolls many dice, even if they're not needed or used for the current attack. Logic is apparently only used to determine the display, not the existence, of certain roll results.


So, this puts me back on the path of re-writing chunks of the libAttack macro.
I should change my profile name to Freddy because JSON and I don't quite get along yet.

Post Reply

Return to “D&D 3.5/Pathfinder 1e Campaign Macros”