STAR TREK 2d20
Page 3 of 6 First 12345 ... Last
  1. #21
    Quote Originally Posted by Sterno View Post
    I haven’t looked at your code but it sounds like you need to add a Db handler for when your new property updates. If you open up the 2E or CorrRPG ruleset, look through the code for how it does this for the other fields. Search for DB.addHandler or even just “onUpdate” to kind of see how it works, and narrow it down by focusing on one of those properties you can change to force an update and make sure your property’s handler calls the same thing
    Thank you, found the missing part. Updating my new "Saves As" field now also updates the Saving throws. Now I have to dig deeper into the code to set it R/O when you lock the NPC sheet.

  2. #22
    Sorry, I am not a Lua programmer, and I do not have a lot of experience writing extensions for FG.

    It seems that locking the NPC sheet is done by the function "update()" in npc_main.lua. Is there a way to extend this function, or do I need to include the complete npc_main.lua file from the 2e ruleset + my changes in the extension?

  3. #23
    Yeah, it's a little harder for a file like npc_main.lua that's referenced in the campaign xml rather than in base.xml, because you can't replace it as easily. What you basically need to do is create your own record_npc.xml, create a windowclass for npc_combat (the window in record_npc.xml in CoreRPG that references that lua file), use merge="join", and then add a script tag to point at your script. The rest of your xml file should be pretty much empty... you just need to build enough structure to get you down to where your script is defined so you can override that. By using the merge tag, you don't have to replace everything. I don't have the link but I known "damned" on these forums has a link to a short tutorial vid on how to do this in his signature

    Then your script that you point it at can define an "update" function and within it you can do something like

    Code:
    function update()   
       super.update();
       myThingToDo();
    end
    At least, that's the broad strokes of how you'd do it. It's a lot easier if it's a file that's specified in base.xml because if it had a name like "NpcMain" or something, you could do create your own file and in it's onInit do:
    Code:
    local fOldUpdate;
    function onInit()
       fOldUpdate = NpcMain.update;
       NpcMain.update = myNewUpdate;
    end
    
    function myNewUpdate()
       fOldUpdate();
       doMyNewStuff();
    end
    I recently made an Armor Damage for 2E extension where I needed to override some scripts that were defined in the UI xml files, just like you're trying to do. It might help to look at that as an example. It should still be on the first page of these forums somewhere. My extension wasn't super complicated, so there's not a ton of code to wade through.
    Last edited by Sterno; May 19th, 2020 at 13:06. Reason: Had some parenthesis in the wrong place which would have 100% made this not work

  4. #24
    Quote Originally Posted by FlynnTheAvatar View Post
    Sorry, I am not a Lua programmer, and I do not have a lot of experience writing extensions for FG.

    It seems that locking the NPC sheet is done by the function "update()" in npc_main.lua. Is there a way to extend this function, or do I need to include the complete npc_main.lua file from the 2e ruleset + my changes in the extension?
    Thats a complicated question to answer. There are various ways to do it and really depends on exactly what you want. You could insert code into you xml on the specific controls you're changing, you could add a new function, you could replace the entire item_main.lua with your own.

    It really depends on what you need and what you know how to do.

    You might try and pose the question in the Work Shop forum with sample bits of code you're trying to use.
    ---
    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.

  5. #25
    Quote Originally Posted by Sterno View Post
    Yeah, it's a little harder for a file like npc_main.lua that's referenced in the campaign xml rather than in base.xml, because you can't replace it as easily. What you basically need to do is create your own record_npc.xml, create a windowclass for npc_combat (the window in record_npc.xml in CoreRPG that references that lua file), use merge="join", and then add a script tag to point at your script. The rest of your xml file should be pretty much empty... you just need to build enough structure to get you down to where your script is defined so you can override that. By using the merge tag, you don't have to replace everything. I don't have the link but I known "damned" on these forums has a link to a short tutorial vid on how to do this in his signature

    Then your script that you point it at can define an "update" function and within it you can do something like

    Code:
    function update()   
       super.update();
       myThingToDo();
    end

    Thank you very much, this was exactly what I was searching for. I reduced my custom npc sheet to the following:
    Code:
    <root>
      <windowclass name="npc_combat" merge="join">
        <script>
          function update()   
            super.update();
            local nodeRecord = getDatabaseNode();
            local bReadOnly = WindowManager.getReadOnlyState(nodeRecord);
    
            updateControl("savesAs", bReadOnly);
            savesAs.setReadOnly(bReadOnly);
          end
        </script>
        <sheetdata>
          <label_column name="savesas_label">
            <!-- anchored to="hitDice_label" position="bottom" offset="-10" / -->
            <static textres="npc_label_savesas" />
          </label_column>
          <string_columnh name="savesAs">
            <!-- anchored to="hitDice" position="bottom" offset="-10" / -->
            <script>
              function onValueChanged()
                local node = getDatabaseNode();
                local nodeNPC = node.getChild("..");
                CombatManagerADND.updateNPCSaves(nodeNPC, nodeNPC, true);
                window.onSummaryChanged();
              end
            </script>
          </string_columnh>
        </sheetdata>
      </windowclass>
    
    </root>
    Locking and unlocking the sheet works correctly. But I am not sure how I can insert the label and string text field correctly into the NPC sheet. The two controls are simply added to the bottom, overlaying the powers fields. I guess using <anchored to="ANOTHER OBJECT"/> might be the solution?
    Last edited by FlynnTheAvatar; May 20th, 2020 at 20:53. Reason: Fixed quoting.

  6. #26
    Look at "insertbefore" and that should get ya where you want.


    <label_encounter_weaponlist name="label_weapons" insertbefore="maplinks_label" />
    ---
    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.

  7. #27
    Quote Originally Posted by celestian View Post
    Look at "insertbefore" and that should get ya where you want.


    <label_encounter_weaponlist name="label_weapons" insertbefore="maplinks_label" />
    Thank you very much. So, the saves are done, too:
    Rat, Giant (Basic).jpg

    I created a pull request with my changes.

  8. #28
    Quote Originally Posted by FlynnTheAvatar View Post
    I created a pull request with my changes.
    I'll check out the repo once the day job lets out
    ---
    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.

  9. #29
    Quote Originally Posted by celestian View Post
    I'll check out the repo once the day job lets out
    Sorry, I am sure that you have a lot to do. But do you think you have time to check my pull request?

  10. #30
    Quote Originally Posted by FlynnTheAvatar View Post
    Sorry, I am sure that you have a lot to do. But do you think you have time to check my pull request?
    I checked gitlab and did not see any. See it now and processed merge.

    One thing you might want to check, I corrected the hook in the 2E ruleset that did not properly calculate the entire span of the matrix (was to small). You should not need the matrix fix bit of code any longer.

    I'm going to try and have gitlab send me notices for these things so I can resolve them quicker for you.
    ---
    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.

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
  •  
DICE PACKS BUNDLE

Log in

Log in