PDA

View Full Version : Sorting dice results in chat output



Joram Mistwalker
July 25th, 2022, 05:33
I was able to modify the manager_actions.lua to not show the total of the dice rolled, but have been unable to figure out a way to sort the results by value. I would like to have the output message sorted low to high on the dice results, regardless of the die size. Any help?

Moon Wizard
July 25th, 2022, 06:18
You don't really want to override ActionsManager, as that is one of the very low level scripts that drives rolls in the CoreRPG layer.

If you want to turn off the dice total for specific rolls, just set "rMessage.dicedisplay = 0" on the result message passed to ActionsManager.messageResult or Comm.deliverChatMessage.

Regards,
JPG

damned
July 25th, 2022, 23:27
This code can help you sort the dice into order:


table.sort(rRoll.aDice, function(a,b) return a.result > b.result end);

Joram Mistwalker
July 26th, 2022, 01:06
You don't really want to override ActionsManager, as that is one of the very low level scripts that drives rolls in the CoreRPG layer.

If you want to turn off the dice total for specific rolls, just set "rMessage.dicedisplay = 0" on the result message passed to ActionsManager.messageResult or Comm.deliverChatMessage.

Regards,
JPG

Think that is what I did, but just to make sure...

-- 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;
rMessage.diceskipexpr = rRoll.diceskipexpr;
rMessage.dicedisplay = 0;


If that is not the right place to add it, please let me know. It does seem to be working correctly, though.

Joram Mistwalker
July 26th, 2022, 01:08
This code can help you sort the dice into order:


table.sort(rRoll.aDice, function(a,b) return a.result > b.result end);


First off, thanks. Your original post put me in the right direction to set up removing the totals. Second, where would I insert this code?

Moon Wizard
July 26th, 2022, 01:44
Yes, but by modifying the ActionsManager, you are affecting every roll in the system, including rolls that shouldn't be affected (such as table rolls). By setting that information after getting the rMessage table back from ActionsManager, you don't need to modify ActionsManager at all, and it will only affect specific rolls that shouldn't display the total.

Regards,
JPG

Joram Mistwalker
July 26th, 2022, 02:39
Yes, but by modifying the ActionsManager, you are affecting every roll in the system, including rolls that shouldn't be affected (such as table rolls). By setting that information after getting the rMessage table back from ActionsManager, you don't need to modify ActionsManager at all, and it will only affect specific rolls that shouldn't display the total.

Regards,
JPG

Ok. Will see how I can apply that to what I am doing. Thanks for the advice. This is for a build of Sentinel Comics RPG and I am using Ian Ward's Dice Pool extension, so those are really the only rolls that I do not need totals on.

Honestly, I am kinda sledgehammer programming, so mostly just get lucky in figuring out what I am doing... :D

Moon Wizard
July 26th, 2022, 03:31
No worries; I just like to give advice to make sure people's stuff works the longest without any CoreRPG ruleset changes having an impact.

Cheers,
JPG

damned
July 26th, 2022, 06:23
This is not a simple post/thread but it is what you should try and get your head around -

https://www.fantasygrounds.com/forums/showthread.php?35531-Coding-dice-rolls-(actions)-in-CoreRPG

Joram Mistwalker
July 27th, 2022, 02:12
This is not a simple post/thread but it is what you should try and get your head around -

https://www.fantasygrounds.com/forums/showthread.php?35531-Coding-dice-rolls-(actions)-in-CoreRPG

Yeah, I have tried to dig into that post a couple of times before. Have not been very successful, but really need to try again. Thanks.

damned
July 27th, 2022, 02:25
Its not easy to get my head around for sure!

You might find that you can do what you want in MoreCore without any actual coding.
Most of these rolls are already supported in MoreCore from the character sheet and you can pull stats into the rolls to in many cases using Roll Parameters.

Otherwise if you are coding something new you might look at the Ruleset Wizard. Its a 3rd party tool that can make a lot of these things much easier to do. You will still need some Lua but it helps with a lot of the steps involved.