Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function convertHexToRgb(hex)
- local hex = hex:gsub("#", "");
- if hex:len() == 3 then
- 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;
- else
- return tonumber("0x" .. hex:sub(1, 2)) / 255, tonumber("0x" .. hex:sub(3, 4)) / 255, tonumber("0x" .. hex:sub(5, 6)) / 255;
- end
- end
- local function printAllChatFrames(msg)
- if msg then
- local r, g, b = convertHexToRgb("C6FF1A");
- for i = 1, 20 do
- _G["ChatFrame" .. i]:AddMessage(msg, r, g, b);
- end
- end
- end
- local function getItemSlot(item)
- for bag = 0, NUM_BAG_SLOTS do
- for bagSlot = 1, GetContainerNumSlots(bag) do
- local _, _, _, _, _, _, itemLink = GetContainerItemInfo(bag, bagSlot);
- if itemLink ~= nil and string.match(itemLink, item) then
- return bag, bagSlot;
- end
- end
- end
- end
- local function eventHandler(self, event, ...)
- if event == "COMBAT_LOG_EVENT_UNFILTERED" then
- local _, logEvent, _, _, srcName, _, _, _, _, _, _, _, spellName = select(1, ...);
- if logEvent == "SPELL_CREATE" and spellName == "Create Soulwell" then
- if IsInInstance() then
- local bag, bagSlot = getItemSlot("Healthstone");
- if bag and bagSlot then
- if HEALTHSTONE_CHARGES < 3 then -- 1 or 2 healthstones left.
- PickupContainerItem(bag, bagSlot);
- if CursorHasItem() then
- DeleteCursorItem();
- HEALTHSTONE_CHARGES = 0;
- printAllChatFrames("Healthstones are available.");
- end
- end
- else -- no healthstones in bags.
- printAllChatFrames("Healthstones are available.");
- end
- end
- elseif logEvent == "SPELL_CAST_SUCCESS" and srcName == UnitName("player") and spellName == "Healthstone" then
- HEALTHSTONE_CHARGES = HEALTHSTONE_CHARGES - 1;
- end
- elseif event == "ITEM_PUSH" then
- local _, iconID = select(1, ...);
- if iconID == 538745 then
- HEALTHSTONE_CHARGES = 3;
- end
- elseif event == "PLAYER_ENTERING_WORLD" then
- if not getItemSlot("Healthstone") then
- HEALTHSTONE_CHARGES = 0;
- end
- end
- end
- local frame = CreateFrame("Frame");
- frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
- frame:RegisterEvent("PLAYER_ENTERING_WORLD");
- frame:RegisterEvent("ITEM_PUSH");
- frame:SetScript("OnEvent", eventHandler);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement