PDA

View Full Version : [5E] Critical Damage modification



Maspalio
September 17th, 2021, 15:22
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


-- 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

LordEntrails
September 17th, 2021, 23:53
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

Maspalio
September 18th, 2021, 11:34
Thanks a lot LordEntrails, i'll have a look at it.