Module:Item table
From bg3.wiki
More actions
Display a table of items queried from the weapons
or equipment
Cargo tables.
File tree
- Module:Item table: Root module
- Module:Item table/doc: Documentation page for module
- Module:Item table/common columns: Defines columns that apply to both equipment and weapon tables
- Module:Item table/weapon columns: Defines the columns unique to weapon tables
- Module:Item table/equipment columns: Defines the columns unique to equipment tables
Usage
table
(required)- Specify which Cargo table you are querying from. This is either
weapons
orequipment
. Weapon and equipment tables have their own set of columns (see below). where
(required)- The SQL
where
clause to select items from the specified table. columns
(optional)- A comma-separated list of columns for the output table. The available options depend on whether this is an equipment table or weapon table.
- For
weapons
tables - Default value:
name_fancy, enchantment, damage, damage_type, weight, price, special
- Available columns:
name
: Simple, no-frills name.name_fancy
: Name and icon with a rarity colour-coded frame.enchantment
: The weapon's enchantment level (+1/+2/+3).properties
: The basic weapon properties like one-handed, finesse, reach, etc.damage
: Simple damage type display with colour-coded damage text, but no fancy templates.damage_type
: Damage type display with colour-coded text. Meant to be paired withdamage
.damage_combined
: A fancier damage display that combines the damage value and type into a single column.damage_fancy
: Likedamage_combined
, except it also shows damage dice and the total damage range of the weapon.weight
: The weight of the weapon in both kg and lb.price
: The base cost of the weapon (i.e. before any vendor price modifiers).special
: Special properties of the weapon such as passives or unique weapon actions.where_to_find
: Location(s) where this weapon can be found.bugs
: List any bugs associated with the weapon. For use on bug list pages.
- For
equipment
tables - Default value:
name_fancy, type, weight, price, special
- Available columns:
name
: Simple, no-frills name.name_fancy
: Name and icon with a rarity colour-coded frame.type
: The type of item (e.g. ring, medium armour, cloak, etc.). This also lists the required armour proficiency if it is not obvious from the item type.enchantment
: The weapon's enchantment level (+1/+2/+3).armour_class
: The AC of the item. This can be the base AC of an armour or the bonus AC from an item like a shield or magic robes.stealth_disadvantage
: Whether the item imposes disadvantage on stealth checks. This is only relevant for armours.weight
: The weight of the weapon in both kg and lb.price
: The base cost of the weapon (i.e. before any vendor price modifiers).special
: Special properties of the weapon such as passives or unique weapon actions.where_to_find
: Location(s) where this item can be found.bugs
: List any bugs associated with the item. For use on bug list pages.
- For
order by
(optional)- Default value:
rarity_order, name
- Set the default sort order of the table. This is a comma separated list of Cargo field names. The user is free to sort the table using the arrows on each column.
default
(optional)- Default value: "No items found."
- Text to insert in place of an empty table if the query returns no results.
limit
(optional)- Set the max size of the table. If it exceeds this number, it will add a "View more" link to paginate the table.
offset
(optional)- Default value: 0
- Skip the first n results of the query. This is usually used with
limit
.
Weapon examples
Default table format
Markup{{#invoke: Item table | main | table = weapons | where = name = "Nyrulna" OR name = "Voss' Silver Sword" }}Renders as
Item | Ench. | Damage | Damage type | Weight | Price | Special |
---|---|---|---|---|---|---|
Voss' Silver Sword | +2 | 1d8 + 2 1d4 | Slashing Psychic | 1.35 kg 2.7 lb | 630 |
|
Nyrulna | +3 | 1d6 + 3 1d6 | Piercing Thunder | 1.8 kg 3.6 lb | 840 |
|
Alternative table format
Markup{{#invoke: Item table | main | table = weapons | where = name = "Nyrulna" OR name = "Voss' Silver Sword" | columns = name_fancy, properties, enchantment, damage_combined, weight, price, special }}Renders as
Item | Properties | Ench. | Damage | Weight | Price | Special |
---|---|---|---|---|---|---|
Voss' Silver Sword | Martial Versatile | +2 | 1d8 + 2 + 1d4 | 1.35 kg 2.7 lb | 630 |
|
Nyrulna | Martial Versatile Thrown | +3 | 1d6 + 3 + 1d6 | 1.8 kg 3.6 lb | 840 |
|
Comparison of different damage column options
Markup{{#invoke: Item table | main | table = weapons | where = name = "Nyrulna" OR name = "Voss' Silver Sword" | columns = name_fancy, damage, damage_type, damage_combined, damage_fancy }}Renders as
Item | Damage | Damage type | Damage | Damage |
---|---|---|---|---|
Voss' Silver Sword | 1d8 + 2 1d4 | Slashing Psychic | 1d8 + 2 + 1d4 | ![]() ![]() 1d8 + 2 + 1d4 |
Nyrulna | 1d6 + 3 1d6 | Piercing Thunder | 1d6 + 3 + 1d6 | ![]() ![]() 1d6 + 3 + 1d6 |
Bug list example
Markup{{#invoke: Item table | main | table = weapons | where = bugs IS NOT NULL AND (rarity = "legendary") | columns = name_fancy, bugs }}Renders as
Item | Bugs |
---|---|
Bloodthirst |
|
Crimson Mischief |
|
Shar's Spear of Evening |
|
Equipment examples
Default table format
Markup{{#invoke: Item table | main | table = equipment | where = rarity = "legendary" AND legacy IS NULL }}Renders as
Item | Type | Weight | Price | Special |
---|---|---|---|---|
Gloves of Soul Catching | Gloves | 0.5 kg 1 lb | 960 |
|
Helldusk Armour | Heavy Armour | 20 kg 40 lb | 8000 |
|
Helm of Balduran | Helmets (Medium Armour) | 2 kg 4 lb | 760 |
|
Mask of the Shapeshifter | Helmets | 0.5 kg 1 lb | 1 |
|
Viconia's Walking Fortress | Shields | 2.7 kg 5.4 lb | 760 |
|
Armour example
Markup{{#invoke: Item table | main | table = equipment | where = type LIKE "%Armour" AND legacy IS NULL and rarity = "very rare" | columns = name_fancy, armour_class, stealth_disadvantage, weight, price, special }}Renders as
Item | Armour Class | Stealth disadvantage | Weight | Price | Special |
---|---|---|---|---|---|
Adamantine Scale Mail | 16 | Yes | 12 kg 24 lb | 1300 |
|
Adamantine Splint Armour | 18 | Yes | 19 kg 38 lb | 3800 |
|
Armour of Agility | 17 | No | 12 kg 24 lb | 2900 |
|
Armour of Landfall | 13 | No | 4.5 kg 9 lb | 1700 |
|
Armour of Moonbasking | 11 | No | 4.5 kg 9 lb | 1400 |
|
Armour of Persistence | 20 | Yes | 20 kg 40 lb | 6400 |
|
Armour of the Sporekeeper | 13 | No | 4.5 kg 9 lb | 1050 |
|
Bhaalist Armour | 14 | No | 5.85 kg 11.7 lb | 2000 |
|
Blackguard's Plate | 19 | Yes | 20 kg 40 lb | 6400 |
|
Dark Justiciar Half-Plate (Very Rare) | 17 | No | 12 kg 24 lb | 2900 |
|
Elegant Studded Leather | 14 | No | 5.85 kg 11.7 lb | 2000 |
|
Emblazoned Plate of the Marshal | 19 | Yes | 20 kg 40 lb | 6400 |
|
Flame Enamelled Armour | 16 | Yes | 12 kg 24 lb | 2900 |
|
Reaper's Embrace | 19 | Yes | 20 kg 40 lb | 6400 |
|
Sharpened Snare Cuirass | 14 | No | 5.4 kg 10.8 lb | 830 |
|
An item set example
Markup{{#invoke: Item table | main | table = equipment | where = name LIKE "%Bonespike%" | columns = name_fancy, type, special }}Renders as
Item | Type | Special |
---|---|---|
Bonespike Boots | Boots |
|
Bonespike Garb | Clothing |
|
Bonespike Gloves | Gloves |
|
Bonespike Helmet | Helmets |
|
Bug list example
Markup{{#invoke: Item table | main | table = equipment | where = bugs IS NOT NULL AND (rarity = "legendary") | columns = name_fancy, bugs }}Renders as
Item | Bugs |
---|---|
Gloves of Soul Catching |
|
Helldusk Armour |
|
Helm of Balduran |
|
Item location example
Markup{{#invoke: Item table | main | table = equipment | where = name = "Amulet of Restoration" | columns = name_fancy, where_to_find }}Renders as
Item | Where to find |
---|---|
Amulet of Restoration |
|
Source code
local p = {}
-- Strip leading/trailing whitespace
local function strip(s)
return string.match(s, "^%s*(.-)%s*$")
end
-- Prepare the HTML element for the table ready to be filled with rows
local function prepare_table(columns, table_data)
local table_outer = mw.html.create("table")
:addClass("wikitable")
:addClass("sortable")
local table_header = table_outer:tag("tr")
for _, column in ipairs(columns) do
local column_name = table_data.columns[column].name
table_header:tag("th"):wikitext(column_name)
end
return table_outer
end
-- Produce the comma separated list of the cargo fields that need to be queried to
-- fill out the specified columns. This is passed into the query function.
local function field_string(columns, table_data)
local query_fields = {}
-- Produce a set from potentially overlapping lists of cargo fields
for _, column_name in ipairs(columns) do
local column = table_data.columns[column_name]
for _, field in ipairs(column.cargo_fields) do
query_fields[field] = true
end
end
local query_str = {}
for field, _ in pairs(query_fields) do
table.insert(query_str, field)
end
return table.concat(query_str, ', ')
end
function p.main(frame)
local args = frame.args
local table_definitions = nil
if args["table"] == "weapons" then
table_definitions = require("Module:Item table/weapon columns")
elseif args["table"] == "equipment" then
table_definitions = require("Module:Item table/equipment columns")
else
mw.addWarning("Invalid table specified. Expected 'weapons' or 'equipment'.")
return ""
end
-- Use either user-defined set of columns (specified as a comma-separated list)
-- or the default set of columns defined for that type of table.
local columns = {}
for column in string.gmatch(args.columns or "", "[^,]+") do
column = strip(column)
if table_definitions.columns[column] then
table.insert(columns, column)
else
mw.addWarning(string.format("Unknown column %s; skipping", column))
end
end
if #columns == 0 then
columns = table_definitions.default
end
-- Arguments passed into the mw.ext.cargo.query function.
-- They have a different name convention (camelcase vs lowercase with spaces)
local query_args = {
where = args["where"],
limit = args["limit"],
offset = args["offset"],
orderBy = args["order by"] or "rarity_order, name"
}
local results = mw.ext.cargo.query(
args["table"],
field_string(columns, table_definitions),
query_args
)
if #results > 0 then
local output_table = prepare_table(columns, table_definitions)
for _, item in ipairs(results) do
local row = output_table:tag('tr')
for _, column_name in ipairs(columns) do
local column = table_definitions.columns[column_name]
row:node(column.formatter(item))
end
end
return output_table
else
return args["default"] or "<div><i>No items found.</i></div>"
end
end
return p