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.
Printable View
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?
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
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:function update()
super.update();
myThingToDo();
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.Code:local fOldUpdate;
function onInit()
fOldUpdate = NpcMain.update;
NpcMain.update = myNewUpdate;
end
function myNewUpdate()
fOldUpdate();
doMyNewStuff();
end
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.
Thank you very much, this was exactly what I was searching for. I reduced my custom npc sheet to the following:
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?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>
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:
Attachment 35835
I created a pull request with my changes.
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.