-
March 31st, 2022, 08:12 #101
The value of the rolled dice is stored per dice in rRoll.aDice. Run a "Debug.chat(rRoll.aDice)" to see how it is set up. There is also a variable "Result" per dice. If I remember correctly, "Result" is what the dice shows and "Value" what is used for calculation. If you have a system where - say - 1 is replaced by an icon, "Result" could be "1" and "Value" something else.
Last edited by Mephisto; March 31st, 2022 at 16:59.
-
March 31st, 2022, 16:47 #102
- Join Date
- Dec 2018
- Location
- England, UK
- Posts
- 198
Thanks. I had considered looking at this part of rRoll.
Will investigate further and see what I can sort out.
-
March 31st, 2022, 17:04 #103
- Join Date
- Jun 2020
- Posts
- 536
-
April 3rd, 2022, 23:48 #104
- Join Date
- Jun 2020
- Posts
- 536
As promised, I have a much better result handler for you now. (See below code.) You can ignore my TODO statement in there (I still have work to do w/r/t combat automation where I'll be editing this further.) Essentially I am turning the resolver into some thing like a recursive function where it repeats the roll on a 10 or 1, and then adds the previous roll to a field in the next roll called "previousRoll" and setting the description so I know in the next calling of the function that it is a crit. Then, if it's a crit, we know not to do it again, and to alter the resulting dice table with the red / green indicators (and make it negative for the crit fails.)
This seems to work quite well for me now with both rolls happening first then the result showing, so I hope it works for you as well! Oh and feel free to format the description however you like.
Code:function resolveAbility(rSource, rTarget, rRoll) local rollResult = 0; local dicetable = rRoll.aDice; local desc = rRoll.sDesc; -- Skill / Ability rolls start with a single d10 if dicetable and dicetable[1].type == "d10" then rollResult = dicetable[1].result; end if rollResult == 10 and not string.match(desc, "CRITICAL") then -- Explode once local rExplodeRoll = { sType = rRoll.sType, sDesc = "[" .. desc .. "][CRITICAL SUCCESS]", aDice = {expr = "1d10" }, nMod = rRoll.nMod, nTarget = rRoll.nTarget }; rExplodeRoll.previousRoll = rollResult; return ActionsManager.performAction(nil, rSource, rExplodeRoll); elseif rollResult == 1 and not string.match(desc, "CRITICAL") then local rExplodeRoll = { sType = rRoll.sType, sDesc = "[" .. desc .. "][CRITICAL FAILURE]", aDice = {expr = "1d10" }, nMod = rRoll.nMod, nTarget = rRoll.nTarget }; rExplodeRoll.previousRoll = rollResult; return ActionsManager.performAction(nil, rSource, rExplodeRoll); end -- Check if we had a Crit Success or Failure local isCrit = false; if string.match(desc, "CRITICAL SUCCESS") then isCrit = true; -- Add the current roll to the previous and make it green rRoll.aDice = { {type = "d10", result = rRoll.previousRoll}, {type = "g10", result = rRoll.aDice[1].result}, }; elseif string.match(desc, "CRITICAL FAILURE") then isCrit = true; -- Subtract the current roll from the previous and make it red rRoll.aDice = { {type = "d10", result = rRoll.previousRoll}, {type = "r10", result = rRoll.aDice[1].result * -1}, }; end local rMessage = ActionsManager.createActionMessage(rSource, rRoll); local playerName = ActorManager.getDisplayName(rSource); -- TODO Display HIT or MISS for "attack" if not isCrit then rMessage.text = "[".. desc .. "]"; end if rRoll.sType == "attack" then rMessage.text = "[ATTACK]".. rMessage.text; end Comm.deliverChatMessage(rMessage); end
-
April 5th, 2022, 07:44 #105
- Join Date
- Dec 2018
- Location
- England, UK
- Posts
- 198
Hi Seansps,
Many thanks for this. I had also been looking at using ActionsManager.performAction routine but couldn't get the parameters right to feed into it. I will go through this in more detail over the next few days and see if it works for my application.
-
April 8th, 2022, 10:41 #106
- Join Date
- Dec 2018
- Location
- England, UK
- Posts
- 198
The code works a treat for a single d6 exploding dice when 2d6 roll max value (12).
I am now going to see how I can get it to roll additional d6's when the exploding d6 rolls a 6. This may take a while.
Example - initial roll us 12, first exploding d6 is a 6, second exploding d6 is also a 6, third exploding d6 is a 4. Giving a total roll of 28..
-
April 8th, 2022, 13:40 #107
- Join Date
- Jun 2020
- Posts
- 536
I see, yours need to keep going! It’s easily done. In rRoll add a field like “isExplode = 1” and do that whenever you need it to explode. Then check that instead of the description like I am doing, and return when doing the perform action. Because you have multiple explosions, you’ll also want to keep track of each die roll in an array instead of what I’m doing (previousDieRoll.) Then, if it is not exploding, you would check that array and add all those die to the current dice table.
Edit: Or really, just keep checking if any dice is a 6, and roll again for those. You’ll have to keep track of the other dice in a var on rRoll, though, so you can display the final message.Last edited by seansps; April 8th, 2022 at 13:43.
-
April 9th, 2022, 21:52 #108
- Join Date
- Dec 2018
- Location
- England, UK
- Posts
- 198
Thanks for the additional advice . I will look at this during the coming week and report back on the outcome.
-
April 21st, 2022, 07:44 #109
- Join Date
- Dec 2018
- Location
- England, UK
- Posts
- 198
Well I have worked out a solution but it is not pretty. The code used is below:
function AttributeCheck(rSource, rTarget, rRoll)
local nRollResult = 0;
local dicetable = rRoll.aDice;
local nFirstResult = 0;
local nSecondResult = 0;
local sDescription = rRoll.sDesc;
local nExplode = tonumber(rRoll.nExplode);
-- Debug.chat("initial",rRoll,nExplode);
if nExplode == 1 then
nFirstResult = dicetable[1].result;
nSecondResult = dicetable[2].result;
nRollResult = nFirstResult + nSecondResult;
else
nRollResult = tonumber(rRoll.previousRoll);
end
-- Debug.chat("Initial Roll Result",dicetable,nRollResult);
if nRollResult == 12 and tonumber(rRoll.nExplode) == 1 then
local rExplodeRoll = {
sType = rRoll.sType,
sDesc = sDescription,
aDice = {expr = "1d6"},
nMod = rRoll.nMod,
nTarget = rRoll.nTarget,
nBonuses = rRoll.nBonuses,
TN = rRoll.TN,
};
rExplodeRoll.previousRoll = nRollResult;
rExplodeRoll.ReRoll = tonumber(rRoll.ReRoll) + 1;
-- Debug.chat("Previous Roll",rRoll,rExplodeRoll);
return ActionsManager.performAction(nil, rSource, rExplodeRoll);
end
-- Debug.chat("Roll Check",nRollResult,rRoll.aDice[1].result);
repeat
if nRollResult > 11 and rRoll.aDice[1].result == 6 and tonumber(rRoll.previousRoll) < 24 then
rRoll.nExplode = 1;
local rExplodeRoll = {
sType = rRoll.sType,
sDesc = sDescription,
aDice = {expr = "1d6"},
nMod = rRoll.nMod,
nTarget = rRoll.nTarget,
nBonuses = rRoll.nBonuses,
TN = rRoll.TN,
};
rExplodeRoll.previousRoll = nRollResult + rRoll.aDice[1].result;
rExplodeRoll.ReRoll = tonumber(rRoll.ReRoll) + 1;
-- Debug.chat("Previous Roll",rRoll,rExplodeRoll);
return ActionsManager.performAction(nil, rSource, rExplodeRoll);
else
rRoll.nExplode = 0;
end
-- Debug.chat("explode check",rRoll,rExplodeRoll);
until rRoll.nExplode == 0;
local isCrit = false;
if nRollResult > 11 then
isCrit = true;
rRoll.aDice = {
{type = "d6", result = rRoll.previousRoll},
{type = "g6", result = rRoll.aDice[1].result},
};
-- Debug.chat("Dice Array",nReRoll,rRoll.aDice);
end
if nRollResult == 2 then
rRoll.aDice = {
{type = "r6", result = rRoll.aDice[1].result},
{type = "r6", result = rRoll.aDice[2].result},
};
end
local rMessage = ActionsManager.createActionMessage(rSource, rRoll);
if nRollResult > 11 then
rMessage.diemodifier = rRoll.nBonuses;
end
-- Debug.chat("Message",rMessage);
local nDiceRoll = ActionsManager.total(rRoll);
local nTotal = nDiceRoll + rRoll.nBonuses;
-- get the Dice Roll + Modifiers total
-- Debug.chat("Roll total",nDiceRoll,nTotal);
local nTargetNumber = tonumber(rRoll.TN);
-- Debug.chat(nTargetNumber);
if isCrit then
sSaveResult = "\n[CRITICAL SUCCESS]";
-- Append a Critical Success Message
-- update the roll result for a Critical Success (result - d6)
sMargin = "\nMargin of Success = " .. tostring(nTotal-nTargetNumber);
elseif nDiceRoll == 2 then
sSaveResult = "\n[FUMBLE]";
sMargin = "\nAutomatic Failure";
elseif nTotal >= nTargetNumber then
sSaveResult = "\n[SUCCESS]";
sMargin = "\nMargin of Success = " .. tostring(nTotal-nTargetNumber);
else
sSaveResult = "\n[FAILURE]";
sMargin = "\nMargin of Failure = " .. tostring(nTargetNumber-nTotal);
end
rMessage.text = rMessage.text .. sSaveResult .. sMargin;
Comm.deliverChatMessage(rMessage);
end
There are some values I have defined in the roll parameters - rRoll.TN, rRoll.nExplode & rRoll.ReRoll.
The code is set to allow a maximum of 3 exploding dice (as per the rules for BT:ATOW) allowing a max dice value of 30. The exploding 6's are added together and displayed as the first dice in the chat window. The final dice roll is displayed as the second dice.
I will continue to see if I can improve the code layout but for now I am working on the rest of the ruleset and character sheet layout.
-
April 21st, 2022, 13:55 #110
- Join Date
- Jun 2020
- Posts
- 536
Awesome! Hey, if it works it works. You can always go back later and refactor code. Glad I was able to help. There may be better ways to implement what we wanted but this style seemed to work for me too!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks