-
January 12th, 2022, 01:10 #1
Getting link references to module/DB entries
Hi, I'm writing a Random Encounter Generator for PF2. I'm pretty much done with the code to calculate the budget and find appropriate monsters (I get a list of all creatures using DB.getChildrenGlobal("reference.npcdata"), let me know if this is a problem).
When I try to create a new Battle (Encounter) record, I'm trying to use NPCManager.addLinkToBattle(), but that requires to pass a sLinkRecord. Where can I find this link from the DB?Daniel Salles de Araújo (@dsaraujo)
Developer of PFRPG2 GM Enhancements - Improve your Pathfinder 2E game!
Check out the Pathfinder Deck of Endless NPCs!
-
January 12th, 2022, 02:22 #2
NPCManager.addLinkToBattle is a function that adds an existing encounter, random encounter or NPC record to an existing (or new) encounter (battle). You need to have created a new battle first, or have an existing one you want to add to.
The function is defined as: function addLinkToBattle(nodeBattle, sLinkClass, sLinkRecord, nMult)
nodeBattle = the node for the new/existing encounter that you want to add to.
sLinkClass = battle (an existing encounter), battlerandom (a random encounter - the randomness of the encounter will be calculated when adding) or npc for an individual bestiary record.
sLinkRecord = the full database path (as a string) to the battle, battlerandom or npc record.
nMult = the number of NPCs in the entry in the encounter.
Looking at the definition for DB.getChildrenGlobal here: https://fantasygroundsunity.atlassia...ChildrenGlobal
It can be seen that the data returned is "The child nodes are returned as databasenode objects in a table with keys corresponding to the names of the child nodes. If the database node does not exist, an empty table is returned." Each row in the LUA take is a key, value - with the key being the database node as a string and the value being a database node object. Use the key value for the relevant record as sLinkRecord when you call NPCManager.addLinkToBattle.
Hope this helps.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!
-
January 12th, 2022, 15:58 #3
As usual, that nails, thanks Trenloe. All that I need are the key values. Hopefully I will have a functional version by the end of the day!
Daniel Salles de Araújo (@dsaraujo)
Developer of PFRPG2 GM Enhancements - Improve your Pathfinder 2E game!
Check out the Pathfinder Deck of Endless NPCs!
-
January 12th, 2022, 16:19 #4
If you just have the target record databasenode you can use .getNodeName: https://fantasygroundsunity.atlassia...de#getNodeName
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!
-
January 12th, 2022, 16:28 #5
Edit: getNodeName() gave me the reference full path!
Unfortunately the keys are just numeric values and not the reference link.
So something like
Code:local creatures = DB.getChildrenGlobal("reference.npcdata"); local nCreatures = 1; -- Filter for only level appropriate creatures for key, localNPC in pairs(creatures) do local nNPCLevel = DB.getValue(localNPC, "level"); if isCreatureInRange(nNPCLevel, nPartyLevel, nBudgetSize) then encounterList[nCreatures] = localNPC; encounterKeys[nCreatures] = key; print(key); nCreatures = nCreatures + 1; end end
Last edited by dsaraujo; January 12th, 2022 at 16:45.
Daniel Salles de Araújo (@dsaraujo)
Developer of PFRPG2 GM Enhancements - Improve your Pathfinder 2E game!
Check out the Pathfinder Deck of Endless NPCs!
-
January 12th, 2022, 16:58 #6
That seems to be potentially a bug in the FGU API.
In that case use localNPC.getNodeName: https://fantasygroundsunity.atlassia...de#getNodeNamePrivate 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!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks