PDA

View Full Version : Very simple dice rolling



alloowishus
February 23rd, 2024, 03:29
I read the sticky on this but all I want to do is roll a simple dice combo and get back the total. I.e. "5d10" or "5d10+5". Is there an easy way to do this? Thanks.

Trenloe
February 23rd, 2024, 03:38
As explained in the coding dice rolls thread, FG rolls are asynchronous - you put the roll together and then tell FG to execute the roll, and that's where the code ends. If you want to do some processing of the result, then you need to code in the onRoll result handler - which is all explained in the thread. You can't code to roll the dice and then have your code pause until the result is returned, as this would hang the whole of FG.

One way around this is not to roll dice, but work out the dice rolls using random numbers - as the dice don't roll, you have the result immediately available in your code and can have the roll and result handler all in the same function. Have a look at the evalDiceString function in the CoreRPG ruleset -> scripts\manager_dice.lua file.

peterb
February 23rd, 2024, 23:24
Googling for "lua dice" gave the following link: https://github.com/brianherbert/dice/blob/master/roll.lua, which you could modify for your needs.

damned
February 24th, 2024, 02:56
You need to provide more info.
You can type /die 5d10+5 in chat and it will roll and output the result.

This works in almost every ruleset.

If you are wanting to play an otherwise unsupported game try XCore it supports a lot of dice mechanics and writing new rolls is quite trivial.