5E Character Create Playlist
Page 11 of 12 First ... 9101112 Last
  1. #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.

  2. #102
    Thanks. I had considered looking at this part of rRoll.

    Will investigate further and see what I can sort out.

  3. #103
    Quote Originally Posted by Brotherkelly View Post
    Thanks. I had considered looking at this part of rRoll.

    Will investigate further and see what I can sort out.
    I’ll take a look later this weekend too— but if you figure out how to fix the solution I have, would love to know how!

  4. #104
    Quote Originally Posted by Brotherkelly View Post
    Thanks. I had considered looking at this part of rRoll.

    Will investigate further and see what I can sort out.
    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

  5. #105
    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.

  6. #106
    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..

  7. #107
    Quote Originally Posted by Brotherkelly View Post
    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..
    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.

  8. #108
    Thanks for the additional advice . I will look at this during the coming week and report back on the outcome.

  9. #109
    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.

  10. #110
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
DICE PACKS BUNDLE

Log in

Log in