Anonymous

Module:Monsters: Difference between revisions

From Melvor Idle
no edit summary
No edit summary
No edit summary
Line 763: Line 763:


-- Find drop chance of specified item from specified monster.  
-- Find drop chance of specified item from specified monster.  
-- Usage: |Monster Name|Item Name|numFormat=(perc/frac)
-- Usage: |Monster Name|Item Name
function p.getItemDropChance(frame)
function p.getItemDropChance(frame)
   local args = frame.args ~= nil and frame.args or frame
   local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]
  local MonsterName = args[1]
   local ItemName = frame.args ~= nil and frame.args[2] or frame[2]
   local ItemName = args[2]
  local numFormat = args.numFormat ~= nil and args.numFormat ~= ''
    
    
   local monster = p.getMonster(MonsterName)
   local monster = p.getMonster(MonsterName)
Line 785: Line 783:


local totalWt = 0
local totalWt = 0
    for i, row in pairs(monster.lootTable) do
for i, row in pairs(monster.lootTable) do
      totalWt = totalWt + row[2]
totalWt = totalWt + row[2]
    end
end
 
mw.log(monster['id'], item['id'])
  for i, row in Shared.skpairs(monster.lootTable) do
for i, row in Shared.skpairs(monster.lootTable) do
      local thisItem = Items.getItemByID(row[1])
local thisItem = Items.getItemByID(row[1])
     
mw.log(thisItem['id'])
      if item['id'] == thisItem['id'] then
if item['id'] == thisItem['id'] then
    local dropChance = (row[2] / totalWt * lootChance)
    local dropChance = (row[2] / totalWt * lootChance)
    end
    end
  end
end
if numFormat == 'perc' or nil then
return Shared.round(dropChance, 2, 2)
elseif numFormat == 'frac' then
return Shared.fraction(dropChance, 100)
end
end
  end
  mw.log(dropChance)
  return Shared.round(dropChance, 2, 2)
end
end


318

edits