PDA

View Full Version : Setting the Duration of an Effect with a Die Roll



Saagael
February 7th, 2020, 01:15
I'm currently working on a custom ruleset and one thing I'd like to be able to do is have it so that when an effect is added to an actor on the CT, roll a die and have the duration of the effect set to the result of the die. I'm able to initiate the roll when the effect is added to the actor, but I'm having trouble getting the result to post back to the effect. Specifically, I am currently unable to get the effect's database node in the onRoll event of the dice action.

Here's some of the related functions I'm working with:


function onEffectAddStart(rEffect)
local sTimer = string.match(rEffect.sName, "TIMER:%s*(%S+)%s*");
if sTimer then
ActionTimer.performRoll(nil, nil, sTimer, rEffect, false);
end
end

function performRoll(draginfo, rActor, sDie, rEffect, bSecretRoll)
local rRoll = {};

rRoll.sType = "timer";
rRoll.aDice = { };
rRoll.sDesc = "[TIMER]";
rRoll.bSecret = bSecretRoll;

if rEffect then
rRoll.rEffect = rEffect;
end

rRoll.aDice, rRoll.nMod = StringManager.convertStringToDice(sDie)

ActionsManager.performAction(draginfo, rActor, rRoll);
end

function onRoll(rSource, rTarget, rRoll)
Debug.chat(rRoll.rEffect);
local rMessage = ActionsManager.createActionMessage(rSource, rRoll);
rMessage.icon = "action_timer";
Comm.deliverChatMessage(rMessage);
end



I know that I'll likely need to create an OOB message to handle actually setting the duration element, but I'm unable to even get the effect into the onRoll callback. Setting rActor as the effect didn't work. I haven't looked super deeply but I'm guessing there's a bunch of code in CoreRPG that's translating it and somewhere the effect gets dropped because it's not a pc or ct type.

I'm hoping there's some way of doing this, possibly used in another ruleset or extension I've not looked at. Otherwise I think that means I'd have to reimplement ActionManager.performAction to work with this. Is there some other function that might do this?

celestian
February 7th, 2020, 01:44
I do this in the AD&D 2e ruleset.

You can track what I do at getPowerRoll(rActor, nodeAction, sSubRoll). I also do it by level at getLevelBasedDurationValue(nodeAction). Both in scripts/manager_power.lua.

The bit of code is here in getPowerRoll()



-- roll dice for duration if exists --celestian
local nRollDuration = 0;
local dDurationDice = DB.getValue(nodeAction, "durdice");
local nModDice = DB.getValue(nodeAction, "durmod", 0);
local nDurationValue = PowerManager.getLevelBasedDurationValue(nodeAction );
if (nDurationValue > 0) then
nModDice = nModDice + nDurationValue;
end
if (dDurationDice and dDurationDice ~= "") then
nRollDuration = StringManager.evalDice(dDurationDice, nModDice);
else
nRollDuration = nModDice;
end



Crack open the ruleset and I'm sure you'll find what you need.

Trenloe
February 7th, 2020, 09:46
Specifically, I am currently unable to get the effect's database node in the onRoll event of the dice action
How were you doing this? My experience is that the database node object can't be passed through the whole action process, which is asynchronous and uses OOB messaging. But you can add the database node name as a string and then use that to access the data later in the process.

Something like rRoll.sDBnode = dbnode.getNodeName()

https://www.fantasygrounds.com/refdoc/databasenode.xcp#getNodeName

As an aside : I also seem to remember experiencing issues passing a LUA table (such as rActor) through OOB messaging, so I just keep the data in the OOB messaging table to simple strings and numbers.

Trenloe
February 7th, 2020, 10:51
As an aside : I also seem to remember experiencing issues passing a LUA table (such as rActor) through OOB messaging, so I just keep the data in the OOB messaging table to simple strings and numbers.
Yep, this appears to be by design, as FGU has just posted an update that includes this: "[DEV] deliverOOBMessage was not ignoring non-string,non-number fields. Fixed."

Saagael
February 7th, 2020, 14:00
Crack open the ruleset and I'm sure you'll find what you need.

Thanks! I did, and I managed to find the solution, which turned out to be waaaay easier than I expected. I didn't realize that just adding dice to the roll that's used as part of the base effect action would set the duration, but it does! Thanks for pointing me in the right direction.