-
-
Save KevinTyrrell/6afc5186d9d9bdece7535e71197bac0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Picks up an item in the inventory, if present. | |
-- name - (string) name of the item in the inventory. | |
function r_pick_up(name) | |
local bag, slot = r_find_item(name) | |
if bag then | |
PickupContainerItem(bag, slot) | |
end | |
end | |
-- Uses an item in your inventory, if present. | |
-- name - (string) name of the item in the inventory. | |
function r_use_item(name) | |
local bag, slot = r_find_item(name) | |
if bag then | |
UseContainerItem(bag, slot) | |
end | |
end | |
-- Returns true if the player is in the named zone. | |
function r_in_zone(name) | |
return GetZoneText() == name | |
end | |
-- Returns bag,slot of an item, if present. | |
-- Returns nil if the item does not exist. | |
-- name - (string) name of the item in the inventory. | |
function r_find_item(name) | |
if not name then return nil end | |
for bag=0,4 do | |
for slot=0, GetContainerNumSlots(bag) do | |
local link = GetContainerItemLink(bag,slot) | |
if link and r_item_link_to_name(link) == name then | |
return bag, slot | |
end | |
end | |
end | |
return nil | |
end | |
-- Returns the name of an item if provided an item link. | |
-- link - (ItemLink) item link of the item provided by the WoW API. | |
function r_item_link_to_name(link) | |
if link then | |
local _, _, id = string.find(link, "item:(%d+):%d+:%d+:%d+") | |
if id then | |
return GetItemInfo(id) | |
end | |
end | |
return nil | |
end | |
-- Prints an object to the default chat frame. | |
function r_print(obj) | |
formatted = obj | |
if (obj == nil) then | |
formatted = "nil" | |
elseif (obj == true) then | |
formatted = "true" | |
elseif (obj == false) then | |
formatted = "false" | |
end | |
DEFAULT_CHAT_FRAME:AddMessage(formatted) | |
end | |
-- Tab targets if there is no current target. | |
function r_tab_target() | |
if not GetUnitName("target") then | |
TargetNearestEnemy() | |
end | |
end | |
-- Feeds the pet a food item. | |
-- food - (string) name of the item in the inventory. | |
function r_feed_pet(food) | |
if not food then return end | |
CastSpellByName("Feed Pet") | |
r_pick_up(food) | |
end | |
-- Uses a regular mount or an AQ mount depending on where the player is. | |
-- name - (string) name of the mount in the inventory. | |
function r_smart_mount(mount, aq_mount) | |
if not mount or not aq_mount then return end | |
if not r_in_zone("Ahn'Qiraj") then | |
r_use_item(mount) | |
else | |
r_use_item(aq_mount) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment