/trunk/Livestock
movingaspects = 0, -- Smart Mounting casts AotC / AotP when outside and moving |
slowfall = 0, -- Smart Mounting casts Slow Fall / Levitate while falling and not in combat |
useweights = 0, -- Whether or not Smart Mounting should use weighted summons |
version = 1.5, -- New mount detection |
} |
LIVESTOCK_VERSION = GetAddOnMetadata("Livestock", "Version"); |
if event == "ADDON_LOADED" and arg1 == "Livestock" then |
for k, v in pairs(defaults) do |
if not LivestockSettings[k] then |
if k == "version" then -- clear mounts if version detect is missing |
LivestockSettings.Mounts = {} |
end |
LivestockSettings[k] = v |
end |
end |
end |
function Livestock.CompanionEvent(self, event, ...) |
--print(format("DEBUG: '%s'", event)) |
if event == "PLAYER_LOGIN" then -- when the player logs in, make sure the map is set right for Smart Detection and sort out the companions |
if GetNumCompanions("CRITTER") == 0 then |
donotsummon = true |
elseif kind == "LAND" then |
mounts = 0 -- reset mounts to 0 so we can start counting land mounts |
for k in pairs(settings) do -- Check the list of mounts, pull out fast land mounts (or slow ones if the filter lets them through), increment mounts, and add the index of the mounts to mountstable |
if (settings[k].type == "land" or settings[k].type == "variable") then |
if (settings[k].type == "land") then |
mounts = mounts + 1 |
tinsert(mountstable, settings[k].index) |
end |
elseif kind == "FLYING" then -- code is the same for flying mounts with the appropriate changes; perhaps this could be a function call? |
mounts = 0 |
for k in pairs(settings) do |
if (settings[k].type == "flying" or settings[k].type == "variable") then |
if (settings[k].type == "flying") then |
mounts = mounts + 1 |
tinsert(mountstable, settings[k].index) |
end |
text:SetText( name ) |
tinsert(texttable, text) -- set the text of the button to reflect the name of the companion, and store the fontstring itself in a table of fontstrings |
local name2 = strconcat(name, "-") |
if name and kind == "LAND" and settings[name2] then |
name = strconcat(name, "-") |
end |
if name and settings[name].show == 1 then -- if the name isn't nil (Blizzard bug sometimes returns nil for companion names >:o) and the settings say this companion is selected then |
text:SetTextColor(1, 1, 1) -- set the color of the text to be white |
elseif name then |
return |
end |
local name2 = strconcat(name, "-") |
if companionType == "LAND" and settings[name2] then |
name = strconcat(name, "-") |
end |
settings[name].show = 1 - settings[name].show -- toggle the shown setting |
if settings[name].show == 1 then |
text:SetTextColor(1, 1, 1) |
else |
text:SetTextColor(0.4, 0.4, 0.4) -- color the fontstring according to the new setting |
end |
if settings[name].type == "variable" then -- if this is a variable mount, then the index gets toggled off but the fontstring in the OTHER menu will stay at the previous color and this needs to be fixed. |
local checktext = text:GetText() -- get the relevant text of the button that we just clicked on |
if companionType == "LAND" then |
checktable = flyingText |
else |
checktable = landText |
end -- pick the table that's the opposite of the one that contains the font string we just clicked on |
for _, v in ipairs(checktable) do |
if v:GetText() == checktext then -- find the fontstring in the table whose text matches the text of the button we just clicked on, and change the color accordingly |
if settings[name].show == 1 then |
v:SetTextColor(1, 1, 1) |
else |
v:SetTextColor(0.4, 0.4, 0.4) |
end |
end |
end |
end |
elseif action == "check" then -- if this is a "check all" button |
for k in pairs(settings) do -- if these are critters or if the mounts in the settings have the same type as the companionType, lowercased (either "land" or "flying") then toggle them on |
if companionType == "CRITTER" or settings[k].type == companionType:lower() then |
if companionType == "CRITTER" or settings[k].speed == "epic" then |
settings[k].show = 1 |
end |
if companionType == "CRITTER" then |
settings[k].show = 1 |
end |
if companionType == "WATER" and settings[k].type == "water" then |
settings[k].show = 1 |
end |
if companionType == "LAND" and settings[k].type == "land" then |
settings[k].show = 1 |
end |
if companionType == "FLYING" and settings[k].type == "flying" then |
settings[k].show = 1 |
end |
end |
for _, v in ipairs(buildtable[companionType].text) do -- iterate over the fontstrings and set them all to white |
v:SetTextColor(1, 1, 1) |
elseif action == "uncheck" then -- otherwise it should be an "uncheck all" button |
for k in pairs(settings) do -- if these or critters or if the mounts in the settings have the same type as the companionType, lowercased (either "land" or "flying") then toggle them on |
if companionType == "CRITTER" or settings[k].type == companionType:lower() then |
if companionType == "CRITTER" then |
settings[k].show = 0 |
end |
if companionType == "WATER" and settings[k].type == "water" then |
settings[k].show = 0 |
end |
if companionType == "LAND" and settings[k].type == "land" then |
settings[k].show = 0 |
end |
if companionType == "FLYING" and settings[k].type == "flying" then |
settings[k].show = 0 |
end |
end |
for _, v in ipairs(buildtable[companionType].text) do -- iterate over the fontstrings and set them all to grey |
v:SetTextColor(0.4, 0.4, 0.4) |
end |
for i = 1, GetNumCompanions("MOUNT") do |
--local outland, northrend, very, fast, changes, location |
local _, name, spellID, icon = GetCompanionInfo("MOUNT",i) -- we need not only the name but also the spellID because we will parse this spell's tooltip |
GameTooltip_SetDefaultAnchor(LivestockTooltip, UIParent) |
LivestockTooltip:SetHyperlink("spell:"..spellID) -- pull up the tooltip object we created and set it to the ID of the spell |
local _, name, _, _, _, mountFlags = GetCompanionInfo("MOUNT",i) |
local name2 = strconcat(name, "-") |
if name and not LivestockSettings.Mounts[name] then -- if the name is valid and we don't have SV data for it, we need to make it |
local flying,variable,water |
for i = 1, LivestockTooltip:NumLines() do -- iterate over the number of lines in the tooltip |
local text = _G["LivestockTooltipTextLeft"..i]:GetText() -- get the text from each line |
for word in string.gmatch(text, "%S+") do -- look at each word in the line. NOT %a+ because that apparently doesn't capture unicode characters, for the localized clients. |
-- check for flying |
for index,value in ipairs(L.LIVESTOCK_FLYING_NAMES) do |
if strfind(word, value) then |
flying = true |
end |
end |
-- check for variable |
for index,value in ipairs(L.LIVESTOCK_VARIABLE_NAMES) do |
if strfind(word, value) then |
variable = true |
end |
end |
-- check for water |
for index,value in ipairs(L.LIVESTOCK_WATER_NAMES) do |
if strfind(word, value) then |
water = true |
end |
end |
end |
end -- parse the tooltip. The variables outland, northrend, very, fast, location, and changes are set to true if the corresponding text is found |
LivestockSettings.Mounts[name] = { index = i, } -- set the index of the mount |
--print(format("New Mount: '%s' is mount-index, flying mount is '%s'", i, name)) |
if flying then -- if the tooltip contains either of these words, it's a flying mount |
if mountFlags == 7 then -- flying mount |
LivestockSettings.Mounts[name].type = "flying" |
elseif variable then -- variable |
LivestockSettings.Mounts[name].type = "variable" |
elseif water then -- water |
elseif mountFlags == 31 then -- variable |
LivestockSettings.Mounts[name].type = "flying" |
LivestockSettings.Mounts[name2] = { index = i, } |
LivestockSettings.Mounts[name2].type = "land" |
LivestockSettings.Mounts[name2].show = 1 |
elseif mountFlags == 12 then -- water |
LivestockSettings.Mounts[name].type = "water" |
else -- otherwise, a land mount |
LivestockSettings.Mounts[name].type = "land" |
end |
LivestockSettings.Mounts[name].speed = "epic" |
LivestockSettings.Mounts[name].show = 1 |
--print(name.." - "..LivestockSettings.Mounts[name].type) |
elseif name then -- if we do have SV data for it, update the index. |
LivestockSettings.Mounts[name].index = i |
--print(format("Old Mount: '%s' is mount-index, flying mount is '%s'", i, name)) |
if LivestockSettings.Mounts[name2] then |
LivestockSettings.Mounts[name2].index = i |
end |
else |
mountfail = true |
--print(format("Old Mount: '%s' is mount-index", i)) |
return |
end |
LivestockTooltip:Hide() -- hide our dummy tooltip |
end |
end |
Livestock.RecycleTable(temp) |
for k in pairs(LivestockSettings.Mounts) do -- go through the land mounts and add the ones that are selected to the temp table |
if (LivestockSettings.Mounts[k].type == "land" or LivestockSettings.Mounts[k].type == "variable") and LivestockSettings.Mounts[k].show == 1 then |
--print(format("DEBUG: '%s' is mount-index, land mount is '%s'", LivestockSettings.Mounts[k].index, k)) |
if (LivestockSettings.Mounts[k].type == "land") and LivestockSettings.Mounts[k].show == 1 then |
tinsert(temp, LivestockSettings.Mounts[k].index) |
end |
end |
--for index in pairs(LivestockSettings.Mounts) do DEFAULT_CHAT_FRAME:AddMessage(LivestockSettings.Mounts[index].index.." "..tostring(index)) end |
if #temp == 0 then -- if no mounts are selected, prompt the user to select one |
print(L.LIVESTOCK_INTERFACE_NOLANDMOUNTSCHECKED) |
else |
for k in pairs(LivestockSettings.Mounts) do -- go through the water mounts and add the ones that are selected to the temp table |
if (LivestockSettings.Mounts[k].type == "water" and LivestockSettings.Mounts[k].show == 1 and k ~= "Abyssal Seahorse") then |
--print(format("DEBUG: '%s' is mount-index, water mount is '%s'", LivestockSettings.Mounts[k].index, k)) |
tinsert(temp, LivestockSettings.Mounts[k].index) |
end |
end |
--for index in pairs(LivestockSettings.Mounts) do DEFAULT_CHAT_FRAME:AddMessage(LivestockSettings.Mounts[index].index.." "..tostring(index)) end |
end |
if #temp == 0 then -- if no mounts are selected, choose a land mount instead |
Livestock.RecycleTable(temp) |
for k in pairs(LivestockSettings.Mounts) do -- go through the flying mounts and add the ones that are selected to the temp table |
if (LivestockSettings.Mounts[k].type == "flying" or LivestockSettings.Mounts[k].type == "variable") and LivestockSettings.Mounts[k].show == 1 then |
--print(format("DEBUG: '%s' is mount-index, flying mount is '%s'", LivestockSettings.Mounts[k].index, k)) |
if (LivestockSettings.Mounts[k].type == "flying") and LivestockSettings.Mounts[k].show == 1 then |
tinsert(temp, LivestockSettings.Mounts[k].index) |
end |
end |
if #temp == 0 then -- if no mounts are selected, prompt the user to select one (or pick a land mount?) |
--print(L.LIVESTOCK_INTERFACE_NOFLYINGMOUNTSCHECKED) |
Livestock.PickLandMount() |
return |
end |
Version 1.5 |
- Separated ground and flying mount selections (Thanks XDragonX) |
- Mount detection overhaul |
Version 1.4.2 |
- Attempt to fix incorrect ground mount after login |
## Notes: Enables easy random summoning of vanity pets and mounts, including the option of "smart mounting." |
## Author: Recompense - Uldum(US) |
## X-eMail: scott.snowman@gmail.com |
## Version: 1.4.2 |
## Version: 1.5 |
## SavedVariablesPerCharacter: LivestockSettings |
LibRecompense\RecompenseTools.lua |
L.LIVESTOCK_FONTSTRING_MOVINGHUNTERASPECTSLABEL = "Montura Inteligente lanza Aspecto de la Manada cuando te mueves (exteriores, fuera de combate)" |
L.LIVESTOCK_FONTSTRING_SLOWFALLLABEL = "Montura Inteligente lanza Levitar / Ca\195\173da lenta cuando caes (fuera de combate)" |
L.LIVESTOCK_FLYING_NAMES = {"Draco", "Viento", "Grifo", "grifo", "Al'ar", "Razaescarcha", "Drag\195\179n", "Raya", "F\195\169nix", "Vermis", "Mimiron", "Ébano"} |
L.LIVESTOCK_VARIABLE_NAMES = {"celestial", "decapitado", "Invencible", "Alfombra", "paseo", "Guardián", "X-51", "M\195\161quina", "Amor"} |
L.LIVESTOCK_WATER_NAMES = {"Caballito","marina"} |
L.LIVESTOCK_MENU_MORE = "M\195\161s >>>" |
L.LIVESTOCK_MENU_SELECTALL = "Seleccionar todos" |
L.LIVESTOCK_MENU_SELECTNONE = "Seleccionar ninguno" |
L.LIVESTOCK_FONTSTRING_WATERWALKINGLABEL = "'Smart Mounting' invoque %s quand vous \195\170tes sous l'eau." |
L.LIVESTOCK_FONTSTRING_CRUSADERSUMMONLABEL = "Lance automatiquement 'Smart Mounting' apr\195\168s l'invocation d'Aura de crois\195\169." |
L.LIVESTOCK_FLYING_NAMES = {"Drake", "Coursier", "Griffon", "griffon", "Al'ar", "couvegivre", "Faucon", "Raie", "Phénix", "Wyrm", "Mimiron", "d'ébène", "Hippogriffe"} |
L.LIVESTOCK_VARIABLE_NAMES = {"céleste", "sans tête", "Invincible", "Tapis", "X-53", "Gardien", "X-51", "volante", "Fusée", "fusée"} |
L.LIVESTOCK_WATER_NAMES = {"Hippocampe", "Tortue"} |
L.LIVESTOCK_MENU_MORE = "Plus..." |
L.LIVESTOCK_MENU_SELECTALL = "Tout s\195\169lectionner" |
L.LIVESTOCK_MENU_SELECTNONE = "Tout d\195\169s\195\169lectionner" |
L.LIVESTOCK_FONTSTRING_MOVINGHUNTERASPECTSLABEL = "Smart Mounting casts AotC / AotP when moving (outdoors, out of combat)" |
L.LIVESTOCK_FONTSTRING_SLOWFALLLABEL = "Smart Mounting casts Levitate / Slow Fall when falling (out of combat)" |
L.LIVESTOCK_FLYING_NAMES = {"Drake", "Wind", "Gryph", "gryph", "Al'ar", "Frostbrood", "Dragon", "Ray", "Phoenix", "Wyrm", "Mimiron", "Ebon"} |
L.LIVESTOCK_VARIABLE_NAMES = {"Celestial", "Headless", "Invincible", "Carpet", "Touring", "Guardian", "X-51", "Machine", "Love"} |
L.LIVESTOCK_WATER_NAMES = {"Sea"} |
L.LIVESTOCK_MENU_MORE = "More >>>" |
L.LIVESTOCK_MENU_SELECTALL = "Select all" |
L.LIVESTOCK_MENU_SELECTNONE = "Select none" |