Thread: Library List Filter
-
August 14th, 2017, 12:26 #1
Library List Filter
I want to sort a list of NPCs by hit dice (HD), which is in the format '1d8' or '3d10+3' for example. I created a function in the scripts/library file that allows you to sort the HD filter by the first number only. But the pull-down filter menu still lists the full HD field, so there might be multiple sort fields for a 1 HD creature (1d6, 1d8+1, 1d10). Is there a way to populate the pull-down filter menu with just the first number of the HD so it filters based on just the first number of the HD field (1, 2, 3, etc)?
I can post a screenshot if my description is confusing.
-
August 14th, 2017, 17:38 #2
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,561
You will need to write a custom filter getValue function in order to support a campaign index list filter like this.
Try checking out the 5E ruleset in the data_library_5E.lua file for a couple examples (NPC type = custom filter value, Spell source = custom filter value, plus multiple filter values per record).
Regards,
JPG
-
August 14th, 2017, 21:05 #3
Leo, try something like
Code:["npc"] = { bExport = true, aDataMap = { "npc", "reference.npcdata" }, aDisplayIcon = { "button_people", "button_people_down" }, -- sRecordDisplayClass = "npc", aGMListButtons = { "button_npc_letter", "button_npc_hd", "button_npc_type" }; aCustomFilters = { ["HitDice"] = { sField = "hitDice", fGetValue = getNPCHitDice }, ["Type"] = { sField = "type", sType = "string" }, },
You probably want DB.getValue(vNode, "hd", "") instead of DB.getValue(vNode, "hitDice", "") if it's for 5e.
Code:-- get hitDice and get just the first number function getNPCHitDice(vNode) local sHitDice = StringManager.trim(DB.getValue(vNode, "hitDice", "")); local sHD = sHitDice:match("^%d+"); if sHD then sHitDice = StringManager.trim(sHD); end return sHitDice; end
So, I played with this a little today and was wondering.... I've a field that has multiple entries. like "Arid, Temperate, Mountain, Hills"
I was trying to think of a way so that the search fields listed, instead of having all those on one line ... would have "Arid" then "Hills" then etc... instead and actually work on search.
I can certainly chop it into one field by just splitting on comma but im wondering if it's possible to have a single object have multiple entries so that if they selected "Arid" or "Hills" for search the creatures with both would show in both?
I've a similar situation with spells and Spheres and Schools. Some will have multiple spheres and/or schools and this would also be useful there.Last edited by celestian; August 14th, 2017 at 21:08.
---
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.
-
August 14th, 2017, 21:33 #4
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,561
I believe what you are asking is exactly what the Spell source field does in 5E. Look at the getSpellSourceValue function in data_library_5#.lua.
Cheers,
JPG
-
August 14th, 2017, 22:07 #5---
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.
-
August 14th, 2017, 23:47 #6
Thanks for the replies.
I had actually swiped your 'NPC Type' filter from 5E, Moon. My function was slightly different than celestian's, but I got the same result with the changes. A screenshot will probably help you understand what I'm asking...
screenshot0001.jpg
I want the filter list to read 1, 2, 3... excluding everything other than the first number. I was able to sort the list so it doesn't place the 12, 14, 16 before the 1, but my bigger issue is how to get all of the 1dxx + x HD monsters to filter as 1, and so on.
The answer might be that it's not possible, or it's possible but very complicated. If that's the case, I will move on
-
August 15th, 2017, 01:22 #7
I actually noticed the same problem and sorted (pun!) it out. This is what I did. Keep in mind this is for my output which is specifcally a number only. Not 1+1 or 3+5 or the like. I had issues with 100 being before 1 so...
This was the bit in the "npc" section.
Code:["HitDice"] = { sField = "hitDice", fGetValue = getNPCHitDice,fSort = sortNPCHitDice },
Code:-- see if this will sort HD better function sortNPCHitDice(aFilterValues) local function fNPCSortValue(a) local v = tonumber(a) or 0; return v; end table.sort(aFilterValues, function(a,b) return fNPCSortValue(a) < fNPCSortValue(b); end); return aFilterValues; end
---
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.
-
August 15th, 2017, 11:59 #8
Thanks, celestian. I will use the sort function, that's good enough for me. I think that's the best I'm gonna do with that.
-
August 16th, 2017, 02:19 #9
Seems to be working now. Thanks celestian and JPG!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks