pr6i6e6st
July 15th, 2020, 19:17
hey guys! i've been working on something for 5e here for the past couple of weeks that is really coming together, and i believe the last thing i need is to be able to replace some things.
so i have a window. the window has 6 windowlists (traits, actions, reactions, legendary actions, lair actions, innate spells).
i have, through trial and error, found how to find and replace the attack bonus of an action that is built up in the action windowlist when i drop an npc on the window. problem is that it does this for the damage as well.
i ultimately want to try and achieve at least 3 things here, but just need a to understand what the pattern i need is and why that pattern works as it does.
1 - replace the attack bonus
2 - replace the damage bonus
3 - replace the DC stated in the text.
this is my parseComponents() function, largely taken from the npc_skills.lua from 5e. the "actionSource" is the "Action" list windowinstance that is created and is being edited by this function. the parseComponents() function is currently called upon by an onDrop() function that creates the windowinstance of the action and then calls on the parseComponents() function to edit after.
function parseComponents(actionSource)
aComponents = {};
if DB.getValue(getDatabaseNode(), "dexbasedattacks", 0) == 0 then
AttackBonus = tostring(proficiency.getValue() + DB.getValue(getDatabaseNode(), "abilities.strength.bonus", 0));
else
AttackBonus = tostring(proficiency.getValue() + DB.getValue(getDatabaseNode(), "abilities.dexterity.bonus", 0));
end
-- Get the comma-separated strings
local aClauses, aClauseStats = StringManager.split(DB.getValue(actionSource, "desc", ""), ",;\r", true);
Debug.console("parseComponents(), aClauses, aClauseStats", aClauses, aClauseStats);
-- Check each comma-separated string for a potential skill roll or auto-complete opportunity
for i = 1, #aClauses do
local nStarts, nEnds, sLabel, sSign, sMod = string.find(aClauses[i], "([%w%s\(\)]*[%w\(\)]+:)%s*([%+%-–]?)(%d*)");
Debug.console("parseComponents(), nStarts, nEnds, sLabel, sSign, sMod", nStarts, nEnds, sLabel, sSign, sMod);
if nStarts then
-- Calculate modifier based on mod value and sign value, if any
local nAllowRoll = 0;
local nMod = 0;
if sMod ~= "" then
local ReCheck = StringManager.multireplace(DB.getValue(actionSourc e, "desc", ""), sMod, AttackBonus);
DB.setValue(actionSource, "desc", "string", ReCheck);
Debug.console("ReCheck", ReCheck);
nAllowRoll = 1;
nMod = tonumber(sMod) or 0;
if sSign == "-" or sSign == "–" then
nMod = 0 - nMod;
end
end
-- Insert the possible skill into the skill list
table.insert(aComponents, {nStart = aClauseStats[i].startpos, nLabelEnd = aClauseStats[i].startpos + nEnds, nEnd = aClauseStats[i].endpos, sLabel = sLabel, nMod = nMod, nAllowRoll = nAllowRoll });
end
end
bParsed = true;
end
thanks in advance for any explanations, elaboratons, assistance or suggestions. You're always a magnificent help.
so i have a window. the window has 6 windowlists (traits, actions, reactions, legendary actions, lair actions, innate spells).
i have, through trial and error, found how to find and replace the attack bonus of an action that is built up in the action windowlist when i drop an npc on the window. problem is that it does this for the damage as well.
i ultimately want to try and achieve at least 3 things here, but just need a to understand what the pattern i need is and why that pattern works as it does.
1 - replace the attack bonus
2 - replace the damage bonus
3 - replace the DC stated in the text.
this is my parseComponents() function, largely taken from the npc_skills.lua from 5e. the "actionSource" is the "Action" list windowinstance that is created and is being edited by this function. the parseComponents() function is currently called upon by an onDrop() function that creates the windowinstance of the action and then calls on the parseComponents() function to edit after.
function parseComponents(actionSource)
aComponents = {};
if DB.getValue(getDatabaseNode(), "dexbasedattacks", 0) == 0 then
AttackBonus = tostring(proficiency.getValue() + DB.getValue(getDatabaseNode(), "abilities.strength.bonus", 0));
else
AttackBonus = tostring(proficiency.getValue() + DB.getValue(getDatabaseNode(), "abilities.dexterity.bonus", 0));
end
-- Get the comma-separated strings
local aClauses, aClauseStats = StringManager.split(DB.getValue(actionSource, "desc", ""), ",;\r", true);
Debug.console("parseComponents(), aClauses, aClauseStats", aClauses, aClauseStats);
-- Check each comma-separated string for a potential skill roll or auto-complete opportunity
for i = 1, #aClauses do
local nStarts, nEnds, sLabel, sSign, sMod = string.find(aClauses[i], "([%w%s\(\)]*[%w\(\)]+:)%s*([%+%-–]?)(%d*)");
Debug.console("parseComponents(), nStarts, nEnds, sLabel, sSign, sMod", nStarts, nEnds, sLabel, sSign, sMod);
if nStarts then
-- Calculate modifier based on mod value and sign value, if any
local nAllowRoll = 0;
local nMod = 0;
if sMod ~= "" then
local ReCheck = StringManager.multireplace(DB.getValue(actionSourc e, "desc", ""), sMod, AttackBonus);
DB.setValue(actionSource, "desc", "string", ReCheck);
Debug.console("ReCheck", ReCheck);
nAllowRoll = 1;
nMod = tonumber(sMod) or 0;
if sSign == "-" or sSign == "–" then
nMod = 0 - nMod;
end
end
-- Insert the possible skill into the skill list
table.insert(aComponents, {nStart = aClauseStats[i].startpos, nLabelEnd = aClauseStats[i].startpos + nEnds, nEnd = aClauseStats[i].endpos, sLabel = sLabel, nMod = nMod, nAllowRoll = nAllowRoll });
end
end
bParsed = true;
end
thanks in advance for any explanations, elaboratons, assistance or suggestions. You're always a magnificent help.