PDA

View Full Version : Custom action - using the modifier stack to adjust difficulty?



meguido
March 31st, 2020, 10:28
Hello,
I created in ext to CoreRPG Vermine RPG

I want add difficulty to modifier in the Box Modifier

exp : Add +1 in box modifier add +1 to difficulty (base Difficulty 5 +1 = 6) wiew image

32837

Manager_action_ability
--
-- Please see the license.html file included with this distribution for
-- attribution and copyright information.
--

function onInit()
CustomDiceManager.add_roll_type("vermine", performAction, onLanded, true, "all");
end

function getDieMax(sType)
Debug.console("getDieMax: ", sType);
local sDie = string.match(sType, "d(%d+)");
if tonumber(sDie) > 1000 then
tempmax = tonumber(sDie);
while tempmax > 20 do
tempmax = tempmax - 1000;
end
else tempmax = tonumber(sDie);
end
max = tempmax;
return max;
end

function performRoll(draginfo, rActor, nSkillLev, sAbilityStat, bSecretRoll)
local rRoll = { };
rRoll.sType = "vermine";
rRoll.aDice = { };
rRoll.nMod = 0;
rRoll.nSkillLev = nSkillLev;
rRoll.sDesc = "";
rRoll.sDesc = rRoll.sDesc .. " " .. StringManager.capitalize(sAbilityStat);
local count = nSkillLev;
Debug.console("count:", count);

while count > 0 do
table.insert(rRoll.aDice, "d10");
count = count - 1;

end
rRoll.bSecret = bSecretRoll;
ActionsManager.performAction(draginfo, rActor, rRoll);
end

function initLastDice(aDice)
aSavedDice = {};
for i , v in ipairs (aDice) do
aSavedDice[i] = { type=v.type, result=0, exploded=true };
end
return aSavedDice;
end

function onLanded(rSource, rTarget, rRoll, nSkillLev)
Debug.console("onLanded: ", rSource, rTarget, rRoll);

if not nSuccesses then nSuccesses = 0;
end
if not nFails then nFails = 0;
end

local nSuccessLevel = 5;
rRoll.nSuccessLevel = nSuccessLevel;

for i , v in ipairs (rRoll.aDice) do
if rRoll.aDice[i].result == 10 then
nSuccesses = nSuccesses + 1;
elseif rRoll.aDice[i].result >= nSuccessLevel then
nSuccesses = nSuccesses + 1;
elseif rRoll.aDice[i].result < nSuccessLevel then
nFails = nFails + 1;
end
end


rRoll.nFails = nFails;
rRoll.nSuccesses = nSuccesses;
Debug.console("nSuccesses1: ", nSuccesses, " nFails1: ", nFails, "nSuccessLevel1:", nSuccessLevel);

local rMessage = ActionsManager.createActionMessage(rSource, rRoll);

rMessage = createChatMessage(rSource, rRoll, sDesc1);
rMessage.type = "dice";
rMessage.text = rMessage.text .. "\nDiff = ".. rRoll.nSuccessLevel;
rMessage.text = rMessage.text .. "\nSucces: " .. rRoll.nSuccesses;
if nSuccesses == 0 then
rMessage.text = rMessage.text .. "\n[Echec]";
end
Comm.deliverChatMessage(rMessage);

nSuccesses = nil;
nFails = nil;
end

function createChatMessage(rSource, rRoll)
local rMessage = ActionsManager.createActionMessage(rSource, rRoll);
rMessage.dicedisplay = 0;


return rMessage;
end

Attribute
exp
<number_charabilityscore name="vigueur" source="stats.vigueur.core">
<anchored to="vig" position="insidetopleft" offset="9,6" height="20" width="20" />
<script>
function action(draginfo)
local nodeWin = window.getDatabaseNode();
if nodeWin then
local rActor = ActorManager.getActor("pc", nodeWin.getChild("..."));
local nAttribLev = getValue();
nAttribLev = nAttribLev + (DB.getValue(nodeWin, "stats." .. self.target[1] .. ".mod", 0));
ActionAbility.performRoll(draginfo, rActor, nAttribLev, self.target[1]);
end
end

function onDragStart(button, x, y, draginfo)
return action(draginfo);
end

function onDoubleClick(x,y)
return action();
end
</script>
<target>vigueur</target>
</number_charabilityscore>

Trenloe
March 31st, 2020, 11:29
I've moved this to a new thread.

Essentially you need to change the nSuccessLevel in the onLanded function to be adjusted by the value of the modifier stack.

The function ModifierStack.getSum() will return the current total in the modifier stack. So you can use this to adjust the nSuccessLevel value.

There are other functions available in the ModifierStack script package - such as Reset() which can be used to clear the modifier stack after making a roll. See the various functions available in desktop\scripts\modifierstack.lua