pr6i6e6st
June 26th, 2020, 01:03
I've done it. I've finally done it! I've made it so i can drag a stat block of an NPC onto another NPC statblock to merge them together! ability scores are combined in a way that if NPC-A has a strength of 12, and NPC-B has a strength of 14, the combined total will be 16.
This is going to make statblocks so much easier for me! so i figured i'd share here too!
Instructions:
extract the npc_main.lua from the .zip file at the bottom of the post
open up your fantasy grounds directory and navigate to your rulesets folder
extract the 5e ruleset and replace the npc_main.lua into the 5e/campaign/scripts folder
enjoy!
If someone could turn this into an extension or if we could just make this built into the code for 5e, that would be freaking fantastic btw
Original Text
Hey guys. i'm trying to alter the npc_main.lua to make it so if i drop an NPC on an NPC sheet, it will get all sorts of stuff from the dropped NPC.
starting off easy, i want to add actions and traits. i almost have it but i'm struggling to get the actions from the draginfo. this is what i have at the moment, but it only adds actions and traits of what it already has, just because i'm unsure how to fetch from the draginfo.
Moon Wizard
June 26th, 2020, 01:24
The drop information only contains the class and recordname of the window link dropped (which is what a link is for FG). This means that you don't have a "windowinstance" object in the drop; just the class and recordname. You would need to use the DB/databasenode scripts to work with the path to pull any data you want from the dropped path.
Regards,
JPG
pr6i6e6st
June 26th, 2020, 04:46
The drop information only contains the class and recordname of the window link dropped (which is what a link is for FG). This means that you don't have a "windowinstance" object in the drop; just the class and recordname. You would need to use the DB/databasenode scripts to work with the path to pull any data you want from the dropped path.
Regards,
JPG
ok i think i understand what you mean. i'm still missing something though. it looks like i can get the table of actions or traits from the entity, but my "for _v in pairs(Actions)" part and same for traits, doesn't seem to be operating. as the debug's within them don't even show up on the console. god i have to be close.
function onDrop(x, y, draginfo)
if WindowManager.getReadOnlyState(getDatabaseNode()) then
return true;
end
if draginfo.isType("shortcut") then
local sClass = draginfo.getShortcutData();
local nodeSource = draginfo.getDatabaseNode();
local NPCActions = DB.getPath(nodeSource, "actions");
local NPCTraits = DB.getPath(nodeSource, "traits");
Debug.console("NPC nodeSource =", nodeSource);
Debug.console("NPC NPCTraits =", NPCTraits);
Debug.console("NPC NPCActions =", NPCActions);
if sClass == "reference_spell" or sClass == "power" then
addSpellDrop(nodeSource);
elseif sClass == "reference_backgroundfeature" then
addAction(DB.getValue(nodeSource, "name", ""), DB.getText(nodeSource, "text", ""));
elseif sClass == "reference_classfeature" then
addAction(DB.getValue(nodeSource, "name", ""), DB.getText(nodeSource, "text", ""));
elseif sClass == "reference_feat" then
addAction(DB.getValue(nodeSource, "name", ""), DB.getText(nodeSource, "text", ""));
elseif sClass == "reference_racialtrait" or sClass == "reference_subracialtrait" then
addTrait(DB.getValue(nodeSource, "name", ""), DB.getText(nodeSource, "text", ""));
end
if sClass == "npc" then
Debug.console("Drop is NPC");
Debug.console("DB.getChildren(nodeSource, 'actions')", DB.getChildren(nodeSource, "actions"));
Debug.console("DB.getChildren(nodeSource, 'traits')", DB.getChildren(nodeSource, "traits"));
local Actions = DB.getChildren(nodeSource, "actions");
local Traits = DB.getChildren(nodeSource, "traits");
for _,v in ipairs(Actions) do
local actionNode = v.getDatabaseNode();
Debug.console("NPC onDrop =", actionNode);
addAction(DB.getValue(actionNode, "name", ""), DB.getText(actionNode, "desc", ""));
end
for _,v in ipairs(Traits) do
local traitNode = v.getDatabaseNode();
Debug.console("NPC onDrop =", traitNode);
addTrait(DB.getValue(traitNode, "name", ""), DB.getText(traitNode, "desc", ""));
end
end
return true;
end
end
37168
pr6i6e6st
June 26th, 2020, 06:26
I'm DOING IT! holy crap it's working! now to get the text fields to add everything and to merge the ability scores!
function onDrop(x, y, draginfo)
if WindowManager.getReadOnlyState(getDatabaseNode()) then
return true;
end
if draginfo.isType("shortcut") then
local sClass = draginfo.getShortcutData();
local nodeSource = draginfo.getDatabaseNode();
local NPCACtext = DB.getValue(nodeSource, "actext", "");
local NPCDamageresistances = DB.getValue(nodeSource, "damageresistances", "");
local NPChd = DB.getValue(nodeSource, "hd", "");
local NPClanguages = DB.getValue(nodeSource, "languages", "");
local NPCsavingthrows = DB.getValue(nodeSource, "savingthrows", "");
local NPCsenses = DB.getValue(nodeSource, "senses", "");
local NPCtext = DB.getValue(nodeSource, "text", "");
local NPCtype = DB.getValue(nodeSource, "type", "");
local NPCActions = DB.getPath(nodeSource, "actions");
local NPCRections = DB.getPath(nodeSource, "reactions");
local NPCTraits = DB.getPath(nodeSource, "traits");
local NPCInnateSpells = DB.getPath(nodeSource, "innatespells");
local NPCSpells = DB.getPath(nodeSource, "spells");
local NPCLairActions = DB.getPath(nodeSource, "lairactions");
local NPCLegendaryActions = DB.getPath(nodeSource, "legendaryactions");
Debug.console("NPC nodeSource =", nodeSource);
Debug.console("NPC NPCTraits =", NPCTraits);
Debug.console("NPC NPCActions =", NPCActions);
if sClass == "reference_spell" or sClass == "power" then
addSpellDrop(nodeSource);
elseif sClass == "reference_backgroundfeature" then
addAction(DB.getValue(nodeSource, "name", ""), DB.getText(nodeSource, "text", ""));
elseif sClass == "reference_classfeature" then
addAction(DB.getValue(nodeSource, "name", ""), DB.getText(nodeSource, "text", ""));
elseif sClass == "reference_feat" then
addAction(DB.getValue(nodeSource, "name", ""), DB.getText(nodeSource, "text", ""));
elseif sClass == "reference_racialtrait" or sClass == "reference_subracialtrait" then
addTrait(DB.getValue(nodeSource, "name", ""), DB.getText(nodeSource, "text", ""));
end
if sClass == "npc" then
Debug.console("Drop is NPC");
Debug.console("DB.getChildren(nodeSource, 'actions')", DB.getChildren(NPCActions, "actions"));
Debug.console("DB.getChildren(nodeSource, 'traits')", DB.getChildren(NPCTraits, "traits"));
local Actions = DB.getChildren(NPCActions, "actions");
local Traits = DB.getChildren(NPCTraits, "traits");
local Reactions = DB.getChildren(NPCRections, "reactions");
local InnateSpells = DB.getChildren(NPCInnateSpells, "innatespells");
local Spells = DB.getChildren(NPCSpells, "spells");
local LairActions = DB.getChildren(NPCLairActions, "lairactions");
local LegendaryActions = DB.getChildren(NPCLegendaryActions, "legendaryactions");
for _,w in pairs(Actions) do
local actionNode = w;
Debug.console("NPC onDrop =", actionNode);
addAction(DB.getValue(actionNode, "name", ""), DB.getText(actionNode, "desc", ""));
end
for _,w in pairs(Traits) do
local traitNode = w;
Debug.console("NPC onDrop =", traitNode);
addTrait(DB.getValue(traitNode, "name", ""), DB.getText(traitNode, "desc", ""));
end
for _,w in pairs(Reactions) do
local reactionNode = w;
Debug.console("NPC onDrop =", reactionNode);
addTrait(DB.getValue(reactionNode, "name", ""), DB.getText(reactionNode, "desc", ""));
end
for _,w in pairs(InnateSpells) do
local innateSpellNode = w;
Debug.console("NPC onDrop =", innateSpellNode);
addTrait(DB.getValue(innateSpellNode, "name", ""), DB.getText(innateSpellNode, "desc", ""));
end
for _,w in pairs(Spells) do
local spellNode = w;
Debug.console("NPC onDrop =", spellNode);
addTrait(DB.getValue(spellNode, "name", ""), DB.getText(spellNode, "desc", ""));
end
for _,w in pairs(LairActions) do
local lairActionNode = w;
Debug.console("NPC onDrop =", lairActionNode);
addTrait(DB.getValue(lairActionNode, "name", ""), DB.getText(lairActionNode, "desc", ""));
end
for _,w in pairs(LegendaryActions) do
local legendaryActionNode = w;
Debug.console("NPC onDrop =", legendaryActionNode);
addTrait(DB.getValue(legendaryActionNode, "name", ""), DB.getText(legendaryActionNode, "desc", ""));
end
end
return true;
end
end
Three of Swords
June 27th, 2020, 11:55
I've done it. I've finally done it! I've made it so i can drag a stat block of an NPC onto another NPC statblock to merge them together! ability scores are combined in a way that if NPC-A has a strength of 12, and NPC-B has a strength of 14, the combined total will be 16.
I really like the idea of being able to drag an NPC to another so the abilities and traits get copied. Does it convert DCs, attack mods, etc?
But I'm curious. Why would the 'combined' NPC have a 16 Str, which is higher than either of the two original NPCs? Not criticizing. Just trying to figure out the logic behind this decision.
pr6i6e6st
June 27th, 2020, 13:18
I really like the idea of being able to drag an NPC to another so the abilities and traits get copied. Does it convert DCs, attack mods, etc?
But I'm curious. Why would the 'combined' NPC have a 16 Str, which is higher than either of the two original NPCs? Not criticizing. Just trying to figure out the logic behind this decision.
I haven’t figured out stringmanager functions quite yet so it just copies things over, likely needing a bit of an edit.
I made the stats add up that way so you’re treating the dropped npc like a template. So where I have a bunch of commoner statblocks done up with various race traits and such, I can drag and drop that on a knight or champion or bandit and have one of those with the racial features, including the stat boost.
Good work!
JPG
Thank you muchly
Powered by vBulletin® Version 4.2.1 Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.