Skip to content

Instantly share code, notes, and snippets.

@seutje
Created November 1, 2019 00:15
Show Gist options
  • Save seutje/550391adb845b486ae876d28d6799ff0 to your computer and use it in GitHub Desktop.
Save seutje/550391adb845b486ae876d28d6799ff0 to your computer and use it in GitHub Desktop.
AutoCarrot Fixed
if not AutoCarrotDB then
AutoCarrotDB = { enabled = true, ridingGloves = true, mithrilSpurs = true }
end
local f = CreateFrame("Frame")
f:RegisterEvent('PLAYER_LOGIN')
f:RegisterEvent('BAG_UPDATE')
f:SetScript("OnUpdate", function()
if(not AutoCarrotDB.enabled) then return end
if(IsMounted()) then
local itemId = GetInventoryItemID("player", 13) -- trinket slot 1
if(itemId) then
if(itemId ~= 11122) then
AutoCarrotDB.trinketId = itemId
EquipItemByName(11122, 13)
end
else
AutoCarrotDB.trinketId = nil
EquipItemByName(11122, 13)
end
if(AutoCarrotDB.ridingGloves and AutoCarrotDB.enchantHandsLink) then
itemLink = GetInventoryItemLink("player", 10) -- hands
if(itemLink) then
if(itemLink ~= AutoCarrotDB.enchantHandsLink) then
AutoCarrotDB.handsLink = itemLink
EquipItemByName(AutoCarrotDB.enchantHandsLink, 10)
end
else
AutoCarrotDB.handsLink = nil
EquipItemByName(AutoCarrotDB.enchantHandsLink, 10)
end
end
if(AutoCarrotDB.mithrilSpurs and AutoCarrotDB.enchantBootsLink) then
itemLink = GetInventoryItemLink("player", 8)
if(itemLink) then
if(itemLink ~= AutoCarrotDB.enchantBootsLink) then
AutoCarrotDB.bootsLink = itemLink
EquipItemByName(AutoCarrotDB.enchantBootsLink, 8)
end
else
AutoCarrotDB.bootsLink = nil
EquipItemByName(AutoCarrotDB.enchantBootsLink, 8)
end
end
else
local itemId = GetInventoryItemID("player", 13) -- trinket
if(itemId) then
if(itemId ~= 11122) then
AutoCarrotDB.trinketId = itemId
elseif(AutoCarrotDB.trinketId) then
EquipItemByName(AutoCarrotDB.trinketId, 13)
end
else
AutoCarrotDB.trinketId = nil
end
if(AutoCarrotDB.ridingGloves and AutoCarrotDB.enchantHandsLink) then
itemLink = GetInventoryItemID("player", 10) -- hands
if(itemLink) then
if(itemLink ~= AutoCarrotDB.enchantHandsLink) then
AutoCarrotDB.handsLink = itemLink
elseif(AutoCarrotDB.handsLink) then
EquipItemByName(AutoCarrotDB.handsLink, 10)
end
else
AutoCarrotDB.handsLink = nil
end
end
if(AutoCarrotDB.mithrilSpurs and AutoCarrotDB.enchantBootsLink) then
itemLink = GetInventoryItemLink("player", 8)
if(itemLink) then
if(itemLink ~= AutoCarrotDB.enchantBootsLink) then
AutoCarrotDB.bootsLink = itemLink
elseif(AutoCarrotDB.bootsLink) then
EquipItemByName(AutoCarrotDB.bootsLink, 8)
end
else
AutoCarrotDB.bootsLink = nil
end
end
end
end)
f:SetScript('OnEvent', function(self, event, ...)
for bag = 0, NUM_BAG_SLOTS do
for slot = 0, GetContainerNumSlots(bag) do
local link = GetContainerItemLink(bag, slot)
if(link) then
local itemId, enchantId = link:match("item:(%d+):(%d+)")
if(enchantId == "930") then -- riding gloves
AutoCarrotDB.enchantHandsId = tonumber(itemId)
AutoCarrotDB.enchantHandsLink = link
elseif(enchantId == "464") then -- mithril spurs
AutoCarrotDB.enchantBootsLink = link
end
end
end
end
end)
-- Print handler
function AutoCarrot_Print(msg)
print("|cff00ff00Auto|cffed9121Carrot|r: "..(msg or ""))
end
-- Slash handler
local function OnSlash(key, value, ...)
if key and key ~= "" then
if key == "enabled" and tonumber(value) then
local enable = tonumber(value) == 1 and true or false
AutoCarrotDB.enabled = enable
AutoCarrot_Print("'enabled' set: "..( enable and "true" or "false" ))
elseif key == "ridinggloves" and tonumber(value) then
local enable = tonumber(value) == 1 and true or false
AutoCarrotDB.ridingGloves = enable
AutoCarrot_Print("'ridingGloves' set: "..( enable and "true" or "false" ))
elseif key == "mithrilspurs" and tonumber(value) then
local enable = tonumber(value) == 1 and true or false
AutoCarrotDB.mithrilSpurs = enable
AutoCarrot_Print("'mithrilSpurs' set: "..( enable and "true" or "false" ))
AutoCarrot_Print("Found boots: "..AutoCarrotDB.enchantBootsId)
end
else
AutoCarrot_Print("Slash commands")
AutoCarrot_Print(" - enabled 0/1")
AutoCarrot_Print(" - ridingGloves 0/1")
AutoCarrot_Print(" - mithrilSpurs 0/1")
end
end
SLASH_AUTOCARROT1 = "/autocarrot";
SLASH_AUTOCARROT2 = "/ac";
SlashCmdList["AUTOCARROT"] = function(msg)
msg = string.lower(msg)
msg = { string.split(" ", msg) }
if #msg >= 1 then
local exec = table.remove(msg, 1)
OnSlash(exec, unpack(msg))
end
end
## Interface: 11302
## Title: AutoCarrot
## Author: kebabstorm
## Notes: Equips Carrot on a Stick automatically when mounted
## SavedVariablesPerCharacter: AutoCarrotDB
## Version: 1.13.4
AutoCarrot.lua
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment