PDA

View Full Version : A question about posting rolls to chat-



Brenn
June 5th, 2015, 02:14
Here is what I currently have (dropped dice have a red line through them):

10129

Is there any way I can just post the correct total on the lines with the dropped dice on them without having to do two lines for every roll? (and have it look 'natural')

damned
June 5th, 2015, 02:29
what extension are you using for this?

Brenn
June 5th, 2015, 02:50
None, I'm inheriting core. Just did the code in the past couple of days.

damned
June 5th, 2015, 03:11
so your Song of Ice and Fire ruleset is where the code is?
post your code and someone may have some suggestions for you.

Brenn
June 5th, 2015, 03:21
Ok here goes, however to avoid posting stuff from multiple files I will say that I have basically 4 die types, all of which are d6 based. A 'r' in the name indicates the graphic for a removed die:


<die name="d6"> <icon>d6icon</icon>
<position>307,-68</position>
</die>

<!-- Dice for chat roll display -->
<die name="b6">
<model>d6</model>
<icon>b6icon</icon>
</die>
<die name="br6">
<model>d6</model>
<icon>br6icon</icon>
</die>
<die name="dr6">
<model>d6</model>
<icon>dr6icon</icon>
</die>


and here is the meat of it, catching events off of core's ActionManager:


function onInit() ActionsManager.registerModHandler("dice", modRoll);
ActionsManager.registerResultHandler("dice", onRoll);
end


function modRoll(rSource, rTarget, rRoll)
rRoll['bonus'] = ModifierList.getBonusDice();
for i = 1, rRoll.bonus, 1 do
table.insert(rRoll.aDice, "b6");
end
rRoll.nMod = ModifierList.getModifier();
end


function onRoll(rSource, rTarget, rRoll)
Debug.console("Bonus: ", rRoll.bonus);
local numBonus = tonumber(rRoll.bonus);
local numPenalty = ModifierList.getPenaltyDice();
local numToDrop = numBonus + numPenalty;
for i = 1, numToDrop, 1 do
dropLowest(rRoll);
end
local rMessage = createRollMessage(rSource, rRoll);
Comm.deliverChatMessage(rMessage);
rMessage = createTotalRollMessage(rSource, rRoll);
Comm.deliverChatMessage(rMessage);


end


function dropLowest(rRoll)
local minVal = 7;
local minIndex = 0;
for k,v in pairs(rRoll.aDice) do
if not string.find(v.type, "r") then
if minVal > v.result then
minVal = v.result;
minIndex = k;
end
end
end
if minIndex > 0 then
local minDie = rRoll.aDice[minIndex];
local minType = minDie.type;
minDie.type = string.sub(minType,1,1).."r"..string.sub(minType,2);
rRoll.aDice[minIndex] = minDie;
end
end


function createRollMessage(rSource, rRoll)
local sDesc = rRoll.sDesc;

-- Build the basic message to deliver
local rMessage = ChatManager.createBaseMessage(rSource, rRoll.sUser);
rMessage.type = rRoll.sType;
rMessage.text = rMessage.text .. sDesc;
rMessage.dice = rRoll.aDice;
--rMessage.diemodifier = rRoll.nMod;

-- Check to see if this roll should be secret (GM or dice tower tag)
if rRoll.bSecret then
rMessage.secret = true;
if rRoll.bTower then
rMessage.icon = "dicetower_icon";
end
elseif User.isHost() and OptionsManager.isOption("REVL", "off") then
rMessage.secret = true;
end

-- Don't show total as it will be inaccurate
rMessage.dicedisplay = 0;

return rMessage;
end


function createTotalRollMessage(rSource, rRoll)
removeDroppedDice(rRoll);
-- Build the basic message to deliver
local rMessage = ChatManager.createBaseMessage(rSource, rRoll.sUser);
rMessage.type = rRoll.sType;
rMessage.text = "";
rMessage.dice = rRoll.aDice;
rMessage.diemodifier = rRoll.nMod;

-- Check to see if this roll should be secret (GM or dice tower tag)
if rRoll.bSecret then
rMessage.secret = true;
if rRoll.bTower then
rMessage.icon = "dicetower_icon";
end
elseif User.isHost() and OptionsManager.isOption("REVL", "off") then
rMessage.secret = true;
end
-- Show total.
rMessage.dicedisplay = 1;

return rMessage;
end


function removeDroppedDice(rRoll)
while removedDropped(rRoll) do end;
end


function removedDropped(rRoll)
for k,v in pairs(rRoll.aDice) do
if string.find(v.type, "r") then
table.remove(rRoll.aDice,k);
return true;
end
end
return false;
end

Trenloe
June 5th, 2015, 04:00
Perhaps include the modifier in createRollMessage but no total so you have the complete roll shown, then have a line immediately after that writes the total of the roll (minus the dropped dice) to the chat window? This will be another line of text, but it won't be another line that includes dice.

Brenn
June 5th, 2015, 04:07
Yeah, I thought about that, but I'm not sure as to how to make it appear large and 'in the bubble' like the totals do. I'm hit and miss on this stuff do to my nature of getting done what my group needs in FG and then shelving the coding for quite a while...

Trenloe
June 5th, 2015, 05:19
I was more thinking of just writing the total (with any appropriate text) using rMessage.text - no dice, no bubble.

I can't think of a way of displaying the removed dice *and* having the correct total on the same line. I was thinking of making specific dice with icons for 1, 2, 3, etc. (d61, d62, d63) and replacing these dice types in the dice table, but with a result of 0 for the removed dice. The problem with this is that FG automatically writes the result onto the die icon in a fixed font (you can't change the font, nor remove it without removing it from all die icons), so setting the result to 0 would display a 0 written over the dice icon anyway.

Another, although not ideal solution if you want to display the original roll modifier, is to apply the removed dice to the roll modifier as a negative and don't display the overall modifier for the roll. e.g. if the normal modifer was +2 and the removed dice total was 6 then apply a modifier to the roll of -4.

Brenn
June 5th, 2015, 10:50
Ok thanks Trenloe, I'll fool around with these and see if I can come to a happy medium. I just wanted to make sure I wasn't missing anything. There's been a lot added since I last fooled around with this. 3.0 was still in test at that point, I believe.

Moon Wizard
June 5th, 2015, 23:03
Have you looked at this chatwindow event yet?
https://www.fantasygrounds.com/refdoc/chatwindow.xcp#onDiceTotal

Cheers,
JPG

Trenloe
June 5th, 2015, 23:21
Have you looked at this chatwindow event yet?
https://www.fantasygrounds.com/refdoc/chatwindow.xcp#onDiceTotal
Nice one, I'd forgotten about onDiceTotal. That should do the trick. :)

Moon Wizard
June 5th, 2015, 23:25
Yeah, I wrote it to support systems that dropped dice or totaled success/failure as the relevant roll result.

The implementation in the Unity version will support dice sets and dropped dice internally.

Regards,
JPG

Brenn
June 6th, 2015, 00:53
Awesome!!!! Thanks M_W! I'm happy!

damned
June 6th, 2015, 01:15
Awesome!!!! Thanks M_W! I'm happy!

can you post the working code?

Brenn
June 6th, 2015, 02:12
10151
The die definitions didn't change. here are the other two final snippets:



function onInit()
ActionsManager.registerModHandler("dice", modRoll);
ActionsManager.registerPostRollHandler("dice", onRoll);
end


function modRoll(rSource, rTarget, rRoll)
rRoll['bonus'] = ModifierList.getBonusDice();
for i = 1, rRoll.bonus, 1 do
table.insert(rRoll.aDice, "b6");
end
rRoll.nMod = ModifierList.getModifier();
end


function onRoll(rSource, rRoll)
Debug.console("Bonus: ", rRoll.bonus);
local numBonus = tonumber(rRoll.bonus);
local numPenalty = ModifierList.getPenaltyDice();
local numToDrop = numBonus + numPenalty;
for i = 1, numToDrop, 1 do
dropLowest(rRoll);
end
end


function dropLowest(rRoll)
local minVal = 7;
local minIndex = 0;
for k,v in pairs(rRoll.aDice) do
if not string.find(v.type, "r") then
if minVal > v.result then
minVal = v.result;
minIndex = k;
end
end
end
if minIndex > 0 then
local minDie = rRoll.aDice[minIndex];
local minType = minDie.type;
minDie.type = string.sub(minType,1,1).."r"..string.sub(minType,2);
rRoll.aDice[minIndex] = minDie;
end
end


and



<windowclass name="chat" merge="join">
<sheetdata>
<chatwindow name="chat">
<script>
function onDiceTotal(messageData)
local aDice = messageData.dice;
local total = 0;
for k,v in pairs(aDice) do
if not string.find(v.type, "r") then
total = total + v.result;
end
end
return true, (total + messageData.diemodifier);
end
</script>
</chatwindow>
</sheetdata>
</windowclass>

Brenn
June 6th, 2015, 02:16
<redacted />

Brenn
June 6th, 2015, 02:19
<redacted />

Mask_of_winter
June 6th, 2015, 10:52
Any chance this will get released as a community ruleset or official one at some point?

damned
June 6th, 2015, 12:49
<redacted />

The Forum equivalent of texting your Ex after a big night out.

Brenn
June 6th, 2015, 15:43
heh, yep...

Brenn
June 6th, 2015, 15:49
Mask, I'm only doing a very rudimentary implementation- basically a die roller with a simple character sheet with abilities you can roll. This won't be a full blown ruleset. With everything I've done in the past, because of copyright stuff I don't bother to release. I write FG stuff to suit my groups needs. My group is a mix of face to face and remote players.

All that said, if you PM me I'll send you what I have if you want to push further with it. I'll probably be wrapping up what I'm going to do with this in the next few days.

vikingbrad
June 22nd, 2015, 07:23
eds. My group is a mix of face to face and remote players.



Do your face to face players roll their own physical dice?

Trying to find if anyone has attempted anything to allow dice rolls to be typed-in after being physically rolled by a face to face player.

Looks a bit tricky.

damned
June 22nd, 2015, 09:31
VikingBrad here is a way to do it - perfect? no. will it work - yes.

Drag something on to your hotbar - anything - it doesnt matter. close Fantasy Grounds and locate the following file:

If doing as GM
%appdata%\fantasy grounds\campaign\<campaign_name>\usersettings\hotkeys_host.xml

or if doing as a player
%appdata%\fantasy grounds\cache\<campaign_name>\usersettings\hotkeys.xml

edit it in notepad++ or just plain old notepad

paste this code in between the <bank number="0"> and </bank> tags - see he existing entry as a reference. note you cant have duplicate key numbers within a bank...


<key number="4">
<description>[ATTACK (M)] Weapon [CRIT 20]</description>
<icon>action_attack</icon>
<data>
<type>attack</type>
<slot number="0">
<string>[ATTACK (M)] Weapon [CRIT 20]</string>
</slot>
</data>
</key>
<key number="5">
<description>[DAMAGE (M)] Weapon</description>
<icon>action_damage</icon>
<data>
<type>damage</type>
<slot number="0">
<number>0</number>
<string>[DAMAGE (M)] Weapon</string>
</slot>
</data>
</key>

save the file and reload fantasy grounds.

Player rolls a 12 you add his bonuses in (you now need to do all that manually) and add the final number eg 16 into the modifier box and click hotkey 4 or press [f4] and your roll of 16 will go as an Attack Roll. You can drag this on to the target and it will declare a hit or miss. you do basically the same thing with damage.

vikingbrad
June 22nd, 2015, 13:18
Player rolls a 12 you add his bonuses in (you now need to do all that manually) and add the final number eg 16 into the modifier box and click hotkey 4 or press [f4] and your roll of 16 will go as an Attack Roll. You can drag this on to the target and it will declare a hit or miss. you do basically the same thing with damage.

Great that works.

I still need to do a lot more playing around with player instance beside GM instance to get the flow of it working.

Thanks for all your help

damned
June 22nd, 2015, 13:57
there are a couple of 5e sessions on this Saturday (and Sunday cos were special in Aus) at FGDaze! that you can still join in if you are quick. Will help you see and experience the player side of the table.

Trenloe
June 22nd, 2015, 14:30
Expanding on damned's post #23 above. You can drag the result of any action (attack, damage, save, etc.) from the chat window to the hotkeys, then you can use the modifier approach without the need to modify the XML. Create a PC with negative bonuses for the relevant actions and keep rolling them until the result is 0 and then add them to the hotkey bar. You might have to roll a while until you get 0 as damned mentions below... Damage of 0 should be able to do pretty easily - clear the damage dice and any bonuses, then drag the empty damage entry directly to the hotkey bar.

damned
June 22nd, 2015, 14:48
Expanding on damned's post #23 above. You can drag any action (attack, damage, save, etc.) from a PC to the hotkeys, then you can use the modifier approuch without the need to modify the XML. Just create a PC with 0 bonuses for the relevant actions before you add them to the hotkey bar.

Hi Trenloe - I coudnt find any way to drag a damage with 0 value - I could with attacks by adding a negative bonus at least 2 higher than their positive bonuses and continuing to roll until i got a 0 but as I still couldnt do it for damage I suggested editing the XML. And the descriptions contain extra info that may not be accurate for the actual attack. And its actually quicker than going thru all that above... sometimes you just cant roll the number you need.

Although... you prolly know a trick or two I havent worked out...

kdconwell1
June 22nd, 2015, 18:04
Thanks I got into a game that will be helpful to me. I have always rolled up wizards, so now I got armor and did tht 15 to eight rule and the dm said that was fine, but I got armor for my ranger and put it into my inventory but it doesn't seem to be changing my ac, also I got two short swords according to the rules, but I can only put the longbow and one short sword in my weapons so I put the second in my inventory so it would keep track of weight. Thanks in advance Kevin

Trenloe
June 22nd, 2015, 18:12
but I got armor for my ranger and put it into my inventory but it doesn't seem to be changing my ac
You update your AC manually on the main tab of the character sheet.

Brenn
June 22nd, 2015, 23:51
Do your face to face players roll their own physical dice?

Trying to find if anyone has attempted anything to allow dice rolls to be typed-in after being physically rolled by a face to face player.

Looks a bit tricky.


They do. I've considered doing this as a basic core extension, and it would be doable- I just have to figure how to set it up. There would have to be a configuration for each client as auto-roll or entry I'm thinking, then capture onDiceTotal event and do a dialog and manipulate the table, though the manual entry seems like it would be more of a pain than it is worth, that said I've been doing some early work with eclipse phase and I think I might want this. I'll tinker with it. It definitely has it's uses in the WotC stuff if you play like I do.
If I do do it I will do it as a CoreRPG extension to make it useful across the board.

vikingbrad
June 23rd, 2015, 00:26
Going to start a new thread as it deserves its own discussion