Difference between revisions of "Module:PGVillagerItemOutput"

From Nookipedia, the Animal Crossing wiki
m (fixing new line issues)
(removing the item name parameter for now)
(2 intermediate revisions by the same user not shown)
Line 24: Line 24:
 
         where = "pg_house.game HOLDS 'DnM' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
 
         where = "pg_house.game HOLDS 'DnM' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
 
         orderBy = 'pg_house.villager',
 
         orderBy = 'pg_house.villager',
         limit = 300,
+
         limit = 410,
 
         default = ''
 
         default = ''
 
     }
 
     }
Line 36: Line 36:
 
         where = "pg_house.game HOLDS 'DnM+' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
 
         where = "pg_house.game HOLDS 'DnM+' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
 
         orderBy = 'pg_house.villager',
 
         orderBy = 'pg_house.villager',
         limit = 300,
+
         limit = 410,
 
         default = ''
 
         default = ''
 
     }
 
     }
Line 48: Line 48:
 
         where = "pg_house.game HOLDS 'PG' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
 
         where = "pg_house.game HOLDS 'PG' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
 
         orderBy = 'pg_house.villager',
 
         orderBy = 'pg_house.villager',
         limit = 300,
+
         limit = 410,
 
         default = ''
 
         default = ''
 
     }
 
     }
Line 58: Line 58:
 
     local args4 = {
 
     local args4 = {
 
     join = 'pg_villager.romanized_name = pg_house.villager',
 
     join = 'pg_villager.romanized_name = pg_house.villager',
         where = "pg_house.game HOLDS 'DmMe+' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
+
         where = "pg_house.game HOLDS 'DnMe+' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
 
         orderBy = 'pg_house.villager',
 
         orderBy = 'pg_house.villager',
         limit = 300,
+
         limit = 410,
 
         default = ''
 
         default = ''
 
     }
 
     }
 
     local resultsDnMeplus = cargo.query( tables4, fields4, args4 )
 
     local resultsDnMeplus = cargo.query( tables4, fields4, args4 )
 
      
 
      
        if not tableEmpty(resultsDnM) then
+
    if not tableEmpty(resultsDnM) then
 
     print = print .. "In ''[[Doubutsu no Mori]]'', this item appears in the homes of "
 
     print = print .. "In ''[[Doubutsu no Mori]]'', this item appears in the homes of "
 
    for r = 1, #resultsDnM do
 
    for r = 1, #resultsDnM do
Line 139: Line 139:
 
end
 
end
 
if not tableEmpty(resultsDnM) or not tableEmpty(resultsDnMplus) or not tableEmpty(resultsPG) or not tableEmpty(resultsDnMeplus) then
 
if not tableEmpty(resultsDnM) or not tableEmpty(resultsDnMplus) or not tableEmpty(resultsPG) or not tableEmpty(resultsDnMeplus) then
print = print .. "\n\nFor villagers who have the " .. frame.args['1'] .. " placed on the floor in their house, there is a chance that the villager will gift it to the player."
+
print = print .. "\n\nFor villagers who have this item placed on the floor in their house, there is a chance that the villager will gift it to the player."
 
end
 
end
 
if tableEmpty(resultsDnM) and tableEmpty(resultsDnMplus) and tableEmpty(resultsPG) and tableEmpty(resultsDnMeplus) then
 
if tableEmpty(resultsDnM) and tableEmpty(resultsDnMplus) and tableEmpty(resultsPG) and tableEmpty(resultsDnMeplus) then
Line 375: Line 375:
 
    args4 = {
 
    args4 = {
 
    join = 'pg_villager.romanized_name = pg_house.villager',
 
    join = 'pg_villager.romanized_name = pg_house.villager',
        where = "pg_house.game HOLDS 'DmMe+' AND pg_house.wallpaper = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
+
        where = "pg_house.game HOLDS 'DnMe+' AND pg_house.wallpaper = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
 
        orderBy = 'pg_house.villager',
 
        orderBy = 'pg_house.villager',
 
        limit = 300,
 
        limit = 300,
Line 423: Line 423:
 
    args4 = {
 
    args4 = {
 
    join = 'pg_villager.romanized_name = pg_house.villager',
 
    join = 'pg_villager.romanized_name = pg_house.villager',
        where = "pg_house.game HOLDS 'DmMe+' AND pg_house.flooring = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
+
        where = "pg_house.game HOLDS 'DnMe+' AND pg_house.flooring = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
 
        orderBy = 'pg_house.villager',
 
        orderBy = 'pg_house.villager',
 
        limit = 300,
 
        limit = 300,

Revision as of 19:23, November 26, 2022

Module documentation (view)


Usage

This Lua module outputs the villager data info for item pages from every first generation Animal Crossing game in regards to their furniture, clothing, umbrella, and interior items. These are put through {{PGFurnitureVillagers}}, {{PGInteriorVillagers}}, {{PGClothingVillagers}}, and {{PGUmbrellaVillagers}}. Please refer to the documentation of each of these templates for more information.


local p = {}
local cargo = mw.ext.cargo

function tableEmpty(s)
	if s == nil then
		return s == nil or s == ''
	else
		return next(s) == nil
	end
end

function isEmpty(s)
	return s == nil or s == ''
end

function p.furnitureOutput( frame )
	local print = ''

	-- Cargo query for pg_house and pg_villager (Doubutsu no Mori)
    local tables1 = 'pg_house,pg_villager'
    local fields1 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
    local args1 = {
    	join = 'pg_villager.romanized_name = pg_house.villager',
        where = "pg_house.game HOLDS 'DnM' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
        orderBy = 'pg_house.villager',
        limit = 410,
        default = ''
    }
    local resultsDnM = cargo.query( tables1, fields1, args1 )
    
    -- Cargo query for pg_house and pg_villager (Doubutsu no Mori+)
    local tables2 = 'pg_house,pg_villager'
    local fields2 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
    local args2 = {
    	join = 'pg_villager.romanized_name = pg_house.villager',
        where = "pg_house.game HOLDS 'DnM+' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
        orderBy = 'pg_house.villager',
        limit = 410,
        default = ''
    }
    local resultsDnMplus = cargo.query( tables2, fields2, args2 )
    
	-- Cargo query for pg_house and pg_villager (Animal Crossing)
    local tables3 = 'pg_house,pg_villager'
    local fields3 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
    local args3 = {
    	join = 'pg_villager.romanized_name = pg_house.villager',
        where = "pg_house.game HOLDS 'PG' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
        orderBy = 'pg_house.villager',
        limit = 410,
        default = ''
    }
    local resultsPG = cargo.query( tables3, fields3, args3 )
    
    -- Cargo query for pg_house and pg_villager (Doubutsu no Mori e+)
    local tables4 = 'pg_house,pg_villager'
    local fields4 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
    local args4 = {
    	join = 'pg_villager.romanized_name = pg_house.villager',
        where = "pg_house.game HOLDS 'DnMe+' AND pg_house.items LIKE '%\"" .. frame.args['1']:gsub("\'","\\'") .. "\"%'",
        orderBy = 'pg_house.villager',
        limit = 410,
        default = ''
    }
    local resultsDnMeplus = cargo.query( tables4, fields4, args4 )
    
    if not tableEmpty(resultsDnM) then
    	print = print .. "In ''[[Doubutsu no Mori]]'', this item appears in the homes of "
	    for r = 1, #resultsDnM do
	    	if r == #resultsDnM and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsDnM[r].image .. "|x25px|link=|alt=|" .. resultsDnM[r].villager .. "]] [[" .. resultsDnM[r].pageName .. "|" .. resultsDnM[r].villager .. "]]"
	        if r == #resultsDnM then
	        	print = print .. '.'
	        elseif r-1 == 0 and r+1 == #resultsDnM then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    if not tableEmpty(resultsDnMplus) or not tableEmpty(resultsPG) or not tableEmpty(resultsDnMeplus) then
	    	print = print .. "\n\n"
	    end
    end
	if not tableEmpty(resultsDnMplus) then
    	print = print .. "In ''[[Animal Crossing|Doubutsu no Mori+]]'', this item appears in the homes of "
	    for r = 1, #resultsDnMplus do
	    	if r == #resultsDnMplus and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsDnMplus[r].image .. "|x25px|link=|alt=|" .. resultsDnMplus[r].villager .. "]] [[" .. resultsDnMplus[r].pageName .. "|" .. resultsDnMplus[r].villager .. "]]"
	        if r == #resultsDnMplus then
	        	print = print .. '.'
	        elseif r-1 == 0 and r+1 == #resultsDnMplus then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    if not tableEmpty(resultsPG) or not tableEmpty(resultsDnMeplus) then
	    	print = print .. "\n\n"
	    end
	end
    if not tableEmpty(resultsPG) then
    	print = print .. "In ''[[Animal Crossing]]'', this item appears in the homes of "
	    for r = 1, #resultsPG do
	    	if r == #resultsPG and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsPG[r].image .. "|x25px|link=|alt=|" .. resultsPG[r].villager .. "]] [[" .. resultsPG[r].pageName .. "|" .. resultsPG[r].villager .. "]]"
	        if r == #resultsPG then
	        	print = print .. '.'
	        elseif r-1 == 0 and r+1 == #resultsPG then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    if not tableEmpty(resultsDnMeplus) then
	    	print = print .. "\n\n"
	    end
    end
	if not tableEmpty(resultsDnMeplus) then
    	print = print .. "In ''[[Doubutsu no Mori e+]]'', this item appears in the homes of "
	    for r = 1, #resultsDnMeplus do
	    	if r == #resultsDnMeplus and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsDnMeplus[r].image .. "|x25px|link=|alt=|" .. resultsDnMeplus[r].villager .. "]] [[" .. resultsDnMeplus[r].pageName .. "|" .. resultsDnMeplus[r].villager .. "]]"
	        if r == #resultsDnMeplus then
	        	print = print .. '.'
	        elseif r-1 == 0 and r+1 == #resultsDnMeplus then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	end
	if not tableEmpty(resultsDnM) or not tableEmpty(resultsDnMplus) or not tableEmpty(resultsPG) or not tableEmpty(resultsDnMeplus) then
		print = print .. "\n\nFor villagers who have this item placed on the floor in their house, there is a chance that the villager will gift it to the player."
	end
	if tableEmpty(resultsDnM) and tableEmpty(resultsDnMplus) and tableEmpty(resultsPG) and tableEmpty(resultsDnMeplus) then
		print = print .. "No villagers have this item in their home."
    end
    return print
end

function p.clothingOutput( frame )
	local print = ''

	-- Cargo query for pg_villager (Doubutsu no Mori)
    local tables1 = 'pg_villager'
    local fields1 = "pg_villager.image=icon,pg_villager.romanized_name=villager,pg_villager._pageTitle=pageName"
    local args1 = {
        where = "pg_villager.clothing_dnm = '" .. frame.args['1']:gsub("\'","\\'").. "'",
        orderBy = 'pg_villager.romanized_name',
        limit = 300,
        default = ''
    }
    local resultsDnM = cargo.query( tables1, fields1, args1 )
    
	-- Cargo query for pg_villager (Doubutsu no Mori+)
    local tables2 = 'pg_villager'
    local fields2 = "pg_villager.image=icon,pg_villager.romanized_name=villager,pg_villager._pageTitle=pageName"
    local args2 = {
        where = "pg_villager.clothing_plus = '" .. frame.args['1']:gsub("\'","\\'").. "'",
        orderBy = 'pg_villager.romanized_name',
        limit = 300,
        default = ''
    }
    local resultsDnMplus = cargo.query( tables2, fields2, args2 )
    
	-- Cargo query for pg_villager (Animal Crossing)
    local tables3 = 'pg_villager'
    local fields3 = "pg_villager.image=icon,pg_villager.romanized_name=villager,pg_villager._pageTitle=pageName"
    local args3 = {
        where = "pg_villager.clothing = '" .. frame.args['1']:gsub("\'","\\'").. "' AND in_pg=1",
        orderBy = 'pg_villager.romanized_name',
        limit = 300,
        default = ''
    }
    local resultsPG = cargo.query( tables3, fields3, args3 )
    
    -- Cargo query for pg_villager (Doubutsu no Mori e+)
    local tables4 = 'pg_villager'
    local fields4 = "pg_villager.image=icon,pg_villager.romanized_name=villager,pg_villager._pageTitle=pageName"
    local args4 = {
        where = "pg_villager.clothing = '" .. frame.args['1']:gsub("\'","\\'").. "' AND in_pg=0",
        orderBy = 'pg_villager.romanized_name',
        limit = 300,
        default = ''
    }
    local resultsDnMeplus = cargo.query( tables4, fields4, args4 )
    
    if not tableEmpty(resultsDnM) then
    	print = print .. "In ''[[Doubutsu no Mori]]'', this item is worn by "
	    for r = 1, #resultsDnM do
	    	if r == #resultsDnM and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsDnM[r].icon .. "|25px|link=|alt=|" .. resultsDnM[r].villager .. "]] [[" .. resultsDnM[r].pageName .. "|" .. resultsDnM[r].villager .. "]]"
	        if r == #resultsDnM then
	        	print = print .. ' '
	        elseif r-1 == 0 and r+1 == #resultsDnM then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    print = print .. " as their default outfit."
	    if not tableEmpty(resultsDnMplus) or not tableEmpty(resultsPG) or not tableEmpty(resultsDnMeplus) then
	    	print = print .. "\n\n"
	    end
    end
	if not tableEmpty(resultsDnMplus) then
    	print = print .. "In ''[[Animal Crossing|Doubutsu no Mori+]]'', this item is worn by "
	    for r = 1, #resultsDnMplus do
	    	if r == #resultsDnMplus and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsDnMplus[r].icon .. "|25px|link=|alt=|" .. resultsDnMplus[r].villager .. "]] [[" .. resultsDnMplus[r].pageName .. "|" .. resultsDnMplus[r].villager .. "]]"
	        if r == #resultsDnMplus then
	        	print = print .. ' '
	        elseif r-1 == 0 and r+1 == #resultsDnMplus then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    print = print .. " as their default outfit."
	    if not tableEmpty(resultsPG) or not tableEmpty(resultsDnMeplus) then
	    	print = print .. "\n\n"
	    end
	end
    if not tableEmpty(resultsPG) then
    	print = print .. "In ''[[Animal Crossing]]'', this item is worn by "
	    for r = 1, #resultsPG do
	    	if r == #resultsPG and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsPG[r].icon .. "|25px|link=|alt=|" .. resultsPG[r].villager .. "]] [[" .. resultsPG[r].pageName .. "|" .. resultsPG[r].villager .. "]]"
	        if r == #resultsPG then
	        	print = print .. ' '
	        elseif r-1 == 0 and r+1 == #resultsPG then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    print = print .. " as their default outfit."
	    if not tableEmpty(resultsDnMeplus) then
	    	print = print .. "\n\n"
	    end
    end
	if not tableEmpty(resultsDnMeplus) then
    	print = print .. "In ''[[Doubutsu no Mori e+]]'', this item is worn by "
	    for r = 1, #resultsDnMeplus do
	    	if r == #resultsDnMeplus and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsDnMeplus[r].icon .. "|25px|link=|alt=|" .. resultsDnMeplus[r].villager .. "]] [[" .. resultsDnMeplus[r].pageName .. "|" .. resultsDnMeplus[r].villager .. "]]"
	        if r == #resultsDnMeplus then
	        	print = print .. ' '
	        elseif r-1 == 0 and r+1 == #resultsDnMeplus then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    print = print .. " as their default outfit."
	end
	if tableEmpty(resultsDnM) and tableEmpty(resultsDnMplus) and tableEmpty(resultsPG) and tableEmpty(resultsDnMeplus) then
		print = print .. "No villagers wear this item as their default outfit."
    end
    return print
end

function p.umbrellaOutput( frame )
	local print = ''

	-- Cargo query for pg_villager
    local tables = 'pg_villager'
    local fields = "pg_villager.image=icon,pg_villager.romanized_name=villager,pg_villager._pageTitle=pageName"
    local args = {
        where = "pg_villager.umbrella = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
        orderBy = 'pg_villager.romanized_name',
        limit = 300,
        default = ''
    }
    local results = cargo.query( tables, fields, args )
    if not tableEmpty(results) then
    	print = print .. "This item is used by "
	    for r = 1, #results do
	    	if r == #results and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. results[r].icon .. "|25px|link=|alt=|" .. results[r].villager .. "]] [[" .. results[r].pageName .. "|" .. results[r].villager .. "]]"
	        if r == #results then
	        	print = print .. ' '
	        elseif r-1 == 0 and r+1 == #results then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    print = print .. " as their default umbrella during periods of [[weather|rain]]."
	else
		print = print .. "No villagers use this item as their default umbrella during periods of [[weather|rain]]."
    end
    return print
end

function p.interiorOutput( frame )
	local print = ''

	-- Declare variables
	local tables1
	local fields1
	local args1
	local resultsDnM
	local tables2
	local fields2
	local args2
	local resultsDnMplus
	local tables3
	local fields3
	local args3
	local resultsPG
	local tables4
	local fields4
	local args4
	local resultsDnMeplus
	-- Switch between wallpaper and carpets
	if not isEmpty(frame.args['type']) and frame.args['type']:lower() == "wallpaper" then
		-- Cargo query for pg_house and pg_villager (Doubutsu no Mori)
	    tables1 = 'pg_house,pg_villager'
	    fields1 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
	    args1 = {
	    	join = 'pg_villager.romanized_name = pg_house.villager',
	        where = "pg_house.game HOLDS 'DnM' AND pg_house.wallpaper = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
	        orderBy = 'pg_house.villager',
	        limit = 300,
	        default = ''
	    }
	    resultsDnM = cargo.query( tables1, fields1, args1 )
	    
	    -- Cargo query for pg_house and pg_villager (Doubutsu no Mori+)
	    tables2 = 'pg_house,pg_villager'
	    fields2 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
	    args2 = {
	    	join = 'pg_villager.romanized_name = pg_house.villager',
	        where = "pg_house.game HOLDS 'DnM+' AND pg_house.wallpaper = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
	        orderBy = 'pg_house.villager',
	        limit = 300,
	        default = ''
	    }
	    resultsDnMplus = cargo.query( tables2, fields2, args2 )
	    
		-- Cargo query for pg_house and pg_villager (Animal Crossing)
	    tables3 = 'pg_house,pg_villager'
	    fields3 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
	    args3 = {
	    	join = 'pg_villager.romanized_name = pg_house.villager',
	        where = "pg_house.game HOLDS 'PG' AND pg_house.wallpaper = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
	        orderBy = 'pg_house.villager',
	        limit = 300,
	        default = ''
	    }
	    resultsPG = cargo.query( tables3, fields3, args3 )
	    
	    -- Cargo query for pg_house and pg_villager (Doubutsu no Mori e+)
	    tables4 = 'pg_house,pg_villager'
	    fields4 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
	    args4 = {
	    	join = 'pg_villager.romanized_name = pg_house.villager',
	        where = "pg_house.game HOLDS 'DnMe+' AND pg_house.wallpaper = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
	        orderBy = 'pg_house.villager',
	        limit = 300,
	        default = ''
	    }
	    resultsDnMeplus = cargo.query( tables4, fields4, args4 )
	elseif not isEmpty(frame.args['type']) and frame.args['type']:lower() == "carpet" then
		-- Cargo query for pg_house and pg_villager (Doubutsu no Mori)
	    tables1 = 'pg_house,pg_villager'
	    fields1 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
	    args1 = {
	    	join = 'pg_villager.romanized_name = pg_house.villager',
	        where = "pg_house.game HOLDS 'DnM' AND pg_house.flooring = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
	        orderBy = 'pg_house.villager',
	        limit = 300,
	        default = ''
	    }
	    resultsDnM = cargo.query( tables1, fields1, args1 )
	    
	    -- Cargo query for pg_house and pg_villager (Doubutsu no Mori+)
	    tables2 = 'pg_house,pg_villager'
	    fields2 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
	    args2 = {
	    	join = 'pg_villager.romanized_name = pg_house.villager',
	        where = "pg_house.game HOLDS 'DnM+' AND pg_house.flooring = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
	        orderBy = 'pg_house.villager',
	        limit = 300,
	        default = ''
	    }
	    resultsDnMplus = cargo.query( tables2, fields2, args2 )
	    
		-- Cargo query for pg_house and pg_villager (Animal Crossing)
	    tables3 = 'pg_house,pg_villager'
	    fields3 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
	    args3 = {
	    	join = 'pg_villager.romanized_name = pg_house.villager',
	        where = "pg_house.game HOLDS 'PG' AND pg_house.flooring = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
	        orderBy = 'pg_house.villager',
	        limit = 300,
	        default = ''
	    }
	    resultsPG = cargo.query( tables3, fields3, args3 )
	    
	    -- Cargo query for pg_house and pg_villager (Doubutsu no Mori e+)
	    tables4 = 'pg_house,pg_villager'
	    fields4 = "pg_villager.image=image,pg_house.villager=villager,pg_house._pageTitle=pageName"
	    args4 = {
	    	join = 'pg_villager.romanized_name = pg_house.villager',
	        where = "pg_house.game HOLDS 'DnMe+' AND pg_house.flooring = '" .. frame.args['1']:gsub("\'","\\'") .. "'",
	        orderBy = 'pg_house.villager',
	        limit = 300,
	        default = ''
	    }
	    resultsDnMeplus = cargo.query( tables4, fields4, args4 )
	end

	if not tableEmpty(resultsDnM) then
    	print = print .. "In ''[[Doubutsu no Mori]]'', this item appears in the homes of "
	    for r = 1, #resultsDnM do
	    	if r == #resultsDnM and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsDnM[r].image .. "|x25px|link=|alt=|" .. resultsDnM[r].villager .. "]] [[" .. resultsDnM[r].pageName .. "|" .. resultsDnM[r].villager .. "]]"
	        if r == #resultsDnM then
	        	print = print .. ''
	        elseif r-1 == 0 and r+1 == #resultsDnM then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    if not isEmpty(frame.args['type']) and frame.args['type']:lower() == "wallpaper" then
	    	print = print .. ' as the default wallpaper.'
	    elseif not isEmpty(frame.args['type']) and frame.args['type']:lower() == "carpet" then
	    	print = print .. ' as the default carpet.'
	    end
	    if not tableEmpty(resultsDnMplus) or not tableEmpty(resultsPG) or not tableEmpty(resultsDnMeplus) then
	    	print = print .. "\n\n"
	    end
    end
	if not tableEmpty(resultsDnMplus) then
    	print = print .. "In ''[[Animal Crossing|Doubutsu no Mori+]]'', this item appears in the homes of "
	    for r = 1, #resultsDnMplus do
	    	if r == #resultsDnMplus and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsDnMplus[r].image .. "|x25px|link=|alt=|" .. resultsDnMplus[r].villager .. "]] [[" .. resultsDnMplus[r].pageName .. "|" .. resultsDnMplus[r].villager .. "]]"
	        if r == #resultsDnMplus then
	        	print = print .. ''
	        elseif r-1 == 0 and r+1 == #resultsDnMplus then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    if not isEmpty(frame.args['type']) and frame.args['type']:lower() == "wallpaper" then
	    	print = print .. ' as the default wallpaper.'
	    elseif not isEmpty(frame.args['type']) and frame.args['type']:lower() == "carpet" then
	    	print = print .. ' as the default carpet.'
	    end
	    if not tableEmpty(resultsPG) or not tableEmpty(resultsDnMeplus) then
	    	print = print .. "\n\n"
	    end
	end
    if not tableEmpty(resultsPG) then
    	print = print .. "In ''[[Animal Crossing]]'', this item appears in the homes of "
	    for r = 1, #resultsPG do
	    	if r == #resultsPG and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsPG[r].image .. "|x25px|link=|alt=|" .. resultsPG[r].villager .. "]] [[" .. resultsPG[r].pageName .. "|" .. resultsPG[r].villager .. "]]"
	        if r == #resultsPG then
	        	print = print .. ''
	        elseif r-1 == 0 and r+1 == #resultsPG then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    if not isEmpty(frame.args['type']) and frame.args['type']:lower() == "wallpaper" then
	    	print = print .. ' as the default wallpaper.'
	    elseif not isEmpty(frame.args['type']) and frame.args['type']:lower() == "carpet" then
	    	print = print .. ' as the default carpet.'
	    end
	    if not tableEmpty(resultsDnMeplus) then
	    	print = print .. "\n\n"
	    end
    end
	if not tableEmpty(resultsDnMeplus) then
    	print = print .. "In ''[[Doubutsu no Mori e+]]'', this item appears in the homes of "
	    for r = 1, #resultsDnMeplus do
	    	if r == #resultsDnMeplus and r-1 ~= 0 then
	        	print = print .. 'and '
	        end
	        print = print .. "[[File:" .. resultsDnMeplus[r].image .. "|x25px|link=|alt=|" .. resultsDnMeplus[r].villager .. "]] [[" .. resultsDnMeplus[r].pageName .. "|" .. resultsDnMeplus[r].villager .. "]]"
	        if r == #resultsDnMeplus then
	        	print = print .. ''
	        elseif r-1 == 0 and r+1 == #resultsDnMeplus then
		        	print = print .. ' '
	        else
	        	print = print .. ', '
	        end
	    end
	    if not isEmpty(frame.args['type']) and frame.args['type']:lower() == "wallpaper" then
	    	print = print .. ' as the default wallpaper.'
	    elseif not isEmpty(frame.args['type']) and frame.args['type']:lower() == "carpet" then
	    	print = print .. ' as the default carpet.'
	    end
	end
	if tableEmpty(resultsDnM) and tableEmpty(resultsDnMplus) and tableEmpty(resultsPG) and tableEmpty(resultsDnMeplus) then
		print = print .. "No villagers have this item in their home."
    end
    return print
end

return p