DICE PACKS BUNDLE
  1. #1
    leozelig's Avatar
    Join Date
    Jun 2007
    Location
    Eastern USA
    Posts
    1,852
    Blog Entries
    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.

  2. #2
    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

  3. #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" },
    		},
    Here is the code I used for mine. This will grab the first number of the value and return it as the HitDice.

    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
    Quote Originally Posted by Moon Wizard View Post
    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
    Everytime I read something you post I find something else to play with, thanks

    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.

  4. #4
    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

  5. #5
    Quote Originally Posted by Moon Wizard View Post
    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
    Wow, sure nuff. It handles it just by splitting. That's WAY easier than I expected!

    Works perfectly.
    ---
    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.

  6. #6
    leozelig's Avatar
    Join Date
    Jun 2007
    Location
    Eastern USA
    Posts
    1,852
    Blog Entries
    1
    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

  7. #7
    Quote Originally Posted by leozelig View Post
    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
    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
    You just need to come up with a similar sort function that'll deal with your values.
    ---
    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.

  8. #8
    leozelig's Avatar
    Join Date
    Jun 2007
    Location
    Eastern USA
    Posts
    1,852
    Blog Entries
    1
    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.

  9. #9
    leozelig's Avatar
    Join Date
    Jun 2007
    Location
    Eastern USA
    Posts
    1,852
    Blog Entries
    1
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
FG Spreadshirt Swag

Log in

Log in