PDA

View Full Version : News trying to code a wild die



AlkarGreener
December 16th, 2020, 13:00
FG ruleset coning newb here, but some experience with scripting.

I am trying to code the Star Wars OpenD6 wild die. To start simple, I have coded it in game_elements.xml as follows. Note, this is in FGU if it matters.

<!--wild die, DEV 15 Dec 2020, Mykl Sandusky
function SystemMessage is a copy from \scripts\manager_chat.lua
- only shows when a standard die type is user for the name
- unsure how to make it a different color than the standard d6
- unsure how to limit to 1 die being rolled
- unsure how to roll an additional die when a 6 is rolled
- NOTE: Savage Worlds ruleset uses a wild die, can that code be used?
-->
<die name="dF" label="wild die">
<model>d6</model>
<icon>d6icon</icon>
<position>160,-68</position>
<script>
function onValue(result)
local modresult = result;
if result == 1 then
modresult = 0;
SystemMessage("ZERO rolled on the wild die!");
end
if result == 6 then
SystemMessage("SIX rolled on the wild die!");
rollWildDie();
end
return math.ceil(modresult);
end
function rollWildDie()
SystemMessage("ROLL ANOTHER DIE!");
end
function SystemMessage(sText)
local msg = {font = "systemfont"};
msg.text = sText;
Comm.addChatMessage(msg);
end
</script>
</die>

For now, I have added rollWildDie to confirm it will be called when a 6 is rolled. I need it to roll the wild die again and add the value, including keep rolling as long as a 6 is returned.
I would also like to block right-clicking and selecting multiple dice.
Also, I have been unable to call the global SystemMessage function. Well, I assumed it was global.

Any suggestions?

Moon Wizard
December 16th, 2020, 21:05
You can not do that in a die script. The die script only supports returning a value; and has no context besides the single die.

You'll need to look at some of the other rulesets that have roll handlers set up that apply modifications/rerolls. These are typically based on top of CoreRPG. Basically, you would need to save off or embed entire roll data, set up which dice to reroll, and store any resolved roll information. Then, when the rolls all complete, you need to put together the results from the data you saved plus the latest rolls.

Some examples:
* 5E advantage/disadvantage (adds extra die, and takes highest/lowest, then removes the other one)
* 5E weapon rerolls (generates replacement number; no actual reroll)
* Savage Worlds wild die (If max rolled, then generate a new roll and add up when done)

Regards,
JPG

AlkarGreener
December 17th, 2020, 10:09
Thanks, appreciated. I downloaded Savage Worlds and am looking at the scripting. Do you have any recommendations to help find it, or to script what I need? Since none of it is commented, and it is not PowerShell (which I use fairly often), it is not obvious to me where to look.

Admittedly, I should RTFM, but I don't know where the FM is. :)

Moon Wizard
December 17th, 2020, 22:03
There is a whole developer's guide section to the wiki; but that only covers the low-level API. There is no documentation of the rulesets themselves; though many are accessible for viewing as examples of how the API can be used. However, the base developer wiki gives a lot of detail about all the pieces that the rulesets use.
https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644285/Developer+Guide

I'm not familiar with Savage Worlds specifically; but it looks like PC trait rolls get boiled down to a call to TraitManager.rollTrait, and build the initial roll from there. You'd have to follow the logic from there to see what it does. Remember that SavageWorlds is layered on top of CoreRPG, so you may need to search in both rulesets.

Generally, when people are new to building rulesets or extensions, I suggest starting with simple modifications to existing content (i.e. modifying an existing roll, adding/removing fields, etc.)

Regards,
JPG

AlkarGreener
December 18th, 2020, 10:50
Thanks. I am hoping to get the wild die and a character sheet working.

damned
December 18th, 2020, 11:09
In FGU /die 1d6e will explode and sum for you