Log in

View Full Version : Registering a custom die roll



illiante
April 8th, 2025, 16:55
I am new to FGU, and am trying to create what I think is an extremely basic extension to roll exploding 4dF. I'm struggling with something that seems very simple based on numerous GitHub repos I've examined, and that is using `CustomDiceManager.add_roll_type` in my script's onInit.

I am getting a runtime error saying that `CustomDiceManager` is nil.

I am assuming I'm missing something in `extension.xml` that is supposed to bring in the core API or maybe CoreRPG?


<?xml version="1.0" encoding="iso-8859-1"?>
<root version="3.3">
<properties>
<name>Threa</name>
<description>Threa Extension for CoreRPG</description>
<author>Rocky Lhotka</author>
<version>1.0</version>
<license>CC-BY-NC-SA 4.0</license>
<loadorder>1000</loadorder>
<ruleset>
<name>CoreRPG</name>
</ruleset>
</properties>

<announcement text="Threa Extension for CoreRPG" font="emotefont" />
3
<base>
<!-- Register scripts -->
<script name="threainit" file="scripts/Threa_init.lua" />
<script name="threadice" file="scripts/Threa_dice.lua" />
</base>
</root>


In `Threa_dice.lua` my `onInit` is:


function onInit()
Debug.console("Threa_dice.lua: onInit called");
-- Register the custom roll type
if CustomDiceManager then
CustomDiceManager.add_roll_type("exp", onCustomRoll, onCustomRollLanded, true, "all");
Debug.console("Threa_dice.lua: Custom roll type 'exp' registered");
else
Debug.console("Threa_dice.lua: CustomDiceManager is not available");
end
end

Moon Wizard
April 8th, 2025, 17:39
Where is "CustomDiceManager" coming from?
That's not one of the built-in API packages; nor one of the packages provided in CoreRPG layer. It's not referenced in any code that I've seen.

If you look at the examples in the built-in rulesets (5E, 4E, 3.5E, etc.); you can make a roll like you are asking by calling:


local rRoll = { sType = "dice", sDesc = "Roll", aDice = { expr = "4dF!" }, nMod = 0 };
ActionsManager.performAction(draginfo, nil, rRoll);

where the call can be made based on some UI action (button press; click; etc.) or through UI dragging (onDragStart control event).

Regards,
JPG

illiante
April 8th, 2025, 17:54
That is probably my issue - I'm trying to learn this by skimming forums, github repos, etc. and there's a lot of contradictory or incomplete stuff out there. That "CustomDiceManager" is used in a lot of repos without any explicit reference that I can find, so my assumption was that it was built-in.

What it is _supposed_ to do is make it so I can chat "/roll exp" and get my exploding dice roll.

I haven't even gotten to the point of figuring out how to create a UI element like a button or UI dragging, so I have no frame of reference for how to trigger an action as you suggest.

What is the simplest thing you can recommend to trigger my code?

(also, thanks for the "4dF!" - that is excellent!)

---

For future reference - now that I know it isn't built-in, I did some deeper searching on GitHub and did find at least one instance of where this "CustomDiceManager" is implemented:

https://github.com/mattkeehan/fg-lua/blob/1e9a28d4c7ea8583962c3244fffc8f85ebfa358a/MoreCore/scripts/manager_custom_dice.lua

Zacchaeus
April 8th, 2025, 18:48
You are probably better off staring here https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644285/Developer+Guide

Or make a copy of the CoreRPG or 5e rulesets, unzip the copy and study those. Anything on GitHub and other places is likely to be extension code which is not necessarily going to use code that is actually in the rulesets, but rather is added to the existing code, and is use for very specific circumstances.

Moon Wizard
April 8th, 2025, 19:15
You can already make a given dice roll by using a chat command:


/die 4dF!


Regards,
JPG

LordEntrails
April 8th, 2025, 20:15
Our resident AI can confirm, but CustomDiceManager sounds like it comes from MoreCore or XCore community rulesets. So you would have to layer on those to actually use it.

illiante
April 8th, 2025, 22:17
You can already make a given dice roll by using a chat command:


/die 4dF!


Regards,
JPG

I tried that, with excitement.

Unfortunately, it doesn't explode the way our system does. We only explode when 4dF==4, not on individual + dice.

Which is fine, it means my efforts to create this function haven't been wasted after all.

illiante
April 8th, 2025, 22:20
You are probably better off staring here https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644285/Developer+Guide

Or make a copy of the CoreRPG or 5e rulesets, unzip the copy and study those. Anything on GitHub and other places is likely to be extension code which is not necessarily going to use code that is actually in the rulesets, but rather is added to the existing code, and is use for very specific circumstances.

I was hoping to avoid creating a whole new ruleset, but rather building an extension to CoreRPG. I have yet to find any good walkthrough or tutorial on how to do such a thing, so I've been muddling through all the stuff I can find via google and various AI chatbots. Pretty painful so far I'm afraid - as I'm new to FGU and lua (though have 35+ years experience as a developer, so not _entirely_ without resources).

Zacchaeus
April 8th, 2025, 22:38
I should have linked the part relating to extensions rather than the whole thing. I wasn't suggesting that you create a new ruleset but understanding how the ruleset works might help in understanding how extensions fit in. At any rate this was the bit that I really was referring you to https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996645657/Developer+Guide+-+Extensions

illiante
April 8th, 2025, 22:51
I should have linked the part relating to extensions rather than the whole thing. I wasn't suggesting that you create a new ruleset but understanding how the ruleset works might help in understanding how extensions fit in. At any rate this was the bit that I really was referring you to https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996645657/Developer+Guide+-+Extensions

Thank you for that link, that is very helpful.

When it says to copy and modify an existing extension - that makes sense - but the only extensions I have on my machine are themes. Is there a good (simple) start point that shows how to enhance the CoreRPG character sheet?

Trenloe
April 8th, 2025, 22:51
The guide here is still valid: https://www.fantasygrounds.com/forums/showthread.php?35531-Coding-dice-rolls-(actions)-in-CoreRPG

Post #26 in that thread has an example extension that triggers a roll via a chat slashhandler, you can use this as your starting point and the beginning posts in that thread describing the process should help you on your way.

EDIT: the main extra coding you're going to need to do is the exploding dice, which may require another action type that takes the original result and rolls again, adding the original result. Although you can probably code this into the original action type.