STAR TREK 2d20
  1. #1

    Setting the Duration of an Effect with a Die Roll

    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:
    Code:
    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?

  2. #2
    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()

    Code:
        -- 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.
    ---
    Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
    Documentation for AD&D 2E ruleset.
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
    Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.

  3. #3
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,408
    Quote Originally Posted by Saagael View Post
    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/refdo...cp#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.
    Last edited by Trenloe; February 7th, 2020 at 09:52.
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,408
    Quote Originally Posted by Trenloe View Post
    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."
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  5. #5
    Quote Originally Posted by celestian View Post
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Starfinder Playlist

Log in

Log in