/Tukui/modules/tooltip/tooltipilvl.lua

http://github.com/Asphyxia/Tukui · Lua · 42 lines · 34 code · 4 blank · 4 comment · 13 complexity · 63050d2fe9397ce992f516ae9132854b MD5 · raw file

  1. -- Credits to Gsuz
  2. local T, C, L = unpack(Tukui)
  3. if C.tooltip.enable ~= true then return end
  4. -- Setup slotnames
  5. local SlotName = {
  6. "Head","Neck","Shoulder","Back","Chest","Wrist",
  7. "Hands","Waist","Legs","Feet","Finger0","Finger1",
  8. "Trinket0","Trinket1","MainHand","SecondaryHand","Ranged","Ammo"
  9. }
  10. -- Scan target's items
  11. local function GetItemLVL(unit)
  12. local total, item = 0, 0;
  13. for i in pairs(SlotName) do
  14. local slot = GetInventoryItemLink(unit, GetInventorySlotInfo(SlotName[i] .. "Slot"));
  15. if (slot ~= nil) then
  16. item = item + 1;
  17. total = total + select(4, GetItemInfo(slot))
  18. end
  19. end
  20. if (item > 0) then
  21. return floor(total / item);
  22. end
  23. return 0;
  24. end
  25. -- Insert into tooltip
  26. GameTooltip:HookScript("OnTooltipSetUnit", function(self, ...)
  27. if (IsShiftKeyDown()) then
  28. local _, unit = GameTooltip:GetUnit();
  29. if (unit and CanInspect(unit)) then
  30. if (not ((InspectFrame and InspectFrame:IsShown()) or (Examiner and Examiner:IsShown()))) then
  31. NotifyInspect(unit);
  32. GameTooltip:AddLine("Item Level: " .. GetItemLVL(unit));
  33. ClearInspectPlayer(unit);
  34. GameTooltip:Show();
  35. end
  36. end
  37. end
  38. end)