Starfinder Playlist
  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
    14,533
    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

  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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Product Walkthrough Playlist

Log in

Log in