PDA

View Full Version : Remove a die before rolling? [Ruleset Wizard]



AlkarGreener
January 1st, 2021, 12:18
I need to remove a die before rolling, e.g. the field says '3' so 2 dice need to be rolled. I have been going nuts trying to get the right string.

Trenloe
January 1st, 2021, 12:21
A bit more info to allow us to try to help you.

What ruleset are you changing?
Where in the action process are you wanting to make this change? Information on the action process here: https://www.fantasygrounds.com/forums/showthread.php?35531-Coding-dice-rolls-(actions)-in-CoreRPG
Are all of the dice already there in a LUA table and you just want to remove one of them?

AlkarGreener
January 1st, 2021, 12:25
I am creating a custom ruleset based on CoreRPG using Ruleset Wizard.
No action process; just trying to deliver a generic roll.
No idea how to create a LUA table.

I have a number field. I need to roll one die less than the value of that number field.

After doing that I add a single die that reports success on 6 and failure on 1. The requirement is only one of the dice rolled can report a success or failure.

Trenloe
January 1st, 2021, 12:28
How far have you got in creating the roll action?

Trenloe
January 1st, 2021, 12:33
To clarify - what you want to do requires a custom "action" within Fantasy Grounds. You aren't just doing a generic roll - because you're changing the initial dice to roll and also you want to add the additional die.

So, you need a custom action. The thread I linked above goes through that in details. However, if you're not that familiar with programming and LUA, you may want to look into the MoreCore ruleset which is specifically created to make it easier to create custom rolls (actions). MoreCore can be found here: https://www.fantasygrounds.com/forums/showthread.php?34860-MoreCore-Ruleset

AlkarGreener
January 1st, 2021, 12:33
I don't have to create in using Ruleset Wizard; just enter the dice roll string.

{dexterity_number}d6+d6!1s6f1+{dexterity_modifier}

{dexterity_number}d6 = the total number of dice
d6!1s6f1 = the die that needs to replace one of the total (wild die)
{dexterity_modifier} = the modifer


For testing,
{dexterity_number} = 3
{dexterity_modifier} = 2

I need a total of 3d6
2 are normal
1 is the wild die


I can't get the correct syntax for {dexterity_number} - 1.

Trenloe
January 1st, 2021, 12:35
Ah, OK, you're using the Ruleset Wizard. Sorry, I missed that in your subsequent post. I'll let someone with more knowledge of ruleset wizard try to assist you.

AlkarGreener
January 1st, 2021, 12:35
As an initial test, I wrote this script. It rolls only the wild die.


--[[
Star Wars Open D6 Wild Die
Mykl Sandusky
based on https://www.fantasygrounds.com/forums/showthread.php?35531-Coding-dice-rolls-(actions)-in-CoreRPG
last modified: 22 Dec 2020
]]

function onInit() -- // runs when campaign loads
GameSystem.actions["wilddie"] = { bUseModStack = false }; -- define action
ActionsManager.registerResultHandler("wildie", onRoll); -- register action & returned result
Comm.registerSlashHandler("wilddie", processRoll); -- register chat command & function it calls
end

function onHover() -- // when hovering, use the hand cursor
setHoverCursor("hand");
end

function onButtonPress() -- // when a button is pressed
processRoll(sCommand, sParams); -- call processRoll
end

--[[ too easy to roll multiple times when drag is enabled; commenting out for for now, 26 Dec 2020, Mykl Sandusky
function onDragStart(target, button, x, y, dragdata) -- // when the drag starts
end

function onDragEnd(target, dragdata) -- // when the drag ends
processRoll(sCommand, sParams); -- call processRoll
end
]]

function processRoll(sCommand, sParams) -- // initial function
performRoll(draginfo, rActor, bSecretRoll); -- call performRoll
end

function performRoll(draginfo, rActor, bSecretRoll) -- // roll the die
local rRoll = getRoll(rActor, bSecretRoll); -- obtains roll properties from getRoll
ActionsManager.performAction(draginfo, rActor, rRoll); -- rolls the dice
end

function getRoll(rActor, bSecretRoll) -- // define roll properties
local rRoll = {}; -- initialise a blank rRoll record
rRoll.sType = "wildie";
rRoll.aDice = { "d6" };
rRoll.nMod = 0;
rRoll.sDesc = "Wild Die!";
rRoll.bSecret = bSecretRoll; -- for GM secret rolls
return rRoll;
end

function onRoll(rSource, rTarget, rRoll) -- // return the results
local rMessage = ActionsManager.createActionMessage(rSource, rRoll); -- define message to return
local nTotal = ActionsManager.total(rRoll); -- define the total of the roll
if nTotal == 1 then
rMessage.text = rMessage.text .. "[A ONE WAS ROLLED]"; -- report if a 1 is rolled in the message to return
end
if nTotal == 6 then
rMessage.text = rMessage.text .. "[A SIX WAS ROLLED] Rolling another die.";-- report is a 6 was rolled in the message to return
processRoll(); -- roll the wild die again
end
Comm.deliverChatMessage(rMessage); -- deliver message to chat
return math.ceil(nTotal); -- return the die value
end

Trenloe
January 1st, 2021, 12:38
As an initial test, I wrote this script. It rolls only the wild die.


--[[
Star Wars Open D6 Wild Die
Mykl Sandusky
based on https://www.fantasygrounds.com/forums/showthread.php?35531-Coding-dice-rolls-(actions)-in-CoreRPG
last modified: 22 Dec 2020
]]

function onInit() -- // runs when campaign loads
GameSystem.actions["wilddie"] = { bUseModStack = false }; -- define action
ActionsManager.registerResultHandler("wildie", onRoll); -- register action & returned result
Comm.registerSlashHandler("wilddie", processRoll); -- register chat command & function it calls
end
...
...
Yeah, that's a custom action - called "wilddie".

AlkarGreener
January 1st, 2021, 12:48
It is killing that n-1 doesn't work.

I have this function that set r as the correct value, but can't make the dice roll string use rd6

function onButtonPress()
n = window.dexterity_number.getValue();
r = n-1;
end

I posted before creating a hidden field and settings it's value to r, then using that field in the dice roll string rather than the original. Wish me luck on that method.

damned
January 1st, 2021, 12:51
A few things -
wildie is not the same as wilddie
i dont think this string /die 1d6!1s6f1 does what you think it does
dont you just want /die 1d6!s6f1 but even then are you counting successes or total of all dice including explosions?
in which case /die 1d6! covers the wild die

now you can do simple math in the new die rollers like:
/die (3-1)d6!
so /die ({dexterity_number}-1)d6! in theory should work however there is some glitch there in the RW and despite it reporting (eg) /die 2d6! it doesnt work
so you could create a hidden field and on the hidden field set the value to ({dexterity_number}-1) and then use /die {dexterity_number_hidden}d6!

Or you can go the route of writing a custom dice handler which is fine - but a little tricky with exploding dice

AlkarGreener
January 1st, 2021, 12:57
In the Star Wars OpenD6 / WEG system, the wild die is the only die requiring logic, so /die 1d6!1s6f1 is working well enough.

if a 1 is rolled, it highlights as a failure
if a 6 is rolled, it highlights as a success and rolls another die, continuing if another 6 is rolled.

My first attempt was to use (3-1)d6.... which reporting 2d6 but only rolled 1, just like the glitch you mentioned.

I am working on using the hidden field method now.

Thanks for the reply. I don't feel as stupid now.

Then I want to work on adding chat text when a success or failure occurs on the wild die. :)

damned
January 1st, 2021, 13:24
Ok so you do want to count Success and Failure as well as the Dice Total?
If so I would still drop the 1s6f1 part of the roll because FG will only report the Success or failure and not the Dice total which (I think?) is more important?
I would report the Success Fail result in the text.

Create the roll.
Roll the roll.
Count Fails
Count Successes
Count Total
Append Custom Messages
Write to chat

AlkarGreener
January 1st, 2021, 13:34
I need to report the dice total and if a 1 was rolled on the wild die. I had been using a failure to highlight it. With the hidden field it changes the math so I can't use it.

{nDexterity}d6+d6!+{dexterity_modifier}

Works except for reporting if a 1 is rolled only on the wild die 'd6!'. Since the die is highlighted in chat if a 6 is rolled, that is enough in that case. The challenge is when a 1 is roiled, the GM decides what the impact is. Right now, I can always use the last die in chat and see if it is a 1, but I would really like to highlight it somehow.

The script I wrote is for a wild die on the table, which is rolled by itself. The first thing I did was make sure everything can be rolled manually from the table. You would select the number of d6, manually subtracting 1, then roll the wild die & add the 2 rolls together. Since that uses a custom script, I could write to chat.

Now, I am trying to automate that in the character sheet. It appears I need a slightly modified version of the default script, eh?

I was really trying to avoid that, but it is what it is.

damned
January 1st, 2021, 14:22
Like this?

https://www.fantasygrounds.com/forums/attachment.php?attachmentid=42418

42418

AlkarGreener
January 1st, 2021, 14:23
Yes.

damned
January 1st, 2021, 14:32
So field one is:

dex_score it has the following Lua attached

function onValueChanged()

window.dex_hidden.setValue(window.dex_score.getVal ue() - 1);

end


field two is:

dex_mod

You could add code to dex_score to also set this value

field three is:

dex_hidden

and should be set to Invisible (True)

Button one is:

Default using Ruleset Wizard only and gives a partial result using the following settings:

Dice Roll string: 1d6!+{dex_hidden}r6+{dex_mod}
Roll Description Text: Dexterity [{dex_score}] Roll
Use Modifier Stack: (True)

Button two is:

My custom button which gives a descriptive result using the following settings:

Dice Roll string: 1d6!+{dex_hidden}r6+{dex_mod}
result handler Function: managerRoll.skillRoll
Roll Description Text: Dexterity [{dex_score}] Roll
Use Modifier Stack: (True)

managerRoll is a Script file with the following code:


function skillRoll(rSource, rTarget, rRoll)
-- Name the function and accept 3 parameters

local nSuccesses = 0;
-- Set nSuccesses variable - we will track Successes here
local nFails = 0;
-- Set nSuccesses variable - we will track Successes here
local nTotal = 0;
-- Set nDice variable - we will count # dice here

local rMessage = ActionsManager.createActionMessage(rSource, rRoll);
-- initialise the message function

for k,v in ipairs(rRoll.aDice) do
-- Iterate through all dice rolled (explosions)
nTotal = nTotal + rRoll.aDice[k].result;

end

if rRoll.aDice[1].result >= 6 then
-- Test if the DICE is a 6
nSuccesses = 1;
-- increment success count by 1
rMessage.text = rMessage.text .. "\n[Successes] " .. nSuccesses .. "\n[Total] " .. nTotal;
elseif rRoll.aDice[1].result == 1 then
-- Test if the DICE is a 1
nFails = 1;
-- increment success count by 1
rMessage.text = rMessage.text .. "\n[Fails] " .. nFails .. "\n[Total] " .. nTotal;
else
rMessage.text = rMessage.text .. "\n[Total] " .. nTotal;
end

rMessage.dicedisplay = 1;
Comm.deliverChatMessage(rMessage);
-- Deliver message to Chat

end

AlkarGreener
January 1st, 2021, 14:36
Thanks. Entering it now.

AlkarGreener
January 1st, 2021, 14:45
Works like a charm. Thank you very much.

damned
January 1st, 2021, 15:01
So you should be able to take that example and expand on it
Auto generate the modifier value based on the attribute score
Most likely you will roll from the Skill rather than the Attribute but you can use the same techniques
Add a hidden field to the Skill that holds the derived number of dice and keep that field up to date with onValueChanged() on the Attribute Score and on the Skill Score
You might notice that my nTotal is incorrect - I havent included the dex_mod value so you should fix that AND I am not checking the Modifier Stack in my code either so you will also need to add that in

AlkarGreener
January 1st, 2021, 15:06
Gotcha. I did fix the dex mod value and just noted the modifier stack isn't add. I can get to that.

Appreciate for the direction.

In this game, the attribute is use for skills unless a specific skill was modified, so I will need to keep the ability to roll from the attribute there, but will use this technique for modified skills.