Module:GE cost table

-- -- Implements Template:GE Set Cost Table --

local p = {}

local is_empty = require('Module:Paramtest').is_empty local coins = require('Module:Coins')._amount local gep = require('Module:Exchange')._price

function p.make_table( frame ) local parameters = frame:getParent.args

local set_name = parameters['set'] or ''

local ret = mw.html.create('table') :addClass('wikitable') :tag('caption') :wikitext(set_name..' Grand Exchange cost') :done :done

local function make_row(builder,item_name, item_image, item_price, item_qty) local ret_name = item_name local ret_image local ret_price

if item_image then ret_image = '' else ret_image = '' end

if item_price then ret_price = item_price else ret_price = gep(ret_name) end

builder:tag('tr') :tag('td') :css('text-align','center') :wikitext(ret_image) :done :tag('td') :wikitext(..ret_name.. .. ((item_qty > 1) and (' × ' .. item_qty) or '')) :done :tag('td') :css('text-align','right') :attr('title', (item_qty > 1) and (ret_price .. ' coins each') or '') :wikitext(tonumber(ret_price) and (coins(ret_price * item_qty)..' &#91;view&#93; ') or ret_price) :done :done end

local total_price = 0 for i=1,20 do		local rt_name = parameters['name'..i]		local rt_price = parameters['price'..i]		local rt_image = parameters['image'..i]		local rt_qty = tonumber(parameters['qty'..i]) or 1 if rt_name then make_row(ret,rt_name,rt_image,rt_price,rt_qty) if not rt_price then total_price = total_price + gep(rt_name) * rt_qty end end end

if not parameters.notot then ret:tag('tr') :tag('th') :attr('colspan','2') :wikitext('Total price') :done :tag('td') :css({ background = '#F0F0F0',						['text-align'] = 'right' }) :wikitext(coins(total_price)) :done :done end

return ret end

return p