5E Product Walkthrough Playlist
Page 2 of 2 First 12
  1. #11
    leozelig's Avatar
    Join Date
    Jun 2007
    Location
    Eastern USA
    Posts
    1,406
    Blog Entries
    1
    Yes, I changed it from "table" to "artifact". Here's a little more detail on what I am trying to do:

    I have 3 scripts with similar architecture: ActionArtifact, ActionCritical, and ActionFumble. The first two scripts roll on a table designated on the char sheet when the player rolls a critical hit or fumble. This is modified by the Luck ability score (adds mod to crit and subtracts from fumble), so the modRoll function is looking for effects that modify the Luck score. The ActionArtifact script rolls a d20 + Int mod on a designated table when the player double-clicks or drags the rollable field on the char sheet, so I need the modRoll function to account for effects that modify the Int score. Basically, when all three rolls are set as "table", the modRoll function for ActionFumble runs for all 3 scripts. That makes sense if each action type can only have one mod handler associated with it. Since TableManager changes the roll type to "table", creating unique action types for each script (artifact, critical, fumble) doesn't work. The scripts otherwise contain the standard getRoll and performRoll functions, so nothing fancy going on there.

    Thanks for any help you can offer Trenloe. Clearly I am not understanding something about mod handlers, or I am simply bumping up against the limitations of the ruleset API.

  2. #12
    leozelig's Avatar
    Join Date
    Jun 2007
    Location
    Eastern USA
    Posts
    1,406
    Blog Entries
    1
    I'm going to try copying the TableManager.performRoll function to my scripts, removing the unnecessary parts and leaving rRoll.sType = "artifact", "critical", or "fumble". I will update this thread with my solution if it works.

  3. #13
    leozelig's Avatar
    Join Date
    Jun 2007
    Location
    Eastern USA
    Posts
    1,406
    Blog Entries
    1
    So, here's what ended up working for me. I inserted one line of code in the getRoll function (blue text), and I added the result handler for processing the table output. I simplified the code a little, but this is most of it:

    Code:
    function onInit()
        ActionsManager.registerModHandler("artifact", modRoll);
        ActionsManager.registerResultHandler("artifact", TableManager.onTableRoll);
    end
    
    function getRoll(rActor)
        local rRoll = {};
        rRoll.sType = "artifact";
        rRoll.aDice = {"d20"};
        
        local _,nodeActor = ActorManager.getTypeAndNode(rActor);
        rRoll.nMod = DB.getValue(nodeActor, "artifactcheck.total", 0);
        
        rRoll.sTable = "Table 7-1: Artifact Checks";
        local sCustom = DB.getValue(nodeActor, "artifacttable", "");
        if sCustom ~= "" then
            rRoll.sTable = sCustom;
        end
        
        rRoll.sDesc = "[ARTIFACT CHECK] " .. rRoll.sTable;
    
    
        -- Resolve table node
        rRoll.nodeTable = TableManager.findTable(rRoll.sTable);
        if not rRoll.nodeTable then
            local sTableSansModule = StringManager.split(rRoll.sTable, "@")[1];
            rRoll.nodeTable = DB.findNode(sTableSansModule .. "@*");
        end
        
        if rRoll.nodeTable then
            rRoll.sNodeTable = rRoll.nodeTable.getPath();
        else
            rRoll.sType = "dice";
            ChatManager.SystemMessage(Interface.getString("char_error_missingtable"));
        end
    
        return rRoll;
    end
    
    function performRoll(draginfo, rActor)
        local rRoll = getRoll(rActor);
            
        ActionsManager.performAction(draginfo, rActor, rRoll);
    end
    
    
    function modRoll(rSource, rTarget, rRoll)
        local aAddDesc = {};
        local aAddDice = {};
        local nAddMod = 0;
    
    
        if rSource then
            local bEffects = false;
            
            -- Get ability effect modifiers
            local nAbilityMod, nAbilityEffects = ActorManagerMCC.getAbilityEffectsBonus(rSource, "intelligence");
            if nAbilityEffects > 0 then
                bEffects = true;
                nAddMod = nAddMod + nAbilityMod;
            end
            
            -- If effects happened, then add note
            if bEffects then
                local sEffects = "";
                local sMod = StringManager.convertDiceToString(aAddDice, nAddMod, true);
                if sMod ~= "" then
                    sEffects = "[" .. Interface.getString("effects_tag") .. " " .. sMod .. "]";
                else
                    sEffects = "[" .. Interface.getString("effects_tag") .. "]";
                end
                table.insert(aAddDesc, sEffects);
            end
        end
        
        if #aAddDesc > 0 then
            rRoll.sDesc = rRoll.sDesc .. " " .. table.concat(aAddDesc, " ");
        end
        for _,vDie in ipairs(aAddDice) do
            if vDie:sub(1,1) == "-" then
                table.insert(rRoll.aDice, "-p" .. vDie:sub(3));
            else
                table.insert(rRoll.aDice, "p" .. vDie:sub(2));
            end
        end
        
        rRoll.nMod = rRoll.nMod + nAddMod;
    end
    Last edited by leozelig; May 5th, 2021 at 11:05.

Thread Information

Users Browsing this Thread

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

Posting Permissions

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

Log in

Log in