Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.25 KB | None | 0 0
  1. function convertHexToRgb(hex)
  2.     local hex = hex:gsub("#", "");
  3.     if hex:len() == 3 then
  4.         return (tonumber("0x" .. hex:sub(1, 1)) * 17) / 255, (tonumber("0x" .. hex:sub(2, 2)) * 17) / 255, (tonumber("0x" .. hex:sub(3, 3)) * 17) / 255;
  5.     else
  6.         return tonumber("0x" .. hex:sub(1, 2)) / 255, tonumber("0x" .. hex:sub(3, 4)) / 255, tonumber("0x" .. hex:sub(5, 6)) / 255;
  7.     end
  8. end
  9.  
  10. local function printAllChatFrames(msg)
  11.     if msg then
  12.         local r, g, b = convertHexToRgb("C6FF1A");
  13.         for i = 1, 20 do
  14.             _G["ChatFrame" .. i]:AddMessage(msg, r, g, b);
  15.         end
  16.     end
  17. end
  18.  
  19. local function getItemSlot(item)
  20.     for bag = 0, NUM_BAG_SLOTS do
  21.         for bagSlot = 1, GetContainerNumSlots(bag) do
  22.             local _, _, _, _, _, _, itemLink = GetContainerItemInfo(bag, bagSlot);
  23.             if itemLink ~= nil and string.match(itemLink, item) then
  24.                 return bag, bagSlot;
  25.             end
  26.         end
  27.     end
  28. end
  29.  
  30. local function eventHandler(self, event, ...)
  31.     if event == "COMBAT_LOG_EVENT_UNFILTERED" then
  32.         local _, logEvent, _, _, srcName, _, _, _, _, _, _, _, spellName = select(1, ...);
  33.         if logEvent == "SPELL_CREATE" and spellName == "Create Soulwell" then
  34.             if IsInInstance() then
  35.                 local bag, bagSlot = getItemSlot("Healthstone");
  36.                 if bag and bagSlot then
  37.                     if HEALTHSTONE_CHARGES < 3 then  -- 1 or 2 healthstones left.
  38.                         PickupContainerItem(bag, bagSlot);
  39.                         if CursorHasItem() then
  40.                             DeleteCursorItem();
  41.                             HEALTHSTONE_CHARGES = 0;
  42.                             printAllChatFrames("Healthstones are available.");
  43.                         end
  44.                     end
  45.                 else  -- no healthstones in bags.
  46.                     printAllChatFrames("Healthstones are available.");
  47.                 end
  48.             end
  49.         elseif logEvent == "SPELL_CAST_SUCCESS" and srcName == UnitName("player") and spellName == "Healthstone" then
  50.             HEALTHSTONE_CHARGES = HEALTHSTONE_CHARGES - 1;
  51.         end
  52.     elseif event == "ITEM_PUSH" then
  53.         local _, iconID = select(1, ...);
  54.         if iconID == 538745 then
  55.             HEALTHSTONE_CHARGES = 3;
  56.         end
  57.     elseif event == "PLAYER_ENTERING_WORLD" then
  58.         if not getItemSlot("Healthstone") then
  59.             HEALTHSTONE_CHARGES = 0;
  60.         end
  61.     end
  62. end
  63.  
  64. local frame = CreateFrame("Frame");
  65. frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
  66. frame:RegisterEvent("PLAYER_ENTERING_WORLD");
  67. frame:RegisterEvent("ITEM_PUSH");
  68. frame:SetScript("OnEvent", eventHandler);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement