FG Spreadshirt Swag
  1. #1

    [5E] Critical Damage modification

    Hello,

    I need some help modifying the critical damage system for 5E.

    Currently, if i'm correct when you roll a critical attack, damage is doubled.

    What should i change in the code below to roll a D10 in addition of the normal damage die, instead of double the damage die ? i.e. : critical hit with a sword is (d8) x2. I'd like to have (d8) + (d10).

    Thanks for your help

    Code:
    -- Add critical dice by clause
    	for kClause,vClause in ipairs(rRoll.clauses) do
    		local bApplyCritToClause = true;
    		local aSplitByDmgType = StringManager.split(vClause.dmgtype, ",", true);
    		for _,vDmgType in ipairs(aSplitByDmgType) do
    			if vDmgType == "critical" then
    				bApplyCritToClause = false;
    				break;
    			end
    		end
    		
    		if bApplyCritToClause then
    			local bNewMax = false;
    			local aCritClauseDice = {};
    			local aCritClauseReroll = {};
    			for kDie,vDie in ipairs(vClause.dice) do
    				if vDie:sub(1,1) == "-" then
    					table.insert(aNewDice, "-g" .. vDie:sub(3));
    				else
    					table.insert(aNewDice, "g" .. vDie:sub(2));
    				end
    				table.insert(aCritClauseDice, vDie);
    				if vClause.reroll then
    					table.insert(aCritClauseReroll, vClause.reroll[kDie]);
    				end
    				
    				if kClause <= rRoll.nOrigClauses and vDie:sub(1,1) ~= "-" then
    					local nDieSides = tonumber(vDie:sub(2)) or 0;
    					if nDieSides > nMaxSides then
    						bNewMax = true;
    						nMaxSides = nDieSides;
    					end
    				end
    			end
    
    			if #aCritClauseDice > 0 then
    				local rNewClause = { dice = {}, reroll = {}, modifier = 0, stat = "", bCritical = true };
    				if vClause.dmgtype == "" then
    					rNewClause.dmgtype = "critical";
    				else
    					rNewClause.dmgtype = vClause.dmgtype .. ",critical";
    				end
    				for kDie, vDie in ipairs(aCritClauseDice) do
    					table.insert(rNewClause.dice, vDie);
    					table.insert(rNewClause.reroll, aCritClauseReroll[kDie]);
    				end
    				table.insert(aNewClauses, rNewClause);
    				
    				if bNewMax then
    					nMaxClause = #aNewClauses;
    					nMaxDieIndex = #aNewDice + 1;
    				end
    			end
    		end
    	end
    	if nMaxSides > 0 then
    		local nCritDice = 0;
    		if rRoll.bWeapon then
    			local sSourceNodeType, nodeSource = ActorManager.getTypeAndNode(rSource);
    			if nodeSource and (sSourceNodeType == "pc") then
    				if rRoll.range == "R" then
    					nCritDice = DB.getValue(nodeSource, "weapon.critdicebonus.ranged", 0);
    				else
    					nCritDice = DB.getValue(nodeSource, "weapon.critdicebonus.melee", 0);
    				end
    			end
    		end
    		
    		if nCritDice > 0 then
    			for i = 1, nCritDice do
    				table.insert(aNewDice, nMaxDieIndex, "g" .. nMaxSides);
    				table.insert(aNewClauses[nMaxClause].dice, "d" .. nMaxSides);
    				if aNewClauses[nMaxClause].reroll then
    					table.insert(aNewClauses[nMaxClause].reroll, aNewClauses[nMaxClause].reroll[1]);
    				end
    			end
    		end
    	end
    	local aFinalClauses = {};
    	for _,vClause in ipairs(aNewClauses) do
    		table.insert(rRoll.clauses, vClause);
    	end
    	rRoll.aDice = aNewDice;
    end

  2. #2
    LordEntrails's Avatar
    Join Date
    May 2015
    Location
    -7 UTC
    Posts
    17,147
    Blog Entries
    9
    You might want to look at this extension, it changes crit behavior in different ways than what you are looking to do, but might provide some insight.
    https://forge.fantasygrounds.com/shop/items/115/view

    Problems? See; How to Report Issues, Bugs & Problems
    On Licensing & Distributing Community Content
    Community Contributions: Gemstones, 5E Quick Ref Decal, Adventure Module Creation, Dungeon Trinkets, Balance Disturbed, Dungeon Room Descriptions
    Note, I am not a SmiteWorks employee or representative, I'm just a user like you.

  3. #3
    Thanks a lot LordEntrails, i'll have a look at it.

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