PDA

View Full Version : Using the Comm.throwDice method



kalannar
August 6th, 2014, 20:15
Creating a numbercontrol that rolls a dice and adds modifiers. I am using the Comm.throwDice function but not sure what i need to pass in the dice variable. Can anyone give me an example for having it roll a d20? Thank you.

Dakadin
August 6th, 2014, 21:11
Here is an example:


local sDragType = "dice";
local aDice = {"d20"};
local iModifier = 2;
local sDescription = "d20+2 Test"

Comm.throwDice(sDragType, aDice, iModifier, sDescription);


Please let me know if you have any questions.

kalannar
August 7th, 2014, 23:23
is there a function that rolls a dice and returns the result?

Dakadin
August 7th, 2014, 23:41
is there a function that rolls a dice and returns the result?

The best way to do that is to use the action scripts in the CoreRPG compatible rulesets as an example. Pick the ruleset you are most comfortable with and look in the /scripts folder for the manager_action_*.lua files. Replace the * with the type of action you want to look at. The onInit should register a results handler. Look at the function name in the 2nd parameter. Here is an example from manager_action_skill.lua of the 3.5E ruleset:


ActionsManager.registerResultHandler("skill", onRoll);

The onRoll function is where you want to look. You should see this line in the onRoll function which gets the total of the dice result:


local nTotal = ActionsManager.total(rRoll);

Then you can write code to use it however you want.

One thing to be aware of is if you are making a new action type don't forget to add it to the manager_gamesystem.lua file in the actions section.

Trenloe
August 7th, 2014, 23:49
You also might find this thread useful: https://www.fantasygrounds.com/forums/showthread.php?21542-Need-Help-Trying-to-create-a-custom-rollable-field-like-Initiative