Skip to content

Instantly share code, notes, and snippets.

@rissole
Created November 22, 2014 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rissole/53b97b577e575fd3e07e to your computer and use it in GitHub Desktop.
Save rissole/53b97b577e575fd3e07e to your computer and use it in GitHub Desktop.
SellOMatic Lua file cleaned up & fixed
SellOMatic = LibStub("AceAddon-3.0"):NewAddon("SellOMatic", "AceEvent-3.0", "AceConsole-3.0");
local L = LibStub("AceLocale-3.0"):GetLocale("SellOMatic");
-- Addon variables
local SOMNone, merchant;
function SellOMatic:OnInitialize()
SellOMatic:Create_SOMNone();
end;
-- ENABLE / DISABLE FUNCTIONS
function SellOMatic:OnEnable()
SellOMatic:RegisterEvent("MERCHANT_SHOW");
SellOMatic:RegisterEvent("MERCHANT_CLOSED");
SellButton:Hide();
end;
function SellOMatic:OnDisable()
SellOMatic:UnregisterEvent("MERCHANT_SHOW");
SellOMatic:UnregisterEvent("MERCHANT_CLOSED");
end;
-- MERCHANT FUNCTIONS
function SellOMatic:MERCHANT_SHOW()
merchant = true;
SellButton:Show();
if self:HasJunk() == false then SOMNone:Show() end;
end;
function SellOMatic:MERCHANT_CLOSED()
merchant = false;
SellButton:Hide();
SOMNone:Hide();
end;
-- MAIN ADDON FUNCTIONS
function SellOMatic:CheckMerchant()
local items = GetMerchantNumItems();
if merchant and items > 0 then return true end;
return false;
end;
function SellOMatic:HasJunk()
for bag = 0,NUM_BAG_SLOTS do
for slot = 1,GetContainerNumSlots(bag) do
local texture, itemCount, locked, quality, readable, lootable, itemLink = GetContainerItemInfo(bag, slot);
if texture ~= nil and quality == 0 then
return true;
end;
end;
end;
return false;
end;
function SellOMatic:Sell()
if self:HasJunk() then
SellOMatic:SellJunk();
SOMNone:Show();
end;
end;
function SellOMatic:SellJunk()
local num = 0;
if SellOMatic:CheckMerchant() then
SellOMatic:Print("true");
for bag = 0,NUM_BAG_SLOTS do
for slot = 1,GetContainerNumSlots(bag) do
local texture, itemCount, locked, quality, readable, lootable, itemLink = GetContainerItemInfo(bag, slot);
if texture ~= nil and quality == 0 then
if not CursorHasItem() then
num = num + 1;
UseContainerItem(bag, slot);
SellOMatic:Print(L["Selling"]..": "..itemLink);
end;
end;
end;
end;
end;
SellOMatic:Print(num.." "..L["item(s) sold"]);
SellOMatic:Print(L["You've earned"]..": "..GetCoinText(self:CalcProfit()," "));
end;
function SellOMatic:CalcProfit()
local profit = 0;
for bag = 0,NUM_BAG_SLOTS do
for slot = 1,GetContainerNumSlots(bag) do
local texture, itemCount, locked, quality, readable, lootable, itemLink = GetContainerItemInfo(bag, slot);
if texture ~= nil and quality == 0 then
local _, _, _, _, _, _, _, _, _, _, itemSellPrice = GetItemInfo(itemLink);
profit = profit + itemSellPrice * itemCount;
end;
end;
end;
return profit;
end;
-- MERCHANT BUTTON FUNCTIONS
function SellOMatic:Create_SOMNone()
SOMNone = CreateFrame("Frame","SOMNone",SellButton);
SOMNone:ClearAllPoints();
SOMNone:SetPoint("TOPRIGHT",SellButton,"TOPRIGHT",0,0);
SOMNone:SetHeight(32);
SOMNone:SetWidth(32);
SOMNone.texture = SOMNone:CreateTexture()
SOMNone.texture:SetAllPoints(SOMNone);
SOMNone.texture:SetTexture(0.3,0.3,0.3,0.7);
SOMNone:Hide();
end;
function SellOMatic:SOMButtonTooltip_Show()
GameTooltip_SetDefaultAnchor(GameTooltip,SellButton);
GameTooltip:ClearAllPoints();
GameTooltip:SetPoint("TOPLEFT",SellButton,"TOPRIGHT",-30,40);
GameTooltip:SetText(GetCoinTextureString(SellOMatic:CalcProfit()),1,1,1);
GameTooltip:Show();
end;
function SellOMatic:SOMButtonTooltip_Hide()
GameTooltip:Hide();
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment