PDA

View Full Version : Example of coding new type of roll?



altepeter
March 8th, 2018, 21:17
MoreCore seems like it's added tons of useful new rolls for various systems. Great work!

Has anyone posted a complete example of how you add a new roll? In other words, all the Lua/XML you would need to add a new type of roll to CoreRPG or to MoreCore? I assume this has been posted before but I wasn't able to find it.

Many thanks in advance,
Joe

damned
March 8th, 2018, 21:45
Hi altepeter

The first thing to do is use a roll from /scripts (as opposed to /desktop/scripts) as your base Template. Use one that is close already in usage as your template.

1. In your /scripts/manager_custom_mynewroll.lua roll set the Roll type:
local sCmd = "mynewroll";
2. Include this new script in /base.xml
<script name="CustomDiceMyNewRoll" file="scripts/manager_custom_mynewroll.lua" />
3. Create a new Button Icon for the roll and store in /graphics/icons folder
4. Define in /graphics/graphics_icons.xml
<icon name="mynewroll" file="graphics/icons/button_mynewroll.png" />
5. Setup the auto Icon definition in /campaign/template_campaign.xml
Add to the <template name="button_rolls_type"> in 3 places - 2 as mynewroll (icons and values) and 1 as MyNewRoll (tooltips).
Add to the <template name="button_rolls"> in 3 places - 2 as mynewroll (icons and values) and 1 as MyNewRoll (tooltips).
6. Add to /campaign/record_cas.xml
Add to the <string_column name="clichatcommand"> just above the elseif == nil statement
elseif sCommand == "mynewroll" then
nodeWin.getChild("rollstype").setValue("mynewroll");
7. Add it to the /dicehelp command via /scripts/dicehelp.lua
Add it to the function createHelpMessage()

And then package up those changed files and send to me (with permission to use/include/share) so that it can be included in the next version of MoreCore and you wont have to redo your changes after the next update.

mozmonar
March 9th, 2018, 00:12
Oh very handy. I was just tinkering with this earlier today. I was playing with the boon bane Rolls trying to make the icon in the chat window red for banes and green for boons. When I changed the "d" and "r" for banes it had an unexpected result for me. The icon indeed changed to a red icon, but the rolls were d20s. I imagine it had something to do with me not changing the template stuff. Will explore it when I am home from work.

dulux-oz
March 9th, 2018, 01:24
The other option is to use the die-codes/tools in the UDR (Universal Die Roller) in DORCore (https://www.fantasygrounds.com/forums/showthread.php?42221-DORCore-An-Advanced-Beta-Release-Of-A-New-Ruleset) - it might suit your needs better without having to "code" anything.

mozmonar
March 10th, 2018, 00:25
Hey damned

So as mentioned above I have been tinkering with the banes/boons trying to customize them a little. I was trying to change the die icon that shows up in the chat to red for banes and green for boons. When I made the a change in the manager_custom_bane.lua (see below) after defining the dice in gamelements.xml and graphics_icons.xml the result is that the banes now roll d20 though the icon chat change worked. I am not able to figure out why this change caused this result. Can you point me to what is happening?



-- table.insert(rRoll.aDice, "d" .. sSize);
table.insert(rRoll.aDice, "r" .. sSize);

damned
March 10th, 2018, 00:33
Have a look at the Stunt Die mechanic - its /stunt
See what dice it uses... Hint its not d6.
Ill make the change in my copy - post what what you find here.

mozmonar
March 10th, 2018, 00:45
Yeah I have been looking at different things. I looked at stunt I also looked at critical damage in 5e which is where I got the idea to change the "d" to "r". I guess I am failing see what about that seemingly innocuous change makes the die selection "default" to d20 rather than parse the #d# code

damned
March 10th, 2018, 00:49
Dont change that code.
If you type /stunt in the chat window see what rolls and is displayed.

damned
March 10th, 2018, 00:59
The red die is not a d6 it is a d1006.
The next build of MoreCore will contain:

Red Dice d4-d20 called using d1004,d1006,d1008,d10010,d10012,d10020
Green Dice d4-d20 called using d2004,d2006,d2008,d20010,d20012,d20020
Blue Dice d4-d20 called using d3004,d3006,d3008,d30010,d30012,d30020

So in the /bane script you change Line #71 from:
table.insert(rRoll.aDice, "d" .. sSize);
to
table.insert(rRoll.aDice, "d100" .. sSize);

and if you want Boons to be blue or green you would use d300 or d200....

mozmonar
March 10th, 2018, 01:51
My ultimate goal would be to create a single roll for boon/bane and and a way to increment a counter on the character sheet like a boon number field and a bane number field. Then when you want to roll your boon or banes the /boonbane (whatever it is called) gets rolled it subtracts banes from boons. If the value is positive it rolls that number of boons...if the result is negative it rolls that number of banes...if the result is 0 then it rolls nothing. That way you could have a single /roll entry on the character sheet. I worked out how to make the banes negative by changing the the following bits below.


-- nBane = 0 - rRoll.aDice[1].result;
nBane = rRoll.aDice[1].result;

...

-- table.insert(rRoll.aDice, "d" .. sSize);
table.insert(rRoll.aDice, "-d" .. sSize);

mozmonar
March 10th, 2018, 02:04
I'd like to replace this functional but less elegant solution with a single roll that can figure out what to roll and then roll it.

22580

damned
March 10th, 2018, 02:07
I am sure there are ways to do it mozmonar
I look forward to seeing what you come up with!

mozmonar
March 10th, 2018, 02:35
I am sure there are ways to do it mozmonar
I look forward to seeing what you come up with!

I hope I am not coming across as critical or unappreciative of what you have done. I am very much leaning on you for help and guidance and find looking through your scripts invaluable (though I frequently understand very little of it hehe.)

damned
March 10th, 2018, 02:50
I hope I am not coming across as critical or unappreciative of what you have done. I am very much leaning on you for help and guidance and find looking through your scripts invaluable (though I frequently understand very little of it hehe.)

Its a community - the more people that contribute the better. The more we help each other the better. I dont understand it all either...!

Trenloe
March 10th, 2018, 03:31
Has anyone posted a complete example of how you add a new roll? In other words, all the Lua/XML you would need to add a new type of roll to CoreRPG or to MoreCore?
Yes.

Find it all here: https://www.fantasygrounds.com/forums/showthread.php?35531-Fantasy-Grounds-v3-X-CoreRPG-based-Actions-(dice-rolling)

TriOpticon
March 10th, 2018, 04:29
That is all very helpful. Is there documentation about what a roll table (rRoll) should contain? I did not see it on https://www.fantasygrounds.com/refdoc/ and I am not 100% sure what is part of FG and what is part of MoreCore or other rulesets.


Look at the code in /orderresult which should give you some clues on comparing dice results.damned suggested I looked at this die within MoreCore and I did and it was very helpful so I thought I would post here since this is about rolling dice and not really MoreCore specific. Maybe it will help others understand when the next person searches for die roll information

When outputting the contents of what a roll looked like before rolling, this is what came out (rRoll):

{ s'sType' = s'orderresult', s'aDice' = { #1 = s'd6', #2 = s'd6', #3 = s'd6' }, s'nMod' = #0, s'sDesc' = s'Testing' }

After the roll, this is the contents:

{ s'aDice' = { #1 = { s'result' = #1, s'type' = s'd6' }, #2 = { s'result' = #4, s'type' = s'd6' }, #3 = { s'result' = #6, s'type' = s'd6' } }, s'nMod' = #0, s'sType' = s'orderresult', s'bSecret' = bFALSE, s'sDesc' = s'Testing' }

So the result is added (along with bSecret) which can then be manipulated (sorted or checked for doubles) when it calls the function after the initial roll is finished.

mozmonar, for your situation could you just have a Boon +/- defined as /mod 1 and then Bane +/- as /mod -1 ? Then after you click all the boons and banes and do the /boonbane roll your createRoll can check if the Modifier (nMod in rRoll) is positive or negative or zero (in which case just send a message to chat saying nothing is rolled)? And then based on that it could set the correct number of dice in rRoll (table.insert(rRoll.aDice, "d100"..sSize); for banes), etc?

Trenloe
March 10th, 2018, 22:00
That is all very helpful. Is there documentation about what a roll table (rRoll) should contain?
It's in the comments of the manager_actions.lua file in CoreRPG. And is also in post #2 of the thread I linked in my previous post.

mozmonar
March 10th, 2018, 22:15
Typed in wrong window...ignore.

altepeter
March 11th, 2018, 15:22
Thanks very much damned, delux, and Trenloe --- extremely helpful. If you or others have the time, I'd like to ask a few more questions:

1) About MoreCore specifically: is there already functionality to change the type of roll based on a flag of some kind? I'm thinking of something like the shadowrun karma mechanics, where normally you'd roll for number of successes with a bunch of d6, but occasionally you'd modify the roll with karma and make the same number of dice explode. Ideally you'd be able to add a karma flag to the character sheet, or modifier stack, or similar, so you didn't need two or more buttons for each skill.
2) Related --> does the modifier stack accept non-integer values, like the string "karma"?

Again, many, many thanks for your assistance. This appears to be a great online community!

Best,
Joe

Trenloe
March 11th, 2018, 15:43
1) About MoreCore specifically: is there already functionality to change the type of roll based on a flag of some kind? I'm thinking of something like the shadowrun karma mechanics, where normally you'd roll for number of successes with a bunch of d6, but occasionally you'd modify the roll with karma and make the same number of dice explode. Ideally you'd be able to add a karma flag to the character sheet, or modifier stack, or similar, so you didn't need two or more buttons for each skill.
2) Related --> does the modifier stack accept non-integer values, like the string "karma"?
1) The easiest way for MoreCore to handle this would be to have a different roll setup, or maybe a flag in the same roll. Either way, it will require the roll handler to be setup to handle it, and the relevant roll added to the character sheet. You'd end up with two separate rolls - one with karma and one without it.
2) Nope. The modifier box only takes numbers. You could maybe look at applying a "KARMA" effect to a character for one roll, then look for that effect in the dice roller.

mozmonar
March 11th, 2018, 21:41
Well I have hit a very confusing situation. After playing with the MoreCore Ruleset to mess around with the custom /bane and /boon rolls I achieved partially what I was trying to achieve. I wanted to make the banes show up with red negative dice in the chat and the boons to show up with green. I was able to get this to work.

At this point I decide to move those changes to the SotDL MoreCore extension. I added the custom dice to the gameelements.xml. I added the proper icons in the graphics folders and defined them in the graphics_icons.xml. I copied my modified manager_custom_bane and boon scripts to the scripts folder and added them to the extension.xml.

I deleted the modified MoreCore ruleset and reverted it to the standard one. Then fired up FG, loaded a MoreCore campaign with only the modified MCSotDL extension loaded. This is where I get the unexpected (to me anyway) results. If I have the bane script listed first in the extension.xml then the /bane uses the roll from MoreCore ruleset but the /boon from my extension. If I have the boon script listed first in the extension/xml the opposite is true. I can't work out why this is happening.

22619

damned
March 11th, 2018, 21:55
1) The easiest way for MoreCore to handle this would be to have a different roll setup, or maybe a flag in the same roll. Either way, it will require the roll handler to be setup to handle it, and the relevant roll added to the character sheet. You'd end up with two separate rolls - one with karma and one without it.
2) Nope. The modifier box only takes numbers. You could maybe look at applying a "KARMA" effect to a character for one roll, then look for that effect in the dice roller.

I believe it would be two rolls.
However why dont you use the Shadowrun ruleset instead?

While you cant have a Text label Modifier manipulate the Roll Functionality MoreCore does retain the Name of the /mod roll being used and uses it in the description. So you can have Karma appear in the roll description from a /mod 0 but it wont mechanically alter anything but the Chat Message.

SammyWest
March 11th, 2018, 21:57
Rand() is the easiest function you can use lol.

Trenloe
March 11th, 2018, 22:21
Rand() is the easiest function you can use lol.
LOL. If you're using not using LUA, maybe... and also not coding a FG action - there's much more to it that just a random number. ;)

damned
March 12th, 2018, 05:22
Well I have hit a very confusing situation. After playing with the MoreCore Ruleset to mess around with the custom /bane and /boon rolls I achieved partially what I was trying to achieve. I wanted to make the banes show up with red negative dice in the chat and the boons to show up with green. I was able to get this to work.

At this point I decide to move those changes to the SotDL MoreCore extension. I added the custom dice to the gameelements.xml. I added the proper icons in the graphics folders and defined them in the graphics_icons.xml. I copied my modified manager_custom_bane and boon scripts to the scripts folder and added them to the extension.xml.

I deleted the modified MoreCore ruleset and reverted it to the standard one. Then fired up FG, loaded a MoreCore campaign with only the modified MCSotDL extension loaded. This is where I get the unexpected (to me anyway) results. If I have the bane script listed first in the extension.xml then the /bane uses the roll from MoreCore ruleset but the /boon from my extension. If I have the boon script listed first in the extension/xml the opposite is true. I can't work out why this is happening.

22619

I havent time to peek just now.
Typically I would register a new roll - all the steps were posted a page or two back.
call them /bboons or /bbs or /bb or /bsbs or whatever and register the new roll in your extension.

mozmonar
March 12th, 2018, 05:33
I havent time to peek just now.
Typically I would register a new roll - all the steps were posted a page or two back.
call them /bboons or /bbs or /bb or /bsbs or whatever and register the new roll in your extension.
I had considered that. But I avoided it because I already have so many PCs and NPCs with multiple /bane and /boon rolls linked on them and I was trying to avoid having to go change them all.

If I can't work out what the issue is I will probably just unpack the MoreCore and replace the rolls there since I know they worked there. I know that it will overwrite if/when a new version is released. I have more work to do on it still.

damned
March 12th, 2018, 05:55
You have three scripts with the same name - DesktopManagerSotDL

<script name="DesktopManagerSotDL" file="scripts/data_library_com.lua" />
<script name="DesktopManagerSotDL" file="scripts/manager_custom_boon.lua" />
<script name="DesktopManagerSotDL" file="scripts/manager_custom_bane.lua" />

They all need unique names.

<script name="DesktopManagerSotDL" file="scripts/data_library_com.lua" />
<script name="CustomDiceBoon" file="scripts/manager_custom_boon.lua" />
<script name="CustomDiceBane" file="scripts/manager_custom_bane.lua" />

mozmonar
March 12th, 2018, 05:58
That makes sense. So the last one listed is the only one to execute. Cut and paste you are a fickle friend!

p.s. Thank you :)

mozmonar
March 13th, 2018, 06:47
Thanks again damned
After changing the script name it worked perfectly. The banes show red negative dice, the boons show green positive. I slightly altered the text string as well. Appreciate you holding my hand through my awkward fumblings through the xml and Lua stuff.