PDA

View Full Version : Table Roll Modifiers within the Code



Brotherkelly
February 17th, 2021, 18:37
Hi All, I would like to know if it is possible to add modifiers in the LUA code when rolling on a Table. The attached table is a good example where 2d6 are rolled and it could have a 0, +1 or +2 modifier depending on the targets motive type. I know I can use the modifier box in the main desktop to add this number but can it be done within the code to automate the process. The current section of code that calls the table to be rolled on is:

TableManager.processTableRoll("", "Vehicle Motive Systems Damage");

I have started to look at the Manager_table.lua code (from CoreRPG Ruleset copied into my own extension) but cannot see what could be done, if anything.

Any help would be greatly appreciated.

superteddy57
February 17th, 2021, 19:04
Sure, but it would need to be coded and made into an extension. In this case after the table is rolled, you would have to parse out the text and then send it to the modifier box. This is a simplified description of the process, but that is how I would do it.

Brotherkelly
February 18th, 2021, 08:02
Sure, but it would need to be coded and made into an extension. In this case after the table is rolled, you would have to parse out the text and then send it to the modifier box. This is a simplified description of the process, but that is how I would do it.

Thanks. I will see what I can do but may well come back for some more advice.

Brotherkelly
March 4th, 2021, 08:15
It seems you modification I needed was fairly straightforward.

I have copied the manager_table.lua file from the CoreRPG ruleset and renamed it to manager_table2.lua. Then it was a case of modifying the processTableRoll function to add a third parameter - nRollMod. See below for the changes (highlighted in Bold):

function processTableRoll(sCommand, sParams, nRollMod)
-- nRollMod used to allow external modifier to be used from within certain attack/damage rolls

local aTableName = {};
local aColumnName = {};
local aDiceString = {};
local bHide = false;
local bError = false;

local aWords = StringManager.parseWords(sParams, "%(%)%[%]:");
local sFlag = "";
for k = 1, #aWords do
if aWords[k] == "-c" or aWords[k] == "-d" then
sFlag = aWords[k];
elseif aWords[k] == "-hide" then
sFlag = aWords[k];
bHide = true;
elseif aWords[k]:sub(1,1) == "-" then
bError = true;
break;
else
if sFlag == "" then
table.insert(aTableName, aWords[k]);
elseif sFlag == "-c" then
table.insert(aColumnName, aWords[k]);
elseif sFlag == "-d" then
table.insert(aDiceString, aWords[k]);
elseif sFlag == "-hide" then
bError = true;
break;
end
end
end

local sTable = table.concat(aTableName, " ");
if bError or not sTable or sTable == "" then
ChatManager.SystemMessage("Usage: /rollon tablename -c [column name] [-d dice] [-hide]");
return;
end
local nodeTable = findTable(sTable);
if not nodeTable then
ChatManager.SystemMessage(Interface.getString("table_error_lookupfail") .. " (" .. sTable .. ")");
return;
end

local rTableRoll = {};
rTableRoll.nodeTable = nodeTable;
if bHide then
rTableRoll.bSecret = true;
end
rTableRoll.nColumn = findColumn(nodeTable, table.concat(aColumnName, " "));
if #aDiceString > 0 then
local sDice = table.concat(aDiceString, "");
rTableRoll.aDice, rTableRoll.nMod = StringManager.convertStringToDice(sDice);
else
rTableRoll.aDice, rTableRoll.nMod = getTableDice(nodeTable);
end

-- Addition of nRollMod. Roll code driven modifier.
rTableRoll.nMod = rTableRoll.nMod + nRollMod;
performRoll(nil, nil, rTableRoll, false);
end

So if you need to parse a modifier to a table when it is rolled you would now use the following command:

TableManager2.processTableRoll("", "Table Name", Modifier);

Where TableName is the name of the table you are calling and Modifier is the number applied to the roll within the table. This can either be a variable defined in your code or a fixed value.

Here are a couple of examples I use:

-- Vehicle Motive System Critical
if sMotiveType ~= nil then
if sMotiveType == "v" then
nMotiveMod = 2;
elseif sMotiveType == "h" or sMotiveType == "w" then
nMotiveMod = 1;
else
nMotiveMod = 0;
end

TableManager2.processTableRoll("", "Vehicle Motive Systems Damage", nMotiveMod);
end

-- Structure Critical hit check
-- Debug.chat("Structure = ",ArmourTxValue);
if ArmourTxValue > 0 then
TableManager2.processTableRoll("", "Mech Attack Critical", 0);
end


The second use of TableManager2 could actually use the Core TableManager call as the modifier is set to 0.

If you find any issue with this then let me know.